Skip to content

Commit

Permalink
Country stats
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronClaydon committed Nov 8, 2024
1 parent 954dffd commit e99442c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/stats/calculator/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type OperatorsStats struct {
Total int

Datasources map[string]int
Countries map[string]int
}

func GetOperators() OperatorsStats {
Expand All @@ -20,6 +21,7 @@ func GetOperators() OperatorsStats {
stats.Total = int(numberoperators)

stats.Datasources = CountAggregate(operatorsCollection, "$datasource.datasetid")
stats.Countries = CountCountries(stats.Datasources)

return stats
}
2 changes: 2 additions & 0 deletions pkg/stats/calculator/realtimejourneys.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type RealtimeJourneyStats struct {
TransportTypes map[ctdf.TransportType]int
Features map[string]int
Datasources map[string]int
Countries map[string]int
}

func GetRealtimeJourneys() RealtimeJourneyStats {
Expand Down Expand Up @@ -138,6 +139,7 @@ func GetRealtimeJourneys() RealtimeJourneyStats {
TransportTypes: transportTypes,
Features: features,
Datasources: datasources,
Countries: CountCountries(datasources),
NotActivelyTracked: numberActiveRealtimeJourneysNotActivelyTracked,
}
}
6 changes: 5 additions & 1 deletion pkg/stats/calculator/servicealerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type ServiceAlertsStats struct {
Inactive int

Datasources map[string]int
Countries map[string]int
}

func GetServiceAlerts() ServiceAlertsStats {
Expand All @@ -40,11 +41,14 @@ func GetServiceAlerts() ServiceAlertsStats {
}
}

datasources := CountAggregate(collection, "$datasource.datasetid")

return ServiceAlertsStats{
Total: numberActiveAlerts + numberInactiveAlerts,
Active: numberActiveAlerts,
Inactive: numberInactiveAlerts,

Datasources: CountAggregate(collection, "$datasource.datasetid"),
Datasources: datasources,
Countries: CountCountries(datasources),
}
}
2 changes: 2 additions & 0 deletions pkg/stats/calculator/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type ServicesStats struct {

TransportTypes map[string]int
Datasources map[string]int
Countries map[string]int
}

func GetServices() ServicesStats {
Expand All @@ -26,6 +27,7 @@ func GetServices() ServicesStats {

stats.TransportTypes = CountAggregate(servicesCollection, "$transporttype")
stats.Datasources = CountAggregate(servicesCollection, "$datasource.datasetid")
stats.Countries = CountCountries(stats.Datasources)

return stats
}
2 changes: 2 additions & 0 deletions pkg/stats/calculator/stops.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type StopsStats struct {
Total int

Datasources map[string]int
Countries map[string]int
}

func GetStops() StopsStats {
Expand All @@ -20,6 +21,7 @@ func GetStops() StopsStats {
stats.Total = int(numberStops)

stats.Datasources = CountAggregate(stopsCollection, "$datasource.datasetid")
stats.Countries = CountCountries(stats.Datasources)

return stats
}
15 changes: 15 additions & 0 deletions pkg/stats/calculator/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package calculator

import (
"context"
"strings"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
Expand Down Expand Up @@ -30,3 +31,17 @@ func CountAggregate(collection *mongo.Collection, aggregateKey string) map[strin

return countMap
}

func CountCountries(datasources map[string]int) map[string]int {
countries := map[string]int{}

for datasource, count := range datasources {
// Making a big assumption here
datasourceSplit := strings.Split(datasource, "-")
country := datasourceSplit[0]

countries[country] = count
}

return countries
}

0 comments on commit e99442c

Please sign in to comment.