Restructure stats command
This commit is contained in:
parent
1ce3920c03
commit
3691890b95
@ -16,17 +16,46 @@ func init() {
|
|||||||
|
|
||||||
var statsCmd = &cobra.Command{
|
var statsCmd = &cobra.Command{
|
||||||
Aliases: []string{"stats"},
|
Aliases: []string{"stats"},
|
||||||
Use: "stats <prefix> <n>",
|
Use: "stats",
|
||||||
Short: "Shows statistics of the collection",
|
Short: "Shows statistics of the collection",
|
||||||
SilenceErrors: true,
|
SilenceErrors: true,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
Stats()
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func Stats() {
|
||||||
client := storageConnect()
|
client := storageConnect()
|
||||||
coll := &Collection{client.Database("serra").Collection("cards")}
|
coll := &Collection{client.Database("serra").Collection("cards")}
|
||||||
totalcoll := &Collection{client.Database("serra").Collection("total")}
|
totalcoll := &Collection{client.Database("serra").Collection("total")}
|
||||||
l := Logger()
|
l := Logger()
|
||||||
defer storageDisconnect(client)
|
defer storageDisconnect(client)
|
||||||
|
|
||||||
|
// Show Value Stats
|
||||||
|
showValueStats(coll, totalcoll)
|
||||||
|
|
||||||
|
// Reserved List
|
||||||
|
showReservedListStats(coll)
|
||||||
|
|
||||||
|
// Rarities
|
||||||
|
showRarityStats(coll)
|
||||||
|
|
||||||
|
// Colors
|
||||||
|
showColorStats(coll)
|
||||||
|
|
||||||
|
// Artists
|
||||||
|
showArtistStats(coll)
|
||||||
|
|
||||||
|
// Mana Curve of Collection
|
||||||
|
showManaCurveStats(coll)
|
||||||
|
|
||||||
|
// Show cards added per month
|
||||||
|
showCardsAddedPerMonth(coll)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func showValueStats(coll *Collection, totalcoll *Collection) {
|
||||||
// Value and Card Numbers
|
// Value and Card Numbers
|
||||||
stats, _ := coll.storageAggregate(mongo.Pipeline{
|
stats, _ := coll.storageAggregate(mongo.Pipeline{
|
||||||
bson.D{
|
bson.D{
|
||||||
@ -52,6 +81,35 @@ var statsCmd = &cobra.Command{
|
|||||||
fmt.Printf("Normal: %s%.0f%s\n", Purple, stats[0]["count"], Reset)
|
fmt.Printf("Normal: %s%.0f%s\n", Purple, stats[0]["count"], Reset)
|
||||||
fmt.Printf("Foil: %s%d%s\n", Purple, stats[0]["count_foil"], Reset)
|
fmt.Printf("Foil: %s%d%s\n", Purple, stats[0]["count_foil"], Reset)
|
||||||
|
|
||||||
|
// Total Value
|
||||||
|
fmt.Printf("\n%sTotal Value%s\n", Green, Reset)
|
||||||
|
normalValue, err := getFloat64(stats[0]["value"])
|
||||||
|
if err != nil {
|
||||||
|
l.Error(err)
|
||||||
|
normalValue = 0
|
||||||
|
}
|
||||||
|
foilValue, err := getFloat64(stats[0]["value_foil"])
|
||||||
|
if err != nil {
|
||||||
|
l.Error(err)
|
||||||
|
foilValue = 0
|
||||||
|
}
|
||||||
|
count_all, err := getFloat64(stats[0]["count_all"])
|
||||||
|
if err != nil {
|
||||||
|
l.Error(err)
|
||||||
|
foilValue = 0
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
fmt.Printf("Average Card: %s%.2f%s%s\n", Pink, totalValue/count_all, getCurrency(), Reset)
|
||||||
|
total, _ := totalcoll.storageFindTotal()
|
||||||
|
|
||||||
|
fmt.Printf("History: \n")
|
||||||
|
showPriceHistory(total.Value, "* ", true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func showReservedListStats(coll *Collection) {
|
||||||
reserved, _ := coll.storageAggregate(mongo.Pipeline{
|
reserved, _ := coll.storageAggregate(mongo.Pipeline{
|
||||||
bson.D{
|
bson.D{
|
||||||
{"$match", bson.D{
|
{"$match", bson.D{
|
||||||
@ -68,8 +126,9 @@ var statsCmd = &cobra.Command{
|
|||||||
count_reserved = reserved[0]["count"].(int32)
|
count_reserved = reserved[0]["count"].(int32)
|
||||||
}
|
}
|
||||||
fmt.Printf("Reserved List: %s%d%s\n", Yellow, count_reserved, Reset)
|
fmt.Printf("Reserved List: %s%d%s\n", Yellow, count_reserved, Reset)
|
||||||
|
}
|
||||||
|
|
||||||
// Rarities
|
func showRarityStats(coll *Collection) {
|
||||||
rar, _ := coll.storageAggregate(mongo.Pipeline{
|
rar, _ := coll.storageAggregate(mongo.Pipeline{
|
||||||
bson.D{
|
bson.D{
|
||||||
{"$group", bson.D{
|
{"$group", bson.D{
|
||||||
@ -87,67 +146,9 @@ var statsCmd = &cobra.Command{
|
|||||||
fmt.Printf("Rares: %s%.0f%s\n", Pink, ri.Rares, Reset)
|
fmt.Printf("Rares: %s%.0f%s\n", Pink, ri.Rares, Reset)
|
||||||
fmt.Printf("Uncommons: %s%.0f%s\n", Yellow, ri.Uncommons, Reset)
|
fmt.Printf("Uncommons: %s%.0f%s\n", Yellow, ri.Uncommons, Reset)
|
||||||
fmt.Printf("Commons: %s%.0f%s\n", Purple, ri.Commons, Reset)
|
fmt.Printf("Commons: %s%.0f%s\n", Purple, ri.Commons, Reset)
|
||||||
|
}
|
||||||
|
|
||||||
// Colors
|
func showCardsAddedPerMonth(coll *Collection) {
|
||||||
sets, _ := coll.storageAggregate(mongo.Pipeline{
|
|
||||||
bson.D{
|
|
||||||
{"$match", bson.D{
|
|
||||||
{"coloridentity", bson.D{{"$size", 1}}}}}},
|
|
||||||
bson.D{
|
|
||||||
{"$group", bson.D{
|
|
||||||
{"_id", "$coloridentity"},
|
|
||||||
{"count", bson.D{{"$sum", bson.D{{"$multiply", bson.A{1.0, "$serra_count"}}}}}},
|
|
||||||
}}},
|
|
||||||
bson.D{
|
|
||||||
{"$sort", bson.D{
|
|
||||||
{"count", -1},
|
|
||||||
}}},
|
|
||||||
})
|
|
||||||
|
|
||||||
fmt.Printf("\n%sColors%s\n", Green, Reset)
|
|
||||||
for _, set := range sets {
|
|
||||||
x, _ := set["_id"].(primitive.A)
|
|
||||||
s := []interface{}(x)
|
|
||||||
fmt.Printf("%s: %s%.0f%s\n", convertManaSymbols(s), Purple, set["count"], Reset)
|
|
||||||
}
|
|
||||||
// Artists
|
|
||||||
artists, _ := coll.storageAggregate(mongo.Pipeline{
|
|
||||||
bson.D{
|
|
||||||
{"$group", bson.D{
|
|
||||||
{"_id", "$artist"},
|
|
||||||
{"count", bson.D{{"$sum", 1}}},
|
|
||||||
}}},
|
|
||||||
bson.D{
|
|
||||||
{"$sort", bson.D{
|
|
||||||
{"count", -1},
|
|
||||||
}}},
|
|
||||||
bson.D{
|
|
||||||
{"$limit", 10}},
|
|
||||||
})
|
|
||||||
fmt.Printf("\n%sTop Artists%s\n", Green, Reset)
|
|
||||||
for _, artist := range artists {
|
|
||||||
fmt.Printf("%s: %s%d%s\n", artist["_id"].(string), Purple, artist["count"], Reset)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mana Curve of Collection
|
|
||||||
cmc, _ := coll.storageAggregate(mongo.Pipeline{
|
|
||||||
bson.D{
|
|
||||||
{"$group", bson.D{
|
|
||||||
{"_id", "$cmc"},
|
|
||||||
// {"count", bson.D{{"$sum", bson.D{{"$multiply", bson.A{1.0, "$serra_count"}}}}}},
|
|
||||||
{"count", bson.D{{"$sum", 1}}},
|
|
||||||
}}},
|
|
||||||
bson.D{
|
|
||||||
{"$sort", bson.D{
|
|
||||||
{"_id", 1},
|
|
||||||
}}},
|
|
||||||
})
|
|
||||||
fmt.Printf("\n%sMana Curve%s\n", Green, Reset)
|
|
||||||
for _, mc := range cmc {
|
|
||||||
fmt.Printf("%.0f: %s%d%s\n", mc["_id"], Purple, mc["count"], Reset)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show cards added per month
|
|
||||||
fmt.Printf("\n%sCards added over time%s\n", Green, Reset)
|
fmt.Printf("\n%sCards added over time%s\n", Green, Reset)
|
||||||
type Caot struct {
|
type Caot struct {
|
||||||
Id struct {
|
Id struct {
|
||||||
@ -180,33 +181,66 @@ var statsCmd = &cobra.Command{
|
|||||||
mapstructure.Decode(mo, moo)
|
mapstructure.Decode(mo, moo)
|
||||||
fmt.Printf("%d-%02d: %s%d%s\n", moo.Id.Year, moo.Id.Month, Purple, moo.Count, Reset)
|
fmt.Printf("%d-%02d: %s%d%s\n", moo.Id.Year, moo.Id.Month, Purple, moo.Count, Reset)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Total Value
|
|
||||||
fmt.Printf("\n%sTotal Value%s\n", Green, Reset)
|
func showManaCurveStats(coll *Collection) {
|
||||||
normalValue, err := getFloat64(stats[0]["value"])
|
cmc, _ := coll.storageAggregate(mongo.Pipeline{
|
||||||
if err != nil {
|
bson.D{
|
||||||
l.Error(err)
|
{"$group", bson.D{
|
||||||
normalValue = 0
|
{"_id", "$cmc"},
|
||||||
}
|
{"count", bson.D{{"$sum", 1}}},
|
||||||
foilValue, err := getFloat64(stats[0]["value_foil"])
|
}}},
|
||||||
if err != nil {
|
bson.D{
|
||||||
l.Error(err)
|
{"$sort", bson.D{
|
||||||
foilValue = 0
|
{"_id", 1},
|
||||||
}
|
}}},
|
||||||
count_all, err := getFloat64(stats[0]["count_all"])
|
})
|
||||||
if err != nil {
|
fmt.Printf("\n%sMana Curve%s\n", Green, Reset)
|
||||||
l.Error(err)
|
for _, mc := range cmc {
|
||||||
foilValue = 0
|
fmt.Printf("%.0f: %s%d%s\n", mc["_id"], Purple, mc["count"], 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)
|
func showArtistStats(coll *Collection) {
|
||||||
fmt.Printf("Foils: %s%.2f%s%s\n", Pink, foilValue, getCurrency(), Reset)
|
artists, _ := coll.storageAggregate(mongo.Pipeline{
|
||||||
fmt.Printf("Average Card: %s%.2f%s%s\n", Pink, totalValue/count_all, getCurrency(), Reset)
|
bson.D{
|
||||||
total, _ := totalcoll.storageFindTotal()
|
{"$group", bson.D{
|
||||||
|
{"_id", "$artist"},
|
||||||
fmt.Printf("History: \n")
|
{"count", bson.D{{"$sum", 1}}},
|
||||||
showPriceHistory(total.Value, "* ", true)
|
}}},
|
||||||
return nil
|
bson.D{
|
||||||
},
|
{"$sort", bson.D{
|
||||||
|
{"count", -1},
|
||||||
|
}}},
|
||||||
|
bson.D{
|
||||||
|
{"$limit", 10}},
|
||||||
|
})
|
||||||
|
fmt.Printf("\n%sTop Artists%s\n", Green, Reset)
|
||||||
|
for _, artist := range artists {
|
||||||
|
fmt.Printf("%s: %s%d%s\n", artist["_id"].(string), Purple, artist["count"], Reset)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func showColorStats(coll *Collection) {
|
||||||
|
sets, _ := coll.storageAggregate(mongo.Pipeline{
|
||||||
|
bson.D{
|
||||||
|
{"$match", bson.D{
|
||||||
|
{"coloridentity", bson.D{{"$size", 1}}}}}},
|
||||||
|
bson.D{
|
||||||
|
{"$group", bson.D{
|
||||||
|
{"_id", "$coloridentity"},
|
||||||
|
{"count", bson.D{{"$sum", bson.D{{"$multiply", bson.A{1.0, "$serra_count"}}}}}},
|
||||||
|
}}},
|
||||||
|
bson.D{
|
||||||
|
{"$sort", bson.D{
|
||||||
|
{"count", -1},
|
||||||
|
}}},
|
||||||
|
})
|
||||||
|
|
||||||
|
fmt.Printf("\n%sColors%s\n", Green, Reset)
|
||||||
|
for _, set := range sets {
|
||||||
|
x, _ := set["_id"].(primitive.A)
|
||||||
|
s := []interface{}(x)
|
||||||
|
fmt.Printf("%s: %s%.0f%s\n", convertManaSymbols(s), Purple, set["count"], Reset)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user