-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathquickstat.rb
61 lines (47 loc) · 1.14 KB
/
quickstat.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'quickstats'
require 'pp'
rx = []
ry = []
File.open 'set.txt', 'r' do |f|
str = f.readlines.join.gsub("\n", '')
begin
m = str.match /\d+.\d+/
break if m.nil?
rx << m.to_s.to_f
str = m.post_match
m = str.match /\d+.\d+/
ry << m.to_s.to_f
str = m.post_match
end until m.nil?
k = 0.15
rx_opt = []
rx_opt.push rx.first
(rx.size-1).times do |i|
rx_opt << (k * rx[i+1] + (1-k) * rx_opt[i]).round(1)
end
ry_opt = []
ry_opt.push ry.first
(ry.size-1).times do |i|
ry_opt << (k * ry[i+1] + (1-k) * ry_opt[i]).round(1)
end
require 'flotr'
# Create a new plot
plot = Flotr::Plot.new("Test plot")
raw_x = Flotr::Data.new(:label => "rotation x", :color => "green")
rx.each_with_index { |x, i| raw_x << [i, x]}
rotation_x = Flotr::Data.new(:label => "rotation x", :color => "red")
rx_opt.each_with_index do |x, i|
rotation_x << [i, x]
end
rotation_y = Flotr::Data.new(:label => "rotation y", :color => "blue")
ry_opt.each_with_index do |y, i|
rotation_y << [i, y]
end
plot << rotation_x << raw_x #<< rotation_y
plot.show
p rx
p rx_opt
p '--'
p ry
p ry_opt
end