Sha256: fd7f04af21cbceb85f3cb29071b69910bf6ff6d8c341ff81af25b9a3afc51297
Contents?: true
Size: 1.23 KB
Versions: 3
Compression:
Stored size: 1.23 KB
Contents
require 'fileutils' require 'json' module SandiMeter class HtmlGenerator def copy_assets!(path) asset_dir_path = File.join(path, 'sandi_meter/assets') FileUtils.mkdir(asset_dir_path) unless Dir.exists?(asset_dir_path) Dir[File.join(File.dirname(__FILE__), "../../html/*.{js,css}")].each do |file| FileUtils.cp file, File.join(asset_dir_path, File.basename(file)) end FileUtils.cp File.join(File.dirname(__FILE__), "../../html", "index.html"), File.join(path, 'sandi_meter', 'index.html') end def generate_data!(path) raw_data = File.read(File.join(path, 'sandi_meter', 'sandi_meter.log')).split("\n") raw_data.map! { |row| row.split(';').map(&:to_i) } data = [] raw_data.each do |row| hash = {} row.first(8).each_slice(2).each_with_index do |el, i| hash["r#{i + 1}0"] = el.first hash["r#{i + 1}1"] = el.last end hash['timestamp'] = row.last * 1000 data << hash end index_file = File.join(path, 'sandi_meter', 'index.html') index = File.read(index_file) index.gsub!('<% plot_data %>', data.to_json) File.open(index_file, 'w') do |file| file.write(index) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sandi_meter-0.0.6 | lib/sandi_meter/html_generator.rb |
sandi_meter-0.0.5 | lib/sandi_meter/html_generator.rb |
sandi_meter-0.0.4 | lib/sandi_meter/html_generator.rb |