Skip to content

Commit

Permalink
replace sum by total
Browse files Browse the repository at this point in the history
  • Loading branch information
gernotstarke committed Nov 7, 2023
1 parent 706e927 commit e4c2cd0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions internal/plausible/callPlausible.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var plausibleClient = plausible.NewClient(APIKEY)

// StatsForSite collects all relevant statistics for a given site
// (currently 7D, 30D and 12M), and updates the Sums accordingly
func StatsForSite(thisSite string, stats *types.SiteStats, sums *types.SumOfAllSites) {
func StatsForSite(thisSite string, stats *types.SiteStats, totals *types.SumOfAllSites) {

// Get a handler to perform queries for a given site
siteHandler := plausibleClient.Site(thisSite)
Expand All @@ -31,20 +31,20 @@ func StatsForSite(thisSite string, stats *types.SiteStats, sums *types.SumOfAllS
var stats7D types.VisitorsAndViews = SiteMetrics(siteHandler, plausible.Last7Days())
stats.Visitors7d = stats7D.Visitors
stats.Pageviews7d = stats7D.Pageviews
sums.SumOfVisitors7d += stats7D.VisitorNr
sums.SumOfPageviews7d += stats7D.PageViewNr
totals.SumOfVisitors7d += stats7D.VisitorNr
totals.SumOfPageviews7d += stats7D.PageViewNr

var stats30D = SiteMetrics(siteHandler, plausible.Last30Days())
stats.Visitors30d = stats30D.Visitors
stats.Pageviews30d = stats30D.Pageviews
sums.SumOfVisitors30d += stats30D.VisitorNr
sums.SumOfPageviews30d += stats30D.PageViewNr
totals.SumOfVisitors30d += stats30D.VisitorNr
totals.SumOfPageviews30d += stats30D.PageViewNr

var stats12M = SiteMetrics(siteHandler, plausible.Last12Months())
stats.Visitors12m = stats12M.Visitors
stats.Pageviews12m = stats12M.Pageviews
sums.SumOfVisitors12m += stats12M.VisitorNr
sums.SumOfPageviews12m += stats12M.PageViewNr
totals.SumOfVisitors12m += stats12M.VisitorNr
totals.SumOfPageviews12m += stats12M.PageViewNr

}

Expand Down
4 changes: 2 additions & 2 deletions internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ type Arc42Statistics struct {
// Stats4Site contains the statistics per site or subdomain
Stats4Site [len(Arc42sites)]SiteStats

// Sums contains the sum of all the statistics over all sites
Sums SumOfAllSites
// Totals contains the sum of all the statistics over all sites
Totals SumOfAllSites
}

// VisitorsAndViews is a temporarily-used struct.
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func loadStats4AllSites() types.Arc42Statistics {

// TODO: let StatsForSite update the Stats4Site and the Sums struct
// set the statistic data from plausible.io
plausible.StatsForSite(site, &a42s.Stats4Site[index], &a42s.Sums)
plausible.StatsForSite(site, &a42s.Stats4Site[index], &a42s.Totals)

// set some URLs so the templates get smaller
setURLsForSite(&a42s.Stats4Site[index])
Expand Down

0 comments on commit e4c2cd0

Please sign in to comment.