ix-cli 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/ix-json-stats +88 -0
  3. data/bin/ix-timeline +1 -1
  4. metadata +10 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15f8772d153342e10644bf937e7c51a0d56871cec2e1bdfeff7c7e35180bb171
4
- data.tar.gz: 2e1c119cbd9bdd142391d208ae805d753b1878fad963b09cb1f1c99e9b1bae6e
3
+ metadata.gz: 851dd936fd3a8e70b756a840029f054c6f8bbf4cc0e5bd4dd8f1b51f3fee30e0
4
+ data.tar.gz: c37c306492ca2cf93ce32f4dcc23d746cdc7e838a7bf73303b3592fd8f104d2d
5
5
  SHA512:
6
- metadata.gz: 1cad8247e42f9a05f021b253a26301799fe7cbd38a9e904b263f6a2f9875f714737b2a60e6d0f4ff40b3b9eaaa6190d197bb0e3aa57506c647d061b7ff60750c
7
- data.tar.gz: 9ea79a8c6fdf2031b0a163ac600569aa964205eb8d62692118ac76fee9df903d853f5c0a814eeed5cde25b54707bf69b0c90c12a1b45a25b8faba207423c7dea
6
+ metadata.gz: 3ad199f03befc45812c48b92e700aaef2c35b787eaafeb061cce9675bf88bbc7f0ebc6a69eb46e28d32878ee1eefdbf851da0289c57cfe2ef491eb04898c1eb7
7
+ data.tar.gz: 70e5e6fa0a4c17dfc6227775e3fa25150f498bbbd75211a2c6158f09d1230e422f38725c92f1129fa50479264b93502d2fb519e1c59effff118a88fca83ec871
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'json'
4
+ require 'optparse'
5
+ require 'isna'
6
+
7
+ options = {}
8
+ options[:count] = 10
9
+ options[:errors] = false
10
+
11
+ OptionParser.new do |opts|
12
+
13
+ opts.banner = "Usage: #{$0} [OPTIONS]"
14
+
15
+ opts.on('-k', '--keys [KEYS]', 'List of keys to parse from json separated by :.') do |value|
16
+ options[:keys] = value
17
+ end
18
+
19
+ opts.on('-c', '--count [NUMBER]', 'Number of top N items to show.') do |value|
20
+ options[:count] = value.to_i
21
+ end
22
+
23
+ opts.on('-e', '--errors', 'If we should report errors.') do |value|
24
+ options[:errors] = value
25
+ end
26
+
27
+ end.parse!
28
+
29
+ required_options = [:keys]
30
+ required_options.each do |option|
31
+ unless options[option]
32
+ $stderr.puts "Can not run #{option.to_s} was not given."
33
+ exit 1
34
+ end
35
+ end
36
+
37
+ map = {}
38
+ keys = options[:keys].split(':')
39
+
40
+ STDIN.each_line do |line|
41
+ begin
42
+ object = JSON.parse(line)
43
+ object.each do |k, v|
44
+ next unless keys.include?(k)
45
+ submap = map[k] ||= {}
46
+ submap[v] ||= 0
47
+ submap[v] += 1
48
+ end
49
+ rescue => error
50
+ if options[:errors]
51
+ $stderr.puts error.message
52
+ end
53
+ end
54
+ end
55
+
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
71
+ end
72
+
73
+ puts ""
74
+ puts "#{category.to_s.to_ansi.cyan.to_s} (#{total})"
75
+
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]
82
+ end
83
+
84
+ end
85
+ end
86
+
87
+ print_map(map, options[:count])
88
+
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  class Token
4
- REGEX = /(^)(\d+)(\s+)(\w+)(\s+)(.*)/
4
+ REGEX = /(^)([^ ]+)(\s+)(\w+)(\s+)(.*)/
5
5
  attr_accessor :column
6
6
  def initialize(string)
7
7
  @string = string
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ix-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuyoshi Tlacaelel
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2020-02-05 00:00:00.000000000 Z
@@ -24,8 +24,8 @@ dependencies:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.0.4
27
- description:
28
- email:
27
+ description:
28
+ email:
29
29
  executables:
30
30
  - ix
31
31
  - ix-acronym
@@ -143,6 +143,7 @@ executables:
143
143
  - ix-json-paths-pretty
144
144
  - ix-json-pp
145
145
  - ix-json-query
146
+ - ix-json-stats
146
147
  - ix-json-records-to-array
147
148
  - ix-json-remove-key
148
149
  - ix-json-replace-values
@@ -423,6 +424,7 @@ files:
423
424
  - bin/ix-json-records-to-array
424
425
  - bin/ix-json-remove-key
425
426
  - bin/ix-json-replace-values
427
+ - bin/ix-json-stats
426
428
  - bin/ix-json-template
427
429
  - bin/ix-json-to-csv
428
430
  - bin/ix-json-to-dot
@@ -576,10 +578,10 @@ files:
576
578
  - bin/ix-wrap
577
579
  - bin/ix-xy
578
580
  - bin/ix-zebra
579
- homepage:
581
+ homepage:
580
582
  licenses: []
581
583
  metadata: {}
582
- post_install_message:
584
+ post_install_message:
583
585
  rdoc_options: []
584
586
  require_paths:
585
587
  - lib
@@ -594,8 +596,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
594
596
  - !ruby/object:Gem::Version
595
597
  version: '0'
596
598
  requirements: []
597
- rubygems_version: 3.0.6
598
- signing_key:
599
+ rubygems_version: 3.1.2
600
+ signing_key:
599
601
  specification_version: 4
600
602
  summary: ix - string manipulation tools
601
603
  test_files: []