diff --git a/readme.md b/readme.md index 8a0c400..a09dd6b 100644 --- a/readme.md +++ b/readme.md @@ -43,6 +43,10 @@ Calculate value of all sets db.sets.aggregate({$match: {serra_prices: {$exists: true}}}, {$project: {name: 1, "totalValue": {$arrayElemAt: ["$serra_prices", -1]} }}, {$group: {_id: null, total: {$sum: "$totalValue.value" }}}) +Calculate what cards gained most value in percent + + db.cards.aggregate({$project: {set: 1, collectornumber:1, name: 1, "old": {$arrayElemAt: ["$serra_prices.value", -2]}, "current": {$arrayElemAt: ["$serra_prices.value", -1]} }}, {$match: {old: {$gt: 2}}} ,{$project: {name: 1,set:1,collectornumber:1,current:1, "rate": {$subtract: [{$divide: ["$current", {$divide: ["$old", 100]}]}, 100]} }}, {$sort: { rate: -1}}) + # MongoDB Operations Do a database dump diff --git a/serra.go b/serra.go index 7d70aed..0b14955 100644 --- a/serra.go +++ b/serra.go @@ -19,12 +19,14 @@ var opts struct { Sets bool `docopt:"sets"` Stats bool `docopt:"stats"` Missing bool `docopt:"missing"` + Raising bool `docopt:"raising"` Update bool `docopt:"update"` CardId []string `docopt:""` SetCode string `docopt:",--set"` Count int64 `docopt:"--count"` Sort string `docopt:"--sort"` Rarity string `docopt:"--rarity"` + Limit float64 `docopt:"--limit"` } // Main Loop @@ -37,6 +39,7 @@ Usage: serra remove ... serra cards [--rarity=] [--set=] [--sort=] serra card ... + serra raising [--limit=] serra missing serra set serra sets @@ -68,6 +71,8 @@ Options: serra.Sets() } else if opts.Missing { serra.Missing(opts.SetCode) + } else if opts.Raising { + serra.Raising(opts.Limit) } else if opts.Set { serra.ShowSet(opts.SetCode) } else if opts.Update { diff --git a/src/serra/root.go b/src/serra/root.go index 7c0e253..1c7cd37 100644 --- a/src/serra/root.go +++ b/src/serra/root.go @@ -398,6 +398,69 @@ func Update() error { return nil } +func Raising(limit float64) error { + + client := storage_connect() + coll := &Collection{client.Database("serra").Collection("cards")} + defer storage_disconnect(client) + + // db.cards.aggregate({$project: {set: 1, collectornumber:1, name: 1, "old": {$arrayElemAt: ["$serra_prices.value", -2]}, "current": {$arrayElemAt: ["$serra_prices.value", -1]} }}, {$match: {old: {$gt: 2}}} ,{$project: {name: 1,set:1,collectornumber:1,current:1, "rate": {$subtract: [{$divide: ["$current", {$divide: ["$old", 100]}]}, 100]} }}, {$sort: { rate: -1}}) + raise_pipeline := mongo.Pipeline{ + bson.D{{"$project", + bson.D{ + {"name", true}, + {"set", true}, + {"collectornumber", true}, + {"old", + bson.D{{"$arrayElemAt", + bson.A{"$serra_prices.value", -2}, + }}, + }, + {"current", + bson.D{{"$arrayElemAt", + bson.A{"$serra_prices.value", -1}, + }}, + }, + }, + }}, + bson.D{{"$match", + bson.D{{"old", bson.D{{"$gt", limit}}}}, + }}, + bson.D{{"$project", + bson.D{ + {"name", true}, + {"set", true}, + {"old", true}, + {"current", true}, + {"collectornumber", true}, + {"rate", + bson.D{{"$subtract", + bson.A{ + bson.D{{"$divide", + bson.A{"$current", + bson.D{{"$divide", + bson.A{"$old", 100}, + }}, + }, + }}, + 100, + }, + }}, + }, + }, + }}, + bson.D{{"$sort", + bson.D{{"rate", -1}}}}, + bson.D{{"$limit", 20}}, + } + raise, _ := coll.storage_aggregate(raise_pipeline) + for _, e := range raise { + fmt.Printf("%s+%.0f%%%s %s%s%s (%s/%s) (%.2f->%s%.2f EUR%s) \n", Green, e["rate"], Reset, Yellow, e["name"], Reset, e["set"], e["collectornumber"], e["old"], Green, e["current"], Reset) + } + return nil + +} + func Stats() { client := storage_connect()