ix-cli 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/ix-json-stats +57 -28
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb14cdf843c9b38f5aa771f23334ee0bb58ebcc6cd138c56ce2af5d02fbe283d
4
- data.tar.gz: b09c43e5a377df98063a481d8ccefc95ee698b5fbee9416e95e5e9b6e19eb9bf
3
+ metadata.gz: 943f1cbefd1b38913bd4291a440291b6997b9dce730e9990aacd8743f49ca24e
4
+ data.tar.gz: dff95cf081a6d4b9f319fa5b86e97f3265cd115f72137dd6bef6b3ca1167da24
5
5
  SHA512:
6
- metadata.gz: daef124c711c4365df35f28c2366c8f0cab9a3e83110eb2574ccee83298fef06637e1ba183b31a65e4b6c03a79f412cc9308f2fd0769d74d01fa2d078d48e0d1
7
- data.tar.gz: 16807bada66a3cbd525e2cdb7b5726e9b2457bb05b392dbabde129d42e6f808309c6b065a6fa1c4f72a222a55952bc551ec4a35ef51edef49bb33e29b8c37223
6
+ metadata.gz: 523fa547597c6c94e3ba4b6b36dbb076ee5e199818ac72eb97d599c5a1043a0cad0bccd089b55457db447860cc476cb04e380d43d4e9b3fd88b3050ac428a583
7
+ data.tar.gz: 93600db984ace082d9ba956228e7b543dd5766ac7da5cd4e66183009535a6000613399c1cb9bf082b7a4d34002dedbdcc0ef6b73bcd9d3c3e444d2a818dbbe22
@@ -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
- options[:keys] = value
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 = [:keys]
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
- next unless keys.include?(k)
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 print_map(map, sample)
57
- map.each do |category, stats|
58
- values = []
59
- total = 0
60
-
61
- counter = 0
62
- stats.values.sort.reverse.each do |value_1|
63
- stats.each do |key, value_2|
64
- if value_1 == value_2
65
- counter += 1
66
- break if counter > sample
67
- total += value_1
68
- values.push({ :value => value_1, :key => key })
69
- end
70
- end
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
- puts ""
74
- puts "#{category.to_s.to_ansi.cyan.to_s} (#{total})"
90
+ def get_group_objects(map)
91
+ group_objects = []
75
92
 
76
- values.each do |object|
77
- percentage = "%2.2f" % (object[:value] / total.to_f * 100)
78
- h_percentage = (percentage.to_s + '%').rjust(6, ' ').to_ansi.yellow.to_s
79
- value = object[:value].to_s.rjust(10, ' ').to_ansi.green.to_s
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, options[:count])
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])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ix-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuyoshi Tlacaelel