diff --git a/src/serra/helpers.go b/src/serra/helpers.go index ea799ed..617eb10 100644 --- a/src/serra/helpers.go +++ b/src/serra/helpers.go @@ -64,3 +64,28 @@ func show_card_details(card *Card) error { fmt.Println() return nil } + +func convert_mana_symbols(sym []interface{}) string { + var mana string + + if len(sym) == 0 { + mana = mana + "\U0001F6AB" //probibited sign for lands + } + + for _, v := range sym { + switch v { + case "B": + mana = mana + "\U000026AB" //black + case "R": + mana = mana + "\U0001F534" //red + case "G": + mana = mana + "\U0001F7E2" //green + case "U": + mana = mana + "\U0001F535" //blue + case "W": + mana = mana + "\U000026AA" //white + } + } + return mana + +} diff --git a/src/serra/root.go b/src/serra/root.go index 6eff4d0..18961f4 100644 --- a/src/serra/root.go +++ b/src/serra/root.go @@ -237,15 +237,35 @@ func Stats() { groupStage := bson.D{ {"$group", bson.D{ {"_id", "$coloridentity"}, - {"count", bson.D{{"$sum", 1}}}, + {"count", bson.D{{"$sum", bson.D{{"$multiply", bson.A{1.0, "$serra_count"}}}}}}, }}} - sets, _ := coll.storage_aggregate(mongo.Pipeline{groupStage}) + sortStage := bson.D{ + {"$sort", bson.D{ + {"count", -1}, + }}} + sets, _ := coll.storage_aggregate(mongo.Pipeline{groupStage, sortStage}) for _, set := range sets { - // TODO fix primitiveA Problem with loop and reflect - fmt.Printf("* %s %d\n", set["_id"], set["count"]) + x, _ := set["_id"].(primitive.A) + s := []interface{}(x) + fmt.Printf("* %s %.0f\n", convert_mana_symbols(s), set["count"]) } + statsGroup := bson.D{ + {"$group", bson.D{ + {"_id", nil}, + {"value", bson.D{{"$sum", bson.D{{"$multiply", bson.A{"$prices.eur", "$serra_count"}}}}}}, + {"count", bson.D{{"$sum", bson.D{{"$multiply", bson.A{1.0, "$serra_count"}}}}}}, + {"unique", bson.D{{"$sum", 1}}}, + }}, + } + stats, _ := coll.storage_aggregate(mongo.Pipeline{statsGroup}) + + fmt.Printf("\n%sOverall %s\n", Green, Reset) + fmt.Printf("Total Cards: %s%.0f%s\n", Yellow, stats[0]["count"], Reset) + fmt.Printf("Unique Cards: %s%d%s\n", Purple, stats[0]["unique"], Reset) + fmt.Printf("Total Value: %s%.2f%s\n", Pink, stats[0]["value"], Reset) + // LogMessage(fmt.Sprintf("Mana costs in Collection"), "green") // groupStage = bson.D{ // {"$group", bson.D{