about summary refs log tree commit diff
path: root/src/seed.go
diff options
context:
space:
mode:
authormaride <maride@darknebu.la>2019-10-06 16:02:47 +0200
committermaride <maride@darknebu.la>2019-10-06 16:02:47 +0200
commitaa9d6793abf64d0762904b043243222a6db03c4b (patch)
treee23bbf7b2a4a58e303a22d1daec19c9c0f326cb7 /src/seed.go
parente4637ddf366231de52c05d0092ff8ea8583a1601 (diff)
Add non-protected handler for statistics, /api/getStats
Diffstat (limited to 'src/seed.go')
-rw-r--r--src/seed.go19
1 files changed, 19 insertions, 0 deletions
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
+}