-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresult_recorder.rb
More file actions
40 lines (30 loc) · 1.12 KB
/
Copy pathresult_recorder.rb
File metadata and controls
40 lines (30 loc) · 1.12 KB
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
require 'csv'
class ResultRecorder
def self.sanitize_filename(filename)
# source: http://stackoverflow.com/a/10823131/3961937
fn = filename.split /(?<=.)\.(?=[^.])(?!.*\.[^.])/m
fn.map! { |s| s.gsub /[^a-z0-9\-]+/i, '_' }
return fn.join '.'
end
def self.filename(options, r)
sanitize_filename "#{options[:local_name]}-to-#{r[:remote_name]}.csv"
end
def self.record (options, result)
column_header = ["time", "latency", "throughput up", "throughput down", "transmitted_dropped", "received_dropped"]
write_headers=true
fname=filename(options, result)
write_headers=false if File.exists?(fname)
CSV.open(fname, "a+",
:write_headers => write_headers,
:headers => column_header) do |hdr|
column_header=nil #No header after first insertion
data_out = [result[:time],
result[:latency].round(4),
result[:throughput_up].round(4),
result[:throughput_down].round(4),
result[:transmitted_dropped],
result[:received_dropped]]
hdr << data_out
end
end
end