about summary refs log tree commit diff
path: root/src/seed.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/seed.go')
-rw-r--r--src/seed.go24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/seed.go b/src/seed.go
index 3dce55f..dd836ff 100644
--- a/src/seed.go
+++ b/src/seed.go
@@ -1,12 +1,13 @@
 package main
 
 import (
+	"encoding/json"
 	"flag"
 	"fmt"
 	"github.com/pkg/errors"
 	"io/ioutil"
 	"log"
-	"encoding/json"
+	"time"
 )
 
 var (
@@ -54,7 +55,7 @@ func readSeedFile(path string) ([]Challenge, error) {
 				Name: name,
 				Description: desc,
 				Flag: flag,
-				FoundFlag: false,
+				FoundFlag: time.Unix(0, 0),
 				FlagTries: 0,
 				Container: cont,
 				Category: category,
@@ -108,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
+}