Refactor
This commit is contained in:
parent
510e7fe9da
commit
c20f84562e
@ -61,7 +61,7 @@ func Gains(limit float64, sort int) error {
|
||||
currencyField = "$serra_prices.eur"
|
||||
}
|
||||
|
||||
raise_pipeline := mongo.Pipeline{
|
||||
raisePipeline := mongo.Pipeline{
|
||||
bson.D{{"$project",
|
||||
bson.D{
|
||||
{"name", true},
|
||||
@ -109,9 +109,9 @@ func Gains(limit float64, sort int) error {
|
||||
bson.D{{"rate", sort}}}},
|
||||
bson.D{{"$limit", 20}},
|
||||
}
|
||||
raise, _ := coll.storageAggregate(raise_pipeline)
|
||||
raise, _ := coll.storageAggregate(raisePipeline)
|
||||
|
||||
sraise_pipeline := mongo.Pipeline{
|
||||
sraisePipeline := mongo.Pipeline{
|
||||
bson.D{{"$project",
|
||||
bson.D{
|
||||
{"name", true},
|
||||
@ -157,25 +157,25 @@ func Gains(limit float64, sort int) error {
|
||||
bson.D{{"rate", sort}}}},
|
||||
bson.D{{"$limit", 10}},
|
||||
}
|
||||
sraise, _ := setcoll.storageAggregate(sraise_pipeline)
|
||||
sraise, _ := setcoll.storageAggregate(sraisePipeline)
|
||||
|
||||
// percentage coloring
|
||||
var p_color string
|
||||
var pColor string
|
||||
if sort == 1 {
|
||||
p_color = Red
|
||||
pColor = Red
|
||||
} else {
|
||||
p_color = Green
|
||||
pColor = Green
|
||||
}
|
||||
|
||||
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%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("%s%+.0f%%%s %s %s(%s/%s)%s (%.2f->%s%.2f%s%s) \n", pColor, 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%s%s) \n", p_color, e["rate"], Reset, e["name"], Yellow, e["code"], Reset, e["old"], Green, e["current"], getCurrency(), Reset)
|
||||
fmt.Printf("%s%+.0f%%%s %s %s(%s)%s (%.2f->%s%.2f%s%s) \n", pColor, e["rate"], Reset, e["name"], Yellow, e["code"], Reset, e["old"], Green, e["current"], getCurrency(), Reset)
|
||||
}
|
||||
return nil
|
||||
|
||||
|
||||
@ -21,35 +21,34 @@ func modifyCardCount(coll *Collection, c *Card, amount int64, foil bool) error {
|
||||
|
||||
// find already existing card
|
||||
sort := bson.D{{"_id", 1}}
|
||||
search_filter := bson.D{{"_id", c.ID}}
|
||||
stored_cards, err := coll.storageFind(search_filter, sort)
|
||||
searchFilter := bson.D{{"_id", c.ID}}
|
||||
storedCards, err := coll.storageFind(searchFilter, sort)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
stored_card := stored_cards[0]
|
||||
storedCard := storedCards[0]
|
||||
|
||||
// update card amount
|
||||
update_filter := bson.M{"_id": bson.M{"$eq": c.ID}}
|
||||
var update bson.M
|
||||
if foil {
|
||||
update = bson.M{
|
||||
"$set": bson.M{"serra_count_foil": stored_card.SerraCountFoil + amount},
|
||||
"$set": bson.M{"serra_count_foil": storedCard.SerraCountFoil + amount},
|
||||
}
|
||||
} else {
|
||||
update = bson.M{
|
||||
"$set": bson.M{"serra_count": stored_card.SerraCount + amount},
|
||||
"$set": bson.M{"serra_count": storedCard.SerraCount + amount},
|
||||
}
|
||||
}
|
||||
|
||||
coll.storageUpdate(update_filter, update)
|
||||
coll.storageUpdate(bson.M{"_id": bson.M{"$eq": c.ID}}, update)
|
||||
|
||||
var total int64
|
||||
if foil {
|
||||
total = stored_card.SerraCountFoil + amount
|
||||
total = storedCard.SerraCountFoil + amount
|
||||
} else {
|
||||
total = stored_card.SerraCount + amount
|
||||
total = storedCard.SerraCount + amount
|
||||
}
|
||||
LogMessage(fmt.Sprintf("Updating Card \"%s\" amount to %d", stored_card.Name, total), "purple")
|
||||
LogMessage(fmt.Sprintf("Updating Card \"%s\" amount to %d", storedCard.Name, total), "purple")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -148,25 +148,25 @@ func ShowSet(setname string) error {
|
||||
fmt.Printf("Total Cards: %.0f\n", stats[0]["count"])
|
||||
fmt.Printf("Foil Cards: %.0f\n", stats[0]["count_foil"])
|
||||
|
||||
nf_value, err := getFloat64(stats[0]["value"])
|
||||
normalValue, err := getFloat64(stats[0]["value"])
|
||||
if err != nil {
|
||||
LogMessage(fmt.Sprintf("Error: %v", err), "red")
|
||||
nf_value = 0
|
||||
normalValue = 0
|
||||
}
|
||||
foil_value, err := getFloat64(stats[0]["value_foil"])
|
||||
foilValue, err := getFloat64(stats[0]["value_foil"])
|
||||
if err != nil {
|
||||
LogMessage(fmt.Sprintf("Error: %v", err), "red")
|
||||
foil_value = 0
|
||||
foilValue = 0
|
||||
}
|
||||
total_value := nf_value + foil_value
|
||||
totalValue := normalValue + foilValue
|
||||
|
||||
nf_count, _ := getFloat64(stats[0]["count"])
|
||||
foil_count, _ := getFloat64(stats[0]["count_foil"])
|
||||
normalCount, _ := getFloat64(stats[0]["count"])
|
||||
foilCount, _ := getFloat64(stats[0]["count_foil"])
|
||||
|
||||
fmt.Printf("\n%sCurrent Value%s\n", Purple, Reset)
|
||||
fmt.Printf("Total: %.0fx %s%.2f%s%s\n", nf_count+foil_count, Yellow, total_value, getCurrency(), Reset)
|
||||
fmt.Printf("Normal: %.0fx %s%.2f%s%s\n", stats[0]["count"], Yellow, nf_value, getCurrency(), Reset)
|
||||
fmt.Printf("Foil: %.0fx %s%.2f%s%s\n", stats[0]["count_foil"], Yellow, foil_value, getCurrency(), Reset)
|
||||
fmt.Printf("Total: %.0fx %s%.2f%s%s\n", normalCount+foilCount, Yellow, totalValue, getCurrency(), Reset)
|
||||
fmt.Printf("Normal: %.0fx %s%.2f%s%s\n", stats[0]["count"], Yellow, normalValue, getCurrency(), Reset)
|
||||
fmt.Printf("Foil: %.0fx %s%.2f%s%s\n", stats[0]["count_foil"], Yellow, foilValue, getCurrency(), Reset)
|
||||
|
||||
fmt.Printf("\n%sRarities%s\n", Purple, Reset)
|
||||
fmt.Printf("Mythics: %.0f\n", ri.Mythics)
|
||||
|
||||
@ -149,20 +149,20 @@ var statsCmd = &cobra.Command{
|
||||
|
||||
// Total Value
|
||||
fmt.Printf("\n%sTotal Value%s\n", Green, Reset)
|
||||
nf_value, err := getFloat64(stats[0]["value"])
|
||||
normalValue, err := getFloat64(stats[0]["value"])
|
||||
if err != nil {
|
||||
LogMessage(fmt.Sprintf("Error: %v", err), "red")
|
||||
nf_value = 0
|
||||
normalValue = 0
|
||||
}
|
||||
foil_value, err := getFloat64(stats[0]["value_foil"])
|
||||
foilValue, err := getFloat64(stats[0]["value_foil"])
|
||||
if err != nil {
|
||||
LogMessage(fmt.Sprintf("Error: %v", err), "red")
|
||||
foil_value = 0
|
||||
foilValue = 0
|
||||
}
|
||||
total_value := nf_value + foil_value
|
||||
fmt.Printf("Total: %s%.2f%s%s\n", Pink, total_value, getCurrency(), Reset)
|
||||
fmt.Printf("Normal: %s%.2f%s%s\n", Pink, nf_value, getCurrency(), Reset)
|
||||
fmt.Printf("Foils: %s%.2f%s%s\n", Pink, foil_value, getCurrency(), Reset)
|
||||
totalValue := normalValue + foilValue
|
||||
fmt.Printf("Total: %s%.2f%s%s\n", Pink, totalValue, getCurrency(), Reset)
|
||||
fmt.Printf("Normal: %s%.2f%s%s\n", Pink, normalValue, getCurrency(), Reset)
|
||||
fmt.Printf("Foils: %s%.2f%s%s\n", Pink, foilValue, getCurrency(), Reset)
|
||||
total, _ := totalcoll.storageFindTotal()
|
||||
|
||||
fmt.Printf("History: \n")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user