Handle rarity missing for ShowSet

This commit is contained in:
Florian Baumann 2022-01-11 08:40:54 +01:00
parent 77f8fc78ca
commit 3e2efa7660

View File

@ -261,14 +261,33 @@ func ShowSet(setname string) error {
}}}
rar, _ := coll.storage_aggregate(mongo.Pipeline{matchStage, groupStage, sortStage})
// this is maybe the ugliest way someone could choose to verify, if a rarity type is missing
// [
// { _id: { rarity: 'common' }, count: 20 },
// { _id: { rarity: 'uncommon' }, count: 2 }
// ]
// if a result like this is there, 1 rarity type "rare" is not in the array. and needs to be
// initialized with 0, otherwise we get a panic
var rares, uncommons, commons float64
for _, r := range rar {
switch r["_id"] {
case "rare":
rares = r["count"].(float64)
case "uncommon":
uncommons = r["count"].(float64)
case "common":
commons = r["count"].(float64)
}
}
LogMessage(fmt.Sprintf("%s", sets[0].Name), "green")
LogMessage(fmt.Sprintf("Set Cards: %d/%d", len(cards), sets[0].CardCount), "normal")
LogMessage(fmt.Sprintf("Total Cards: %.0f", stats[0]["count"]), "normal")
LogMessage(fmt.Sprintf("Total Value: %.2f EUR", stats[0]["value"]), "normal")
LogMessage(fmt.Sprintf("Released: %s", sets[0].ReleasedAt), "normal")
LogMessage(fmt.Sprintf("Rares: %.0f", rar[1]["count"]), "normal")
LogMessage(fmt.Sprintf("Uncommons: %.0f", rar[2]["count"]), "normal")
LogMessage(fmt.Sprintf("Commons: %.0f", rar[0]["count"]), "normal")
LogMessage(fmt.Sprintf("Rares: %.0f", rares), "normal")
LogMessage(fmt.Sprintf("Uncommons: %.0f", uncommons), "normal")
LogMessage(fmt.Sprintf("Commons: %.0f", commons), "normal")
fmt.Printf("\n%sPrice History:%s\n", Pink, Reset)
for _, e := range sets[0].SerraPrices {
fmt.Printf("* %s %.2f EUR\n", stringToTime(e.Date), e.Value)