From aa9d6793abf64d0762904b043243222a6db03c4b Mon Sep 17 00:00:00 2001 From: maride Date: Sun, 6 Oct 2019 16:02:47 +0200 Subject: Add non-protected handler for statistics, /api/getStats --- src/seed.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/seed.go') diff --git a/src/seed.go b/src/seed.go index af14d38..dd836ff 100644 --- a/src/seed.go +++ b/src/seed.go @@ -109,3 +109,22 @@ func generateJSONFromChallenges() (string, error) { }) return string(marshalled), marshalError } + +// Generate a JSON string from the stored challenges, just containing enough to call it statistics +func generateJSONFromChallengesForStats() (string, error) { + // To include only required information for statistics, we need to strip the challenge + var strippedChallenges []StatsStrippedChallenge + categories := map[string]int{} + + for _, challenge := range challenges { + // Append challenge to list + strippedChallenges = append(strippedChallenges, stripChallengeForStatistics(challenge)) + + categories[challenge.Category]++ + } + + marshalled, marshalError := json.Marshal(map[string]interface{}{ + "challenges": strippedChallenges, + }) + return string(marshalled), marshalError +} -- cgit 1.4.1