togezo 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9c6a839255715bf9c7c9d7b558220ae81f4d85ea
4
+ data.tar.gz: 84f3ad8e1f6758e01f44812afbc2f12e6b15980d
5
+ SHA512:
6
+ metadata.gz: 3c69585db2d9db500f4b477dc7b56be8fadd5106b18e2e1acf97eb7b6c303d6623394ee11e910faa7e14ad4561923bb13d35b0163a30bf20587b5c286a83d0b1
7
+ data.tar.gz: 05e0fcc25e0025f8bf0315f02230696fbbdba4f1d5a75a9cf0683dfc6c83043eb951fc825cfe7d79359a04db3ce77a088b7ac45581484d939b81d340cc74fc07
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in togezo.gemspec
4
+ gemspec
@@ -0,0 +1,18 @@
1
+ # Togezo
2
+
3
+ This is a gem for getting extreme values on a chart via Gaussian/Pearson.
4
+
5
+ ## Installation
6
+
7
+ $ gem install togezo
8
+
9
+ ## Usage
10
+
11
+ togezo = Togezo.init("hoge.dat")
12
+ peaks = togezo.fit
13
+ p peaks
14
+
15
+ ## Contributing
16
+
17
+ Bug reports and pull requests are welcome on GitHub at https://github.com/deepneko/togezo.
18
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "togezo"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,102 @@
1
+ require 'pty'
2
+ require 'expect'
3
+ require 'tempfile'
4
+
5
+ module Togezo
6
+ GAUSSIAN = 0
7
+ PEARSON = 1
8
+
9
+ def self.init(filename, debug=false)
10
+ Togezo.new(filename, debug)
11
+ end
12
+
13
+ class Togezo
14
+ attr_accessor :debug
15
+ attr_reader :positives, :negatives, :peaks
16
+
17
+ def initialize(filename, debug=false)
18
+ @datafile = File.open(filename)
19
+ @constant = nil
20
+ @positives = []
21
+ @negatives = []
22
+ @peaks = []
23
+ end
24
+
25
+ def fit(function=GAUSSIAN, times=1)
26
+ if function = GAUSSIAN
27
+ guess = "Gaussian"
28
+ elsif function = @PEARSON
29
+ guess = "Pearson"
30
+ end
31
+
32
+ PTY.spawn("cfityk") do |r, w, pid|
33
+ w.puts "@0 < #{@datafile.path};"
34
+ w.puts "guess Constant;"
35
+ w.puts "info peaks;"
36
+
37
+ r.sync = true
38
+ r.expect(/\%_1\s+Constant(\sx){4}\s+(\d+(\.\d+)*)\s/, 3) do |line|
39
+ @constant = line[2].to_f
40
+ end
41
+
42
+ 1.upto(times) do |i|
43
+ w.puts "guess #{guess}"
44
+ end
45
+
46
+ w.puts "info peaks"
47
+ 2.upto(times+1) do |i|
48
+ r.expect(/\%_#{i}\s+#{guess}(\s+\d+(\.\d+)*)(\s+\d+(\.\d+)*)\s/, 3) do |line|
49
+ x = line[1].to_f
50
+ y = line[3].to_f
51
+ @positives << [x, y]
52
+ end
53
+ end
54
+
55
+ w.close
56
+ r.close
57
+ end
58
+
59
+ negatives = Tempfile.new("temp")
60
+ @datafile.each_line do |line|
61
+ x, y = line.split(/\s/).map{|m| m.to_f}
62
+ if y < @constant
63
+ new_y = (@constant - y) + @constant
64
+ negatives.puts "#{x} #{new_y}"
65
+ end
66
+ end
67
+ negatives.flush
68
+ negatives.rewind
69
+
70
+ PTY.spawn("cfityk") do |r, w, pid|
71
+ w.puts "@0 < #{negatives.path};"
72
+ w.puts "guess Constant(a=#{@constant});"
73
+
74
+ 1.upto(times) do |i|
75
+ w.puts "guess #{guess}"
76
+ end
77
+
78
+ w.puts "info peaks"
79
+ 2.upto(times+1) do |i|
80
+ r.expect(/\%_#{i}\s+#{guess}(\s+\d+(\.\d+)*)(\s+\d+(\.\d+)*)\s/, 3) do |line|
81
+ x = line[1].to_f
82
+ y = line[3].to_f
83
+ @negatives << [x, y]
84
+ end
85
+ end
86
+
87
+ w.close
88
+ r.close
89
+ end
90
+
91
+ @positives.each do |x, y|
92
+ @peaks << [x, (y+@constant).round(5)]
93
+ end
94
+
95
+ @negatives.each do |x, y|
96
+ @peaks << [x, (@constant-y).round(5)]
97
+ end
98
+
99
+ @peaks.sort!
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,3 @@
1
+ module Togezo
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,261 @@
1
+ 0 46.177
2
+ 1 46.177
3
+ 2 46.168
4
+ 3 46.157
5
+ 4 46.151
6
+ 5 46.144
7
+ 6 46.138
8
+ 7 46.135
9
+ 8 46.133
10
+ 9 46.132
11
+ 10 46.132
12
+ 11 46.133
13
+ 12 46.145
14
+ 13 46.149
15
+ 14 46.157
16
+ 15 46.166
17
+ 16 46.184
18
+ 17 46.195
19
+ 18 46.205
20
+ 19 46.214
21
+ 20 46.225
22
+ 21 46.234
23
+ 22 46.234
24
+ 23 46.241
25
+ 24 46.245
26
+ 25 46.246
27
+ 26 46.239
28
+ 27 46.235
29
+ 28 46.232
30
+ 29 46.229
31
+ 30 46.221
32
+ 31 46.214
33
+ 32 46.207
34
+ 33 46.204
35
+ 34 46.187
36
+ 35 46.173
37
+ 36 46.152
38
+ 37 46.137
39
+ 38 46.119
40
+ 39 46.104
41
+ 40 46.094
42
+ 41 46.082
43
+ 42 46.076
44
+ 43 46.061
45
+ 44 46.065
46
+ 45 46.067
47
+ 46 46.072
48
+ 47 46.08
49
+ 48 46.084
50
+ 49 46.08
51
+ 50 46.071
52
+ 51 46.057
53
+ 52 46.049
54
+ 53 46.043
55
+ 54 46.026
56
+ 55 45.999
57
+ 56 45.98
58
+ 57 45.961
59
+ 58 45.946
60
+ 59 45.937
61
+ 60 45.93
62
+ 61 45.927
63
+ 62 45.918
64
+ 63 45.91
65
+ 64 45.905
66
+ 65 45.913
67
+ 66 45.916
68
+ 67 45.915
69
+ 68 45.909
70
+ 69 45.902
71
+ 70 45.898
72
+ 71 45.89
73
+ 72 45.863
74
+ 73 45.841
75
+ 74 45.826
76
+ 75 45.806
77
+ 76 45.79
78
+ 77 45.775
79
+ 78 45.761
80
+ 79 45.751
81
+ 80 45.739
82
+ 81 45.739
83
+ 82 45.762
84
+ 83 45.778
85
+ 84 45.793
86
+ 85 45.81
87
+ 86 45.842
88
+ 87 45.864
89
+ 88 45.888
90
+ 89 45.91
91
+ 90 45.928
92
+ 91 45.942
93
+ 92 45.953
94
+ 93 45.961
95
+ 94 45.967
96
+ 95 45.97
97
+ 96 45.95
98
+ 97 45.944
99
+ 98 45.931
100
+ 99 45.916
101
+ 100 45.903
102
+ 101 45.884
103
+ 102 45.864
104
+ 103 45.848
105
+ 104 45.835
106
+ 105 45.827
107
+ 106 45.827
108
+ 107 45.82
109
+ 108 45.82
110
+ 109 45.819
111
+ 110 45.82
112
+ 111 45.828
113
+ 112 45.84
114
+ 113 45.848
115
+ 114 45.853
116
+ 115 45.853
117
+ 116 45.847
118
+ 117 45.854
119
+ 118 45.864
120
+ 119 45.876
121
+ 120 45.887
122
+ 121 45.898
123
+ 122 45.902
124
+ 123 45.91
125
+ 124 45.918
126
+ 125 45.928
127
+ 126 45.939
128
+ 127 45.937
129
+ 128 45.932
130
+ 129 45.922
131
+ 130 45.913
132
+ 131 45.903
133
+ 132 45.893
134
+ 133 45.883
135
+ 134 45.871
136
+ 135 45.86
137
+ 136 45.854
138
+ 137 45.846
139
+ 138 45.832
140
+ 139 45.824
141
+ 140 45.818
142
+ 141 45.809
143
+ 142 45.802
144
+ 143 45.801
145
+ 144 45.802
146
+ 145 45.807
147
+ 146 45.811
148
+ 147 45.821
149
+ 148 45.837
150
+ 149 45.848
151
+ 150 45.855
152
+ 151 45.864
153
+ 152 45.871
154
+ 153 45.876
155
+ 154 45.882
156
+ 155 45.878
157
+ 156 45.863
158
+ 157 45.85
159
+ 158 45.838
160
+ 159 45.819
161
+ 160 45.808
162
+ 161 45.79
163
+ 162 45.78
164
+ 163 45.766
165
+ 164 45.749
166
+ 165 45.734
167
+ 166 45.726
168
+ 167 45.717
169
+ 168 45.709
170
+ 169 45.714
171
+ 170 45.712
172
+ 171 45.706
173
+ 172 45.707
174
+ 173 45.712
175
+ 174 45.712
176
+ 175 45.718
177
+ 176 45.721
178
+ 177 45.722
179
+ 178 45.721
180
+ 179 45.713
181
+ 180 45.712
182
+ 181 45.721
183
+ 182 45.717
184
+ 183 45.7
185
+ 184 45.695
186
+ 185 45.683
187
+ 186 45.677
188
+ 187 45.67
189
+ 188 45.66
190
+ 189 45.647
191
+ 190 45.62
192
+ 191 45.582
193
+ 192 45.544
194
+ 193 45.515
195
+ 194 45.487
196
+ 195 45.463
197
+ 196 45.431
198
+ 197 45.404
199
+ 198 45.389
200
+ 199 45.378
201
+ 200 45.379
202
+ 201 45.385
203
+ 202 45.392
204
+ 203 45.395
205
+ 204 45.392
206
+ 205 45.395
207
+ 206 45.402
208
+ 207 45.402
209
+ 208 45.399
210
+ 209 45.411
211
+ 210 45.414
212
+ 211 45.42
213
+ 212 45.427
214
+ 213 45.442
215
+ 214 45.451
216
+ 215 45.452
217
+ 216 45.451
218
+ 217 45.453
219
+ 218 45.453
220
+ 219 45.442
221
+ 220 45.432
222
+ 221 45.427
223
+ 222 45.412
224
+ 223 45.396
225
+ 224 45.378
226
+ 225 45.368
227
+ 226 45.362
228
+ 227 45.352
229
+ 228 45.339
230
+ 229 45.327
231
+ 230 45.324
232
+ 231 45.314
233
+ 232 45.312
234
+ 233 45.318
235
+ 234 45.338
236
+ 235 45.376
237
+ 236 45.416
238
+ 237 45.462
239
+ 238 45.5
240
+ 239 45.534
241
+ 240 45.565
242
+ 241 45.606
243
+ 242 45.646
244
+ 243 45.68
245
+ 244 45.708
246
+ 245 45.719
247
+ 246 45.725
248
+ 247 45.723
249
+ 248 45.732
250
+ 249 45.739
251
+ 250 45.75
252
+ 251 45.767
253
+ 252 45.782
254
+ 253 45.816
255
+ 254 45.852
256
+ 255 45.875
257
+ 256 45.899
258
+ 257 45.927
259
+ 258 45.955
260
+ 259 45.986
261
+ 260 46.014
@@ -0,0 +1,7 @@
1
+ require 'togezo'
2
+
3
+ togezo = Togezo.init(ARGV[0])
4
+ p togezo.fit(Togezo::GAUSSIAN, 5)
5
+ p togezo.positives
6
+ p togezo.negatives
7
+
Binary file
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'togezo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "togezo"
8
+ spec.version = Togezo::VERSION
9
+ spec.authors = ["deepneko"]
10
+ spec.email = ["deep.inu@gmail.com"]
11
+
12
+ spec.summary = %q{Togezo provides extreme values on a chart via Gaussian/Pearson.}
13
+ spec.homepage = "https://github.com/deepneko/togezo"
14
+
15
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
16
+ # delete this section to allow pushing this gem to any host.
17
+ #if spec.respond_to?(:metadata)
18
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
19
+ #else
20
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
21
+ #end
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.10"
29
+ #spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec"
31
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: togezo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - deepneko
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - deep.inu@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".travis.yml"
51
+ - Gemfile
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - lib/togezo.rb
57
+ - lib/togezo/version.rb
58
+ - sample/sample.dat
59
+ - sample/sample.rb
60
+ - togezo-0.1.0.gem
61
+ - togezo.gemspec
62
+ homepage: https://github.com/deepneko/togezo
63
+ licenses: []
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.4.8
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Togezo provides extreme values on a chart via Gaussian/Pearson.
85
+ test_files: []