pulse_meter_visualizer 0.4.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/.gitignore +19 -0
  2. data/.rbenv-version +1 -0
  3. data/.rspec +1 -0
  4. data/.rvmrc +1 -0
  5. data/.travis.yml +8 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +22 -0
  8. data/Procfile +3 -0
  9. data/README.md +40 -0
  10. data/Rakefile +72 -0
  11. data/examples/basic.ru +145 -0
  12. data/examples/basic_sensor_data.rb +96 -0
  13. data/lib/pulse_meter/visualize/app.rb +78 -0
  14. data/lib/pulse_meter/visualize/base.rb +15 -0
  15. data/lib/pulse_meter/visualize/coffee/application.coffee +40 -0
  16. data/lib/pulse_meter/visualize/coffee/collections/page_info_list.coffee +17 -0
  17. data/lib/pulse_meter/visualize/coffee/collections/sensor_info_list.coffee +4 -0
  18. data/lib/pulse_meter/visualize/coffee/collections/widget_list.coffee +14 -0
  19. data/lib/pulse_meter/visualize/coffee/extensions.coffee +26 -0
  20. data/lib/pulse_meter/visualize/coffee/models/dinamic_widget.coffee +34 -0
  21. data/lib/pulse_meter/visualize/coffee/models/page_info.coffee +2 -0
  22. data/lib/pulse_meter/visualize/coffee/models/sensor_info.coffee +2 -0
  23. data/lib/pulse_meter/visualize/coffee/models/widget.coffee +54 -0
  24. data/lib/pulse_meter/visualize/coffee/presenters/area.coffee +2 -0
  25. data/lib/pulse_meter/visualize/coffee/presenters/gauge.coffee +11 -0
  26. data/lib/pulse_meter/visualize/coffee/presenters/line.coffee +2 -0
  27. data/lib/pulse_meter/visualize/coffee/presenters/pie.coffee +20 -0
  28. data/lib/pulse_meter/visualize/coffee/presenters/series.coffee +44 -0
  29. data/lib/pulse_meter/visualize/coffee/presenters/table.coffee +10 -0
  30. data/lib/pulse_meter/visualize/coffee/presenters/timeline.coffee +13 -0
  31. data/lib/pulse_meter/visualize/coffee/presenters/widget.coffee +65 -0
  32. data/lib/pulse_meter/visualize/coffee/router.coffee +21 -0
  33. data/lib/pulse_meter/visualize/coffee/views/dynamic_chart.coffee +91 -0
  34. data/lib/pulse_meter/visualize/coffee/views/dynamic_widget.coffee +58 -0
  35. data/lib/pulse_meter/visualize/coffee/views/page_title.coffee +17 -0
  36. data/lib/pulse_meter/visualize/coffee/views/page_titles.coffee +15 -0
  37. data/lib/pulse_meter/visualize/coffee/views/sensor_info_list.coffee +19 -0
  38. data/lib/pulse_meter/visualize/coffee/views/widget.coffee +99 -0
  39. data/lib/pulse_meter/visualize/coffee/views/widget_chart.coffee +13 -0
  40. data/lib/pulse_meter/visualize/coffee/views/widget_list.coffee +15 -0
  41. data/lib/pulse_meter/visualize/dsl/base.rb +131 -0
  42. data/lib/pulse_meter/visualize/dsl/errors.rb +40 -0
  43. data/lib/pulse_meter/visualize/dsl/layout.rb +27 -0
  44. data/lib/pulse_meter/visualize/dsl/page.rb +33 -0
  45. data/lib/pulse_meter/visualize/dsl/sensor.rb +20 -0
  46. data/lib/pulse_meter/visualize/dsl/widget.rb +37 -0
  47. data/lib/pulse_meter/visualize/dsl/widgets/area.rb +20 -0
  48. data/lib/pulse_meter/visualize/dsl/widgets/gauge.rb +12 -0
  49. data/lib/pulse_meter/visualize/dsl/widgets/line.rb +21 -0
  50. data/lib/pulse_meter/visualize/dsl/widgets/pie.rb +16 -0
  51. data/lib/pulse_meter/visualize/dsl/widgets/table.rb +19 -0
  52. data/lib/pulse_meter/visualize/layout.rb +79 -0
  53. data/lib/pulse_meter/visualize/page.rb +25 -0
  54. data/lib/pulse_meter/visualize/public/css/application.css +56 -0
  55. data/lib/pulse_meter/visualize/public/css/bootstrap.css +4883 -0
  56. data/lib/pulse_meter/visualize/public/css/bootstrap.min.css +729 -0
  57. data/lib/pulse_meter/visualize/public/css/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  58. data/lib/pulse_meter/visualize/public/css/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  59. data/lib/pulse_meter/visualize/public/css/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  60. data/lib/pulse_meter/visualize/public/css/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  61. data/lib/pulse_meter/visualize/public/css/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  62. data/lib/pulse_meter/visualize/public/css/images/ui-bg_glass_75_ffffff_1x400.png +0 -0
  63. data/lib/pulse_meter/visualize/public/css/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  64. data/lib/pulse_meter/visualize/public/css/images/ui-bg_inset-soft_95_fef1ec_1x100.png +0 -0
  65. data/lib/pulse_meter/visualize/public/css/images/ui-icons_222222_256x240.png +0 -0
  66. data/lib/pulse_meter/visualize/public/css/images/ui-icons_2e83ff_256x240.png +0 -0
  67. data/lib/pulse_meter/visualize/public/css/images/ui-icons_454545_256x240.png +0 -0
  68. data/lib/pulse_meter/visualize/public/css/images/ui-icons_888888_256x240.png +0 -0
  69. data/lib/pulse_meter/visualize/public/css/images/ui-icons_cd0a0a_256x240.png +0 -0
  70. data/lib/pulse_meter/visualize/public/css/images/ui-icons_f6cf3b_256x240.png +0 -0
  71. data/lib/pulse_meter/visualize/public/css/jquery-ui-1.8.16.bootstrap.css +1320 -0
  72. data/lib/pulse_meter/visualize/public/favicon.ico +208 -0
  73. data/lib/pulse_meter/visualize/public/img/glyphicons-halflings-white.png +0 -0
  74. data/lib/pulse_meter/visualize/public/img/glyphicons-halflings.png +0 -0
  75. data/lib/pulse_meter/visualize/public/js/application.js +973 -0
  76. data/lib/pulse_meter/visualize/public/js/backbone-min.js +38 -0
  77. data/lib/pulse_meter/visualize/public/js/bootstrap.js +1835 -0
  78. data/lib/pulse_meter/visualize/public/js/jquery-1.7.2.min.js +4 -0
  79. data/lib/pulse_meter/visualize/public/js/jquery-ui-1.8.16.bootstrap.min.js +791 -0
  80. data/lib/pulse_meter/visualize/public/js/jquery-ui-1.8.23.custom.min.js +21 -0
  81. data/lib/pulse_meter/visualize/public/js/jquery-ui-timepicker-addon.js +1687 -0
  82. data/lib/pulse_meter/visualize/public/js/json2.js +487 -0
  83. data/lib/pulse_meter/visualize/public/js/underscore-min.js +32 -0
  84. data/lib/pulse_meter/visualize/sensor.rb +63 -0
  85. data/lib/pulse_meter/visualize/series_extractor.rb +107 -0
  86. data/lib/pulse_meter/visualize/views/main.haml +30 -0
  87. data/lib/pulse_meter/visualize/views/sensors.haml +76 -0
  88. data/lib/pulse_meter/visualize/views/widgets/area.haml +53 -0
  89. data/lib/pulse_meter/visualize/views/widgets/extend_options.haml +11 -0
  90. data/lib/pulse_meter/visualize/views/widgets/gauge.haml +13 -0
  91. data/lib/pulse_meter/visualize/views/widgets/line.haml +54 -0
  92. data/lib/pulse_meter/visualize/views/widgets/pie.haml +13 -0
  93. data/lib/pulse_meter/visualize/views/widgets/table.haml +45 -0
  94. data/lib/pulse_meter/visualize/widget.rb +38 -0
  95. data/lib/pulse_meter/visualize/widgets/gauge.rb +47 -0
  96. data/lib/pulse_meter/visualize/widgets/pie.rb +36 -0
  97. data/lib/pulse_meter/visualize/widgets/timeline.rb +114 -0
  98. data/lib/pulse_meter/visualizer.rb +38 -0
  99. data/lib/pulse_meter_visualizer.rb +2 -0
  100. data/pulse_meter_visualizer.gemspec +41 -0
  101. data/spec/pulse_meter/visualize/app_spec.rb +27 -0
  102. data/spec/pulse_meter/visualize/dsl/layout_spec.rb +64 -0
  103. data/spec/pulse_meter/visualize/dsl/page_spec.rb +62 -0
  104. data/spec/pulse_meter/visualize/dsl/sensor_spec.rb +30 -0
  105. data/spec/pulse_meter/visualize/dsl/widget_spec.rb +6 -0
  106. data/spec/pulse_meter/visualize/dsl/widgets/area_spec.rb +44 -0
  107. data/spec/pulse_meter/visualize/dsl/widgets/gauge_spec.rb +22 -0
  108. data/spec/pulse_meter/visualize/dsl/widgets/line_spec.rb +44 -0
  109. data/spec/pulse_meter/visualize/dsl/widgets/pie_spec.rb +35 -0
  110. data/spec/pulse_meter/visualize/dsl/widgets/table_spec.rb +36 -0
  111. data/spec/pulse_meter/visualize/layout_spec.rb +54 -0
  112. data/spec/pulse_meter/visualize/page_spec.rb +153 -0
  113. data/spec/pulse_meter/visualize/sensor_spec.rb +120 -0
  114. data/spec/pulse_meter/visualize/series_extractor_spec.rb +80 -0
  115. data/spec/pulse_meter/visualize/widgets/area_spec.rb +6 -0
  116. data/spec/pulse_meter/visualize/widgets/gauge_spec.rb +63 -0
  117. data/spec/pulse_meter/visualize/widgets/line_spec.rb +6 -0
  118. data/spec/pulse_meter/visualize/widgets/pie_spec.rb +73 -0
  119. data/spec/pulse_meter/visualize/widgets/table_spec.rb +6 -0
  120. data/spec/pulse_meter/visualizer_spec.rb +42 -0
  121. data/spec/shared_examples/dsl_widget.rb +106 -0
  122. data/spec/shared_examples/widget.rb +97 -0
  123. data/spec/spec_helper.rb +36 -0
  124. metadata +518 -0
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe PulseMeter::Visualize::DSL::Page do
4
+ let(:interval){ 100 }
5
+ let(:sensor_name) { "some_sensor" }
6
+ let!(:sensor){ PulseMeter::Sensor::Timelined::Max.new(sensor_name, :ttl => 1000, :interval => interval) }
7
+ let(:title) { "page title" }
8
+ let(:page){ PulseMeter::Visualize::DSL::Page.new(title) }
9
+
10
+ describe '.new' do
11
+ it "should initialize title and widgets" do
12
+ p = page.to_data
13
+ p.title.should == title
14
+ p.widgets.should == []
15
+ end
16
+ end
17
+
18
+ [:area, :line, :table, :pie, :gauge].each do |widget_type|
19
+
20
+ describe "##{widget_type}" do
21
+ it "should add #{widget_type} widget initialized by args to widgets" do
22
+ page.send(widget_type, :some_widget_name, sensor: sensor_name, width: 7)
23
+ w = page.to_data.widgets.first
24
+ w.width.should == 7
25
+ w.title.should == "some_widget_name"
26
+ w.sensors.first.name.should == sensor_name
27
+ end
28
+
29
+ it "should add #{widget_type} widget initialized by block" do
30
+ page.send(widget_type, :some_widget_name) do |w|
31
+ w.sensor(sensor_name)
32
+ w.sensor(sensor_name)
33
+ w.title "foo_widget"
34
+ w.width 7
35
+ end
36
+ w = page.to_data.widgets.first
37
+ w.type.should == widget_type.to_s
38
+ w.width.should == 7
39
+ w.title.should == "foo_widget"
40
+ w.sensors.size.should == 2
41
+ w.sensors.first.name.should == sensor_name
42
+ w.sensors.last.name.should == sensor_name
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ describe "#title" do
49
+ it "should set page title" do
50
+ page.title "Foo Title"
51
+ page.to_data.title.should == 'Foo Title'
52
+ end
53
+ end
54
+
55
+ describe "#to_data" do
56
+ it "should convert DSL data to Visualize::Page" do
57
+ page.to_data.should be_kind_of(PulseMeter::Visualize::Page)
58
+ end
59
+ end
60
+
61
+ end
62
+
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe PulseMeter::Visualize::DSL::Sensor do
4
+ let(:interval){ 100 }
5
+ let(:name) { "some_sensor" }
6
+ let!(:sensor){ PulseMeter::Sensor::Timelined::Max.new(name, :ttl => 1000, :interval => interval) }
7
+
8
+ describe '.new' do
9
+ it "should save passed name and create Visualize::Sensor with it" do
10
+ described_class.new(name).to_data.name.to_s.should == name
11
+ end
12
+ end
13
+
14
+ describe '#process_args' do
15
+ it "should pass args transparently to Visualize::Sensor" do
16
+ s = described_class.new(name)
17
+ s.process_args color: :red
18
+ s.to_data.color.to_s.should == 'red'
19
+ end
20
+ end
21
+
22
+ describe '#to_data' do
23
+ # actually tested above
24
+ it "should convert dsl data to sensor" do
25
+ described_class.new(name).to_data.should be_kind_of(PulseMeter::Visualize::Sensor)
26
+ end
27
+ end
28
+
29
+ end
30
+
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe PulseMeter::Visualize::DSL::Widget do
4
+ it_should_behave_like "dsl widget"
5
+ end
6
+
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe PulseMeter::Visualize::DSL::Widgets::Area do
4
+ it_should_behave_like "dsl widget"
5
+
6
+ let(:interval){ 100 }
7
+ let(:name) { "some_sensor" }
8
+ let!(:sensor){ PulseMeter::Sensor::Timelined::Max.new(name, :ttl => 1000, :interval => interval) }
9
+
10
+ let(:widget_name){ "some_widget" }
11
+ let(:w){ described_class.new(widget_name) }
12
+
13
+ describe "#to_data" do
14
+ it "should produce PulseMeter::Visualize::Widgets::Area class" do
15
+ w.to_data.should be_kind_of(PulseMeter::Visualize::Widgets::Area)
16
+ end
17
+ end
18
+
19
+ describe "#values_label" do
20
+ it "should set values_label" do
21
+ w.values_label "some y-axis legend"
22
+ w.to_data.values_label.should == "some y-axis legend"
23
+ end
24
+ end
25
+
26
+ describe "#show_last_point" do
27
+ it "should set show_last_point" do
28
+ w.show_last_point true
29
+ w.to_data.show_last_point.should be_true
30
+ end
31
+ end
32
+
33
+ describe "#timespan" do
34
+ it "should set timespan" do
35
+ w.timespan 5
36
+ w.to_data.timespan.should == 5
37
+ end
38
+ it "should raise exception if timespan is negative" do
39
+ expect{ w.timespan(-1) }.to raise_exception(PulseMeter::Visualize::DSL::BadWidgetTimeSpan)
40
+ end
41
+ end
42
+
43
+ end
44
+
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe PulseMeter::Visualize::DSL::Widgets::Gauge do
4
+ it_should_behave_like "dsl widget"
5
+
6
+ let(:interval){ 100 }
7
+ let(:name) { "some_sensor" }
8
+ let!(:sensor){ PulseMeter::Sensor::Timelined::Max.new(name, :ttl => 1000, :interval => interval) }
9
+
10
+ let(:widget_name){ "some_widget" }
11
+ let(:w){ described_class.new(widget_name) }
12
+
13
+ describe "#to_data" do
14
+ it "should produce PulseMeter::Visualize::Widgets::Gauge class" do
15
+ w.to_data.should be_kind_of(PulseMeter::Visualize::Widgets::Gauge)
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+
22
+
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe PulseMeter::Visualize::DSL::Widgets::Line do
4
+ it_should_behave_like "dsl widget"
5
+
6
+ let(:interval){ 100 }
7
+ let(:name) { "some_sensor" }
8
+ let!(:sensor){ PulseMeter::Sensor::Timelined::Max.new(name, :ttl => 1000, :interval => interval) }
9
+
10
+ let(:widget_name){ "some_widget" }
11
+ let(:w){ described_class.new(widget_name) }
12
+
13
+ describe "#to_data" do
14
+ it "should produce PulseMeter::Visualize::Widgets::Area class" do
15
+ w.to_data.should be_kind_of(PulseMeter::Visualize::Widgets::Line)
16
+ end
17
+ end
18
+
19
+ describe "#values_label" do
20
+ it "should set values_label" do
21
+ w.values_label "some y-axis legend"
22
+ w.to_data.values_label.should == "some y-axis legend"
23
+ end
24
+ end
25
+
26
+ describe "#show_last_point" do
27
+ it "should set show_last_point" do
28
+ w.show_last_point true
29
+ w.to_data.show_last_point.should be_true
30
+ end
31
+ end
32
+
33
+ describe "#timespan" do
34
+ it "should set timespan" do
35
+ w.timespan 5
36
+ w.to_data.timespan.should == 5
37
+ end
38
+ it "should raise exception if timespan is negative" do
39
+ expect{ w.timespan(-1) }.to raise_exception(PulseMeter::Visualize::DSL::BadWidgetTimeSpan)
40
+ end
41
+ end
42
+
43
+ end
44
+
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe PulseMeter::Visualize::DSL::Widgets::Pie do
4
+ it_should_behave_like "dsl widget"
5
+
6
+ let(:interval){ 100 }
7
+ let(:name) { "some_sensor" }
8
+ let!(:sensor){ PulseMeter::Sensor::Timelined::Max.new(name, :ttl => 1000, :interval => interval) }
9
+
10
+ let(:widget_name){ "some_widget" }
11
+ let(:w){ described_class.new(widget_name) }
12
+
13
+ describe "#to_data" do
14
+ it "should produce PulseMeter::Visualize::Widgets::Pie class" do
15
+ w.to_data.should be_kind_of(PulseMeter::Visualize::Widgets::Pie)
16
+ end
17
+ end
18
+
19
+ describe "#values_label" do
20
+ it "should set values_label" do
21
+ w.values_label "some y-axis legend"
22
+ w.to_data.values_label.should == "some y-axis legend"
23
+ end
24
+ end
25
+
26
+ describe "#show_last_point" do
27
+ it "should set show_last_point" do
28
+ w.show_last_point true
29
+ w.to_data.show_last_point.should be_true
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe PulseMeter::Visualize::DSL::Widgets::Table do
4
+ it_should_behave_like "dsl widget"
5
+
6
+ let(:interval){ 100 }
7
+ let(:name) { "some_sensor" }
8
+ let!(:sensor){ PulseMeter::Sensor::Timelined::Max.new(name, :ttl => 1000, :interval => interval) }
9
+
10
+ let(:widget_name){ "some_widget" }
11
+ let(:w){ described_class.new(widget_name) }
12
+
13
+ describe "#to_data" do
14
+ it "should produce PulseMeter::Visualize::Widgets::Area class" do
15
+ w.to_data.should be_kind_of(PulseMeter::Visualize::Widgets::Table)
16
+ end
17
+ end
18
+
19
+ describe "#show_last_point" do
20
+ it "should set show_last_point" do
21
+ w.show_last_point true
22
+ w.to_data.show_last_point.should be_true
23
+ end
24
+ end
25
+
26
+ describe "#timespan" do
27
+ it "should set timespan" do
28
+ w.timespan 5
29
+ w.to_data.timespan.should == 5
30
+ end
31
+ it "should raise exception if timespan is negative" do
32
+ expect{ w.timespan(-1) }.to raise_exception(PulseMeter::Visualize::DSL::BadWidgetTimeSpan)
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,54 @@
1
+ require "spec_helper"
2
+
3
+ describe PulseMeter::Visualize::Layout do
4
+ let(:layout) do
5
+ l = PulseMeter::Visualize::DSL::Layout.new
6
+ l.page "page1" do |p|
7
+ p.line "w1"
8
+ p.line "w2"
9
+ p.gchart_options({a: 1})
10
+ end
11
+ l.page "page2" do |p|
12
+ p.line "w3"
13
+ p.line "w4"
14
+ end
15
+ l.to_data
16
+ end
17
+
18
+ describe "#page_infos" do
19
+ it "should return list of page infos with ids" do
20
+ layout.page_infos.should == [
21
+ {title: "page1", id: 1, gchart_options: {a: 1}},
22
+ {title: "page2", id: 2, gchart_options: {}}
23
+ ]
24
+ end
25
+ end
26
+
27
+ describe "#options" do
28
+ it "should return layout options" do
29
+ ldsl = PulseMeter::Visualize::DSL::Layout.new
30
+ ldsl.use_utc true
31
+ ldsl.gchart_options({a: 1})
32
+ l = ldsl.to_data
33
+ l.options.should == {use_utc: true, gchart_options: {a: 1}}
34
+ end
35
+ end
36
+
37
+ describe "#widget" do
38
+ it "should return data for correct widget" do
39
+ w = layout.widget(1, 0)
40
+ w.should include(id: 1, title: "w3")
41
+ w = layout.widget(0, 1, timespan: 123)
42
+ w.should include(id: 2, title: "w2")
43
+ end
44
+ end
45
+
46
+ describe "#widgets" do
47
+ it "should return data for correct widgets of a page" do
48
+ datas = layout.widgets(1)
49
+ datas[0].should include(id: 1, title: "w3")
50
+ datas[1].should include(id: 2, title: "w4")
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,153 @@
1
+ require "spec_helper"
2
+
3
+ describe PulseMeter::Visualize::Page do
4
+ let(:interval){ 100 }
5
+ let!(:a_sensor){ PulseMeter::Sensor::Timelined::Counter.new(:a_sensor, :ttl => 1000, :interval => interval, annotation: 'A') }
6
+ let!(:b_sensor){ PulseMeter::Sensor::Timelined::Counter.new(:b_sensor, :ttl => 1000, :interval => interval, annotation: 'B') }
7
+
8
+ let(:type) { :some_type }
9
+ let(:widget_name){ "some_widget" }
10
+
11
+ let(:redraw_interval){5}
12
+ let(:values_label){'xxxx'}
13
+ let(:width){6}
14
+ let(:show_last_point){false}
15
+ let(:timespan){interval * 2}
16
+ let(:a_color){'#FF0000'}
17
+ let(:b_color){'#FFFF00'}
18
+
19
+ let(:interval_start){ Time.at((Time.now.to_i / interval) * interval) }
20
+ let(:page_title){"Dashboard"}
21
+
22
+
23
+ let(:page) do
24
+ p = PulseMeter::Visualize::DSL::Page.new(page_title)
25
+ p.pie(widget_name) do |w|
26
+ w.redraw_interval redraw_interval
27
+ w.values_label values_label
28
+ w.width width
29
+ w.show_last_point show_last_point
30
+ w.timespan timespan
31
+
32
+ w.sensor :a_sensor, color: a_color
33
+ w.sensor :b_sensor, color: b_color
34
+ end
35
+ p.line(widget_name) do |w|
36
+ w.redraw_interval redraw_interval
37
+ w.values_label values_label
38
+ w.width width
39
+ w.show_last_point show_last_point
40
+ w.timespan timespan
41
+
42
+ w.sensor :a_sensor, color: a_color
43
+ w.sensor :b_sensor, color: b_color
44
+ end
45
+ p.to_data
46
+ end
47
+
48
+ before(:each) do
49
+ Timecop.freeze(interval_start + 1) do
50
+ a_sensor.event(12)
51
+ b_sensor.event(33)
52
+ end
53
+ Timecop.freeze(interval_start + interval + 1) do
54
+ a_sensor.event(111)
55
+ end
56
+ end
57
+
58
+ describe "#widget_data" do
59
+
60
+ it "should generate correct data of single widget" do
61
+ Timecop.freeze(interval_start + 2 * interval - 1) do
62
+ page.widget_data(0)[:id].should == 1
63
+ page.widget_data(1)[:id].should == 2
64
+ end
65
+ end
66
+
67
+ it "should generate correct data of single widget" do
68
+ Timecop.freeze(interval_start + 2 * interval - 1) do
69
+ page.widget_data(0)[:series].should ==
70
+ {
71
+ data: [
72
+ [a_sensor.annotation, 12],
73
+ [b_sensor.annotation, 33]
74
+ ],
75
+ options: [
76
+ {color: a_color},
77
+ {color: b_color}
78
+ ]
79
+ }
80
+ page.widget_data(1)[:series].should ==
81
+ {
82
+ titles: [a_sensor.annotation, b_sensor.annotation],
83
+ rows: [[interval_start.to_i * 1000, 12, 33]],
84
+ options: [
85
+ {color: a_color},
86
+ {color: b_color}
87
+ ]
88
+ }
89
+ end
90
+
91
+ Timecop.freeze(interval_start + 2 * interval - 1) do
92
+ page.widget_data(0, timespan: 0)[:series].should ==
93
+ {
94
+ data: [
95
+ [a_sensor.annotation, 12],
96
+ [b_sensor.annotation, 33]
97
+ ],
98
+ options: [
99
+ {color: a_color},
100
+ {color: b_color}
101
+ ]
102
+ }
103
+ page.widget_data(1, timespan: 1)[:series].should ==
104
+ {
105
+ titles: [a_sensor.annotation, b_sensor.annotation],
106
+ rows: [],
107
+ options: [
108
+ {color: a_color},
109
+ {color: b_color}
110
+ ]
111
+ }
112
+
113
+ end
114
+
115
+
116
+ end
117
+ end
118
+
119
+ describe "#widget_datas" do
120
+ it "should generate correct ids for all widgets" do
121
+ Timecop.freeze(interval_start + 2 * interval - 1) do
122
+ page.widget_datas.map{|h| h[:id]}.should == [1,2]
123
+ end
124
+ end
125
+
126
+ it "should generate correct series data of all widgets" do
127
+ Timecop.freeze(interval_start + 2 * interval - 1) do
128
+
129
+ page.widget_datas.map{|h| h[:series]}.should == [
130
+ {
131
+ data: [
132
+ [a_sensor.annotation, 12],
133
+ [b_sensor.annotation, 33]
134
+ ],
135
+ options: [
136
+ {color: a_color},
137
+ {color: b_color}
138
+ ]
139
+ },
140
+ {
141
+ titles: [a_sensor.annotation, b_sensor.annotation],
142
+ rows: [[interval_start.to_i * 1000, 12, 33]],
143
+ options: [
144
+ {color: a_color},
145
+ {color: b_color}
146
+ ]
147
+ }
148
+ ]
149
+ end
150
+
151
+ end
152
+ end
153
+ end