since option for tops/flops
This commit is contained in:
parent
d39694a072
commit
880880df8e
@ -2,6 +2,7 @@ package serra
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
@ -12,7 +13,9 @@ func init() {
|
|||||||
rootCmd.AddCommand(topsCmd)
|
rootCmd.AddCommand(topsCmd)
|
||||||
rootCmd.AddCommand(flopsCmd)
|
rootCmd.AddCommand(flopsCmd)
|
||||||
topsCmd.Flags().Float64VarP(&limit, "limit", "l", 0, "Minimum card price to be shown in analysis")
|
topsCmd.Flags().Float64VarP(&limit, "limit", "l", 0, "Minimum card price to be shown in analysis")
|
||||||
|
topsCmd.Flags().StringVarP(&since, "since", "s", "0", "Since when should the gains be calculated")
|
||||||
flopsCmd.Flags().Float64VarP(&limit, "limit", "l", 0, "Minimum card price to be shown in analysis")
|
flopsCmd.Flags().Float64VarP(&limit, "limit", "l", 0, "Minimum card price to be shown in analysis")
|
||||||
|
flopsCmd.Flags().StringVarP(&since, "since", "s", "0", "Since when should the losses be calculated")
|
||||||
}
|
}
|
||||||
|
|
||||||
var topsCmd = &cobra.Command{
|
var topsCmd = &cobra.Command{
|
||||||
@ -21,7 +24,7 @@ var topsCmd = &cobra.Command{
|
|||||||
Short: "What cards gained most value",
|
Short: "What cards gained most value",
|
||||||
SilenceErrors: true,
|
SilenceErrors: true,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
Gains(limit, -1)
|
Gains(limit, -1, since)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -32,18 +35,20 @@ var flopsCmd = &cobra.Command{
|
|||||||
Short: "What cards lost most value",
|
Short: "What cards lost most value",
|
||||||
SilenceErrors: true,
|
SilenceErrors: true,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
Gains(limit, 1)
|
Gains(limit, 1, since)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func Gains(limit float64, sort int) error {
|
func Gains(limit float64, sort int, since string) error {
|
||||||
|
|
||||||
client := storage_connect()
|
client := storage_connect()
|
||||||
coll := &Collection{client.Database("serra").Collection("cards")}
|
coll := &Collection{client.Database("serra").Collection("cards")}
|
||||||
setcoll := &Collection{client.Database("serra").Collection("sets")}
|
setcoll := &Collection{client.Database("serra").Collection("sets")}
|
||||||
defer storage_disconnect(client)
|
defer storage_disconnect(client)
|
||||||
|
|
||||||
|
old, _ := strconv.Atoi(since)
|
||||||
|
|
||||||
raise_pipeline := mongo.Pipeline{
|
raise_pipeline := mongo.Pipeline{
|
||||||
bson.D{{"$project",
|
bson.D{{"$project",
|
||||||
bson.D{
|
bson.D{
|
||||||
@ -52,7 +57,7 @@ func Gains(limit float64, sort int) error {
|
|||||||
{"collectornumber", true},
|
{"collectornumber", true},
|
||||||
{"old",
|
{"old",
|
||||||
bson.D{{"$arrayElemAt",
|
bson.D{{"$arrayElemAt",
|
||||||
bson.A{"$serra_prices.value", 0},
|
bson.A{"$serra_prices.value", old},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
{"current",
|
{"current",
|
||||||
@ -101,7 +106,7 @@ func Gains(limit float64, sort int) error {
|
|||||||
{"code", true},
|
{"code", true},
|
||||||
{"old",
|
{"old",
|
||||||
bson.D{{"$arrayElemAt",
|
bson.D{{"$arrayElemAt",
|
||||||
bson.A{"$serra_prices.value", 0},
|
bson.A{"$serra_prices.value", old},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
{"current",
|
{"current",
|
||||||
|
|||||||
@ -11,6 +11,7 @@ var Version = "unknown"
|
|||||||
var count int64
|
var count int64
|
||||||
var limit float64
|
var limit float64
|
||||||
var name string
|
var name string
|
||||||
|
var since string
|
||||||
var rarity, set, sort string
|
var rarity, set, sort string
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user