From c794ed30aaa0fe52346712fc63897bda34bc6a5c Mon Sep 17 00:00:00 2001 From: "Dr. Gernot Starke" Date: Mon, 11 Dec 2023 22:02:17 +0100 Subject: [PATCH 1/2] experimenting with decimal separators --- go-app/cmd/easy2read/main.go | 28 ++++++++++++++++++++++ go-app/go.mod | 1 + go-app/go.sum | 2 ++ go-app/internal/plausible/vpvStatistics.go | 10 ++++++-- go-app/main.go | 5 ++-- 5 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 go-app/cmd/easy2read/main.go diff --git a/go-app/cmd/easy2read/main.go b/go-app/cmd/easy2read/main.go new file mode 100644 index 0000000..9adcf2a --- /dev/null +++ b/go-app/cmd/easy2read/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "golang.org/x/text/language" + "golang.org/x/text/message" +) + +// format large numbers with separators +func formatWithSeparator(numAsString int) string { + + p := message.NewPrinter(language.German) + withCommaThousandSep := p.Sprintf("%d", numAsString) + fmt.Printf("formated string %s", withCommaThousandSep) + + return withCommaThousandSep +} + +func main() { + fmt.Printf("1: %s\n", formatWithSeparator(1)) + fmt.Printf("10: %s\n", formatWithSeparator(10)) + fmt.Printf("100: %s\n", formatWithSeparator(100)) + fmt.Printf("1000: %s\n", formatWithSeparator(1000)) + fmt.Printf("10000: %s\n", formatWithSeparator(10000)) + fmt.Printf("100000: %s\n", formatWithSeparator(100000)) + fmt.Printf("1000000: %s\n", formatWithSeparator(1000000)) + +} diff --git a/go-app/go.mod b/go-app/go.mod index 0fa041d..a709c33 100644 --- a/go-app/go.mod +++ b/go-app/go.mod @@ -20,6 +20,7 @@ require ( github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasthttp v1.50.0 // indirect golang.org/x/sys v0.14.0 // indirect + golang.org/x/text v0.14.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.31.0 // indirect ) diff --git a/go-app/go.sum b/go-app/go.sum index 0732734..9947337 100644 --- a/go-app/go.sum +++ b/go-app/go.sum @@ -61,6 +61,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= diff --git a/go-app/internal/plausible/vpvStatistics.go b/go-app/internal/plausible/vpvStatistics.go index 0a1e720..ca4925d 100644 --- a/go-app/internal/plausible/vpvStatistics.go +++ b/go-app/internal/plausible/vpvStatistics.go @@ -11,6 +11,8 @@ import ( "arc42-status/internal/types" "github.com/andrerfcsantos/go-plausible/plausible" "github.com/rs/zerolog/log" + "golang.org/x/text/language" + "golang.org/x/text/message" "os" "strconv" "sync" @@ -86,8 +88,11 @@ func StatsForSite(thisSite string, stats *types.SiteStats) { wg.Wait() + p := message.NewPrinter(language.German) + // now process results - stats.Visitors7d = stats7D.Visitors + // stats.Visitors7d = stats7D.Visitors + stats.Visitors7d = p.Sprintf("%d", stats7D.VisitorNr) stats.Visitors7dNr = stats7D.VisitorNr stats.Pageviews7d = stats7D.Pageviews stats.Pageviews7dNr = stats7D.PageviewNr @@ -98,8 +103,9 @@ func StatsForSite(thisSite string, stats *types.SiteStats) { stats.Pageviews30dNr = stats30D.PageviewNr stats.Visitors12m = stats12M.Visitors - stats.Pageviews12m = stats12M.Pageviews + stats.Pageviews12m = p.Sprintf("%d", stats12M.PageviewNr) stats.Visitors12mNr = stats12M.VisitorNr + //stats.Pageviews12mNr = stats12M.PageviewNr stats.Pageviews12mNr = stats12M.PageviewNr } diff --git a/go-app/main.go b/go-app/main.go index ef41f03..a05b95c 100644 --- a/go-app/main.go +++ b/go-app/main.go @@ -9,10 +9,11 @@ import ( "strings" ) -const AppVersion = "0.4.4" +const AppVersion = "0.4.5" // version history -// 0.4.4 fix bad hyperlink to github issues +// 0.4.5 fix missing separators in large numbers +// 0.4.4 fix bad hyperlink to GitHub issues // 0.4.3 fix #57 (local svg images for issues and badges) // 0.4.2 merge repositories (site-statistics and status.arc42.org-site) into one! // 0.4.1 added links to issue & bug badges From 2fc0cdb568628b429769e0284f232689432c916a Mon Sep 17 00:00:00 2001 From: "Dr. Gernot Starke" Date: Tue, 12 Dec 2023 21:10:21 +0100 Subject: [PATCH 2/2] added separators to numbers, fixing #55 --- go-app/internal/domain/domain.go | 29 ++++++++++++++++------ go-app/internal/plausible/vpvStatistics.go | 11 ++++---- go-app/internal/types/types.go | 18 +++++++++----- 3 files changed, 39 insertions(+), 19 deletions(-) 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