Merge branch 'feature/use-cmc-as-manacurve'
This commit is contained in:
commit
d1dac680e0
@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
@ -223,48 +222,3 @@ func getFloat64(unknown interface{}) (float64, error) {
|
||||
return math.NaN(), errors.New("Non-numeric type could not be converted to float")
|
||||
}
|
||||
}
|
||||
|
||||
// Splits string by multiple occurances of substring
|
||||
// needed for calcManaCosts
|
||||
func SplitAny(s string, seps string) []string {
|
||||
splitter := func(r rune) bool {
|
||||
return strings.ContainsRune(seps, r)
|
||||
}
|
||||
return strings.FieldsFunc(s, splitter)
|
||||
}
|
||||
|
||||
// Converts mana encoding to mana costs
|
||||
//
|
||||
// calcManaCosts("{2}{B}{B}") -> 4
|
||||
// calcManaCosts("{4}{G}{G}{G}{G}") -> 7
|
||||
// calcManaCosts("{1}{U} // {3}{U}") -> 2 (ignore transform costs)
|
||||
func calcManaCosts(costs string) int {
|
||||
|
||||
var count int
|
||||
|
||||
for _, c := range SplitAny(costs, "{}") {
|
||||
if strings.Contains(c, "//") {
|
||||
break
|
||||
}
|
||||
|
||||
i, err := strconv.Atoi(c)
|
||||
if err != nil {
|
||||
count = count + 1
|
||||
} else {
|
||||
count = count + i
|
||||
}
|
||||
}
|
||||
|
||||
return count
|
||||
}
|
||||
|
||||
func printUniqueValue(arr []int) map[int]int {
|
||||
//Create a dictionary of values for each element
|
||||
dict := make(map[int]int)
|
||||
for _, num := range arr {
|
||||
dict[num] = dict[num] + 1
|
||||
}
|
||||
|
||||
return dict
|
||||
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ package serra
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
@ -129,22 +128,21 @@ var statsCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
// Mana Curve of Collection
|
||||
cards := Cards(rarity, set, sortby, name, oracle, cardType, false, foil)
|
||||
var numCosts []int
|
||||
for _, card := range cards {
|
||||
numCosts = append(numCosts, calcManaCosts(card.ManaCost))
|
||||
|
||||
}
|
||||
dist := printUniqueValue(numCosts)
|
||||
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)
|
||||
|
||||
keys := make([]int, 0, len(dist))
|
||||
for k := range dist {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Ints(keys)
|
||||
for _, k := range keys {
|
||||
fmt.Printf("%d: %s%d%s\n", k, Purple, dist[k], Reset)
|
||||
for _, mc := range cmc {
|
||||
fmt.Printf("%.0f: %s%d%s\n", mc["_id"], Purple, mc["count"], Reset)
|
||||
}
|
||||
|
||||
// Total Value
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user