From: PhiTux Date: Mon, 8 Sep 2025 17:01:54 +0000 (+0200) Subject: added further statistic-functions X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=7f875b97daeab806ba7011b4fc4016376bbe201b;p=DailyTxT.git added further statistic-functions --- diff --git a/backend/handlers/additional.go b/backend/handlers/additional.go index cf391b2..8c71642 100644 --- a/backend/handlers/additional.go +++ b/backend/handlers/additional.go @@ -2651,13 +2651,14 @@ func GetStatistics(w http.ResponseWriter, r *http.Request) { // Define response structure (per day only) type DayStat struct { - Year int `json:"year"` - Month int `json:"month"` - Day int `json:"day"` - WordCount int `json:"wordCount"` - FileCount int `json:"fileCount"` - Tags []int `json:"tags"` - IsBookmarked bool `json:"isBookmarked"` + Year int `json:"year"` + Month int `json:"month"` + Day int `json:"day"` + WordCount int `json:"wordCount"` + FileCount int `json:"fileCount"` + FileSizeBytes int64 `json:"fileSizeBytes"` + Tags []int `json:"tags"` + IsBookmarked bool `json:"isBookmarked"` } dayStats := []DayStat{} @@ -2707,10 +2708,27 @@ func GetStatistics(w http.ResponseWriter, r *http.Request) { } } - // File count (filenames stored decrypted in memory? If encrypted we try decrypt to validate) + // File count and total size fileCount := 0 + var totalFileSize int64 = 0 if filesAny, ok := dayMap["files"].([]any); ok { fileCount = len(filesAny) + // Calculate total file size for this day + for _, fileInterface := range filesAny { + if fileMap, ok := fileInterface.(map[string]any); ok { + if sizeAny, ok := fileMap["size"]; ok { + // Handle both int64 and float64 types + switch size := sizeAny.(type) { + case int64: + totalFileSize += size + case float64: + totalFileSize += int64(size) + case int: + totalFileSize += int64(size) + } + } + } + } } // Tags (IDs are numeric) @@ -2734,13 +2752,14 @@ func GetStatistics(w http.ResponseWriter, r *http.Request) { } dayStats = append(dayStats, DayStat{ - Year: yearInt, - Month: monthInt, - Day: dayNum, - WordCount: wordCount, - FileCount: fileCount, - Tags: tagIDs, - IsBookmarked: isBookmarked, + Year: yearInt, + Month: monthInt, + Day: dayNum, + WordCount: wordCount, + FileCount: fileCount, + FileSizeBytes: totalFileSize, + Tags: tagIDs, + IsBookmarked: isBookmarked, }) } } diff --git a/frontend/src/lib/settings/Statistics.svelte b/frontend/src/lib/settings/Statistics.svelte index 8a7a8b8..a3992f5 100644 --- a/frontend/src/lib/settings/Statistics.svelte +++ b/frontend/src/lib/settings/Statistics.svelte @@ -1,6 +1,6 @@
-

{$t('settings.statistics.title')}

+

{$t('settings.statistics.title')}

{#if years.length === 0}
@@ -441,10 +435,183 @@ {/each}
+ +

{$t('settings.statistics.total')}

+ + +

{$t('settings.statistics.funFacts')}

+ {/if}