-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathcattributes.rb
79 lines (51 loc) · 1.6 KB
/
cattributes.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require 'json'
require 'pp'
cattribute_totals = JSON.parse( File.read( './datasets/cattributes.json' ))
pp cattribute_totals
########################
## group by trait type
trait_types = {}
cattribute_totals.each do |h|
key = h['type'].to_sym
rec = trait_types[ key ] ||= [0,[]]
rec[ 0 ] += h['total'].to_i ## sum up totals
rec[ 1 ] << [h['description'], h['total'].to_i]
end
pp trait_types
require 'copycats'
buf = ""
buf << "# Cattributes Rarity / Popularity Statistics\n"
buf << "\n"
buf < "(Source: [`api.cryptokitties.co/cattributes` (JSON)](https://api.cryptokitties.co/cattributes))\n"
buf << "\n\n"
# quick hack - map copycats keys to (internal) cryptokitties trait type keys
# note: all keys are the same except:
TRAIT_TYPE_MAPPINGS =
{
:color1 => :colorprimary,
:color2 => :colorsecondary,
:color3 => :colortertiary
}
TRAITS.each do |key,h|
next if key == :secret ## skip secret (y gene) trait for now
key = TRAIT_TYPE_MAPPINGS[ key ] if TRAIT_TYPE_MAPPINGS[ key ]
rec = trait_types[ key ]
total = rec[0]
items = rec[1]
buf << "## #{h[:name]} (#{h[:code]})\n\n"
buf << "_#{total} Cats with #{items.size} Cattributes_\n\n"
buf << "| #|Total (%)|Cattribute|\n"
buf << "|-:|--------:|----------|\n"
# note: use reverse to order from most rare to most popular
items.reverse.each_with_index do |item,i|
name = item[0]
count = item[1]
rank = "#{i+1}/#{items.size}"
percent = Float(100*count)/Float(total)
buf << "| #{rank} | #{count} (#{('%2.2f' % percent)}) | "
buf << "**#{name}** |"
buf << "\n"
end
buf << "\n\n"
end
puts buf