gerbilcharts 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/License.txt +21 -0
- data/Manifest.txt +75 -0
- data/PostInstall.txt +7 -0
- data/README.txt +174 -0
- data/Rakefile +4 -0
- data/lib/gerbilcharts.rb +18 -0
- data/lib/gerbilcharts/charts.rb +16 -0
- data/lib/gerbilcharts/charts/area_chart.rb +36 -0
- data/lib/gerbilcharts/charts/bar_chart.rb +33 -0
- data/lib/gerbilcharts/charts/bar_chart_compact.rb +26 -0
- data/lib/gerbilcharts/charts/chart_base.rb +123 -0
- data/lib/gerbilcharts/charts/impulse_chart.rb +30 -0
- data/lib/gerbilcharts/charts/line_chart.rb +35 -0
- data/lib/gerbilcharts/charts/stacked_area_chart.rb +31 -0
- data/lib/gerbilcharts/models.rb +19 -0
- data/lib/gerbilcharts/models/bucketized_timeseries_graph_model.rb +138 -0
- data/lib/gerbilcharts/models/discrete_time_range.rb +63 -0
- data/lib/gerbilcharts/models/graph_model.rb +89 -0
- data/lib/gerbilcharts/models/graph_model_group.rb +240 -0
- data/lib/gerbilcharts/models/monotonous_graph_model.rb +192 -0
- data/lib/gerbilcharts/models/presets.rb +94 -0
- data/lib/gerbilcharts/models/raw_range.rb +68 -0
- data/lib/gerbilcharts/models/round_range.rb +104 -0
- data/lib/gerbilcharts/models/round_time_range.rb +105 -0
- data/lib/gerbilcharts/models/sampled_timeseries_graph_model.rb +80 -0
- data/lib/gerbilcharts/models/simple_timeseries_model_group.rb +68 -0
- data/lib/gerbilcharts/models/time_series_graph_model.rb +34 -0
- data/lib/gerbilcharts/public/brushmetal.css +197 -0
- data/lib/gerbilcharts/public/gerbil.js +327 -0
- data/lib/gerbilcharts/surfaces.rb +32 -0
- data/lib/gerbilcharts/surfaces/area_surface.rb +46 -0
- data/lib/gerbilcharts/surfaces/axis.rb +31 -0
- data/lib/gerbilcharts/surfaces/bar_surface.rb +62 -0
- data/lib/gerbilcharts/surfaces/basic_grid.rb +17 -0
- data/lib/gerbilcharts/surfaces/chart.rb +132 -0
- data/lib/gerbilcharts/surfaces/graph_element.rb +170 -0
- data/lib/gerbilcharts/surfaces/grid.rb +38 -0
- data/lib/gerbilcharts/surfaces/horizontal_axis.rb +32 -0
- data/lib/gerbilcharts/surfaces/horizontal_name_axis.rb +28 -0
- data/lib/gerbilcharts/surfaces/horizontal_time_axis.rb +25 -0
- data/lib/gerbilcharts/surfaces/impulse_surface.rb +47 -0
- data/lib/gerbilcharts/surfaces/legend.rb +59 -0
- data/lib/gerbilcharts/surfaces/line_surface.rb +53 -0
- data/lib/gerbilcharts/surfaces/mark_band.rb +17 -0
- data/lib/gerbilcharts/surfaces/panel.rb +17 -0
- data/lib/gerbilcharts/surfaces/pie_surface.rb +16 -0
- data/lib/gerbilcharts/surfaces/rect.rb +86 -0
- data/lib/gerbilcharts/surfaces/stacked_area_surface.rb +66 -0
- data/lib/gerbilcharts/surfaces/stacked_grid.rb +15 -0
- data/lib/gerbilcharts/surfaces/surface.rb +20 -0
- data/lib/gerbilcharts/surfaces/surface_background.rb +13 -0
- data/lib/gerbilcharts/surfaces/title_panel.rb +44 -0
- data/lib/gerbilcharts/surfaces/tracker.rb +62 -0
- data/lib/gerbilcharts/surfaces/vertical_axis.rb +46 -0
- data/lib/gerbilcharts/svgdc.rb +22 -0
- data/lib/gerbilcharts/svgdc/filters.rb +40 -0
- data/lib/gerbilcharts/svgdc/presentation_attributes.rb +50 -0
- data/lib/gerbilcharts/svgdc/svg_circle.rb +22 -0
- data/lib/gerbilcharts/svgdc/svg_custom_win.rb +36 -0
- data/lib/gerbilcharts/svgdc/svg_element.rb +87 -0
- data/lib/gerbilcharts/svgdc/svg_line.rb +26 -0
- data/lib/gerbilcharts/svgdc/svg_polygon.rb +34 -0
- data/lib/gerbilcharts/svgdc/svg_polyline.rb +27 -0
- data/lib/gerbilcharts/svgdc/svg_rect.rb +29 -0
- data/lib/gerbilcharts/svgdc/svg_shape.rb +10 -0
- data/lib/gerbilcharts/svgdc/svg_text.rb +21 -0
- data/lib/gerbilcharts/svgdc/svg_win.rb +52 -0
- data/lib/gerbilcharts/svgdc/svgdc.rb +335 -0
- data/lib/gerbilcharts/svgdc/transformations.rb +66 -0
- data/lib/gerbilcharts/version.rb +9 -0
- data/setup.rb +1585 -0
- data/test/test_Scratch.rb +21 -0
- data/test/test_charts.rb +119 -0
- data/test/test_gerbilcharts.rb +11 -0
- data/test/test_helper.rb +2 -0
- data/test/test_models.rb +118 -0
- data/test/test_noob.rb +81 -0
- data/test/test_ranges.rb +135 -0
- data/test/test_svgdc.rb +221 -0
- data/test/trafgen.rb +25 -0
- metadata +156 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestScratch < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
end
|
7
|
+
|
8
|
+
def teardown
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def test_1
|
13
|
+
|
14
|
+
g=GerbilCharts::SVGDC::SVGDC.new(300,200)
|
15
|
+
g.circle(40,50,20, :id => "What" )
|
16
|
+
g.render( :file => "/tmp/Scratch1.svg")
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
data/test/test_charts.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestCharts < Test::Unit::TestCase
|
4
|
+
|
5
|
+
attr_reader :test_vector_tm1
|
6
|
+
attr_reader :test_vector_tm2
|
7
|
+
attr_reader :mod1, :mod2, :modbucket1
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@test_vector_tm1 = []
|
11
|
+
@test_vector_tm2 = []
|
12
|
+
@test_vector_tm3 = []
|
13
|
+
tbeg = Time.local( 1978, "jun", 5, 9, 10, 0, 0)
|
14
|
+
sbeg = tbeg
|
15
|
+
sec_inc = 1000
|
16
|
+
|
17
|
+
for i in (0..20)
|
18
|
+
@test_vector_tm1 << [sbeg + i*sec_inc, i*sec_inc*1000 ]
|
19
|
+
@test_vector_tm2 << [sbeg + i*sec_inc, i*sec_inc*1200 ]
|
20
|
+
@test_vector_tm3 << [sbeg + i*sec_inc, i*sec_inc*1000*rand() ]
|
21
|
+
end
|
22
|
+
|
23
|
+
@mod1 = GerbilCharts::Models::TimeSeriesGraphModel.new("External Gateway")
|
24
|
+
@mod1.add_tuples @test_vector_tm1
|
25
|
+
|
26
|
+
@mod2 = GerbilCharts::Models::TimeSeriesGraphModel.new("209.216.22.220")
|
27
|
+
@mod2.add_tuples @test_vector_tm2
|
28
|
+
|
29
|
+
@mod3 = GerbilCharts::Models::TimeSeriesGraphModel.new("udldev Print Server")
|
30
|
+
@mod3.add_tuples @test_vector_tm3
|
31
|
+
|
32
|
+
@modgroup = GerbilCharts::Models::GraphModelGroup.new("Hosts")
|
33
|
+
@modgroup.add(@mod1)
|
34
|
+
@modgroup.add(@mod2)
|
35
|
+
@modgroup.add(@mod3)
|
36
|
+
|
37
|
+
setup_bucketized_models()
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def setup_bucketized_models
|
42
|
+
# bucketized models
|
43
|
+
modbucket1 = GerbilCharts::Models::BucketizedTimeSeriesGraphModel.new("Out Bw",60)
|
44
|
+
tbeg = Time.local( 1978, "jun", 5, 9, 10, 0, 0)
|
45
|
+
sbeg = tbeg
|
46
|
+
|
47
|
+
#second with some gaps
|
48
|
+
sbeg = tbeg
|
49
|
+
test_vector_bucket_1 = []
|
50
|
+
test_vector_bucket_1 << [sbeg + 60, 1000 ]
|
51
|
+
test_vector_bucket_1 << [sbeg + 120, 1000 ]
|
52
|
+
test_vector_bucket_1 << [sbeg + 180, 1000 ]
|
53
|
+
test_vector_bucket_1 << [sbeg + 239, 1000 ]
|
54
|
+
test_vector_bucket_1 << [sbeg + 295, 1000 ]
|
55
|
+
test_vector_bucket_1 << [sbeg + 296, 1000 ]
|
56
|
+
test_vector_bucket_1 << [sbeg + 297, 5000 ]
|
57
|
+
test_vector_bucket_1 << [sbeg + 298, 1000 ]
|
58
|
+
test_vector_bucket_1 << [sbeg + 360, 1000 ]
|
59
|
+
test_vector_bucket_1 << [sbeg + 420, 1000 ]
|
60
|
+
test_vector_bucket_1 << [sbeg + 480, 1000 ]
|
61
|
+
test_vector_bucket_1 << [sbeg + 530, 1000 ]
|
62
|
+
test_vector_bucket_1 << [sbeg + 604, 1000 ]
|
63
|
+
test_vector_bucket_1 << [sbeg + 800, 1000 ]
|
64
|
+
modbucket1.add_tuples(test_vector_bucket_1)
|
65
|
+
|
66
|
+
#second with some gaps
|
67
|
+
modbucket2 = GerbilCharts::Models::BucketizedTimeSeriesGraphModel.new("In Bw",60)
|
68
|
+
sbeg = tbeg
|
69
|
+
test_vector_bucket_2 = []
|
70
|
+
test_vector_bucket_2 << [sbeg + 10, 1800 ]
|
71
|
+
test_vector_bucket_2 << [sbeg + 20, 2600 ]
|
72
|
+
test_vector_bucket_2 << [sbeg + 22, 1000 ]
|
73
|
+
test_vector_bucket_2 << [sbeg + 60, 1000 ]
|
74
|
+
test_vector_bucket_2 << [sbeg + 120, 1900 ]
|
75
|
+
test_vector_bucket_2 << [sbeg + 180, 700 ]
|
76
|
+
test_vector_bucket_2 << [sbeg + 240, 5000 ]
|
77
|
+
test_vector_bucket_2 << [sbeg + 301, 1000 ]
|
78
|
+
test_vector_bucket_2 << [sbeg + 350, 1000 ]
|
79
|
+
test_vector_bucket_2 << [sbeg + 420, 100 ]
|
80
|
+
test_vector_bucket_2 << [sbeg + 470, 500 ]
|
81
|
+
test_vector_bucket_2 << [sbeg + 540, 1000 ]
|
82
|
+
modbucket2.add_tuples(test_vector_bucket_2)
|
83
|
+
|
84
|
+
@modgroupbucketized = GerbilCharts::Models::GraphModelGroup.new("Bandwidth")
|
85
|
+
@modgroupbucketized .add(modbucket1)
|
86
|
+
@modgroupbucketized .add(modbucket2)
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
# test a line chart
|
92
|
+
def test_line_1
|
93
|
+
|
94
|
+
mychart = GerbilCharts::Charts::LineChart.new( :width => 350, :height => 200, :style => 'brushmetal.css')
|
95
|
+
mychart.setmodelgroup(@modgroup)
|
96
|
+
mychart.render('/tmp/c_linechart1.svg')
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
# test a bar chart
|
101
|
+
def test_bar_1
|
102
|
+
|
103
|
+
mychart = GerbilCharts::Charts::BarChart.new( :width => 300, :height => 150, :style => 'brushmetal.css')
|
104
|
+
mychart.setmodelgroup(@modgroup)
|
105
|
+
mychart.render('/tmp/c_barchart1.svg')
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
# test a area chart
|
110
|
+
def test_stacked_area_1
|
111
|
+
|
112
|
+
mychart = GerbilCharts::Charts::StackedAreaChart.new( :width => 350, :height => 200, :style => 'brushmetal.css')
|
113
|
+
mychart.setmodelgroup(@modgroupbucketized)
|
114
|
+
mychart.render('/tmp/c_sachart1.svg')
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
data/test/test_helper.rb
ADDED
data/test/test_models.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestModels < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
# test vector
|
7
|
+
@tvector = []
|
8
|
+
@tvector << [ Time.local(1973,"Apr",2,8,30,0), 0 ]
|
9
|
+
@tvector << [ Time.local(1973,"Apr",2,8,30,10), 0.5 ]
|
10
|
+
@tvector << [ Time.local(1973,"Apr",2,8,30,11), 18 ]
|
11
|
+
@tvector << [ Time.local(1973,"Apr",2,8,30,15), 911 ]
|
12
|
+
@tvector << [ Time.local(1973,"Apr",2,8,30,18), 100 ]
|
13
|
+
@tvector << [ Time.local(1973,"Apr",2,8,30,19), 80 ]
|
14
|
+
@tvector << [ Time.local(1973,"Apr",2,8,30,20), 98 ]
|
15
|
+
@tvector << [ Time.local(1973,"Apr",2,8,30,45), 1002 ]
|
16
|
+
@tvector << [ Time.local(1973,"Apr",2,8,30,58), 3014 ]
|
17
|
+
@tvector << [ Time.local(1973,"Apr",2,8,31,0), 1002 ]
|
18
|
+
@tvector << [ Time.local(1973,"Apr",2,8,32,0), 88 ]
|
19
|
+
@tvector << [ Time.local(1973,"Apr",2,8,32,20), 882]
|
20
|
+
@tvector << [ Time.local(1973,"Apr",2,8,32,21), 3015 ]
|
21
|
+
@tvector << [ Time.local(1973,"Apr",2,8,36,0), 10 ]
|
22
|
+
@tvector << [ Time.local(1973,"Apr",2,8,46,0), 1 ]
|
23
|
+
@tvector << [ Time.local(1973,"Apr",2,8,47,0), 2 ]
|
24
|
+
@tvector << [ Time.local(1973,"Apr",2,8,47,1), 3 ]
|
25
|
+
@tvector << [ Time.local(1973,"Apr",2,8,47,5), 4 ]
|
26
|
+
@tvector << [ Time.local(1973,"Apr",2,8,50,0), 59 ]
|
27
|
+
@tvector << [ Time.local(1973,"Apr",2,8,58,0), 188 ]
|
28
|
+
@tvector << [ Time.local(1973,"Apr",2,9,00,17), 4017 ]
|
29
|
+
@tvector << [ Time.local(1973,"Apr",2,9,20,18), 18 ]
|
30
|
+
@tvector << [ Time.local(1973,"Apr",2,9,40,20), 10 ]
|
31
|
+
@tvector << [ Time.local(1973,"Apr",2,10,13,7), 100 ]
|
32
|
+
@tvector << [ Time.local(1973,"Apr",2,10,14,7), 100 ]
|
33
|
+
@tvector << [ Time.local(1973,"Apr",2,10,15,7), 100 ]
|
34
|
+
@tvector << [ Time.local(1973,"Apr",2,10,17,7), 100 ]
|
35
|
+
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
# Test model simple
|
40
|
+
def test_model_simple
|
41
|
+
m = GerbilCharts::Models::GraphModel.new("TestModelName")
|
42
|
+
assert m.name == "TestModelName"
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
# Test timeseries graph model
|
47
|
+
def test_timeseries_1
|
48
|
+
p "--- Testing basic timeseries model --- "
|
49
|
+
|
50
|
+
# load this into a timeseries model
|
51
|
+
mod = GerbilCharts::Models::TimeSeriesGraphModel.new("TestModel1")
|
52
|
+
@tvector.each do |tpl|
|
53
|
+
mod.add (tpl[0],tpl[1])
|
54
|
+
end
|
55
|
+
|
56
|
+
#dbg_print_model(mod)
|
57
|
+
|
58
|
+
# crop over than 9:00 AM
|
59
|
+
mod.crop_older(Time.local(1973,"Apr",2,9,00,00))
|
60
|
+
|
61
|
+
#dbg_print_model(mod)
|
62
|
+
end
|
63
|
+
|
64
|
+
def dbg_print_model(mod)
|
65
|
+
|
66
|
+
# test various things about the model
|
67
|
+
rx,ry = mod.ranges
|
68
|
+
p "range x = #{rx} y = #{ry}"
|
69
|
+
|
70
|
+
# round ranges
|
71
|
+
rx,ry = mod.round_ranges
|
72
|
+
p "round range x = #{rx} y = #{ry}"
|
73
|
+
|
74
|
+
# labels
|
75
|
+
p "Labels are :"
|
76
|
+
p "First = #{rx.format_min_value}"
|
77
|
+
rx.each_label do |v,s|
|
78
|
+
p "v = #{v} s=#{s}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# testing the bucketized timeseries
|
83
|
+
# with bucket size 5 mins
|
84
|
+
def test_bucketized_1
|
85
|
+
p "--- Testing bucketized model --- "
|
86
|
+
|
87
|
+
# bucketized with sec buckets
|
88
|
+
mod = GerbilCharts::Models::BucketizedTimeSeriesGraphModel.new("TestModel2",5 * 60)
|
89
|
+
@tvector.each do |tpl|
|
90
|
+
mod.add (tpl[0],tpl[1])
|
91
|
+
end
|
92
|
+
|
93
|
+
dbg_print_model(mod)
|
94
|
+
|
95
|
+
# print data points
|
96
|
+
mod.each_tuple do |x,y|
|
97
|
+
p "bkt #{Time.at(x)} = #{y}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# test simple timeseries
|
102
|
+
def test_simple_group_1
|
103
|
+
|
104
|
+
p "Testing simple timeseries model group helper"
|
105
|
+
|
106
|
+
modelgroup = GerbilCharts::Models::SimpleTimeSeriesModelGroup.new( :title => "Sales figures",
|
107
|
+
:timeseries => (1..6).collect { |month| Time.local(2008,month) },
|
108
|
+
:models => [ ["Bruce", 1, 10, 18, 28, 80, 122],
|
109
|
+
["Rex" , 12,22, 45, 70, 218, 109],
|
110
|
+
["Buzo" , 0, 23, 25, 40, 18, 59]
|
111
|
+
]
|
112
|
+
)
|
113
|
+
modelgroup.each_model { |mod| dbg_print_model(mod) }
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
end
|
data/test/test_noob.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
require 'trafgen'
|
4
|
+
|
5
|
+
# tests some easy to use mods
|
6
|
+
# newbies enter here
|
7
|
+
class TestChartsNoob < Test::Unit::TestCase
|
8
|
+
|
9
|
+
|
10
|
+
# test sales figures of 3 sales people
|
11
|
+
# use a simple timeseries model
|
12
|
+
def test_monthly_sales
|
13
|
+
|
14
|
+
mychart = GerbilCharts::Charts::LineChart.new( :width => 350, :height => 200, :style => 'brushmetal.css',
|
15
|
+
:circle_data_points => true )
|
16
|
+
|
17
|
+
modelgroup = GerbilCharts::Models::SimpleTimeSeriesModelGroup.new(
|
18
|
+
:title => "Sales figures",
|
19
|
+
:timeseries => (1..6).collect { |month| Time.local(2008,month) },
|
20
|
+
:models => [ ["Bruce", 1, 10, 18, 28, 80, 122],
|
21
|
+
["Rex" , 112,22, 45, 70, 218, 309],
|
22
|
+
["Buzo" , 0, 23, 25, 40, 18, 59]
|
23
|
+
]
|
24
|
+
)
|
25
|
+
|
26
|
+
mychart.modelgroup=modelgroup
|
27
|
+
|
28
|
+
mychart.render('/tmp/n_monthly_sales.svg')
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
# test daily traffic
|
33
|
+
def test_daily_traf_1
|
34
|
+
|
35
|
+
mychart = GerbilCharts::Charts::ImpulseChart.new( :width => 450, :height => 200, :style => 'brushmetal.css')
|
36
|
+
|
37
|
+
tend = Time.now
|
38
|
+
tbegin = tend - 3600*24
|
39
|
+
|
40
|
+
model1 = GerbilCharts::Models::BucketizedTimeSeriesGraphModel.new( "eth0", 3600 )
|
41
|
+
TimeSeriesDataGenerator.new(tbegin,tend,300,200000, 6000000).each_tuple do |t,v|
|
42
|
+
model1.add(t,v)
|
43
|
+
end
|
44
|
+
|
45
|
+
model2 = GerbilCharts::Models::BucketizedTimeSeriesGraphModel.new( "wan1", 3600 )
|
46
|
+
TimeSeriesDataGenerator.new(tbegin,tend,300,200000, 6000000).each_tuple do |t,v|
|
47
|
+
model2.add(t,v)
|
48
|
+
end
|
49
|
+
|
50
|
+
modelgroup = GerbilCharts::Models::GraphModelGroup.new( "External Traffic")
|
51
|
+
modelgroup.add model2
|
52
|
+
modelgroup.add model1
|
53
|
+
|
54
|
+
mychart.modelgroup=modelgroup
|
55
|
+
mychart.render('/tmp/n_daily_traffic.svg')
|
56
|
+
|
57
|
+
# demo resuses the model in a different view (an area chart this time)
|
58
|
+
myareachart = GerbilCharts::Charts::AreaChart.new( :width => 450, :height => 200, :style => 'brushmetal.css')
|
59
|
+
myareachart.modelgroup=modelgroup
|
60
|
+
myareachart.render('/tmp/n_daily_traffic_area.svg')
|
61
|
+
|
62
|
+
|
63
|
+
# demo to reuse the model ina bar
|
64
|
+
mybarchart = GerbilCharts::Charts::BarChart.new( :width => 450, :height => 200, :style => 'brushmetal.css')
|
65
|
+
mybarchart.modelgroup=modelgroup
|
66
|
+
mybarchart.render('/tmp/n_daily_traffic_bar.svg')
|
67
|
+
|
68
|
+
|
69
|
+
# demo stacked area
|
70
|
+
mysachart = GerbilCharts::Charts::StackedAreaChart.new( :width => 450, :height => 200, :style => 'brushmetal.css')
|
71
|
+
mysachart.modelgroup=modelgroup
|
72
|
+
mysachart.render('/tmp/n_daily_traffic_sa.svg')
|
73
|
+
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
|
data/test/test_ranges.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestRanges < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
# test vector
|
7
|
+
@tvector = []
|
8
|
+
@tvector << [ Time.local(1973,"Apr",2,8,30,0), 0 ]
|
9
|
+
@tvector << [ Time.local(1973,"Apr",2,8,30,10), 0.5 ]
|
10
|
+
@tvector << [ Time.local(1973,"Apr",2,8,30,11), 18 ]
|
11
|
+
@tvector << [ Time.local(1973,"Apr",2,8,30,15), 911 ]
|
12
|
+
@tvector << [ Time.local(1973,"Apr",2,8,30,18), 100 ]
|
13
|
+
@tvector << [ Time.local(1973,"Apr",2,8,30,19), 80 ]
|
14
|
+
@tvector << [ Time.local(1973,"Apr",2,8,30,20), 98 ]
|
15
|
+
@tvector << [ Time.local(1973,"Apr",2,8,30,45), 1002 ]
|
16
|
+
@tvector << [ Time.local(1973,"Apr",2,8,30,58), 3014 ]
|
17
|
+
@tvector << [ Time.local(1973,"Apr",2,8,31,0), 1002 ]
|
18
|
+
@tvector << [ Time.local(1973,"Apr",2,8,32,0), 88 ]
|
19
|
+
@tvector << [ Time.local(1973,"Apr",2,8,32,20), 882]
|
20
|
+
@tvector << [ Time.local(1973,"Apr",2,8,32,21), 3015 ]
|
21
|
+
@tvector << [ Time.local(1973,"Apr",2,8,36,0), 10 ]
|
22
|
+
@tvector << [ Time.local(1973,"Apr",2,8,46,0), 1 ]
|
23
|
+
@tvector << [ Time.local(1973,"Apr",2,8,47,0), 2 ]
|
24
|
+
@tvector << [ Time.local(1973,"Apr",2,8,47,1), 3 ]
|
25
|
+
@tvector << [ Time.local(1973,"Apr",2,8,47,5), 4 ]
|
26
|
+
@tvector << [ Time.local(1973,"Apr",2,8,50,0), 59 ]
|
27
|
+
@tvector << [ Time.local(1973,"Apr",2,8,58,0), 188 ]
|
28
|
+
@tvector << [ Time.local(1973,"Apr",2,9,00,17), 4017 ]
|
29
|
+
@tvector << [ Time.local(1973,"Apr",2,9,20,18), 18 ]
|
30
|
+
@tvector << [ Time.local(1973,"Apr",2,9,40,20), 10 ]
|
31
|
+
@tvector << [ Time.local(1973,"Apr",2,10,13,7), 100 ]
|
32
|
+
@tvector << [ Time.local(1973,"Apr",2,10,14,7), 100 ]
|
33
|
+
@tvector << [ Time.local(1973,"Apr",2,10,15,7), 100 ]
|
34
|
+
@tvector << [ Time.local(1973,"Apr",2,10,17,7), 100 ]
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
# test raw range - simple version
|
39
|
+
def test_raw_range_1
|
40
|
+
r = GerbilCharts::Models::RawRange.new
|
41
|
+
|
42
|
+
[10,20,10,0,0,1001,19920,882991.22].each do |v|
|
43
|
+
r.update v
|
44
|
+
end
|
45
|
+
|
46
|
+
r.min_max do |mn,mx|
|
47
|
+
assert mn==0
|
48
|
+
assert mx==882991.22
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# test - various methods
|
53
|
+
def test_raw_range_2
|
54
|
+
r = GerbilCharts::Models::RawRange.new
|
55
|
+
[10,20,10,0,0,1001,19920,20001].each do |v|
|
56
|
+
r.update v
|
57
|
+
end
|
58
|
+
|
59
|
+
# update from another range
|
60
|
+
r2 = GerbilCharts::Models::RawRange.new
|
61
|
+
r2.update(-10)
|
62
|
+
r2.update 20002
|
63
|
+
r.update_r r2
|
64
|
+
|
65
|
+
# check if updated correctly
|
66
|
+
assert r.rmax == 20002
|
67
|
+
assert r.rmin == -10
|
68
|
+
|
69
|
+
# check scaling
|
70
|
+
fv = r.scale_factor(20002)
|
71
|
+
assert_in_delta(fv,1,0.001)
|
72
|
+
fv = r.scale_factor(10000)
|
73
|
+
assert_in_delta(fv,0.5,0.001)
|
74
|
+
|
75
|
+
# check if reset works
|
76
|
+
r.reset
|
77
|
+
assert_nil(r.rmax)
|
78
|
+
assert_nil(r.rmin)
|
79
|
+
end
|
80
|
+
|
81
|
+
# test round range
|
82
|
+
def test_round_range_1
|
83
|
+
r = GerbilCharts::Models::RawRange.new
|
84
|
+
[10,20,10,0,0,1001,19920,20001].each do |v|
|
85
|
+
r.update v
|
86
|
+
end
|
87
|
+
|
88
|
+
rr = GerbilCharts::Models::RoundRange.new(r)
|
89
|
+
assert_equal(rr.rmax,50000)
|
90
|
+
assert_equal(rr.rmin,0)
|
91
|
+
assert_equal(rr.lmax,10000,"checking ideal label interval")
|
92
|
+
|
93
|
+
r.update(50001)
|
94
|
+
rr = GerbilCharts::Models::RoundRange.new(r)
|
95
|
+
assert_equal(rr.rmax,100000)
|
96
|
+
assert_equal(rr.lmax,25000,"checking ideal label interval for a 100K interval")
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
# test time hours
|
101
|
+
def test_round_time_range_1
|
102
|
+
r = GerbilCharts::Models::RawRange.new
|
103
|
+
tbase = Time.local(1973,"Apr",2,8,30,0)
|
104
|
+
|
105
|
+
@tvector.each do |t|
|
106
|
+
r.update t[0]
|
107
|
+
end
|
108
|
+
|
109
|
+
rr = GerbilCharts::Models::RoundTimeRange.new(r)
|
110
|
+
rr.each_label do |v,s|
|
111
|
+
# p "v = #{v} s=#{s}"
|
112
|
+
end
|
113
|
+
assert_equal(rr.rdelta,7200) # 3 hr range
|
114
|
+
assert_equal(rr.ldelta,1800) # label every 30 mins
|
115
|
+
|
116
|
+
# add a 4 hr gap (9hr range + 2 hr labels)
|
117
|
+
r.update( @tvector.last[0] + 4*3600)
|
118
|
+
rr = GerbilCharts::Models::RoundTimeRange.new(r)
|
119
|
+
rr.each_label do |v,s|
|
120
|
+
# p "v = #{v} s=#{s}"
|
121
|
+
end
|
122
|
+
assert_equal(rr.rdelta,6*3600)
|
123
|
+
assert_equal(rr.ldelta,2*3600)
|
124
|
+
|
125
|
+
# add a new 10hr gap
|
126
|
+
r.update( @tvector.last[0] + 10*3600)
|
127
|
+
rr = GerbilCharts::Models::RoundTimeRange.new(r)
|
128
|
+
rr.each_label do |v,s|
|
129
|
+
# p "v = #{v} s=#{s}"
|
130
|
+
end
|
131
|
+
assert_equal(rr.rdelta,43200)
|
132
|
+
assert_equal(rr.ldelta,10800)
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|