ix-cli 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/ix-sigma-grep +135 -0
  3. metadata +3 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f15816063d5a25ec71bba2ceda821a244c5d19501709a04dd5d8626e613bc9d
4
- data.tar.gz: 6f96b6106a06455777b7f02da0bbffb2c981f2e91d7c28edc1365c28d53580c2
3
+ metadata.gz: 15f8772d153342e10644bf937e7c51a0d56871cec2e1bdfeff7c7e35180bb171
4
+ data.tar.gz: 2e1c119cbd9bdd142391d208ae805d753b1878fad963b09cb1f1c99e9b1bae6e
5
5
  SHA512:
6
- metadata.gz: 5772e7c6123507f3689cdfff44ba52357412722ec0d63938798e7da4d3e2629f416c2d69a173987dda3b4d449f2b3f6b8248f143b509ce1bf70cbb0a384e5d9b
7
- data.tar.gz: 686f1b86366990b487706959b963cf8df3b1f575a114aa54644b5310f8d00d8df235aeadd1d5ee2b96f7ae2111f8fa659852e4fffc0fa8750968e864a5e4167e
6
+ metadata.gz: 1cad8247e42f9a05f021b253a26301799fe7cbd38a9e904b263f6a2f9875f714737b2a60e6d0f4ff40b3b9eaaa6190d197bb0e3aa57506c647d061b7ff60750c
7
+ data.tar.gz: 9ea79a8c6fdf2031b0a163ac600569aa964205eb8d62692118ac76fee9df903d853f5c0a814eeed5cde25b54707bf69b0c90c12a1b45a25b8faba207423c7dea
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
+
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuyoshi Tlacaelel
@@ -238,6 +238,7 @@ executables:
238
238
  - ix-show-tabs
239
239
  - ix-show-trailing-spaces
240
240
  - ix-shuffle
241
+ - ix-sigma-grep
241
242
  - ix-signature
242
243
  - ix-size
243
244
  - ix-slider
@@ -514,6 +515,7 @@ files:
514
515
  - bin/ix-show-tabs
515
516
  - bin/ix-show-trailing-spaces
516
517
  - bin/ix-shuffle
518
+ - bin/ix-sigma-grep
517
519
  - bin/ix-signature
518
520
  - bin/ix-size
519
521
  - bin/ix-slider