roker 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,135 @@
1
+ require 'helper'
2
+
3
+ class TestWeatherParameter < Test::Unit::TestCase
4
+ context "a new WeatherParameter passed a TimeLayout and values" do
5
+ setup do
6
+ @interval = 3.hours
7
+ @start_at = Time.now+1.hour
8
+ @length = 4
9
+ time_spans = []
10
+ @values = []
11
+ (0..(@length-1)).each do |i|
12
+ time_spans << TimeSpan.new(:start_at => @start_at+i*@interval, :duration => @interval)
13
+ @values << i.to_f # just to make each value unique and testable
14
+ end
15
+ @time_layout = TimeLayout.new(:time_spans => time_spans)
16
+ @weather_parameter = WeatherParameter.new(:time_layout => @time_layout, :values => @values)
17
+ end
18
+
19
+ should "have default calculation method" do
20
+ assert_not_nil WeatherParameter::DEFAULT_CALCULATION_METHOD
21
+ assert_equal WeatherParameter::DEFAULT_CALCULATION_METHOD, @weather_parameter.calculation_method
22
+ end
23
+
24
+ should "have time_layout" do
25
+ assert_not_nil @weather_parameter.time_layout
26
+ end
27
+
28
+ should "have values" do
29
+ assert !@weather_parameter.values.empty?
30
+ end
31
+
32
+ should "have value for [1]" do
33
+ assert_equal 1.0, @weather_parameter[1]
34
+ end
35
+
36
+ should "have value_at of 0.0 @start_at" do
37
+ assert_equal 0.0, @weather_parameter.value_at(@start_at)
38
+ end
39
+
40
+ should "have value_at of 0.0 @start_at + half interval" do
41
+ assert_equal 0.0, @weather_parameter.value_at(@start_at+@interval/2)
42
+ end
43
+
44
+ should "have value_at of 1.0 at @start_at + 1.5 x interval" do
45
+ assert_equal 1.0, @weather_parameter.value_at(@start_at+@interval*1.5)
46
+ end
47
+
48
+ should "have value_at of 1.66666666666667 during @start_at + 1.5 x interval - @start_at + 3 x interval" do
49
+ assert_equal((1.0+2.0/3).to_s, @weather_parameter.value_at(TimeSpan.new(:start_at => @start_at+@interval*1.5, :end_at => @start_at+@interval*3)).to_s)
50
+ end
51
+
52
+ should "have value_at of 2.2 during @start_at + 1.5 x interval - @start_at + 4 x interval" do
53
+ assert_equal 2.2, @weather_parameter.value_at(TimeSpan.new(:start_at => @start_at+@interval*1.5, :end_at => @start_at+@interval*4))
54
+ end
55
+
56
+ should "have value_at of 2.2 during @start_at + 1.5 x interval - @start_at + 10 x interval" do
57
+ assert_equal 2.2, @weather_parameter.value_at(TimeSpan.new(:start_at => @start_at+@interval*1.5, :end_at => @start_at+@interval*10))
58
+ end
59
+
60
+ should "have value_at of nil outside time_layout" do
61
+ assert_equal nil, @weather_parameter.value_at(TimeSpan.new(:start_at => @start_at-100, :end_at => @start_at-10))
62
+ end
63
+
64
+ context "with the 'first' calculation method" do
65
+ setup { @weather_parameter.calculation_method = :first }
66
+ should "have value_at of 0.0 @start_at" do
67
+ assert_equal 0.0, @weather_parameter.value_at(@start_at)
68
+ end
69
+
70
+ should "have value_at of 0.0 @start_at + half interval" do
71
+ assert_equal 0.0, @weather_parameter.value_at(@start_at+@interval/2)
72
+ end
73
+
74
+ should "have value_at of 1.0 at @start_at + 1.5 x interval" do
75
+ assert_equal 1.0, @weather_parameter.value_at(@start_at+@interval*1.5)
76
+ end
77
+
78
+ should "have value_at of 1.0 during @start_at + 1.5 x interval - @start_at + 3 x interval" do
79
+ assert_equal 1.0, @weather_parameter.value_at(TimeSpan.new(:start_at => @start_at+@interval*1.5, :end_at => @start_at+@interval*3))
80
+ end
81
+
82
+ should "have value_at of 2.0 during @start_at + 2 x interval - @start_at + 3 x interval" do
83
+ assert_equal 2.0, @weather_parameter.value_at(TimeSpan.new(:start_at => @start_at+@interval*2, :end_at => @start_at+@interval*3))
84
+ end
85
+
86
+ should "have value_at of 1.0 during @start_at + 1.5 x interval - @start_at + 4 x interval" do
87
+ assert_equal 1.0, @weather_parameter.value_at(TimeSpan.new(:start_at => @start_at+@interval*1.5, :end_at => @start_at+@interval*4))
88
+ end
89
+
90
+ should "have value_at of 1.0 during @start_at + 1.5 x interval - @start_at + 10 x interval" do
91
+ assert_equal 1.0, @weather_parameter.value_at(TimeSpan.new(:start_at => @start_at+@interval*1.5, :end_at => @start_at+@interval*10))
92
+ end
93
+
94
+ should "have value_at of nil outside time_layout" do
95
+ assert_equal nil, @weather_parameter.value_at(TimeSpan.new(:start_at => @start_at-100, :end_at => @start_at-10))
96
+ end
97
+ end
98
+
99
+ context "with the 'max' calculation method" do
100
+ setup { @weather_parameter.calculation_method = :max }
101
+ should "have value_at of 0.0 @start_at" do
102
+ assert_equal 0.0, @weather_parameter.value_at(@start_at)
103
+ end
104
+
105
+ should "have value_at of 0.0 @start_at + half interval" do
106
+ assert_equal 0.0, @weather_parameter.value_at(@start_at+@interval/2)
107
+ end
108
+
109
+ should "have value_at of 1.0 at @start_at + 1.5 x interval" do
110
+ assert_equal 1.0, @weather_parameter.value_at(@start_at+@interval*1.5)
111
+ end
112
+
113
+ should "have value_at of 2.0 during @start_at + 1.5 x interval - @start_at + 3 x interval" do
114
+ assert_equal 2.0, @weather_parameter.value_at(TimeSpan.new(:start_at => @start_at+@interval*1.5, :end_at => @start_at+@interval*3))
115
+ end
116
+
117
+ should "have value_at of 2.0 during @start_at + 2 x interval - @start_at + 3 x interval" do
118
+ assert_equal 2.0, @weather_parameter.value_at(TimeSpan.new(:start_at => @start_at+@interval*2, :end_at => @start_at+@interval*3))
119
+ end
120
+
121
+ should "have value_at of 3.0 during @start_at + 1.5 x interval - @start_at + 4 x interval" do
122
+ assert_equal 3.0, @weather_parameter.value_at(TimeSpan.new(:start_at => @start_at+@interval*1.5, :end_at => @start_at+@interval*4))
123
+ end
124
+
125
+ should "have value_at of 3.0 during @start_at + 1.5 x interval - @start_at + 10 x interval" do
126
+ assert_equal 3.0, @weather_parameter.value_at(TimeSpan.new(:start_at => @start_at+@interval*1.5, :end_at => @start_at+@interval*10))
127
+ end
128
+
129
+ should "have value_at of nil outside time_layout" do
130
+ assert_equal nil, @weather_parameter.value_at(TimeSpan.new(:start_at => @start_at-100, :end_at => @start_at-10))
131
+ end
132
+ end
133
+
134
+ end
135
+ end
@@ -0,0 +1,177 @@
1
+ <?xml version="1.0"?>
2
+ <dwml version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.nws.noaa.gov/forecasts/xml/DWMLgen/schema/DWML.xsd">
3
+ <head>
4
+ <product srsName="WGS 1984" concise-name="time-series" operational-mode="official">
5
+ <title>NOAA's National Weather Service Forecast Data</title>
6
+ <field>meteorological</field>
7
+ <category>forecast</category>
8
+ <creation-date refresh-frequency="PT1H">2008-11-23T08:17:11Z</creation-date>
9
+ </product>
10
+ <source>
11
+ <more-information>http://www.nws.noaa.gov/forecasts/xml/</more-information>
12
+ <production-center>Meteorological Development Laboratory<sub-center>Product Generation Branch</sub-center></production-center>
13
+ <disclaimer>http://www.nws.noaa.gov/disclaimer.html</disclaimer>
14
+ <credit>http://www.weather.gov/</credit>
15
+ <credit-logo>http://www.weather.gov/images/xml_logo.gif</credit-logo>
16
+ <feedback>http://www.weather.gov/feedback.php</feedback>
17
+ </source>
18
+ </head>
19
+ <data>
20
+ <location>
21
+ <location-key>point1</location-key>
22
+ <point latitude="42.00" longitude="-81.00"/>
23
+ </location>
24
+ <moreWeatherInformation applicable-location="point1">http://forecast.weather.gov/MapClick.php?textField1=42.00&amp;textField2=-81.00</moreWeatherInformation>
25
+ <time-layout time-coordinate="local" summarization="none">
26
+ <layout-key>k-p24h-n1-1</layout-key>
27
+ <start-valid-time>2008-11-24T07:00:00-05:00</start-valid-time>
28
+ <end-valid-time>2008-11-24T19:00:00-05:00</end-valid-time>
29
+ </time-layout>
30
+ <time-layout time-coordinate="local" summarization="none">
31
+ <layout-key>k-p24h-n2-2</layout-key>
32
+ <start-valid-time>2008-11-23T19:00:00-05:00</start-valid-time>
33
+ <end-valid-time>2008-11-24T08:00:00-05:00</end-valid-time>
34
+ <start-valid-time>2008-11-24T19:00:00-05:00</start-valid-time>
35
+ <end-valid-time>2008-11-25T08:00:00-05:00</end-valid-time>
36
+ </time-layout>
37
+ <time-layout time-coordinate="local" summarization="none">
38
+ <layout-key>k-p12h-n3-3</layout-key>
39
+ <start-valid-time>2008-11-23T19:00:00-05:00</start-valid-time>
40
+ <end-valid-time>2008-11-24T07:00:00-05:00</end-valid-time>
41
+ <start-valid-time>2008-11-24T07:00:00-05:00</start-valid-time>
42
+ <end-valid-time>2008-11-24T19:00:00-05:00</end-valid-time>
43
+ <start-valid-time>2008-11-24T19:00:00-05:00</start-valid-time>
44
+ <end-valid-time>2008-11-25T07:00:00-05:00</end-valid-time>
45
+ </time-layout>
46
+ <time-layout time-coordinate="local" summarization="none">
47
+ <layout-key>k-p3h-n9-4</layout-key>
48
+ <start-valid-time>2008-11-24T04:00:00-05:00</start-valid-time>
49
+ <start-valid-time>2008-11-24T07:00:00-05:00</start-valid-time>
50
+ <start-valid-time>2008-11-24T10:00:00-05:00</start-valid-time>
51
+ <start-valid-time>2008-11-24T13:00:00-05:00</start-valid-time>
52
+ <start-valid-time>2008-11-24T16:00:00-05:00</start-valid-time>
53
+ <start-valid-time>2008-11-24T19:00:00-05:00</start-valid-time>
54
+ <start-valid-time>2008-11-24T22:00:00-05:00</start-valid-time>
55
+ <start-valid-time>2008-11-25T01:00:00-05:00</start-valid-time>
56
+ <start-valid-time>2008-11-25T04:00:00-05:00</start-valid-time>
57
+ </time-layout>
58
+ <time-layout time-coordinate="local" summarization="none">
59
+ <layout-key>k-p6h-n5-5</layout-key>
60
+ <start-valid-time>2008-11-24T01:00:00-05:00</start-valid-time>
61
+ <end-valid-time>2008-11-24T07:00:00-05:00</end-valid-time>
62
+ <start-valid-time>2008-11-24T07:00:00-05:00</start-valid-time>
63
+ <end-valid-time>2008-11-24T13:00:00-05:00</end-valid-time>
64
+ <start-valid-time>2008-11-24T13:00:00-05:00</start-valid-time>
65
+ <end-valid-time>2008-11-24T19:00:00-05:00</end-valid-time>
66
+ <start-valid-time>2008-11-24T19:00:00-05:00</start-valid-time>
67
+ <end-valid-time>2008-11-25T01:00:00-05:00</end-valid-time>
68
+ <start-valid-time>2008-11-25T01:00:00-05:00</start-valid-time>
69
+ <end-valid-time>2008-11-25T07:00:00-05:00</end-valid-time>
70
+ </time-layout>
71
+ <parameters applicable-location="point1">
72
+ <temperature type="maximum" units="Fahrenheit" time-layout="k-p24h-n1-1">
73
+ <name>Daily Maximum Temperature</name>
74
+ <value>42</value>
75
+ </temperature>
76
+ <temperature type="minimum" units="Fahrenheit" time-layout="k-p24h-n2-2">
77
+ <name>Daily Minimum Temperature</name>
78
+ <value>36</value>
79
+ <value>36</value>
80
+ </temperature>
81
+ <temperature type="hourly" units="Fahrenheit" time-layout="k-p3h-n9-4">
82
+ <name>Temperature</name>
83
+ <value>36</value>
84
+ <value>36</value>
85
+ <value>39</value>
86
+ <value>41</value>
87
+ <value>41</value>
88
+ <value>39</value>
89
+ <value>38</value>
90
+ <value>37</value>
91
+ <value>37</value>
92
+ </temperature>
93
+ <temperature type="dew point" units="Fahrenheit" time-layout="k-p3h-n9-4">
94
+ <name>Dew Point Temperature</name>
95
+ <value>26</value>
96
+ <value>27</value>
97
+ <value>30</value>
98
+ <value>31</value>
99
+ <value>32</value>
100
+ <value>32</value>
101
+ <value>32</value>
102
+ <value>31</value>
103
+ <value>30</value>
104
+ </temperature>
105
+ <precipitation type="liquid" units="inches" time-layout="k-p6h-n5-5">
106
+ <name>Liquid Precipitation Amount</name>
107
+ <value>0.00</value>
108
+ <value>0.09</value>
109
+ <value>0.09</value>
110
+ <value>0.06</value>
111
+ <value>0.06</value>
112
+ </precipitation>
113
+ <probability-of-precipitation type="12 hour" units="percent" time-layout="k-p12h-n3-3">
114
+ <name>12 Hourly Probability of Precipitation</name>
115
+ <value>14</value>
116
+ <value>80</value>
117
+ <value>68</value>
118
+ </probability-of-precipitation>
119
+ <wind-speed type="sustained" units="knots" time-layout="k-p3h-n9-4">
120
+ <name>Wind Speed</name>
121
+ <value>12</value>
122
+ <value>11</value>
123
+ <value>15</value>
124
+ <value>18</value>
125
+ <value>16</value>
126
+ <value>16</value>
127
+ <value>22</value>
128
+ <value>29</value>
129
+ <value>31</value>
130
+ </wind-speed>
131
+ <direction type="wind" units="degrees true" time-layout="k-p3h-n9-4">
132
+ <name>Wind Direction</name>
133
+ <value>190</value>
134
+ <value>190</value>
135
+ <value>180</value>
136
+ <value>160</value>
137
+ <value>200</value>
138
+ <value>230</value>
139
+ <value>250</value>
140
+ <value>270</value>
141
+ <value>270</value>
142
+ </direction>
143
+ <cloud-amount type="total" units="percent" time-layout="k-p3h-n9-4">
144
+ <name>Cloud Cover Amount</name>
145
+ <value>68</value>
146
+ <value>74</value>
147
+ <value>80</value>
148
+ <value>87</value>
149
+ <value>94</value>
150
+ <value>100</value>
151
+ <value>100</value>
152
+ <value>100</value>
153
+ <value>100</value>
154
+ </cloud-amount>
155
+ <humidity type="relative" units="percent" time-layout="k-p3h-n9-4">
156
+ <name>Relative Humidity</name>
157
+ <value>66</value>
158
+ <value>69</value>
159
+ <value>70</value>
160
+ <value>67</value>
161
+ <value>70</value>
162
+ <value>76</value>
163
+ <value>79</value>
164
+ <value>79</value>
165
+ <value>75</value>
166
+ </humidity>
167
+ <water-state time-layout="k-p12h-n3-3">
168
+ <waves type="significant" units="feet">
169
+ <name>Wave Height</name>
170
+ <value>2</value>
171
+ <value>5</value>
172
+ <value>11</value>
173
+ </waves>
174
+ </water-state>
175
+ </parameters>
176
+ </data>
177
+ </dwml>
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Greg Sterndale
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-05 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: mocha
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.1
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hpricot
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.6.164
44
+ version:
45
+ description: Weather forecasts from weather.gov
46
+ email: gsterndale@gmail.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.rdoc
54
+ files:
55
+ - .document
56
+ - .gitignore
57
+ - LICENSE
58
+ - README.rdoc
59
+ - Rakefile
60
+ - VERSION
61
+ - lib/numeric.rb
62
+ - lib/roker.rb
63
+ - lib/time.rb
64
+ - lib/time_layout.rb
65
+ - lib/time_span.rb
66
+ - lib/weather_parameter.rb
67
+ - roker
68
+ - roker.gemspec
69
+ - test/helper.rb
70
+ - test/test_roker.rb
71
+ - test/test_time.rb
72
+ - test/test_time_layout.rb
73
+ - test/test_time_span.rb
74
+ - test/test_weather_parameter.rb
75
+ - test/weather_xml.xml
76
+ has_rdoc: true
77
+ homepage: http://github.com/gsterndale/roker
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options:
82
+ - --charset=UTF-8
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ version:
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: "0"
96
+ version:
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.3.5
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Weather forecasts from weather.gov
104
+ test_files:
105
+ - test/helper.rb
106
+ - test/test_roker.rb
107
+ - test/test_time.rb
108
+ - test/test_time_layout.rb
109
+ - test/test_time_span.rb
110
+ - test/test_weather_parameter.rb