-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.rb
executable file
·67 lines (55 loc) · 1.74 KB
/
timer.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
62
63
64
65
66
67
#!/usr/bin/env ruby
require 'optparse'
require_relative './parser.rb'
# 计算每组点用户耗时
# 每个点有两个阶段——传感器阶段或触摸屏阶段
# 输入参数为目标数据文件、传感器在先还是触摸屏在先
# 输出每个点两个阶段的耗时情况
# timer.rb -first_phase [touch|sensor] -input datafile.txt
class Timer
attr_accessor :inputPath
attr_accessor :sensorFirst
attr_accessor :outputPath
attr_accessor :sensorTime
attr_accessor :touchTime
attr_accessor :distance
def initialize inputPath, sensorFirst
@inputPath = inputPath
@sensorFirst = sensorFirst
@outputPath = inputPath.sub(".txt", "time.txt")
@sensorTime = []
@touchTime = []
@distance = []
end
def process
parser = Parser.new @sensorFirst
File.open(@inputPath).each do |line|
parser.feed line
end
sensorTime, sensorDistance, sensorWsqr, touchTime, touchDistance, touchWsqr = parser.parse
File.open(@outputPath, 'w') do |file|
file.write("#{sensorTime.join(",")}\n")
file.write("#{sensorDistance.join(",")}\n")
file.write("#{sensorWsqr.join(",")}\n")
file.write("#{touchTime.join(",")}\n")
file.write("#{touchDistance.join(",")}\n")
file.write("#{touchWsqr.join(",")}\n")
end
end
end
opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: timer.rb --first_phase [touch|sensor] --input datafile.txt --output outfile.txt"
opts.separator ""
opts.separator "Specific options:"
opts.on("-f", "--first_phase [first phase]",
"Choose first phase in the experiment") do |fp|
@sensorFirst = (fp == "sensor")
end
opts.on("-i", "--input [input file]",
"Input file path") do |inputPath|
@inputPath = inputPath
end
end
opt_parser.parse!(ARGV)
t = Timer.new @inputPath, @sensorFirst
t.process