ix-cli 0.0.2 → 0.0.3
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-timeline +241 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f15816063d5a25ec71bba2ceda821a244c5d19501709a04dd5d8626e613bc9d
|
4
|
+
data.tar.gz: 6f96b6106a06455777b7f02da0bbffb2c981f2e91d7c28edc1365c28d53580c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5772e7c6123507f3689cdfff44ba52357412722ec0d63938798e7da4d3e2629f416c2d69a173987dda3b4d449f2b3f6b8248f143b509ce1bf70cbb0a384e5d9b
|
7
|
+
data.tar.gz: 686f1b86366990b487706959b963cf8df3b1f575a114aa54644b5310f8d00d8df235aeadd1d5ee2b96f7ae2111f8fa659852e4fffc0fa8750968e864a5e4167e
|
data/bin/ix-timeline
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
class Token
|
4
|
+
REGEX = /(^)(\d+)(\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,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.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuyoshi Tlacaelel
|
@@ -269,6 +269,7 @@ executables:
|
|
269
269
|
- ix-text-to-morse
|
270
270
|
- ix-tick
|
271
271
|
- ix-time
|
272
|
+
- ix-timeline
|
272
273
|
- ix-times
|
273
274
|
- ix-timestamp
|
274
275
|
- ix-timestamp-sort
|
@@ -544,6 +545,7 @@ files:
|
|
544
545
|
- bin/ix-text-to-morse
|
545
546
|
- bin/ix-tick
|
546
547
|
- bin/ix-time
|
548
|
+
- bin/ix-timeline
|
547
549
|
- bin/ix-times
|
548
550
|
- bin/ix-timestamp
|
549
551
|
- bin/ix-timestamp-sort
|