diff options
Diffstat (limited to 'xport2json.rb')
-rw-r--r-- | xport2json.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/xport2json.rb b/xport2json.rb new file mode 100644 index 0000000..aa1508d --- /dev/null +++ b/xport2json.rb @@ -0,0 +1,51 @@ +require 'nokogiri' +require 'json' + +FN = ARGV.shift.chomp + +doc = File.open("#{FN}.xml") { |f| Nokogiri::XML(f) } + +tstart = doc.css("xport>meta>start").text.to_i +tstep = doc.css("xport>meta>step").text.to_i + +rcvd = [] +rmax = 0 +sent = [] +smax = 0 + +doc.css("xport>data>row").each do |row| + t = (row.css("t").text.to_i - tstart) / tstep + r = row.css("v")[0].text.to_f + s = row.css("v")[1].text.to_f + + rmax = r if r > rmax + smax = s if s > smax + + rcvd << { t: t, v: r } + sent << { t: t, v: s } +end + +rmax *= 1.10 +smax *= 1.10 + +rcvd.each do |r| + r[:v] /= rmax +end + +sent.each do |s| + s[:v] /= smax +end + +File.open("#{FN}.rcvd.json", "w") do |f| + f.puts({ + max: rmax, + data: rcvd + }.to_json) +end + +File.open("#{FN}.sent.json", "w") do |f| + f.puts({ + max: smax, + data: sent + }.to_json) +end |