Module: Columbus3::FlotRenderer

Defined in:
lib/columbus3/renderer/flot_renderer.rb

Overview

make a track into a flot graph (speed and height)

Class Method Summary collapse

Class Method Details

.show(filename, file) ⇒ Object

apply the ERB in html/flot.html.erb and save it in the current directory, under _flot.html



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
# File 'lib/columbus3/renderer/flot_renderer.rb', line 10

def self.show filename, file
  template = File.join(File.dirname(__FILE__), "/../../html/flot.html.erb")
  renderer = ERB.new(File.read(template))
  
  # context: location of css and js + list of files to show
  bower_dir = File.join(File.dirname(__FILE__), "/../../../bower_components")
  @flot_js = [File.join(bower_dir, 'jquery/dist/jquery.min.js'),
              File.join(bower_dir, 'flot/jquery.flot.js'),
              File.join(bower_dir, 'flot/jquery.flot.resize.js'),
              File.join(bower_dir, 'flot/jquery.flot.time.js'),
              File.join(bower_dir, 'flot/jquery.flot.selection.js')                  
             ]
  @file = file
  # TODO: manage the case of sidecar not existing
  @track_info = Sidecar.new @file
  @track_info.load

  # generate the output
  html = renderer.result(binding)

  # save it to file
  File.open(filename, "w") do |file|
    file << html
  end
end

.to_graph_data(filename, force = false) ⇒ Object

make a v900 track into a graph layer cached to disk



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/columbus3/renderer/flot_renderer.rb', line 37

def self.to_graph_data filename, force = false
  target = to_graph_filename filename

  if force or not File.exists? target
    track = V900Track.new filename: filename
    File.open(target, "w") do |file|
      id = Sanitizer::sanitize filename

      file.printf "min_time_\#{id} = \#{track.first.time.to_i * 1000};\\n\nmax_time_\#{id} = \#{track.last.time.to_i * 1000};\\n\nspeed_\#{id} = \#{track.range.each.map { |i| [track[i].time.to_i * 1000, track[i].speed] }};\\n\nheight_\#{id} = \#{track.range.each.map { |i|[track[i].time.to_i * 1000, track[i].height] }};\\n\n"
    end
  end

end

.to_graph_filename(filename) ⇒ Object



56
57
58
# File 'lib/columbus3/renderer/flot_renderer.rb', line 56

def self.to_graph_filename filename
  filename + "_graph.js"
end