ix-cli 0.0.15 → 0.0.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18a93c4bdefb86d113639d482e2990c79d2ef522679af345af47b1ff6ed366ca
4
- data.tar.gz: 2dc28f1d95c328fe921daf120ec952b9f32f91033a393c5a8b05945e7bcd5ce9
3
+ metadata.gz: f57209fb53af43f7c975fd7fcd07103da106c5b1fd949563e5191222cf97551e
4
+ data.tar.gz: da7d25d3ded1343aa1fa471444339fac6e0b771d3ed1c22f72897b42447ac73d
5
5
  SHA512:
6
- metadata.gz: e65bd566ec921c9b34d957de086b31a8b502bb4c5a4c65d81314e1288217ae5925456a65d494c1e8e5109b1e27d9cc9af14f973950d0a11d785d6f765644b267
7
- data.tar.gz: 1431995302b4aa3106b0a703991d7318d2bc00737662b34a0241df9758393a7b6064426012b012b4e543709d8b501c75554d7d10cf759e09c709c8a18547ac95
6
+ metadata.gz: c3c890c30d399afbfab1eff7bd7efab3fbd40bae76ec1916c1e46e3f71ce33e10966783ec737d6128e7b9b5ca87edb7446b480734c8e4e7a6064cbe047d5a599
7
+ data.tar.gz: ed18e8551d241ee7af03d78a1186e34f67d7ca21d1bcca445ba95e3b94a2d6f21ea0f602ed4f9d8b2673384f3017b12f2c5562cf0949cac575cddab19baf5ca9
data/bin/ix-noansi ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ STDIN.each_line do |line|
4
+ puts line.chomp.
5
+ gsub(/\e\[\d+m/, '').
6
+ gsub(/\e\[\d+;\d+m/, '').
7
+ gsub(/\e\[\d+;\d+;\d+m/, '').
8
+ gsub(/\e\[\d+;\d+;\d+;\d+m/, '')
9
+ end
data/bin/ix-percentage CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
+ require 'isna'
5
+
4
6
  # Percentage bar.
5
7
  #
6
8
  # items = (1..100).to_a
@@ -14,7 +16,7 @@
14
16
  class Percentage
15
17
  def initialize(product, divisor, scale = 100)
16
18
  @product = product
17
- @scale = scale - 5
19
+ @scale = scale
18
20
  @pre_percentage = (divisor * @scale / product).to_f
19
21
  @percentage = (@pre_percentage * 100 / @scale)
20
22
  @divisor = divisor
@@ -29,25 +31,28 @@ class Percentage
29
31
  # 0 ~ 50 green
30
32
  # 50 ~ 80 yellow
31
33
  # 80 ~ 100 red
32
- def to_bar(color = true, bar = '|')
33
- filling = (bar * @pre_percentage.to_i)
34
- padding = 0
34
+ def to_bar(color = true, bar = '|', label = '')
35
+ bars = (bar * @pre_percentage.to_f).rjust(@scale, ' ')
35
36
  if color
36
- if to_i >= 0 and to_i < 50
37
- filling = "" + (bar * @pre_percentage.to_f) + ""
38
- end
39
- if to_i >= 50 and to_i < 80
40
- filling = "" + (bar * @pre_percentage.to_f) + ""
37
+ if to_i < 33
38
+ bars = bars.to_ansi.green.to_s
41
39
  end
42
- if to_i >= 80
43
- filling = "" + (bar * @pre_percentage.to_f) + ""
40
+ if to_i >= 33 and to_i < 66
41
+ bars = bars.to_ansi.yellow.to_s
44
42
  end
45
- if filling.size > 0
46
- padding = 13
43
+ if to_i >= 66
44
+ bars = bars.to_ansi.red.to_s
47
45
  end
48
46
  end
49
- bindings = [filling, to_f, '%', @divisor]
50
- "[%-#{@scale + padding}s%7.3f%s] %10.2f incidents for" % bindings
47
+ bindings = {
48
+ :open => '[',
49
+ :close => ']',
50
+ :bars => bars,
51
+ :percentage => (to_f.round(2).to_s.rjust(5, ' ') + '%').to_ansi.pink.to_s,
52
+ :divisor => @divisor.round(2).to_s.rjust(10, ' ').to_ansi.cyan.to_s,
53
+ :label => label
54
+ }
55
+ format("%<open>s%<bars>s%<close>s %<percentage>s %<divisor>s %<label>s", bindings)
51
56
  end
52
57
  end
53
58
 
@@ -76,13 +81,75 @@ class Array
76
81
 
77
82
  end
78
83
 
84
+ require 'optparse'
85
+ require 'json'
86
+
87
+ options = {}
88
+ options[:width] = 40
89
+ options[:label] = ''
90
+ options[:char] = '|'
91
+ options[:color] = 'yes'
92
+
93
+ OptionParser.new do |opts|
94
+
95
+ opts.banner = "Usage: #{$0} [OPTIONS]"
96
+
97
+ opts.on('-c', '--char [STRING]', 'Char to use to print the percentage bar') do |value|
98
+ options[:char] = value
99
+ end
100
+
101
+ opts.on('-w', '--width [NUMBER]', 'Chars to use to print the bar.') do |value|
102
+ options[:width] = value.to_f
103
+ end
104
+
105
+ opts.on('-l', '--label [STRING]', 'Label to use when printing out the layout.') do |value|
106
+ options[:label] = value
107
+ end
108
+
109
+ opts.on('-o', '--color [yes|no]', 'Weather if we should use ansi colors to print colors') do |value|
110
+ options[:color] = value
111
+ end
112
+
113
+
114
+ opts.on('-j', '--json', 'Will parse json keys as var names, and values as numbers') do |value|
115
+ options[:json] = value
116
+ end
117
+
118
+ end.parse!
119
+
120
+ required_options = [:width, :label, :char, :color]
121
+ required_options.each do |option|
122
+ unless options[option]
123
+ $stderr.puts "Can not run #{option.to_s} was not given."
124
+ exit 1
125
+ end
126
+ end
127
+
128
+ if options[:color] == 'yes'
129
+ options[:color] = true
130
+ else
131
+ options[:color] = false
132
+ end
133
+
134
+ if options[:width] < 1
135
+ $stderr.puts "Width can not be less than 1."
136
+ exit 1
137
+ end
79
138
 
80
139
  hash = {}
81
140
 
82
141
  STDIN.each_line do |line|
83
- chunks = line.split(/\s+/)
84
- hash[chunks[0]] ||= []
85
- hash[chunks[0]] << chunks[1].to_f
142
+ if options[:json]
143
+ line = JSON.parse(line)
144
+ line.each do |key, value|
145
+ hash[key] ||= []
146
+ hash[key] << value.to_f
147
+ end
148
+ else
149
+ chunks = line.split(/\s+/)
150
+ hash[chunks[0]] ||= []
151
+ hash[chunks[0]] << chunks[1].to_f
152
+ end
86
153
  end
87
154
 
88
155
  total = 0
@@ -91,12 +158,14 @@ hash.keys.each do |key|
91
158
  total += array.product
92
159
  end
93
160
 
94
- hash.keys.each do |key|
161
+ hash.keys.sort do |a, b|
162
+ hash[a].product <=> hash[b].product
163
+ end.reverse.each do |key|
95
164
  array = hash[key]
96
- p = Percentage.new(total, array.product, 50)
165
+ p = Percentage.new(total, array.product, options[:width])
97
166
 
98
167
  template = "%s %s"
99
- bindings = [p.to_bar, key]
168
+ bindings = [p.to_bar(options[:color], options[:char], options[:label]), key.to_ansi.yellow.to_s]
100
169
  puts template % bindings
101
170
  end
102
171
 
data/bin/ix-timestamp2 CHANGED
@@ -1,14 +1,54 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # Expects a timestamp perline
3
+ require 'json'
4
+ require 'isna'
4
5
 
5
- require 'time'
6
+ start = false
7
+ prev = false
8
+ lineno = 0
9
+ colors = true
6
10
 
7
- STDIN.each do |line|
8
- puts '=' * 80
9
- orignal_time = line.chomp
10
- parsed_time = Time.at(line.chomp.to_i)
11
- puts "#{orignal_time} => #{parsed_time}"
12
- puts ''
11
+ STDIN.each_line do |line|
12
+ begin
13
+ lineno += 1
14
+ json = JSON.parse(line)
15
+ timestamp = json['timestamp'].to_f
16
+ unless start
17
+ start = timestamp
18
+ prev = timestamp
19
+ end
20
+
21
+ object = {
22
+ :time => Time.at(timestamp).to_s.rjust(20, ' '),
23
+ :elapsed => format('%1.3f', (timestamp - start)).to_s.rjust(9, ' '),
24
+ :diff => format('%2.3f', (timestamp - prev)).to_s.rjust(9, ' '),
25
+ :lineno => (('| ') + (lineno.to_s)).ljust(5, ' '),
26
+ :message => json['message']
27
+ }
28
+
29
+ if colors
30
+ object[:time] = object[:time].to_s.to_ansi.cyan.to_s
31
+ object[:elapsed] = object[:elapsed].to_s.to_ansi.pink.to_s
32
+
33
+ if (timestamp - prev) > 1 and (timestamp - prev) < 10
34
+ object[:diff] = object[:diff].to_s.to_ansi.green.to_s
35
+ end
36
+
37
+ if (timestamp - prev) > 10 and (timestamp - prev) < 50
38
+ object[:diff] = object[:diff].to_s.to_ansi.yellow.to_s
39
+ end
40
+
41
+ if (timestamp - prev) > 50
42
+ object[:diff] = object[:diff].to_s.to_ansi.red.to_s
43
+ end
44
+
45
+ object[:lineno] = object[:lineno].to_s.to_ansi.cyan.to_s
46
+ end
47
+
48
+ puts format("%<time>s %<elapsed>s %<diff>s %<lineno>s %<message>s", object)
49
+ prev = timestamp
50
+ rescue => e
51
+ # puts e.message
52
+ end
13
53
  end
14
54
 
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.15
4
+ version: 0.0.17
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
@@ -182,6 +182,7 @@ executables:
182
182
  - ix-ncsa-date-to-timestamp
183
183
  - ix-nested-list
184
184
  - ix-nnjj
185
+ - ix-noansi
185
186
  - ix-noeol
186
187
  - ix-noise
187
188
  - ix-normalize
@@ -463,6 +464,7 @@ files:
463
464
  - bin/ix-ncsa-date-to-timestamp
464
465
  - bin/ix-nested-list
465
466
  - bin/ix-nnjj
467
+ - bin/ix-noansi
466
468
  - bin/ix-noeol
467
469
  - bin/ix-noise
468
470
  - bin/ix-normalize
@@ -584,10 +586,10 @@ files:
584
586
  - bin/ix-wrap
585
587
  - bin/ix-xy
586
588
  - bin/ix-zebra
587
- homepage:
589
+ homepage:
588
590
  licenses: []
589
591
  metadata: {}
590
- post_install_message:
592
+ post_install_message:
591
593
  rdoc_options: []
592
594
  require_paths:
593
595
  - lib
@@ -602,8 +604,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
602
604
  - !ruby/object:Gem::Version
603
605
  version: '0'
604
606
  requirements: []
605
- rubygems_version: 3.0.3
606
- signing_key:
607
+ rubygems_version: 3.3.7
608
+ signing_key:
607
609
  specification_version: 4
608
610
  summary: ix - string manipulation tools
609
611
  test_files: []