skiplan_client 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/Rakefile +1 -1
- data/data/lumi_response.xml +1485 -1485
- data/lib/skiplan_client/attribute_helper.rb +11 -0
- data/lib/skiplan_client/forecast.rb +59 -0
- data/lib/skiplan_client/metrics.rb +63 -0
- data/lib/skiplan_client/version.rb +1 -1
- data/lib/skiplan_client/weather_object.rb +3 -75
- data/lib/skiplan_client.rb +12 -79
- data/test/skiplan_client/forecast_test.rb +37 -0
- data/test/skiplan_client/metrics_test.rb +74 -0
- data/test/skiplan_client/skiplan_client_test.rb +41 -65
- data/test/skiplan_client/weather_object_test.rb +0 -24
- metadata +26 -5
- checksums.yaml +0 -15
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'skiplan_client/attribute_helper'
|
3
|
+
|
4
|
+
class Forecast
|
5
|
+
|
6
|
+
include AttributeHelper
|
7
|
+
|
8
|
+
def initialize(attributes)
|
9
|
+
self.attributes = attributes
|
10
|
+
end
|
11
|
+
|
12
|
+
def weather_am
|
13
|
+
@CIEL_ID
|
14
|
+
end
|
15
|
+
|
16
|
+
def weather_pm
|
17
|
+
@CIEL_ID_APM
|
18
|
+
end
|
19
|
+
|
20
|
+
def temp_am
|
21
|
+
@TEMPERATURE
|
22
|
+
end
|
23
|
+
|
24
|
+
def temp_pm
|
25
|
+
@TEMPERATURE_APM
|
26
|
+
end
|
27
|
+
|
28
|
+
def temp_felt
|
29
|
+
@TEMPERATURE_RESSENTIE
|
30
|
+
end
|
31
|
+
|
32
|
+
def wind_speed
|
33
|
+
@VENT
|
34
|
+
end
|
35
|
+
|
36
|
+
def wind_dir
|
37
|
+
@DIRECTION
|
38
|
+
end
|
39
|
+
|
40
|
+
def avalanche
|
41
|
+
@VALRISQUE
|
42
|
+
end
|
43
|
+
|
44
|
+
def snow_height
|
45
|
+
@CUMUL
|
46
|
+
end
|
47
|
+
|
48
|
+
def last_fall
|
49
|
+
@DERNIERE_CHUTE
|
50
|
+
end
|
51
|
+
|
52
|
+
def fresh_snow
|
53
|
+
@NEIGE
|
54
|
+
end
|
55
|
+
|
56
|
+
def visibility
|
57
|
+
@VISIBILITE
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'skiplan_client/attribute_helper'
|
3
|
+
|
4
|
+
class Metrics
|
5
|
+
|
6
|
+
include AttributeHelper
|
7
|
+
|
8
|
+
METRICS = ['SKI_ALPIN', 'SKI_ALPIN_VERTES', 'SKI_ALPIN_BLEUES', 'SKI_ALPIN_ROUGES', 'SKI_ALPIN_NOIRES',
|
9
|
+
'SKI_NORDIQUE', 'SKI_NORDIQUE_VERTES', 'SKI_NORDIQUE_BLEUES', 'SKI_NORDIQUE_ROUGES', 'SKI_NORDIQUE_NOIRES',
|
10
|
+
'PIETONS', 'RAQUETTES', 'LUGE', 'SNOWPARK']
|
11
|
+
|
12
|
+
def initialize(attributes)
|
13
|
+
self.attributes = attributes.keep_if {|k, v| METRICS.include?(k)} unless attributes.nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
def alpine
|
17
|
+
alpine_metrics = {}
|
18
|
+
alpine_metrics[:total] = get_ratio(@SKI_ALPIN)
|
19
|
+
alpine_metrics[:green] = get_ratio(@SKI_ALPIN_VERTES)
|
20
|
+
alpine_metrics[:blue] = get_ratio(@SKI_ALPIN_BLEUES)
|
21
|
+
alpine_metrics[:red] = get_ratio(@SKI_ALPIN_ROUGES)
|
22
|
+
alpine_metrics[:black] = get_ratio(@SKI_ALPIN_NOIRES)
|
23
|
+
|
24
|
+
alpine_metrics
|
25
|
+
end
|
26
|
+
|
27
|
+
def nordic
|
28
|
+
nordic_metrics = {}
|
29
|
+
nordic_metrics[:total] = get_ratio(@SKI_NORDIQUE)
|
30
|
+
nordic_metrics[:green] = get_ratio(@SKI_NORDIQUE_VERTES)
|
31
|
+
nordic_metrics[:blue] = get_ratio(@SKI_NORDIQUE_BLEUES)
|
32
|
+
nordic_metrics[:red] = get_ratio(@SKI_NORDIQUE_ROUGES)
|
33
|
+
nordic_metrics[:black] = get_ratio(@SKI_NORDIQUE_NOIRES)
|
34
|
+
|
35
|
+
nordic_metrics
|
36
|
+
end
|
37
|
+
|
38
|
+
def pedestrian
|
39
|
+
{:total => get_ratio_km(@PIETONS)}
|
40
|
+
end
|
41
|
+
|
42
|
+
def snowshoes
|
43
|
+
{:total => get_ratio_km(@RAQUETTES)}
|
44
|
+
end
|
45
|
+
|
46
|
+
def sledge
|
47
|
+
{:total => get_ratio(@LUGE)}
|
48
|
+
end
|
49
|
+
|
50
|
+
def snowpark
|
51
|
+
{:total => get_ratio(@SNOWPARK)}
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def get_ratio(hash)
|
57
|
+
"#{hash['ouvertes']}/#{hash['total']}" unless hash.nil?
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_ratio_km(hash)
|
61
|
+
"#{sprintf("%g", hash['lng_ouverts'].to_f)}/#{sprintf("%g", hash['lng_total'].to_f)}km" unless hash.nil?
|
62
|
+
end
|
63
|
+
end
|
@@ -1,80 +1,8 @@
|
|
1
1
|
class WeatherObject
|
2
2
|
|
3
|
-
attr_accessor :
|
4
|
-
:auj_ciel_id_apm,
|
5
|
-
:dem_ciel_id_matin,
|
6
|
-
:dem_ciel_id_apm,
|
7
|
-
:auj_temp_matin,
|
8
|
-
:auj_temp_apm,
|
9
|
-
:dem_temp_matin,
|
10
|
-
:dem_temp_apm,
|
11
|
-
:auj_temp_rst,
|
12
|
-
:auj_vent_kmh,
|
13
|
-
:auj_vent_dir,
|
14
|
-
:auj_vit_rafales,
|
15
|
-
:visibilite,
|
16
|
-
:meteo_jour,
|
17
|
-
:dem_vent_kmh,
|
18
|
-
:dem_vent_dir,
|
19
|
-
:dem_vit_rafales,
|
20
|
-
:dem_visibilite,
|
21
|
-
:meteo_lendemain,
|
22
|
-
:j2_mat_ciel_id,
|
23
|
-
:j2_apm_ciel_id,
|
24
|
-
:j2_temp_matin,
|
25
|
-
:j2_temp_apm,
|
26
|
-
:j2_vent_kmh,
|
27
|
-
:j2_vent_dir,
|
28
|
-
:j2_vit_rafales,
|
29
|
-
:j2_visibilite,
|
30
|
-
:j3_mat_ciel_id,
|
31
|
-
:j3_apm_ciel_id,
|
32
|
-
:j3_temp_matin,
|
33
|
-
:j3_temp_apm,
|
34
|
-
:j3_vent_kmh,
|
35
|
-
:j3_vent_dir,
|
36
|
-
:j3_vit_rafales,
|
37
|
-
:j3_visibilite,
|
38
|
-
:meteo_semaine
|
39
|
-
|
40
|
-
|
41
|
-
def initialize(attributes = {})
|
42
|
-
@auj_ciel_id_matin = attributes[:auj_ciel_id_matin]
|
43
|
-
@auj_ciel_id_apm = attributes[:auj_ciel_id_apm]
|
44
|
-
@dem_ciel_id_matin = attributes[:dem_ciel_id_matin]
|
45
|
-
@dem_ciel_id_apm = attributes[:dem_ciel_id_apm]
|
46
|
-
@auj_temp_matin = attributes[:auj_temp_matin]
|
47
|
-
@auj_temp_apm = attributes[:auj_temp_apm]
|
48
|
-
@dem_temp_matin = attributes[:dem_temp_matin]
|
49
|
-
@dem_temp_apm = attributes[:dem_temp_apm]
|
50
|
-
@auj_temp_rst = attributes[:auj_temp_rst]
|
51
|
-
@auj_vent_kmh = attributes[:auj_vent_kmh]
|
52
|
-
@auj_vent_dir = attributes[:auj_vent_dir]
|
53
|
-
@auj_vit_rafales = attributes[:auj_vit_rafales]
|
54
|
-
@visibilite = attributes[:visibilite]
|
55
|
-
@meteo_jour = attributes[:meteo_jour]
|
56
|
-
@dem_vent_kmh = attributes[:dem_vent_kmh]
|
57
|
-
@dem_vent_dir = attributes[:dem_vent_dir]
|
58
|
-
@dem_vit_rafales = attributes[:dem_vit_rafales]
|
59
|
-
@dem_visibilite = attributes[:dem_visibilite]
|
60
|
-
@meteo_lendemain = attributes[:meteo_lendemain]
|
61
|
-
@j2_mat_ciel_id = attributes[:j2_mat_ciel_id]
|
62
|
-
@j2_apm_ciel_id = attributes[:j2_apm_ciel_id]
|
63
|
-
@j2_temp_matin = attributes[:j2_temp_matin]
|
64
|
-
@j2_temp_apm = attributes[:j2_temp_apm]
|
65
|
-
@j2_vent_kmh = attributes[:j2_vent_kmh]
|
66
|
-
@j2_vent_dir = attributes[:j2_vent_dir]
|
67
|
-
@j2_vit_rafales = attributes[:j2_vit_rafales]
|
68
|
-
@j2_visibilite = attributes[:j2_visibilite]
|
69
|
-
@j3_mat_ciel_id = attributes[:j3_mat_ciel_id]
|
70
|
-
@j3_apm_ciel_id = attributes[:j3_apm_ciel_id]
|
71
|
-
@j3_temp_matin = attributes[:j3_temp_matin]
|
72
|
-
@j3_temp_apm = attributes[:j3_temp_apm]
|
73
|
-
@j3_vent_kmh = attributes[:j3_vent_kmh]
|
74
|
-
@j3_vent_dir = attributes[:j3_vent_dir]
|
75
|
-
@j3_vit_rafales = attributes[:j3_vit_rafales]
|
76
|
-
@j3_visibilite = attributes[:j3_visibilite]
|
77
|
-
@meteo_semaine = attributes[:meteo_semaine]
|
3
|
+
attr_accessor :forecasts, :metrics
|
78
4
|
|
5
|
+
def initialize
|
6
|
+
@forecasts = {}
|
79
7
|
end
|
80
8
|
end
|
data/lib/skiplan_client.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
require 'skiplan_client/version'
|
2
|
+
require 'skiplan_client/forecast'
|
3
|
+
require 'skiplan_client/metrics'
|
2
4
|
require 'open-uri'
|
3
5
|
require 'nokogiri'
|
6
|
+
require 'active_support/core_ext/hash/conversions'
|
4
7
|
|
5
8
|
module SkiplanClient
|
6
9
|
|
7
10
|
# Configuration defaults
|
8
11
|
@config = {
|
9
|
-
:base_url => 'http://www.skiplan.com/php/genererXml.php?pays=france®ion=alpes&
|
12
|
+
:base_url => 'http://www.skiplan.com/php/genererXml.php?pays=france®ion=alpes&station=legrandbornand&v=1'
|
10
13
|
}
|
11
14
|
|
12
15
|
def self.configure(url)
|
@@ -14,94 +17,24 @@ module SkiplanClient
|
|
14
17
|
end
|
15
18
|
|
16
19
|
def self.get_weather(zone)
|
17
|
-
@info = []
|
18
|
-
|
19
20
|
xml = Nokogiri::XML(open(@config[:base_url]))
|
21
|
+
weather = WeatherObject.new
|
20
22
|
|
21
23
|
today_element = xml.xpath('//ZONE[@nom="' + zone + '"]')
|
22
|
-
|
23
|
-
ciel_id_auj_apm = today_element.xpath('./CIEL_ID_APM').text
|
24
|
-
auj_temp_matin = today_element.xpath('./TEMPERATURE').text
|
25
|
-
auj_temp_apm = today_element.xpath('./TEMPERATURE_APM').text
|
26
|
-
auj_temp_rst = today_element.xpath('./TEMPERATURE_RESSENTIE').text
|
27
|
-
auj_vent_kmh = today_element.xpath('./VENT').text
|
28
|
-
auj_vent_dir = today_element.xpath('./DIRECTION').text
|
29
|
-
auj_vit_rafales = today_element.xpath('./RAFALES').text
|
30
|
-
auj_visibilite = today_element.xpath('./VISIBILITE').text
|
31
|
-
|
32
|
-
meteo_jour = xml.xpath('//JOUR/LANGUE[@val="fr"]').text
|
24
|
+
weather.forecasts['j'] = Forecast.new(Hash.from_xml(today_element.to_s)['ZONE'])
|
33
25
|
|
34
26
|
tomorrow_element = xml.xpath('//ZONE[starts-with(@nom,"J+1") and @reference="' + zone + '"]')
|
35
|
-
|
36
|
-
ciel_id_dem_apm = tomorrow_element.xpath('./CIEL_ID_APM').text
|
37
|
-
dem_temp_matin = tomorrow_element.xpath('./TEMPERATURE').text
|
38
|
-
dem_temp_apm = tomorrow_element.xpath('./TEMPERATURE_APM').text
|
39
|
-
dem_vent_kmh = tomorrow_element.xpath('./VENT').text
|
40
|
-
dem_vent_dir = tomorrow_element.xpath('./DIRECTION').text
|
41
|
-
dem_vit_rafales = tomorrow_element.xpath('./RAFALES').text
|
42
|
-
dem_visibilite = tomorrow_element.xpath('./VISIBILITE').text
|
43
|
-
|
44
|
-
meteo_lendemain = xml.xpath('//LENDEMAIN/LANGUE[@val="fr"]').text
|
27
|
+
weather.forecasts['j+1'] = Forecast.new(Hash.from_xml(tomorrow_element.to_s)['ZONE'])
|
45
28
|
|
46
29
|
j2_element = xml.xpath('//ZONE[starts-with(@nom,"J+2") and @reference="' + zone + '"]')
|
47
|
-
|
48
|
-
j2_apm_ciel_id = j2_element.xpath('./CIEL_ID_APM').text
|
49
|
-
j2_temp_matin = j2_element.xpath('./TEMPERATURE').text
|
50
|
-
j2_temp_apm = j2_element.xpath('./TEMPERATURE_APM').text
|
51
|
-
j2_vent_kmh = j2_element.xpath('./VENT').text
|
52
|
-
j2_vent_dir = j2_element.xpath('./DIRECTION').text
|
53
|
-
j2_vit_rafales = j2_element.xpath('./RAFALES').text
|
54
|
-
j2_visibilite = j2_element.xpath('./VISIBILITE').text
|
30
|
+
weather.forecasts['j+2'] = Forecast.new(Hash.from_xml(j2_element.to_s)['ZONE'])
|
55
31
|
|
56
32
|
j3_element = xml.xpath('//ZONE[starts-with(@nom,"J+3") and @reference="' + zone + '"]')
|
57
|
-
|
58
|
-
j3_apm_ciel_id = j3_element.xpath('./CIEL_ID_APM').text
|
59
|
-
j3_temp_matin = j3_element.xpath('./TEMPERATURE').text
|
60
|
-
j3_temp_apm = j3_element.xpath('./TEMPERATURE_APM').text
|
61
|
-
j3_vent_kmh = j3_element.xpath('./VENT').text
|
62
|
-
j3_vent_dir = j3_element.xpath('./DIRECTION').text
|
63
|
-
j3_vit_rafales = j3_element.xpath('./RAFALES').text
|
64
|
-
j3_visibilite = j3_element.xpath('./VISIBILITE').text
|
65
|
-
|
66
|
-
meteo_semaine = xml.xpath('//SEMAINE/LANGUE[@val="fr"]').text
|
33
|
+
weather.forecasts['j+3'] = Forecast.new(Hash.from_xml(j3_element.to_s)['ZONE'])
|
67
34
|
|
35
|
+
metrics = xml.xpath('//INDICES')
|
36
|
+
weather.metrics = Metrics.new(Hash.from_xml(metrics.to_s)['INDICES'])
|
68
37
|
|
69
|
-
|
70
|
-
:auj_ciel_id_apm => ciel_id_auj_apm,
|
71
|
-
:dem_ciel_id_matin => ciel_id_dem_mat,
|
72
|
-
:dem_ciel_id_apm => ciel_id_dem_apm,
|
73
|
-
:auj_temp_matin => auj_temp_matin,
|
74
|
-
:auj_temp_apm => auj_temp_apm,
|
75
|
-
:dem_temp_matin => dem_temp_matin,
|
76
|
-
:dem_temp_apm => dem_temp_apm,
|
77
|
-
:auj_temp_rst => auj_temp_rst,
|
78
|
-
:auj_vent_kmh => auj_vent_kmh,
|
79
|
-
:auj_vent_dir => auj_vent_dir,
|
80
|
-
:auj_vit_rafales => auj_vit_rafales,
|
81
|
-
:visibilite => auj_visibilite,
|
82
|
-
:meteo_jour => meteo_jour,
|
83
|
-
:dem_vent_kmh => dem_vent_kmh,
|
84
|
-
:dem_vent_dir => dem_vent_dir,
|
85
|
-
:dem_vit_rafales => dem_vit_rafales,
|
86
|
-
:dem_visibilite => dem_visibilite,
|
87
|
-
:meteo_lendemain => meteo_lendemain,
|
88
|
-
:j2_mat_ciel_id => j2_mat_ciel_id,
|
89
|
-
:j2_apm_ciel_id => j2_apm_ciel_id,
|
90
|
-
:j2_temp_matin => j2_temp_matin,
|
91
|
-
:j2_temp_apm => j2_temp_apm,
|
92
|
-
:j2_vent_kmh => j2_vent_kmh,
|
93
|
-
:j2_vent_dir => j2_vent_dir,
|
94
|
-
:j2_vit_rafales => j2_vit_rafales,
|
95
|
-
:j2_visibilite => j2_visibilite,
|
96
|
-
:j3_mat_ciel_id => j3_mat_ciel_id,
|
97
|
-
:j3_apm_ciel_id => j3_apm_ciel_id,
|
98
|
-
:j3_temp_matin => j3_temp_matin,
|
99
|
-
:j3_temp_apm => j3_temp_apm,
|
100
|
-
:j3_vent_kmh => j3_vent_kmh,
|
101
|
-
:j3_vent_dir => j3_vent_dir,
|
102
|
-
:j3_vit_rafales => j3_vit_rafales,
|
103
|
-
:j3_visibilite => j3_visibilite,
|
104
|
-
:meteo_semaine => meteo_semaine)
|
105
|
-
@info
|
38
|
+
weather
|
106
39
|
end
|
107
40
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding : UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
gem 'shoulda'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'shoulda'
|
6
|
+
require 'skiplan_client/forecast'
|
7
|
+
|
8
|
+
class ForecastTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
should 'populate forecast with attributes values' do
|
11
|
+
forecast = Forecast.new({'TEMPERATURE' => '+10',
|
12
|
+
'TEMPERATURE_APM' => '+14',
|
13
|
+
'TEMPERATURE_RESSENTIE' => '+4',
|
14
|
+
'VENT' => '4',
|
15
|
+
'DIRECTION' => 'S',
|
16
|
+
'CIEL_ID' => '101',
|
17
|
+
'CIEL_ID_APM' => '101',
|
18
|
+
'VALRISQUE' => '3',
|
19
|
+
'CUMUL' => '100',
|
20
|
+
'NEIGE' => '20',
|
21
|
+
'DERNIERE_CHUTE' => '22/04/2014 08:31',
|
22
|
+
'VISIBILITE' => '100'})
|
23
|
+
|
24
|
+
assert_equal '101', forecast.weather_am
|
25
|
+
assert_equal '101', forecast.weather_pm
|
26
|
+
assert_equal '+10', forecast.temp_am
|
27
|
+
assert_equal '+14', forecast.temp_pm
|
28
|
+
assert_equal '+4', forecast.temp_felt
|
29
|
+
assert_equal '4', forecast.wind_speed
|
30
|
+
assert_equal 'S', forecast.wind_dir
|
31
|
+
assert_equal '3', forecast.avalanche
|
32
|
+
assert_equal '100', forecast.snow_height
|
33
|
+
assert_equal '22/04/2014 08:31', forecast.last_fall
|
34
|
+
assert_equal '20', forecast.fresh_snow
|
35
|
+
assert_equal '100', forecast.visibility
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# encoding : UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
gem 'shoulda'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'shoulda'
|
6
|
+
require 'skiplan_client/metrics'
|
7
|
+
|
8
|
+
class MetricsTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
setup do
|
11
|
+
attributes = {'SKI_ALPIN'=>{'total'=>'44', 'total_periode'=>'44', 'total_periode_hpf'=>'44', 'ouvertes_previsions'=>'0', 'ouvertes'=>'10', 'previsions'=>'0', 'fermees'=>'44', 'lng_total'=>'0.0', 'lng_ouverts'=>'0.0'},
|
12
|
+
'SKI_ALPIN_VERTES'=>{'total'=>'12', 'total_periode'=>'12', 'total_periode_hpf'=>'12', 'ouvertes_previsions'=>'0', 'ouvertes'=>'2', 'previsions'=>'0', 'fermees'=>'12', 'lng_total'=>'0.0', 'lng_ouverts'=>'0.0'},
|
13
|
+
'SKI_ALPIN_BLEUES'=>{'total'=>'15', 'total_periode'=>'15', 'total_periode_hpf'=>'15', 'ouvertes_previsions'=>'0', 'ouvertes'=>'3', 'previsions'=>'0', 'fermees'=>'15', 'lng_total'=>'0.0', 'lng_ouverts'=>'0.0'},
|
14
|
+
'SKI_ALPIN_ROUGES'=>{'total'=>'14', 'total_periode'=>'14', 'total_periode_hpf'=>'14', 'ouvertes_previsions'=>'0', 'ouvertes'=>'4', 'previsions'=>'0', 'fermees'=>'14', 'lng_total'=>'0.0', 'lng_ouverts'=>'0.0'},
|
15
|
+
'SKI_ALPIN_NOIRES'=>{'total'=>'3', 'total_periode'=>'3', 'total_periode_hpf'=>'3', 'ouvertes_previsions'=>'0', 'ouvertes'=>'1', 'previsions'=>'0', 'fermees'=>'3', 'lng_total'=>'0.0', 'lng_ouverts'=>'0.0'},
|
16
|
+
'SKI_NORDIQUE'=>{'total'=>'17', 'total_periode'=>'17', 'total_periode_hpf'=>'17', 'ouvertes_previsions'=>'0', 'ouvertes'=>'6', 'previsions'=>'0', 'fermees'=>'17', 'lng_total'=>'67.9', 'lng_ouverts'=>'0.0'},
|
17
|
+
'SKI_NORDIQUE_VERTES'=>{'total'=>'7', 'total_periode'=>'7', 'total_periode_hpf'=>'7', 'ouvertes_previsions'=>'0', 'ouvertes'=>'2', 'previsions'=>'0', 'fermees'=>'7', 'lng_total'=>'5.9', 'lng_ouverts'=>'0.0'},
|
18
|
+
'SKI_NORDIQUE_BLEUES'=>{'total'=>'4', 'total_periode'=>'4', 'total_periode_hpf'=>'4', 'ouvertes_previsions'=>'0', 'ouvertes'=>'3', 'previsions'=>'0', 'fermees'=>'4', 'lng_total'=>'20.9', 'lng_ouverts'=>'0.0'},
|
19
|
+
'SKI_NORDIQUE_ROUGES'=>{'total'=>'3', 'total_periode'=>'3', 'total_periode_hpf'=>'3', 'ouvertes_previsions'=>'0', 'ouvertes'=>'1', 'previsions'=>'0', 'fermees'=>'3', 'lng_total'=>'18.5', 'lng_ouverts'=>'0.0'},
|
20
|
+
'SKI_NORDIQUE_NOIRES'=>{'total'=>'3', 'total_periode'=>'3', 'total_periode_hpf'=>'3', 'ouvertes_previsions'=>'0', 'ouvertes'=>'0', 'previsions'=>'0', 'fermees'=>'3', 'lng_total'=>'22.6', 'lng_ouverts'=>'0.0'},
|
21
|
+
'PIETONS'=>{'total'=>'12', 'total_periode'=>'12', 'total_periode_hpf'=>'12', 'ouvertes_previsions'=>'9', 'ouvertes'=>'9', 'previsions'=>'0', 'fermees'=>'3', 'lng_total'=>'47.5', 'lng_ouverts'=>'35.0'},
|
22
|
+
'RAQUETTES'=>{'total'=>'14', 'total_periode'=>'14', 'total_periode_hpf'=>'14', 'ouvertes_previsions'=>'0', 'ouvertes'=>'1', 'previsions'=>'0', 'fermees'=>'14', 'lng_total'=>'61.0', 'lng_ouverts'=>'0.0'},
|
23
|
+
'LUGE'=>{'total'=>'4', 'total_periode'=>'4', 'total_periode_hpf'=>'4', 'ouvertes_previsions'=>'0', 'ouvertes'=>'2', 'previsions'=>'0', 'fermees'=>'4', 'lng_total'=>'0.0', 'lng_ouverts'=>'0.0'},
|
24
|
+
'SNOWPARK'=>{'total'=>'8', 'total_periode'=>'8', 'total_periode_hpf'=>'8', 'ouvertes_previsions'=>'0', 'ouvertes'=>'3', 'previsions'=>'0', 'fermees'=>'8', 'lng_total'=>'0.0', 'lng_ouverts'=>'0.0',
|
25
|
+
'BIGAIR'=>{'total'=>'0', 'total_periode'=>'0', 'total_periode_hpf'=>'0', 'ouvertes_previsions'=>'0', 'ouvertes'=>'0', 'previsions'=>'0', 'fermees'=>'0'},
|
26
|
+
'BOX'=>{'total'=>'0', 'total_periode'=>'0', 'total_periode_hpf'=>'0', 'ouvertes_previsions'=>'0', 'ouvertes'=>'0', 'previsions'=>'0', 'fermees'=>'0'},
|
27
|
+
'CHILLZONE'=>{'total'=>'0', 'total_periode'=>'0', 'total_periode_hpf'=>'0', 'ouvertes_previsions'=>'0', 'ouvertes'=>'0', 'previsions'=>'0', 'fermees'=>'0'},
|
28
|
+
'HALFPIPE'=>{'total'=>'0', 'total_periode'=>'0', 'total_periode_hpf'=>'0', 'ouvertes_previsions'=>'0', 'ouvertes'=>'0', 'previsions'=>'0', 'fermees'=>'0'},
|
29
|
+
'HIP'=>{'total'=>'0', 'total_periode'=>'0', 'total_periode_hpf'=>'0', 'ouvertes_previsions'=>'0', 'ouvertes'=>'0', 'previsions'=>'0', 'fermees'=>'0'},
|
30
|
+
'AIRBAG'=>{'total'=>'0', 'total_periode'=>'0', 'total_periode_hpf'=>'0', 'ouvertes_previsions'=>'0', 'ouvertes'=>'0', 'previsions'=>'0', 'fermees'=>'0'},
|
31
|
+
'KICKER'=>{'total'=>'0', 'total_periode'=>'0', 'total_periode_hpf'=>'0', 'ouvertes_previsions'=>'0', 'ouvertes'=>'0', 'previsions'=>'0', 'fermees'=>'0'},
|
32
|
+
'QUATERPIPE'=>{'total'=>'0', 'total_periode'=>'0', 'total_periode_hpf'=>'0', 'ouvertes_previsions'=>'0', 'ouvertes'=>'0', 'previsions'=>'0', 'fermees'=>'0'},
|
33
|
+
'RAIL'=>{'total'=>'0', 'total_periode'=>'0', 'total_periode_hpf'=>'0', 'ouvertes_previsions'=>'0', 'ouvertes'=>'0', 'previsions'=>'0', 'fermees'=>'0'},
|
34
|
+
'STEPUP'=>{'total'=>'0', 'total_periode'=>'0', 'total_periode_hpf'=>'0', 'ouvertes_previsions'=>'0', 'ouvertes'=>'0', 'previsions'=>'0', 'fermees'=>'0'},
|
35
|
+
'WATERSLIDE'=>{'total'=>'0', 'total_periode'=>'0', 'total_periode_hpf'=>'0', 'ouvertes_previsions'=>'0', 'ouvertes'=>'0', 'previsions'=>'0', 'fermees'=>'0'},
|
36
|
+
'WHOOPS'=>{'total'=>'0', 'total_periode'=>'0', 'total_periode_hpf'=>'0', 'ouvertes_previsions'=>'0', 'ouvertes'=>'0', 'previsions'=>'0', 'fermees'=>'0'},
|
37
|
+
'BOARDERCROSS'=>{'total'=>'0', 'total_periode'=>'0', 'total_periode_hpf'=>'0', 'ouvertes_previsions'=>'0', 'ouvertes'=>'0', 'previsions'=>'0', 'fermees'=>'0'},
|
38
|
+
'VIDEOZONE'=>{'total'=>'0', 'total_periode'=>'0', 'total_periode_hpf'=>'0', 'ouvertes_previsions'=>'0', 'ouvertes'=>'0', 'previsions'=>'0', 'fermees'=>'0'},
|
39
|
+
'SPEEDZONE'=>{'total'=>'0', 'total_periode'=>'0', 'total_periode_hpf'=>'0', 'ouvertes_previsions'=>'0', 'ouvertes'=>'0', 'previsions'=>'0', 'fermees'=>'0'}}}
|
40
|
+
@metrics = Metrics.new(attributes)
|
41
|
+
end
|
42
|
+
|
43
|
+
should 'return metrics for alpine slopes' do
|
44
|
+
assert_equal '10/44', @metrics.alpine[:total]
|
45
|
+
assert_equal '2/12', @metrics.alpine[:green]
|
46
|
+
assert_equal '3/15', @metrics.alpine[:blue]
|
47
|
+
assert_equal '4/14', @metrics.alpine[:red]
|
48
|
+
assert_equal '1/3', @metrics.alpine[:black]
|
49
|
+
end
|
50
|
+
|
51
|
+
should 'return metrics for nordic slopes' do
|
52
|
+
assert_equal '6/17', @metrics.nordic[:total]
|
53
|
+
assert_equal '2/7', @metrics.nordic[:green]
|
54
|
+
assert_equal '3/4', @metrics.nordic[:blue]
|
55
|
+
assert_equal '1/3', @metrics.nordic[:red]
|
56
|
+
assert_equal '0/3', @metrics.nordic[:black]
|
57
|
+
end
|
58
|
+
|
59
|
+
should 'return metrics for pedestrians' do
|
60
|
+
assert_equal '35/47.5km', @metrics.pedestrian[:total]
|
61
|
+
end
|
62
|
+
|
63
|
+
should 'return metrics for snowshoes' do
|
64
|
+
assert_equal '0/61km', @metrics.snowshoes[:total]
|
65
|
+
end
|
66
|
+
|
67
|
+
should 'return metrics for sledges' do
|
68
|
+
assert_equal '2/4', @metrics.sledge[:total]
|
69
|
+
end
|
70
|
+
|
71
|
+
should 'return metrics for snowparks' do
|
72
|
+
assert_equal '3/8', @metrics.snowpark[:total]
|
73
|
+
end
|
74
|
+
end
|
@@ -10,82 +10,58 @@ class SkiplanClientTest < Test::Unit::TestCase
|
|
10
10
|
|
11
11
|
should 'retrieve weather data' do
|
12
12
|
|
13
|
-
jour = 'Soleil et ciel bleu pr??dominent. Vent variable faible. Cette nuit : Nuit ??toil??e, puis d??gradation nuageuse en fin de nuit.En fin de nuit vent de sud-est mod??r?? dans le Pays du Mont Blanc. Sur les autres r??gions, vent plus faible.'
|
14
|
-
dem = 'Temps nuageux ?? tr??s nuageux, averses parfois orageuses en journ??e. En d??but de matin??e, vent de sud-est soufflant mod??r??ment dans le Pays du Mont Blanc, avec des rafales atteignant 55 km/h; puis att??nuation. Ailleurs, vent plus faible.'
|
15
|
-
|
16
13
|
SkiplanClient.configure('../../data/lumi_response.xml')
|
17
14
|
weather = SkiplanClient.get_weather('CHINAILLON')
|
18
15
|
|
19
|
-
|
20
|
-
assert_equal '101' ,
|
21
|
-
assert_equal '
|
22
|
-
assert_equal '
|
23
|
-
assert_equal '+
|
24
|
-
assert_equal '+
|
25
|
-
assert_equal '
|
26
|
-
assert_equal '
|
27
|
-
assert_equal '+4' , weather.auj_temp_rst
|
28
|
-
assert_equal '4' , weather.auj_vent_kmh
|
29
|
-
assert_equal 'SE' , weather.auj_vent_dir
|
30
|
-
assert_equal '0' , weather.auj_vit_rafales
|
31
|
-
assert_equal '100' , weather.visibilite
|
32
|
-
assert_equal jour , weather.meteo_jour
|
33
|
-
assert_equal '+17' , weather.dem_temp_matin
|
34
|
-
assert_equal '+21' , weather.dem_temp_apm
|
35
|
-
assert_equal '7' , weather.dem_vent_kmh
|
36
|
-
assert_equal 'SO' , weather.dem_vent_dir
|
37
|
-
assert_equal '0' , weather.dem_vit_rafales
|
38
|
-
assert_equal '100' , weather.dem_visibilite
|
39
|
-
assert_equal dem , weather.meteo_lendemain
|
40
|
-
assert_equal '106' , weather.j2_mat_ciel_id
|
41
|
-
assert_equal '104' , weather.j2_apm_ciel_id
|
42
|
-
assert_equal '+12' , weather.j2_temp_matin
|
43
|
-
assert_equal '+18' , weather.j2_temp_apm
|
44
|
-
assert_equal '7' , weather.j2_vent_kmh
|
45
|
-
assert_equal 'O' , weather.j2_vent_dir
|
46
|
-
assert_equal '0' , weather.j2_vit_rafales
|
47
|
-
assert_equal '100' , weather.j2_visibilite
|
48
|
-
assert_equal '101' , weather.j3_mat_ciel_id
|
49
|
-
assert_equal '103' , weather.j3_apm_ciel_id
|
50
|
-
assert_equal '+16' , weather.j3_temp_matin
|
51
|
-
assert_equal '+20' , weather.j3_temp_apm
|
52
|
-
assert_equal '7' , weather.j3_vent_kmh
|
53
|
-
assert_equal 'O' , weather.j3_vent_dir
|
54
|
-
assert_equal '0' , weather.j3_vit_rafales
|
55
|
-
assert_equal '100' , weather.j3_visibilite
|
56
|
-
assert_equal '' , weather.meteo_semaine
|
16
|
+
today_forecast = weather.forecasts['j']
|
17
|
+
assert_equal '101' , today_forecast.weather_am
|
18
|
+
assert_equal '101' , today_forecast.weather_pm
|
19
|
+
assert_equal '+12' , today_forecast.temp_am
|
20
|
+
assert_equal '+20' , today_forecast.temp_pm
|
21
|
+
assert_equal '+4' , today_forecast.temp_felt
|
22
|
+
assert_equal '4' , today_forecast.wind_speed
|
23
|
+
assert_equal 'SE' , today_forecast.wind_dir
|
57
24
|
|
58
|
-
|
25
|
+
tomorrow_forecast = weather.forecasts['j+1']
|
26
|
+
assert_equal '104' , tomorrow_forecast.weather_am
|
27
|
+
assert_equal '106' , tomorrow_forecast.weather_pm
|
28
|
+
assert_equal '+17' , tomorrow_forecast.temp_am
|
29
|
+
assert_equal '+21' , tomorrow_forecast.temp_pm
|
30
|
+
assert_equal '7' , tomorrow_forecast.wind_speed
|
31
|
+
assert_equal 'SO' , tomorrow_forecast.wind_dir
|
59
32
|
|
60
|
-
|
33
|
+
j2_forecast = weather.forecasts['j+2']
|
34
|
+
assert_equal '106' , j2_forecast.weather_am
|
35
|
+
assert_equal '104' , j2_forecast.weather_pm
|
36
|
+
assert_equal '+12' , j2_forecast.temp_am
|
37
|
+
assert_equal '+18' , j2_forecast.temp_pm
|
38
|
+
assert_equal '7' , j2_forecast.wind_speed
|
39
|
+
assert_equal 'O' , j2_forecast.wind_dir
|
61
40
|
|
62
|
-
|
63
|
-
|
41
|
+
j3_forecast = weather.forecasts['j+3']
|
42
|
+
assert_equal '101' , j3_forecast.weather_am
|
43
|
+
assert_equal '103' , j3_forecast.weather_pm
|
44
|
+
assert_equal '+16' , j3_forecast.temp_am
|
45
|
+
assert_equal '+20' , j3_forecast.temp_pm
|
46
|
+
assert_equal '7' , j3_forecast.wind_speed
|
47
|
+
assert_equal 'O' , j3_forecast.wind_dir
|
48
|
+
end
|
64
49
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
assert_equal '+14' , weather.auj_temp_apm
|
69
|
-
assert_equal '104' , weather.dem_ciel_id_matin
|
70
|
-
assert_equal '106' , weather.dem_ciel_id_apm
|
71
|
-
assert_equal '+14' , weather.dem_temp_matin
|
72
|
-
assert_equal '+13' , weather.dem_temp_apm
|
73
|
-
assert_equal '106' , weather.j2_mat_ciel_id
|
74
|
-
assert_equal '104' , weather.j2_apm_ciel_id
|
75
|
-
assert_equal '+7' , weather.j2_temp_matin
|
76
|
-
assert_equal '+11' , weather.j2_temp_apm
|
77
|
-
assert_equal '101' , weather.j3_mat_ciel_id
|
78
|
-
assert_equal '103' , weather.j3_apm_ciel_id
|
79
|
-
assert_equal '+12' , weather.j3_temp_matin
|
80
|
-
assert_equal '+14' , weather.j3_temp_apm
|
50
|
+
should 'retrieve metrics data' do
|
51
|
+
SkiplanClient.configure('../../data/lumi_response.xml')
|
52
|
+
metrics = SkiplanClient.get_weather('CHINAILLON').metrics
|
81
53
|
|
54
|
+
assert_equal '0/44', metrics.alpine[:total]
|
55
|
+
assert_equal '0/17', metrics.nordic[:total]
|
56
|
+
assert_equal '9/12', metrics.pedestrian[:total]
|
57
|
+
assert_equal '0/14', metrics.snowshoes[:total]
|
58
|
+
assert_equal '0/4', metrics.sledge[:total]
|
59
|
+
assert_equal '0/8', metrics.snowpark[:total]
|
82
60
|
end
|
83
61
|
|
84
62
|
should 'change config url' do
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
assert_equal 'http://api.openweathermap.org/data/2.5/forecast/daily?q=tokyo&mode=xml&units=metric&cnt=1', config
|
63
|
+
config = SkiplanClient.configure('my_new_url')
|
64
|
+
assert_equal 'my_new_url', config
|
89
65
|
end
|
90
66
|
|
91
67
|
end
|
@@ -7,28 +7,4 @@ require 'skiplan_client/weather_object'
|
|
7
7
|
|
8
8
|
class WeatherObjectTest < Test::Unit::TestCase
|
9
9
|
|
10
|
-
should 'test information completed' do
|
11
|
-
@weather_object = []
|
12
|
-
hash_result = {:auj_ciel_id_matin => 'id_ciel_test1',
|
13
|
-
:auj_ciel_id_apm => 'id_ciel_test2',
|
14
|
-
:dem_ciel_id_matin => 'id_ciel_test3',
|
15
|
-
:dem_ciel_id_apm => 'id_ciel_test4',
|
16
|
-
:auj_temp_matin => 'auj_temp_matin',
|
17
|
-
:auj_temp_apm => 'auj_temp_apm',
|
18
|
-
:dem_temp_matin => 'dem_temp_matin',
|
19
|
-
:dem_temp_apm => 'dem_temp_apm'
|
20
|
-
}
|
21
|
-
|
22
|
-
@weather_object = WeatherObject.new(hash_result)
|
23
|
-
|
24
|
-
assert_equal 'id_ciel_test1', @weather_object.auj_ciel_id_matin
|
25
|
-
assert_equal 'id_ciel_test2', @weather_object.auj_ciel_id_apm
|
26
|
-
assert_equal 'id_ciel_test3', @weather_object.dem_ciel_id_matin
|
27
|
-
assert_equal 'id_ciel_test4', @weather_object.dem_ciel_id_apm
|
28
|
-
assert_equal 'auj_temp_matin', @weather_object.auj_temp_matin
|
29
|
-
assert_equal 'auj_temp_apm', @weather_object.auj_temp_apm
|
30
|
-
assert_equal 'dem_temp_matin', @weather_object.dem_temp_matin
|
31
|
-
assert_equal 'dem_temp_apm', @weather_object.dem_temp_apm
|
32
|
-
|
33
|
-
end
|
34
10
|
end
|