ix-cli 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/ix-json-stats +57 -28
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 943f1cbefd1b38913bd4291a440291b6997b9dce730e9990aacd8743f49ca24e
|
4
|
+
data.tar.gz: dff95cf081a6d4b9f319fa5b86e97f3265cd115f72137dd6bef6b3ca1167da24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 523fa547597c6c94e3ba4b6b36dbb076ee5e199818ac72eb97d599c5a1043a0cad0bccd089b55457db447860cc476cb04e380d43d4e9b3fd88b3050ac428a583
|
7
|
+
data.tar.gz: 93600db984ace082d9ba956228e7b543dd5766ac7da5cd4e66183009535a6000613399c1cb9bf082b7a4d34002dedbdcc0ef6b73bcd9d3c3e444d2a818dbbe22
|
data/bin/ix-json-stats
CHANGED
@@ -13,7 +13,12 @@ OptionParser.new do |opts|
|
|
13
13
|
opts.banner = "Usage: #{$0} [OPTIONS]"
|
14
14
|
|
15
15
|
opts.on('-k', '--keys [KEYS]', 'List of keys to parse from json separated by :.') do |value|
|
16
|
-
|
16
|
+
unless value
|
17
|
+
$stderr.puts "Please provide valid --keys got: #{value.inspect}"
|
18
|
+
STDIN.each_line {}
|
19
|
+
exit 1
|
20
|
+
end
|
21
|
+
options[:keys] = value.split(':')
|
17
22
|
end
|
18
23
|
|
19
24
|
opts.on('-c', '--count [NUMBER]', 'Number of top N items to show.') do |value|
|
@@ -26,7 +31,7 @@ OptionParser.new do |opts|
|
|
26
31
|
|
27
32
|
end.parse!
|
28
33
|
|
29
|
-
required_options = [
|
34
|
+
required_options = []
|
30
35
|
required_options.each do |option|
|
31
36
|
unless options[option]
|
32
37
|
$stderr.puts "Can not run #{option.to_s} was not given."
|
@@ -35,13 +40,17 @@ required_options.each do |option|
|
|
35
40
|
end
|
36
41
|
|
37
42
|
map = {}
|
38
|
-
keys = options[:keys].split(':')
|
39
43
|
|
40
44
|
STDIN.each_line do |line|
|
41
45
|
begin
|
42
46
|
object = JSON.parse(line)
|
47
|
+
unless options[:keys]
|
48
|
+
options[:keys] == object.keys
|
49
|
+
end
|
43
50
|
object.each do |k, v|
|
44
|
-
|
51
|
+
if options[:keys]
|
52
|
+
next unless options[:keys].include?(k)
|
53
|
+
end
|
45
54
|
submap = map[k] ||= {}
|
46
55
|
submap[v] ||= 0
|
47
56
|
submap[v] += 1
|
@@ -53,36 +62,56 @@ STDIN.each_line do |line|
|
|
53
62
|
end
|
54
63
|
end
|
55
64
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
65
|
+
def print_value(result, total)
|
66
|
+
percentage = "%2.2f" % (result[:incidents] / total.to_f * 100)
|
67
|
+
h_percentage = (percentage.to_s + '%').rjust(6, ' ').to_ansi.yellow.to_s
|
68
|
+
value = result[:incidents].to_s.rjust(10, ' ').to_ansi.green.to_s
|
69
|
+
key = result[:label]
|
70
|
+
puts "%s %s %s" % [value, h_percentage, key]
|
71
|
+
end
|
72
|
+
|
73
|
+
class GroupObject
|
74
|
+
attr_accessor :category
|
75
|
+
attr_accessor :results
|
76
|
+
def initialize(category)
|
77
|
+
@category = category
|
78
|
+
@results = []
|
79
|
+
end
|
80
|
+
def add_result(label, incidents)
|
81
|
+
@results.push({ :label => label, :incidents => incidents })
|
82
|
+
end
|
83
|
+
def total
|
84
|
+
results.sum do |result|
|
85
|
+
result[:incidents]
|
71
86
|
end
|
87
|
+
end
|
88
|
+
end
|
72
89
|
|
73
|
-
|
74
|
-
|
90
|
+
def get_group_objects(map)
|
91
|
+
group_objects = []
|
75
92
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
key = object[:key]
|
81
|
-
puts "%s %s %s" % [value, h_percentage, key]
|
93
|
+
map.each do |category, hash|
|
94
|
+
group_object = GroupObject.new(category)
|
95
|
+
hash.each do |k, v|
|
96
|
+
group_object.add_result(k, v)
|
82
97
|
end
|
98
|
+
group_objects.push(group_object)
|
99
|
+
end
|
83
100
|
|
101
|
+
group_objects.sort do |a, b|
|
102
|
+
a.category <=> b.category
|
84
103
|
end
|
85
104
|
end
|
86
105
|
|
87
|
-
print_map(map,
|
106
|
+
def print_map(map, sample)
|
107
|
+
get_group_objects(map).each do |group_object|
|
108
|
+
puts "\n#{group_object.category.to_s.to_ansi.cyan.to_s} (#{group_object.total})"
|
109
|
+
group_object.results.sort do |a, b|
|
110
|
+
a[:incidents] <=> b[:incidents]
|
111
|
+
end.reverse.first(sample).each do |result|
|
112
|
+
print_value(result, group_object.total)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
88
116
|
|
117
|
+
print_map(map, options[:count])
|