ix-cli 0.0.2 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 274579108c642bf99aee760136a22d4e7155f1f9de8da3f3a3cc6bd0be9586d6
4
- data.tar.gz: 07a9faea67eb7857f430935c114dd234e86461836dec52657147e68f471cb515
3
+ metadata.gz: 43ba4c089dae9199af259e9f02a035744e7420962a118d853e0e676d2a5dd599
4
+ data.tar.gz: 17d6460e0f39932ec59f1011638deb3df787239106bfac6616ab7355af18f9f7
5
5
  SHA512:
6
- metadata.gz: c64015e5b8ff7a1182f252dbd2a45b7d81786e258447b486af89409cc3bb1bc614fc5fdccb4bad284170685474bcdcae127013bb62f5dc371ca75491ce689a76
7
- data.tar.gz: 3d110e333880291c13048a796d2e35db3c8d0313399a3ee69d60832334ca690bfe70c77f9d4960fa6892670c171f84a1a39f0b48f7b86b8325d7e3bc96ce8c8c
6
+ metadata.gz: 57bc28846bb606f482574a62e5a6b338b1f988ca9b6350929b71849732dec880e9a57f1d1649189cd802a9359a5a8ebe9ac27f080aef42fe62ceb3b448cfe679
7
+ data.tar.gz: 47f05a70186b648cff3277a8cfb2a6df62e5949fe2053d0108ec8d2555e57576d55e1c5fa802236273daeb6093752e8be12c872d3ffcc7d3c36de9e42aaaacca
data/bin/ix-cat CHANGED
@@ -1,7 +1,7 @@
1
- #!/usr/bin/env bash
1
+ #!/usr/bin/env ruby
2
2
 
3
- application=$1
4
- target_path=`dirname $0`
5
- target_file="$target_path/ix-$application"
3
+ application = ARGV[0]
4
+ target_path = File.dirname(__FILE__)
5
+ target_file = "#{target_path}/ix-#{application}"
6
6
 
7
- cat $target_file
7
+ system "cat #{target_file}"
@@ -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
+
data/bin/ix-rps CHANGED
@@ -10,7 +10,6 @@ end
10
10
  trap('QUIT', &shutdown)
11
11
  trap('INT', &shutdown)
12
12
  trap('TERM', &shutdown)
13
- trap('KILL', &shutdown)
14
13
 
15
14
  total_requests = 0
