Skip to content

Commit

Permalink
only display connections on a year scope
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGruber committed Nov 23, 2024
1 parent 6247fc2 commit 0258f92
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
4 changes: 2 additions & 2 deletions charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ func genCharts(db *mongo.Database, mongoCtx context.Context) {
createLineCountChart("Zombie kill activity", allZombieKills, zombieKillsDatas)

connectionsDatas := make([]CountData, 0)
allConnections := getAllConnections(db, mongoCtx)
allConnectionsLastYear := getAllConnectionsLastYear(db, mongoCtx)
for _, v := range officialServers {
data := getConnectionsToServer(db, mongoCtx, v.ServerId)
if len(data) == 0 {
continue
}
connectionsDatas = append(connectionsDatas, CountData{name: v.Name + " " + v.Region, data: data})
}
createLineCountChart("connections", allConnections, connectionsDatas)
createLineCountChart("Last year connections", allConnectionsLastYear, connectionsDatas)
lastMonthConnectionsDatas := make([]CountData, 0)
allConnectionsLastMonth := getAllConnectionsLastMonth(db, mongoCtx)
for _, v := range officialServers {
Expand Down
12 changes: 12 additions & 0 deletions mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ func getAllConnections(db *mongo.Database, mongoCtx context.Context) []CountPerT
return results
}

func getAllConnectionsLastYear(db *mongo.Database, mongoCtx context.Context) []CountPerTime {
ConnectionsCollection := db.Collection(CONNECTIONS_COLLECTION_NAME)
pipeline := getAllConnectionsLastYearPipeline()
cursor, error := ConnectionsCollection.Aggregate(mongoCtx, pipeline)
if error != nil {
panic(error)
}
var results []CountPerTime
cursor.All(mongoCtx, &results)
return results
}

func getAllConnectionsLastMonth(db *mongo.Database, mongoCtx context.Context) []CountPerTime {
ConnectionsCollection := db.Collection(CONNECTIONS_COLLECTION_NAME)
pipeline := getAllConnectionsLastMonthPipeline()
Expand Down
30 changes: 27 additions & 3 deletions mongo_pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,33 @@ func getAllConnectionsLastMonthPipeline() mongo.Pipeline {
return pipeline
}

func getAllConnectionsLastYearPipeline() mongo.Pipeline {
now := time.Now()
gte := time.Date(now.Year(), 0, 0, 0, 0, 0, 0, time.UTC)

pipeline := mongo.Pipeline{
{{"$addFields", bson.D{{"creationDate", bson.D{{"$toDate", "$_id"}}}}}},
{{"$match", bson.D{
{"creationDate", bson.D{
{"$gte", gte},
{"$lt", now},
}},
}}},

{{"$addFields", bson.D{{"yearMonth", bson.D{{"$dateToString", bson.D{
{"format", "%Y-%m"},
{"date", "$creationDate"},
}}}}}}},
{{"$group", bson.D{
{"_id", "$yearMonth"},
{"count", bson.D{{"$sum", 1}}},
}}},
{{"$sort", bson.D{{"_id", 1}}}},
}

return pipeline
}

func getKillsPerServerPipeline(serverId uint32, entityType string) mongo.Pipeline {
pipeline := mongo.Pipeline{
{{"$match", bson.D{{"serverId", serverId}}}},
Expand Down Expand Up @@ -165,9 +192,6 @@ func getAllKillsPipeline(entityType string) mongo.Pipeline {

func getAllConnectionsPipeline() mongo.Pipeline {
pipeline := mongo.Pipeline{
// {{"$match", bson.D{
// {"_id", bson.D{{"$gte", primitive.NewObjectIDFromTimestamp(time.Date(2023, 2, 01, 0, 0, 0, 0, time.UTC))}}},
// }}},
{{"$addFields", bson.D{{"creationDate", bson.D{{"$toDate", "$_id"}}}}}},
{{"$addFields", bson.D{{"yearMonth", bson.D{{"$dateToString", bson.D{
{"format", "%Y-%m"},
Expand Down
4 changes: 3 additions & 1 deletion template.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ <h1>H1emu Charts</h1>
<li>
<a href="./Last month connections.html">Last Month Connections</a>
</li>
<li><a href="./connections.html">All Connections</a></li>
<li>
<a href="./Last year connections.html">Last Year Connections</a>
</li>
<li><a href="./playtime.html">Playtime</a></li>
<li>
<a href="./Top PlayTime Main EU 1.html">Playtime Top EU :)</a>
Expand Down

0 comments on commit 0258f92

Please sign in to comment.