ix-cli 0.0.1 → 0.0.6
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-hypothesis +11 -6
- data/bin/ix-json-stats +88 -0
- data/bin/ix-rps +0 -1
- data/bin/ix-sigma-grep +135 -0
- data/bin/ix-timeline +241 -0
- data/bin/ix-xy +104 -30
- metadata +14 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dae9bc89f4291cfa7e06e18d9b154995746502273999407a9ec61260f58c94f8
|
4
|
+
data.tar.gz: 2e6868c9b9adb7808264c72d9d9dc5c1f93981427a662c7efdc9aeaa015bab9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c371b7203b29f4efefae471e95adf1c1ee70cd1fdb0e071ba643438e629beb4291795b0b694e389dde7050dd28ae0e185fb5929cc950c50c32b51abbfe906b0b
|
7
|
+
data.tar.gz: 6f79d94140316047b0b0d9872f1b1b170b5a9a510482a2b3a921d64c50a2084b8e67faaafba5d2059d39f4316d6aca9b2b7dad86dfa41da38458759d0238d683
|
data/bin/ix-hypothesis
CHANGED
@@ -135,6 +135,15 @@ class Array
|
|
135
135
|
|
136
136
|
def to_bell(text, standard_deviations_to_show = 3, base = :population, kazu_dev = 1, percentage_scale, hide)
|
137
137
|
|
138
|
+
if uniq.size == 1
|
139
|
+
the_variable = text.to_ansi.red.to_s
|
140
|
+
the_value = uniq.first.to_s.to_ansi.green.to_s
|
141
|
+
puts ''
|
142
|
+
puts "# All values of #{the_variable} where found to have the value of #{the_value}"
|
143
|
+
puts '-' * 80
|
144
|
+
return
|
145
|
+
end
|
146
|
+
|
138
147
|
if base == :population
|
139
148
|
sigma = population_standard_deviation
|
140
149
|
end
|
@@ -186,7 +195,7 @@ class Array
|
|
186
195
|
((groups[sigma] ? groups[sigma].size : 0.0) / total.to_f) * 100
|
187
196
|
end.max
|
188
197
|
|
189
|
-
puts [the_min, the_max].inspect
|
198
|
+
# puts [the_min, the_max].inspect
|
190
199
|
|
191
200
|
sigmas_copy.each_with_index do |sigma, index|
|
192
201
|
|
@@ -218,8 +227,6 @@ class Array
|
|
218
227
|
|
219
228
|
bell_line << ("%6.2f%% " % [(size.to_f / total.to_f) * 100]).to_s
|
220
229
|
|
221
|
-
# puts groups[sigma].inspect
|
222
|
-
|
223
230
|
bn = [
|
224
231
|
the_min,
|
225
232
|
(size.to_f / total.to_f) * 100,
|
@@ -231,11 +238,9 @@ class Array
|
|
231
238
|
percentage_scale
|
232
239
|
)
|
233
240
|
|
234
|
-
# bell_line << Percentage.new(total, size, percentage_scale).to_bar
|
235
|
-
|
236
241
|
case (std_dev_ruler).to_f
|
237
242
|
when 0.000
|
238
|
-
|
243
|
+
bell_line << '|' + ('|' * an[1]).to_s.to_ansi.pink.to_s
|
239
244
|
when 0..1
|
240
245
|
bell_line << '|' + ('|' * an[1]).to_s.to_ansi.green.to_s
|
241
246
|
when -1..0
|
data/bin/ix-json-stats
ADDED
@@ -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
data/bin/ix-sigma-grep
ADDED
@@ -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
|
+
|
data/bin/ix-timeline
ADDED
@@ -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
|
data/bin/ix-xy
CHANGED
@@ -1,54 +1,122 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'tmpdir'
|
4
|
+
require 'isna'
|
4
5
|
require 'optparse'
|
5
6
|
|
6
7
|
options = {}
|
8
|
+
options[:title] = 'title'
|
9
|
+
options[:x_label] = 'x'
|
10
|
+
options[:y_label] = 'y'
|
11
|
+
options[:graph_width] = 800
|
12
|
+
options[:graph_height] = 600
|
13
|
+
options[:output] = 'output'
|
14
|
+
|
15
|
+
# option[title] = 'default value'
|
16
|
+
# option[y_label] = 'default value'
|
17
|
+
# option[x_label] = 'default value'
|
18
|
+
# options[:x_max] = 0
|
19
|
+
# options[:x_min] = 0
|
20
|
+
# options[:y_max] = 0
|
21
|
+
# options[:y_min] = 0
|
22
|
+
# option[graph_width] = 'default value'
|
23
|
+
# option[graph_height] = 'default value'
|
24
|
+
# option[output] = 'default value'
|
7
25
|
|
8
26
|
OptionParser.new do |opts|
|
9
27
|
|
10
|
-
|
11
|
-
|
28
|
+
basename = File.basename($0).to_ansi.green.to_s
|
29
|
+
options_hint = "[OPTIONS]".to_ansi.blink.red.to_s
|
30
|
+
opts.banner = "Usage: #{basename} #{options_hint}"
|
12
31
|
|
13
|
-
|
14
|
-
|
32
|
+
opts.on('-t', '--title [TITLE]', 'Title.') do |value|
|
33
|
+
options[:title] = value
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on('-y', '--y-label [TEXT]', 'Y label.') do |value|
|
37
|
+
options[:y_label] = value
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.on('-x', '--x-label [TEXT]', 'X label.') do |value|
|
41
|
+
options[:x_label] = value
|
42
|
+
end
|
15
43
|
|
16
|
-
|
17
|
-
|
44
|
+
opts.on('-m', '--x-max [NUMBER]', 'X max.') do |value|
|
45
|
+
options[:x_max] = value
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on('-i', '--x-min [NUMBER]', 'X min.') do |value|
|
49
|
+
options[:x_min] = value
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on('-a', '--y-max [NUMBER]', 'Y max.') do |value|
|
53
|
+
options[:y_max] = value
|
54
|
+
end
|
18
55
|
|
19
|
-
opts.on(
|
20
|
-
options[:
|
56
|
+
opts.on('-n', '--y-min [NUMBER]', 'Y min.') do |value|
|
57
|
+
options[:y_min] = value
|
21
58
|
end
|
22
59
|
|
23
|
-
opts.on(
|
24
|
-
options[:
|
60
|
+
opts.on('-g', '--graph-width [NUMBER]', 'Graph width.') do |value|
|
61
|
+
options[:graph_width] = value
|
25
62
|
end
|
26
63
|
|
27
|
-
opts.on(
|
28
|
-
options[:
|
64
|
+
opts.on('-r', '--graph-height [NUMBER]', 'Graph height.') do |value|
|
65
|
+
options[:graph_height] = value
|
29
66
|
end
|
30
67
|
|
31
|
-
opts.on(
|
32
|
-
options[:output] =
|
68
|
+
opts.on('-o', '--output [SNAKE]', 'Output.') do |value|
|
69
|
+
options[:output] = value
|
70
|
+
end
|
71
|
+
|
72
|
+
opts.on('-s', '--stats', 'Stats.') do |value|
|
73
|
+
options[:stats] = value
|
33
74
|
end
|
34
75
|
|
35
76
|
end.parse!
|
36
77
|
|
37
|
-
|
38
|
-
|
78
|
+
required_options = [
|
79
|
+
:title,
|
80
|
+
:y_label,
|
81
|
+
:x_label,
|
82
|
+
:graph_width,
|
83
|
+
:graph_height,
|
84
|
+
:output,
|
85
|
+
]
|
86
|
+
|
87
|
+
ranges = [
|
88
|
+
:x_max,
|
89
|
+
:x_min,
|
90
|
+
:y_max,
|
91
|
+
:y_min,
|
92
|
+
]
|
93
|
+
|
94
|
+
need_ranges = ranges.any? { |k| options[k] }
|
95
|
+
|
96
|
+
if need_ranges
|
97
|
+
ranges.each do |r|
|
98
|
+
required_options.push(r)
|
99
|
+
end
|
39
100
|
end
|
40
101
|
|
41
|
-
|
42
|
-
options[
|
102
|
+
required_options.each do |option|
|
103
|
+
unless options[option]
|
104
|
+
$stderr.puts "Can not run #{option.to_s.to_ansi.red.to_s} was not given."
|
105
|
+
exit 1
|
106
|
+
end
|
43
107
|
end
|
44
108
|
|
45
|
-
|
46
|
-
|
109
|
+
def pretty_options(hash, width = 20)
|
110
|
+
r = ''
|
111
|
+
hash.keys.sort.each do |key|
|
112
|
+
k = key.to_s.ljust(width, '.')
|
113
|
+
v = hash[key].to_s.rjust(width, '.')
|
114
|
+
r << [k, v] * ' ' + "\n"
|
115
|
+
end
|
116
|
+
r
|
47
117
|
end
|
118
|
+
puts pretty_options(options)
|
48
119
|
|
49
|
-
unless options[:output]
|
50
|
-
options[:output] = 'output'
|
51
|
-
end
|
52
120
|
|
53
121
|
Dir.mktmpdir do |dir|
|
54
122
|
|
@@ -62,20 +130,26 @@ Dir.mktmpdir do |dir|
|
|
62
130
|
end
|
63
131
|
|
64
132
|
File.open(script_path, 'w+') do |script|
|
65
|
-
script.puts "set term png size
|
133
|
+
script.puts "set term png size #{options[:graph_width]},#{options[:graph_height]}"
|
66
134
|
script.puts "set output \"#{options[:output]}.png\""
|
67
135
|
script.puts "set title \"#{options[:title]}\""
|
68
136
|
script.puts "set xlabel \"#{options[:x_label]}\""
|
69
137
|
script.puts "set ylabel \"#{options[:y_label]}\""
|
70
|
-
script.puts
|
71
|
-
script.puts
|
72
|
-
|
73
|
-
|
74
|
-
|
138
|
+
script.puts 'set grid'
|
139
|
+
script.puts 'set timestamp'
|
140
|
+
if options[:stats]
|
141
|
+
script.puts "stats '#{data_path}'"
|
142
|
+
end
|
143
|
+
if need_ranges
|
144
|
+
script.puts "plot [#{options[:x_min]}:#{options[:x_max]}][#{options[:y_min]}:#{options[:y_max]}] '#{data_path}' notitle with points linecolor rgb '#FF0000'"
|
145
|
+
else
|
146
|
+
script.puts "plot '#{data_path}' notitle with points linecolor rgb '#FF0000'"
|
147
|
+
end
|
148
|
+
script.puts 'quit'
|
75
149
|
end
|
76
150
|
|
77
151
|
system "gnuplot #{script_path}"
|
78
152
|
puts "open #{options[:output]}.png"
|
79
|
-
|
153
|
+
|
80
154
|
end
|
81
155
|
|
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
|
+
version: 0.0.6
|
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.
|
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: []
|