Skip to content

Commit

Permalink
added separators to numbers, fixing #55
Browse files Browse the repository at this point in the history
  • Loading branch information
gernotstarke committed Dec 12, 2023
1 parent c794ed3 commit 2fc0cdb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
29 changes: 22 additions & 7 deletions go-app/internal/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 5 additions & 6 deletions go-app/internal/plausible/vpvStatistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
18 changes: 12 additions & 6 deletions go-app/internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2fc0cdb

Please sign in to comment.