16
15
  requests_per_second = 0
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ options = {}
6
+
7
+ OptionParser.new do |opts|
8
+
9
+ opts.banner = "Usage: #{$0} [OPTIONS]"
10
+
11
+ opts.on('-m', '--min-sigma [min]', 'Min sigma.') do |value|
12
+ options[:min_sigma] = value.gsub(/\\/, '').to_f
13
+ end
14
+
15
+ opts.on('-a', '--max-sigma [max]', 'Max sigma.') do |value|
16
+ options[:max_sigma] = value.gsub(/\\/, '').to_f
17
+ end
18
+
19
+ opts.on('-c', '--column [max]', 'Col to be parsed.') do |value|
20
+ options[:column] = value.to_i
21
+ end
22
+
23
+ opts.on('-k', '--kdev [max]', 'kdev.') do |value|
24
+ options[:kdev] = value.to_i
25
+ end
26
+
27
+ end.parse!
28
+
29
+ required_options = [:min_sigma, :max_sigma, :column, :kdev]
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
+ class Array
38
+ def mean
39
+ product / size
40
+ end
41
+
42
+ def product
43
+ sum
44
+ end
45
+ def sum_of_squares(avg = nil)
46
+ avg = mean unless avg
47
+ sqares = map do |number|
48
+ result = number - avg
49
+ result ** 2
50
+ end
51
+ sqares.sum
52
+ end
53
+
54
+ def variance(minus = 0)
55
+ sum_of_squares / (size - minus)
56
+ end
57
+
58
+ def standard_deviation
59
+ Math.sqrt(variance(1.5))
60
+ end
61
+
62
+ def population_standard_deviation
63
+ Math.sqrt(variance(0))
64
+ end
65
+
66
+ def median
67
+ return size[0] if size == 1
68
+ self[(size + 1) / 2]
69
+ end
70
+
71
+ def sample_standard_deviation
72
+ med = median
73
+ sqr = map do |number|
74
+ result = number - med
75
+ result ** 2
76
+ end
77
+ Math.sqrt(sqr.mean)
78
+ end
79
+
80
+ def sum
81
+ inject do |cumulative, value|
82
+ cumulative += value
83
+ end
84
+ end
85
+
86
+ end
87
+
88
+ data = []
89
+
90
+ STDIN.each_line do |line|
91
+ line.chomp!
92
+ index = options[:column]
93
+ item = line.split(' ')[index - 1]
94
+ data.push({ :number => item.to_f, :line => line })
95
+ end
96
+
97
+ numbers = data.map do |object|
98
+ object[:number]
99
+ end
100
+
101
+ options[:standard_deviation] = numbers.standard_deviation
102
+ options[:min_deviation_from_mean] = (options[:min_sigma] * options[:standard_deviation] + numbers.mean)
103
+ options[:max_deviation_from_mean] = (options[:max_sigma] * options[:standard_deviation] + numbers.mean)
104
+
105
+ data.each do |object|
106
+
107
+ smaller_than_max = (object[:number] > options[:min_deviation_from_mean])
108
+ bigger_than_min = (object[:number] < options[:max_deviation_from_mean])
109
+
110
+ # $stderr.puts [
111
+ # smaller_than_max,
112
+ # object[:number],
113
+ # bigger_than_min,
114
+ # options[:min_deviation_from_mean],
115
+ # options[:max_deviation_from_mean]
116
+ # ].map { |x| x.inspect } * ' '
117
+
118
+
119
+ if smaller_than_max && bigger_than_min
120
+ puts object[:line]
121
+ end
122
+ end
123
+
124
+ def pretty_options(hash, width = 20)
125
+ r = ''
126
+ hash.keys.sort.each do |key|
127
+ k = key.to_s.ljust(width, '.')
128
+ v = hash[key].to_s.rjust(width, '.')
129
+ r << [k, v] * ' ' + "\n"
130
+ end
131
+ r
132
+ end
133
+
134
+ # $stderr.puts pretty_options(options)
135
+
@@ -0,0 +1,241 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ class Token
4
+ REGEX = /(^)([^ ]+)(\s+)(\w+)(\s+)(.*)/
5
+ attr_accessor :column
6
+ def initialize(string)
7
+ @string = string
8
+ @valid = (@string =~ REGEX)
9
+ @parts = @string.scan(REGEX)[0]
10
+ end
11
+ def valid?
12
+ @valid
13
+ end
14
+ def timestamp
15
+ @parts[1].to_i
16
+ end
17
+ def variable
18
+ @parts[3]
19
+ end
20
+ def value
21
+ @parts[5].to_f
22
+ end
23
+ def to_h
24
+ {
25
+ :timestamp => timestamp,
26
+ :variable => variable,
27
+ :value => value
28
+ }
29
+ end
30
+ end
31
+
32
+ # title
33
+ # y_label
34
+ # x_label
35
+ # output
36
+ # graph_width
37
+ # graph_height
38
+ # debug
39
+
40
+ require 'isna'
41
+ require 'optparse'
42
+
43
+ options = {}
44
+
45
+ options[:title] = 'title'
46
+ options[:y_label] = 'y'
47
+ options[:x_label] = 'x'
48
+ options[:output] = 'output'
49
+ options[:graph_width] = 800
50
+ options[:graph_height] = 600
51
+ options[:debug] = false
52
+
53
+ OptionParser.new do |opts|
54
+
55
+ basename = File.basename($0).to_ansi.green.to_s
56
+ options_hint = "[OPTIONS]".to_ansi.blink.red.to_s
57
+ opts.banner = "Usage: #{basename} #{options_hint}"
58
+
59
+ opts.on('-t', '--title [TITLE]', 'Title.') do |value|
60
+ options[:title] = value
61
+ end
62
+
63
+ opts.on('-y', '--y-label [Y_LABEL]', 'Y label.') do |value|
64
+ options[:y_label] = value
65
+ end
66
+
67
+ opts.on('-x', '--x-label [X_LABEL]', 'X label.') do |value|
68
+ options[:x_label] = value
69
+ end
70
+
71
+ opts.on('-o', '--output [OUTPUT]', 'Output.') do |value|
72
+ options[:output] = value
73
+ end
74
+
75
+ opts.on('-g', '--graph-width [GRAPH_WIDTH]', 'Graph width.') do |value|
76
+ options[:graph_width] = value
77
+ end
78
+
79
+ opts.on('-r', '--graph-height [GRAPH_HEIGHT]', 'Graph height.') do |value|
80
+ options[:graph_height] = value
81
+ end
82
+
83
+ opts.on('-d', '--debug [DEBUG]', 'Debug.') do |value|
84
+ options[:debug] = value
85
+ end
86
+
87
+
88
+ end.parse!
89
+
90
+ required_options = [
91
+ :title,
92
+ :y_label,
93
+ :x_label,
94
+ :output,
95
+ :graph_width,
96
+ :graph_height,
97
+ ]
98
+ required_options.each do |option|
99
+ unless options[option]
100
+ $stderr.puts "Can not run #{option.to_s.to_ansi.red.to_s} was not given."
101
+ exit 1
102
+ end
103
+ end
104
+
105
+ def pretty_options(hash, width = 20)
106
+ r = ''
107
+ hash.keys.sort.each do |key|
108
+ k = key.to_s.ljust(width, '.')
109
+ v = hash[key].to_s.rjust(width, '.')
110
+ r << [k, v] * ' ' + "\n"
111
+ end
112
+ r
113
+ end
114
+ puts pretty_options(options)
115
+
116
+
117
+ tokens = []
118
+
119
+ # timestamp name value
120
+ STDIN.each_line do |line|
121
+ token = Token.new(line)
122
+ next unless token.valid?
123
+ tokens.push(token)
124
+ end
125
+
126
+ variables = tokens.map { |token| token.variable }
127
+ variable_map = {}
128
+ variables.uniq.each_with_index do |variable, index|
129
+ variable_map[index + 1] = variable
130
+ end
131
+ puts variable_map.inspect
132
+ tokens.each do |token|
133
+ variable_map.each do |column, variable|
134
+ if token.variable == variable
135
+ token.column = column
136
+ end
137
+ end
138
+ end
139
+
140
+ token_timestamp_map = {}
141
+ tokens.each do |token|
142
+ token_timestamp_map[token.timestamp] ||= []
143
+ token_timestamp_map[token.timestamp].push(token)
144
+ end
145
+
146
+ # generate gnuplot data format
147
+ require 'time'
148
+ class Integer
149
+ def to_gnuplot_date
150
+ Time.at(self).strftime "%d/%m/%Y %H:%M:%S"
151
+ end
152
+ end
153
+
154
+ require 'tmpdir'
155
+ Dir.mktmpdir do |dir|
156
+ # create data file
157
+
158
+ data_file = "#{dir}/data.file"
159
+
160
+ File.open(data_file, 'w+') do |file|
161
+ token_timestamp_map.each do |timestamp, tokens|
162
+ elements = []
163
+ elements.push(timestamp.to_gnuplot_date)
164
+
165
+ min_column = 1
166
+ max_column = tokens.map { |t| t.column }.max
167
+ unexistant_columns = (min_column..max_column).to_a - tokens.map { |t| t.column }
168
+
169
+ unexistant_columns.each_with_index do |column, index|
170
+ unless (tokens.map { |t| t.column }).include?(column)
171
+ if column < (tokens.max { |t| t.column }.column)
172
+ elements.push(0)
173
+ end
174
+ end
175
+ end
176
+
177
+ tokens.sort do |token|
178
+ token.column
179
+ end.reverse.map do |token|
180
+ token.value
181
+ end.each do |value|
182
+ elements.push(value)
183
+ end
184
+
185
+ unexistant_columns.each_with_index do |column, index|
186
+ unless (tokens.map { |t| t.column }).include?(column)
187
+ if column > (tokens.max { |t| t.column }.column)
188
+ elements.push(0)
189
+ end
190
+ end
191
+ end
192
+
193
+ file.puts (elements * ' ')
194
+ end
195
+ end
196
+
197
+ # puts "cat #{data_file}"
198
+ # system "cat #{data_file}"
199
+
200
+ script_file = "#{dir}/script.file"
201
+
202
+ File.open(script_file, 'w+') do |file|
203
+ file.puts '#!/usr/bin/env gnuplot'
204
+ file.puts "set term png transparent truecolor size #{options[:graph_width]},#{options[:graph_height]}"
205
+
206
+ file.puts 'set output ' + (options[:output] + '.png').inspect
207
+
208
+ file.puts 'set tics textcolor rgb "gray"'
209
+ file.puts 'set xlabel textcolor rgb "gray"'
210
+ file.puts 'set ylabel textcolor rgb "gray"'
211
+ file.puts 'set border 1 front lc rgb "gray"'
212
+
213
+ file.puts 'set xdata time'
214
+ file.puts 'set timefmt "%d/%m/%Y %H:%M:%S"'
215
+ file.puts 'set format x "%d/%m/%Y %H:%M:%S"'
216
+ file.puts 'set xtics rotate by 345'
217
+ file.puts 'set xlabel ' + options[:x_label].inspect + ' textcolor rgb "gray"'
218
+ file.puts 'set ylabel ' + options[:y_label].inspect + ' textcolor rgb "gray"'
219
+ file.puts 'set title ' + options[:title].inspect + ' textcolor rgb "gray"'
220
+ file.puts 'set key reverse Left outside' + ' textcolor rgb "gray"'
221
+ file.puts 'set grid'
222
+ # file.puts 'set style data linespoints'
223
+ file.puts 'set style data points'
224
+
225
+ file.puts 'set timestamp' + ' textcolor rgb "gray"'
226
+ # file.puts "stats '#{data_file}'"
227
+
228
+ vars = []
229
+ variable_map.each do |column, variable|
230
+ vars.push("\"#{data_file}\" using 1:#{column + 2} title #{variable.inspect} with points")
231
+ end
232
+
233
+ file.puts "plot #{vars.join(', \\' + "\n")}"
234
+
235
+ end
236
+
237
+ # puts "cat #{script_file}"
238
+ # system "cat #{script_file}"
239
+
240
+ system "gnuplot #{script_file}"
241
+ end
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.2
4
+ version: 0.0.7
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
@@ -238,6 +239,7 @@ executables:
238
239
  - ix-show-tabs
