diff --git a/go-app/internal/domain/domain.go b/go-app/internal/domain/domain.go index a337613..ee1ed9e 100644 --- a/go-app/internal/domain/domain.go +++ b/go-app/internal/domain/domain.go @@ -6,6 +6,8 @@ import ( "arc42-status/internal/plausible" "arc42-status/internal/types" "github.com/rs/zerolog/log" + "golang.org/x/text/language" + "golang.org/x/text/message" "sync" "time" ) @@ -87,14 +89,27 @@ func calculateTotals(stats []types.SiteStats) types.TotalsForAllSites { var totals types.TotalsForAllSites for index := range types.Arc42sites { - totals.SumOfVisitors7d += stats[index].Visitors7dNr - totals.SumOfPageviews7d += stats[index].Pageviews7dNr - totals.SumOfVisitors30d += stats[index].Visitors30dNr - totals.SumOfPageviews30d += stats[index].Pageviews30dNr - totals.SumOfVisitors12m += stats[index].Visitors12mNr - totals.SumOfPageviews12m += stats[index].Pageviews12mNr + totals.SumOfVisitors7dNr += stats[index].Visitors7dNr + totals.SumOfPageviews7dNr += stats[index].Pageviews7dNr + totals.SumOfVisitors30dNr += stats[index].Visitors30dNr + totals.SumOfPageviews30dNr += stats[index].Pageviews30dNr + totals.SumOfVisitors12mNr += stats[index].Visitors12mNr + totals.SumOfPageviews12mNr += stats[index].Pageviews12mNr } - log.Debug().Msgf("Total visits and pageviews (V/PV, 7d, 30d, 12m)= %d/%d, %d/%d, %d/%d", totals.SumOfVisitors7d, totals.SumOfPageviews7d, totals.SumOfVisitors30d, totals.SumOfPageviews30d, totals.SumOfVisitors12m, totals.SumOfPageviews12m) + + // now convert numbers to strings-with-separators + p := message.NewPrinter(language.German) + + totals.SumOfVisitors7d = p.Sprintf("%d", totals.SumOfVisitors7dNr) + totals.SumOfPageviews7d = p.Sprintf("%d", totals.SumOfPageviews7dNr) + + totals.SumOfVisitors30d = p.Sprintf("%d", totals.SumOfVisitors30dNr) + totals.SumOfPageviews30d = p.Sprintf("%d", totals.SumOfPageviews30dNr) + + totals.SumOfVisitors12m = p.Sprintf("%d", totals.SumOfVisitors12mNr) + totals.SumOfPageviews12m = p.Sprintf("%d", totals.SumOfPageviews12mNr) + + log.Debug().Msgf("Total visits and pageviews (V/PV, 7d, 30d, 12m)= %d/%d, %d/%d, %d/%d", totals.SumOfVisitors7dNr, totals.SumOfPageviews7dNr, totals.SumOfVisitors30dNr, totals.SumOfPageviews30dNr, totals.SumOfVisitors12mNr, totals.SumOfPageviews12mNr) return totals } diff --git a/go-app/internal/plausible/vpvStatistics.go b/go-app/internal/plausible/vpvStatistics.go index ca4925d..2ad5eeb 100644 --- a/go-app/internal/plausible/vpvStatistics.go +++ b/go-app/internal/plausible/vpvStatistics.go @@ -91,21 +91,20 @@ func StatsForSite(thisSite string, stats *types.SiteStats) { p := message.NewPrinter(language.German) // now process results - // stats.Visitors7d = stats7D.Visitors + // before #55 these assignments read: stats.Visitors7d = stats7D.Visitors stats.Visitors7d = p.Sprintf("%d", stats7D.VisitorNr) + stats.Pageviews7d = p.Sprintf("%d", stats7D.PageviewNr) stats.Visitors7dNr = stats7D.VisitorNr - stats.Pageviews7d = stats7D.Pageviews stats.Pageviews7dNr = stats7D.PageviewNr - stats.Visitors30d = stats30D.Visitors + stats.Visitors30d = p.Sprintf("%d", stats30D.VisitorNr) + stats.Pageviews30d = p.Sprintf("%d", stats30D.PageviewNr) stats.Visitors30dNr = stats30D.VisitorNr - stats.Pageviews30d = stats30D.Pageviews stats.Pageviews30dNr = stats30D.PageviewNr - stats.Visitors12m = stats12M.Visitors + stats.Visitors12m = p.Sprintf("%d", stats12M.VisitorNr) stats.Pageviews12m = p.Sprintf("%d", stats12M.PageviewNr) stats.Visitors12mNr = stats12M.VisitorNr - //stats.Pageviews12mNr = stats12M.PageviewNr stats.Pageviews12mNr = stats12M.PageviewNr } diff --git a/go-app/internal/types/types.go b/go-app/internal/types/types.go index 4112b97..389f060 100644 --- a/go-app/internal/types/types.go +++ b/go-app/internal/types/types.go @@ -55,12 +55,18 @@ type RepoStats struct { // If certain values are "n/a" (when the external API sends errors), // we let these values count 0. type TotalsForAllSites struct { - SumOfVisitors7d int - SumOfPageviews7d int - SumOfVisitors30d int - SumOfPageviews30d int - SumOfVisitors12m int - SumOfPageviews12m int + SumOfVisitors7dNr int + SumOfVisitors7d string + SumOfPageviews7dNr int + SumOfPageviews7d string + SumOfVisitors30dNr int + SumOfVisitors30d string + SumOfPageviews30dNr int + SumOfPageviews30d string + SumOfVisitors12mNr int + SumOfVisitors12m string + SumOfPageviews12mNr int + SumOfPageviews12m string } // Arc42Statistics collects information about the sites and subdomains