Fix gains

This commit is contained in:
Florian Baumann 2023-02-07 08:32:06 +01:00
parent a6ca327118
commit 482217c8f9
3 changed files with 19 additions and 11 deletions

View File

@ -49,7 +49,11 @@ func Gains(limit float64, sort int, since string) error {
old, _ := strconv.Atoi(since)
// TODO redo this calculation
currencyField := "$serra_prices.usd"
if getCurrency() == "EUR" {
currencyField = "$serra_prices.eur"
}
raise_pipeline := mongo.Pipeline{
bson.D{{"$project",
bson.D{
@ -58,12 +62,12 @@ func Gains(limit float64, sort int, since string) error {
{"collectornumber", true},
{"old",
bson.D{{"$arrayElemAt",
bson.A{"$serra_prices.value", old},
bson.A{currencyField, old},
}},
},
{"current",
bson.D{{"$arrayElemAt",
bson.A{"$serra_prices.value", -1},
bson.A{currencyField, -1},
}},
},
},
@ -107,12 +111,12 @@ func Gains(limit float64, sort int, since string) error {
{"code", true},
{"old",
bson.D{{"$arrayElemAt",
bson.A{"$serra_prices.value", old},
bson.A{currencyField, old},
}},
},
{"current",
bson.D{{"$arrayElemAt",
bson.A{"$serra_prices.value", -1},
bson.A{currencyField, -1},
}},
},
},
@ -159,12 +163,12 @@ func Gains(limit float64, sort int, since string) error {
fmt.Printf("%sCards%s\n", Purple, Reset)
// print each card
for _, e := range raise {
fmt.Printf("%s%+.0f%%%s %s %s(%s/%s)%s (%.2f->%s%.2f EUR%s) \n", p_color, e["rate"], Reset, e["name"], Yellow, e["set"], e["collectornumber"], Reset, e["old"], Green, e["current"], Reset)
fmt.Printf("%s%+.0f%%%s %s %s(%s/%s)%s (%.2f->%s%.2f %s%s) \n", p_color, e["rate"], Reset, e["name"], Yellow, e["set"], e["collectornumber"], Reset, e["old"], Green, e["current"], getCurrency(), Reset)
}
fmt.Printf("\n%sSets%s\n", Purple, Reset)
for _, e := range sraise {
fmt.Printf("%s%+.0f%%%s %s %s(%s)%s (%.2f->%s%.2f EUR%s) \n", p_color, e["rate"], Reset, e["name"], Yellow, e["code"], Reset, e["old"], Green, e["current"], Reset)
fmt.Printf("%s%+.0f%%%s %s %s(%s)%s (%.2f->%s%.2f %s%s) \n", p_color, e["rate"], Reset, e["name"], Yellow, e["code"], Reset, e["old"], Green, e["current"], getCurrency(), Reset)
}
return nil

View File

@ -31,9 +31,9 @@ func getCurrencyField() string {
return "$prices.eur"
case "USD":
return "$prices.usd"
default:
return "$prices.usd"
}
// default
return "$prices.usd"
}
func storage_connect() *mongo.Client {

View File

@ -124,8 +124,12 @@ var updateCmd = &cobra.Command{
t.Date = primitive.NewDateTimeFromTime(time.Now())
mapstructure.Decode(totalvalue[0], &t)
// TODO: eur value chooser
fmt.Printf("\n%sUpdating total value of collection to: %s%.02f EUR%s\n", Green, Yellow, totalvalue[0]["eur"], Reset)
// This is here to be able to fetch currency from
// constructed new priceentry
tmpCard := Card{}
tmpCard.Prices = t
fmt.Printf("\n%sUpdating total value of collection to: %s%.02f %s%s\n", Green, Yellow, tmpCard.getValue(), getCurrency(), Reset)
totalcoll.storage_add_total(t)
return nil