239
240
  - ix-show-trailing-spaces
240
241
  - ix-shuffle
242
+ - ix-sigma-grep
241
243
  - ix-signature
242
244
  - ix-size
243
245
  - ix-slider
@@ -269,6 +271,7 @@ executables:
269
271
  - ix-text-to-morse
270
272
  - ix-tick
271
273
  - ix-time
274
+ - ix-timeline
272
275
  - ix-times
273
276
  - ix-timestamp
274
277
  - ix-timestamp-sort
@@ -421,6 +424,7 @@ files:
421
424
  - bin/ix-json-records-to-array
422
425
  - bin/ix-json-remove-key
423
426
  - bin/ix-json-replace-values
427
+ - bin/ix-json-stats
424
428
  - bin/ix-json-template
425
429
  - bin/ix-json-to-csv
426
430
  - bin/ix-json-to-dot
@@ -513,6 +517,7 @@ files:
513
517
  - bin/ix-show-tabs
514
518
  - bin/ix-show-trailing-spaces
515
519
  - bin/ix-shuffle
520
+ - bin/ix-sigma-grep
516
521
  - bin/ix-signature
517
522
  - bin/ix-size
518
523
  - bin/ix-slider
@@ -544,6 +549,7 @@ files:
544
549
  - bin/ix-text-to-morse
545
550
  - bin/ix-tick
546
551
  - bin/ix-time
552
+ - bin/ix-timeline
547
553
  - bin/ix-times
548
554
  - bin/ix-timestamp
549
555
  - bin/ix-timestamp-sort
@@ -572,10 +578,10 @@ files:
572
578
  - bin/ix-wrap
573
579
  - bin/ix-xy
574
580
  - bin/ix-zebra
575
- homepage:
581
+ homepage:
576
582
  licenses: []
577
583
  metadata: {}
578
- post_install_message:
584
+ post_install_message:
579
585
  rdoc_options: []
580
586
  require_paths:
581
587
  - lib
@@ -590,8 +596,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
590
596
  - !ruby/object:Gem::Version
591
597
  version: '0'
592
598
  requirements: []
593
- rubygems_version: 3.0.6
594
- signing_key:
599
+ rubygems_version: 3.1.2
600
+ signing_key:
595
601
  specification_version: 4
596
602
  summary: ix - string manipulation tools
597
603
  test_files: []