-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.rb
More file actions
40 lines (35 loc) · 679 Bytes
/
Copy pathparser.rb
File metadata and controls
40 lines (35 loc) · 679 Bytes
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
#!/usr/bin/ruby
file = File.new('diabetes.all', 'r')
max = Array.new(8)
min = Array.new(8)
file.each do |line|
entry = line.gsub(' ', '').split(',')
#puts entry
entry.pop
i = 0
entry.each do |c|
max[i] = c.to_f if max[i].nil? or c.to_f > max[i]
min[i] = c.to_f if min[i].nil? or c.to_f < min[i]
i += 1
end
end
#puts "MAX"
#puts max
#puts "MIN"
#puts min
file.rewind
file2write = File.new('parsed.txt', 'w')
file.each do |line|
entry = line.gsub(' ', '').split(',')
#puts entry
n = Array.new(9)
n[8] = entry.pop
i = 0
entry.each do |c|
n[i] = (c.to_f-min[i])/(max[i]-min[i])
i += 1
end
#puts n.to_s
file2write.puts(n.join(", "))
end
file2write.close