This commit is contained in:
Florian Baumann 2022-01-04 14:14:24 +01:00
parent f5b0850ab7
commit c002fbafce
3 changed files with 28 additions and 0 deletions

View File

@ -39,6 +39,10 @@ Set value
db.cards.aggregate([{ $group: { _id: { set: "$set" }, value: { $sum: { $multiply: ["$prices.eur", "$serra_count"] } }, count: { $sum: 1 } } }]) db.cards.aggregate([{ $group: { _id: { set: "$set" }, value: { $sum: { $multiply: ["$prices.eur", "$serra_count"] } }, count: { $sum: 1 } } }])
Color distribution
db.cards.aggregate([{ $group: { _id: { color: "$colors" }, count: { $sum: 1 } } }])
# MongoDB Operations # MongoDB Operations

View File

@ -17,6 +17,7 @@ Usage:
serra set <set> serra set <set>
serra sets serra sets
serra update serra update
serra stats
Options: Options:
-h --help Show this screen. -h --help Show this screen.
@ -35,6 +36,8 @@ Options:
serra.ShowSet(args["<set>"].(string)) serra.ShowSet(args["<set>"].(string))
} else if args["update"].(bool) { } else if args["update"].(bool) {
serra.Update() serra.Update()
} else if args["stats"].(bool) {
serra.Stats()
} }
} }

View File

@ -145,3 +145,24 @@ func Update() {
storage_disconnect(client) storage_disconnect(client)
} }
func Stats() {
LogMessage(fmt.Sprintf("Serra %v\n", version), "green")
LogMessage(fmt.Sprintf("Color distribution in Collection"), "green")
client := storage_connect()
coll := &Collection{client.Database("serra").Collection("cards")}
groupStage := bson.D{
{"$group", bson.D{
{"_id", "$coloridentity"},
{"count", bson.D{{"$sum", 1}}},
}}}
sets, _ := coll.storage_aggregate(groupStage)
for _, set := range sets {
// TODO fix primitiveA Problem with loop and reflect
fmt.Printf("* %s %d\n", set["_id"], set["count"])
}
}