jma_feed 0.0.2 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jma_feed/atom/eqvol.rb +7 -0
- data/lib/jma_feed/atom/extra.rb +7 -0
- data/lib/jma_feed/atom/other.rb +7 -0
- data/lib/jma_feed/atom/regular.rb +7 -0
- data/lib/jma_feed/atom.rb +70 -0
- data/lib/jma_feed/entity/weather_alert/metrics_item.rb +14 -0
- data/lib/jma_feed/entity/weather_alert.rb +348 -0
- data/lib/jma_feed/node/base_node.rb +4 -0
- data/lib/jma_feed/report.rb +14 -1
- data/lib/jma_feed/report_entry/jmx/discharge.rb +4 -0
- data/lib/jma_feed/report_entry/jmx/earthquake.rb +22 -0
- data/lib/jma_feed/report_entry/jmx/earthquake_intensity.rb +14 -0
- data/lib/jma_feed/report_entry/jmx/humidity.rb +20 -0
- data/lib/jma_feed/report_entry/jmx/precipitation.rb +13 -0
- data/lib/jma_feed/report_entry/jmx/significancy.rb +14 -0
- data/lib/jma_feed/report_entry/jmx/snow_fall_depth.rb +20 -0
- data/lib/jma_feed/report_entry/jmx/tidal_level.rb +20 -0
- data/lib/jma_feed/report_entry/jmx/time_define.rb +18 -0
- data/lib/jma_feed/report_entry/jmx/visibility.rb +20 -0
- data/lib/jma_feed/report_entry/jmx/water_level.rb +4 -0
- data/lib/jma_feed/report_entry/jmx/wave_height.rb +20 -0
- data/lib/jma_feed/report_entry/jmx/wind_direction.rb +20 -0
- data/lib/jma_feed/report_entry/jmx/wind_speed.rb +20 -0
- data/lib/jma_feed/report_entry/vphw50.rb +4 -4
- data/lib/jma_feed/report_entry/vprn50.rb +5 -4
- data/lib/jma_feed/report_entry/vpww54.rb +221 -32
- data/lib/jma_feed/report_entry/vxse53.rb +135 -0
- data/lib/jma_feed/report_entry.rb +19 -2
- data/lib/jma_feed/result.rb +21 -22
- data/lib/jma_feed/result_doc.rb +53 -0
- data/lib/jma_feed/result_entry.rb +24 -1
- data/lib/jma_feed/version.rb +1 -1
- data/lib/jma_feed.rb +10 -3
- metadata +26 -8
- data/lib/jma_feed/api.rb +0 -48
- data/lib/jma_feed/entity/alert.rb +0 -176
@@ -0,0 +1,20 @@
|
|
1
|
+
class JMAFeed::JMX::Visibility < Giri::TextNodeInteger
|
2
|
+
xml_attribute :type
|
3
|
+
xml_attribute :unit
|
4
|
+
xml_attribute :ref_id, with_name: "refID"
|
5
|
+
xml_attribute :condition
|
6
|
+
xml_attribute :description
|
7
|
+
|
8
|
+
def time_define
|
9
|
+
(context.time_define_list || []).find{ref_id && ref_id == _1.time_id}
|
10
|
+
end
|
11
|
+
|
12
|
+
def metrics_item
|
13
|
+
@metrics_item ||= JMAFeed::WeatherAlert::MetricsItem.new(
|
14
|
+
name: type,
|
15
|
+
value: self,
|
16
|
+
description: description,
|
17
|
+
time_define: time_define,
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class JMAFeed::JMX::WaveHeight < Giri::TextNodeBigDecimal
|
2
|
+
xml_attribute :type
|
3
|
+
xml_attribute :unit
|
4
|
+
xml_attribute :ref_id, with_name: "refID"
|
5
|
+
# xml_attribute :condition
|
6
|
+
xml_attribute :description
|
7
|
+
|
8
|
+
def time_define
|
9
|
+
(context.time_define_list || []).find{ref_id && ref_id == _1.time_id}
|
10
|
+
end
|
11
|
+
|
12
|
+
def metrics_item
|
13
|
+
@metrics_item ||= JMAFeed::WeatherAlert::MetricsItem.new(
|
14
|
+
name: type,
|
15
|
+
value: self,
|
16
|
+
description: description,
|
17
|
+
time_define: time_define,
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class JMAFeed::JMX::WindDirection < Giri::TextNodeString
|
2
|
+
xml_attribute :type
|
3
|
+
xml_attribute :unit
|
4
|
+
xml_attribute :ref_id, with_name: "refID"
|
5
|
+
xml_attribute :condition
|
6
|
+
xml_attribute :description
|
7
|
+
|
8
|
+
def time_define
|
9
|
+
(context.time_define_list || []).find{ref_id && ref_id == _1.time_id}
|
10
|
+
end
|
11
|
+
|
12
|
+
def metrics_item
|
13
|
+
@metrics_item ||= JMAFeed::WeatherAlert::MetricsItem.new(
|
14
|
+
name: type,
|
15
|
+
value: self,
|
16
|
+
description: description,
|
17
|
+
time_define: time_define,
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class JMAFeed::JMX::WindSpeed < Giri::TextNodeInteger
|
2
|
+
xml_attribute :type
|
3
|
+
xml_attribute :unit
|
4
|
+
xml_attribute :ref_id, with_name: "refID"
|
5
|
+
xml_attribute :condition
|
6
|
+
xml_attribute :description
|
7
|
+
|
8
|
+
def time_define
|
9
|
+
(context.time_define_list || []).find{ref_id && ref_id == _1.time_id}
|
10
|
+
end
|
11
|
+
|
12
|
+
def metrics_item
|
13
|
+
@metrics_item ||= JMAFeed::WeatherAlert::MetricsItem.new(
|
14
|
+
name: type,
|
15
|
+
value: self,
|
16
|
+
description: description,
|
17
|
+
time_define: time_define,
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
@@ -22,19 +22,19 @@ class JMAFeed::VPHW50 < JMAFeed::ReportEntry
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def warning_area_type1
|
26
26
|
warning.find{|w| w.type == "竜巻注意情報(発表細分)"}
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
29
|
+
def warning_area_type2
|
30
30
|
warning.find{|w| w.type == "竜巻注意情報(一次細分区域等)"}
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
33
|
+
def warning_area_type3
|
34
34
|
warning.find{|w| w.type == "竜巻注意情報(市町村等をまとめた地域等)"}
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
37
|
+
def warning_area_type4
|
38
38
|
warning.find{|w| w.type == "竜巻注意情報(市町村等)"}
|
39
39
|
end
|
40
40
|
end
|
@@ -40,6 +40,7 @@ class JMAFeed::VPRN50 < JMAFeed::ReportEntry
|
|
40
40
|
|
41
41
|
xml_node :body do
|
42
42
|
xml_node_collection :meteorological_infos do
|
43
|
+
xml_attribute :type
|
43
44
|
xml_node_collection :meteorological_info do
|
44
45
|
date_time_node :date_time
|
45
46
|
xml_node_collection :item do
|
@@ -82,19 +83,19 @@ class JMAFeed::VPRN50 < JMAFeed::ReportEntry
|
|
82
83
|
end
|
83
84
|
end
|
84
85
|
|
85
|
-
def
|
86
|
+
def info_area_type1
|
86
87
|
meteorological_infos[0].meteorological_info[0]
|
87
88
|
end
|
88
89
|
|
89
|
-
def
|
90
|
+
def info_area_type2
|
90
91
|
meteorological_infos[1].meteorological_info[0]
|
91
92
|
end
|
92
93
|
|
93
|
-
def
|
94
|
+
def info_area_type3
|
94
95
|
meteorological_infos[2].meteorological_info[0]
|
95
96
|
end
|
96
97
|
|
97
|
-
def
|
98
|
+
def info_area_type4
|
98
99
|
meteorological_infos[3].meteorological_info[0]
|
99
100
|
end
|
100
101
|
end
|
@@ -11,67 +11,256 @@
|
|
11
11
|
# </MeteorologicalInfos>
|
12
12
|
#
|
13
13
|
class JMAFeed::VPWW54 < JMAFeed::ReportEntry
|
14
|
+
class WarningItemKind < Giri::BaseNode
|
15
|
+
text_node :name
|
16
|
+
text_node :code
|
17
|
+
text_node :status
|
18
|
+
text_node :condition
|
19
|
+
xml_node :last_kind do
|
20
|
+
text_node :name
|
21
|
+
text_node :code
|
22
|
+
end
|
23
|
+
xml_node_collection :next_kinds do
|
24
|
+
xml_node :next_kind do
|
25
|
+
text_node :name
|
26
|
+
text_node :code
|
27
|
+
date_time_node :date_time do
|
28
|
+
xml_attribute :precision, type: :duration
|
29
|
+
end
|
30
|
+
text_node :sentence
|
31
|
+
end
|
32
|
+
end
|
33
|
+
xml_node :attention do
|
34
|
+
text_node :note, collection: true
|
35
|
+
end
|
36
|
+
xml_node :addition do
|
37
|
+
text_node :note, collection: true
|
38
|
+
end
|
39
|
+
|
40
|
+
def weather_alert
|
41
|
+
@weather_alert ||= JMAFeed::WeatherAlert.all.find{|a| a.code == code}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
14
45
|
xml_node :body do
|
46
|
+
text_node :notice, collection: true
|
15
47
|
xml_node_collection :warning do
|
16
48
|
xml_attribute :type
|
17
49
|
xml_node_collection :item do
|
18
|
-
xml_node_collection :kind
|
19
|
-
text_node :name
|
20
|
-
text_node :code
|
21
|
-
text_node :status
|
22
|
-
text_node :condition
|
23
|
-
xml_node :attention do
|
24
|
-
text_node :note, collection: true
|
25
|
-
end
|
26
|
-
xml_node :addition do
|
27
|
-
text_node :note, collection: true
|
28
|
-
end
|
29
|
-
|
30
|
-
def alert
|
31
|
-
@alert ||= JMAFeed::Alert.all.find{|a| a.code == code}
|
32
|
-
end
|
33
|
-
end
|
50
|
+
xml_node_collection :kind, type: "JMAFeed::VPWW54::WarningItemKind"
|
34
51
|
text_node :change_status
|
35
52
|
xml_node :area, type: "JMAFeed::JMX::Area"
|
36
53
|
|
37
|
-
JMAFeed::
|
54
|
+
JMAFeed::WeatherAlert.clusters.each do |cluster,alerts|
|
38
55
|
define_method cluster do
|
39
56
|
kind.find{|k| alerts.map(&:code).include?(k.code)}
|
40
57
|
end
|
41
58
|
end
|
42
59
|
end
|
43
60
|
end
|
61
|
+
|
44
62
|
xml_node :meteorological_infos do
|
45
63
|
xml_attribute :type
|
46
64
|
xml_node :time_series_info do
|
65
|
+
context :time_define_list do
|
66
|
+
time_defines.time_define
|
67
|
+
end
|
68
|
+
|
47
69
|
xml_node :time_defines do
|
48
|
-
xml_node_collection :time_define
|
49
|
-
xml_attribute :time_id, with_name: :lower_camelcase
|
50
|
-
date_time_node :date_time
|
51
|
-
duration_node :duration
|
52
|
-
text_node :name
|
53
|
-
end
|
70
|
+
xml_node_collection :time_define, type: "JMAFeed::JMX::TimeDefine"
|
54
71
|
end
|
55
72
|
xml_node_collection :item do
|
56
|
-
|
73
|
+
xml_node_collection :kind do
|
74
|
+
text_node :name
|
75
|
+
text_node :code
|
76
|
+
text_node :condition
|
77
|
+
xml_node_collection :property do
|
78
|
+
text_node :type
|
79
|
+
|
80
|
+
JMAFeed::WeatherAlert.metrics_components.each do |metr_component|
|
81
|
+
xml_node_collection "#{metr_component[:name]}_part".to_sym do
|
82
|
+
xml_node :base do
|
83
|
+
xml_node_collection metr_component[:name], type: "JMAFeed::JMX::#{metr_component[:name].to_s.camelize}"
|
84
|
+
|
85
|
+
xml_node_collection :local do
|
86
|
+
text_node :area_name
|
87
|
+
xml_node_collection metr_component[:name], type: "JMAFeed::JMX::#{metr_component[:name].to_s.camelize}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def weather_alert
|
95
|
+
@weather_alert ||= JMAFeed::WeatherAlert.all.find{|a| a.code == code}
|
96
|
+
end
|
97
|
+
|
98
|
+
# EXAMPLE of data structure
|
99
|
+
# {
|
100
|
+
# "土砂災害危険度" => {"全体" => [...]},
|
101
|
+
# "浸水害危険度" => {"全体" => [...]},
|
102
|
+
# "1時間最大雨量" => {"全体" => [...]},
|
103
|
+
# "3時間最大雨量" => {"全体" => [...]},
|
104
|
+
# }
|
105
|
+
# or
|
106
|
+
# {
|
107
|
+
# "土砂災害危険度" => {"山地" => [...], "平地" => [...]},
|
108
|
+
# "浸水害危険度" => {"山地" => [...], "平地" => [...]},
|
109
|
+
# "1時間最大雨量" => {"山地" => [...], "平地" => [...]},
|
110
|
+
# "3時間最大雨量" => {"山地" => [...], "平地" => [...]},
|
111
|
+
# }
|
112
|
+
def weather_alert_metrics
|
113
|
+
return nil unless weather_alert
|
114
|
+
weather_alert.metrics.map do |k,v|
|
115
|
+
metrics_part = property.find{_1.type == v[:property_type]}&.public_send("#{v[:name]}_part")
|
116
|
+
metrics_bases = metrics_part&.map(&:base)
|
117
|
+
metrics_items = if metrics_bases && metrics_bases.length > 0
|
118
|
+
primary_base = metrics_bases.first
|
119
|
+
metrics_bases_area_items = if primary_base.local && primary_base.local.length > 0
|
120
|
+
metrics_bases.map{|b|
|
121
|
+
b.local.map{|l|
|
122
|
+
[
|
123
|
+
l.area_name,
|
124
|
+
l.public_send(v[:name]).map(&:metrics_item)
|
125
|
+
]
|
126
|
+
}.to_h
|
127
|
+
}
|
128
|
+
else
|
129
|
+
metrics_bases.map{|b|
|
130
|
+
[
|
131
|
+
[
|
132
|
+
"全体",
|
133
|
+
b.public_send(v[:name]).map(&:metrics_item)
|
134
|
+
]
|
135
|
+
].to_h
|
136
|
+
}
|
137
|
+
end
|
138
|
+
|
139
|
+
metrics_bases_area_items.find{|area_items|
|
140
|
+
local_area_name, area_metrics_items = area_items.first
|
141
|
+
area_metrics_items.first.name == k
|
142
|
+
}
|
143
|
+
else
|
144
|
+
nil
|
145
|
+
end
|
146
|
+
|
147
|
+
if metrics_items
|
148
|
+
[k, metrics_items]
|
149
|
+
else
|
150
|
+
nil
|
151
|
+
end
|
152
|
+
end.compact.to_h
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
JMAFeed::WeatherAlert.clusters.each do |cluster,alerts|
|
157
|
+
define_method cluster do
|
158
|
+
kind.find{|k| alerts.map(&:code).include?(k.code)}
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
xml_node :area, type: "JMAFeed::JMX::Area"
|
57
163
|
end
|
58
164
|
end
|
59
165
|
end
|
60
166
|
|
61
|
-
def
|
62
|
-
warning
|
167
|
+
def warning_area_type1
|
168
|
+
warning.find{|w| w.type == "気象警報・注意報(府県予報区等)"}
|
169
|
+
end
|
170
|
+
|
171
|
+
def warning_area_type2
|
172
|
+
warning.find{|w| w.type == "気象警報・注意報(一次細分区域等)"}
|
173
|
+
end
|
174
|
+
|
175
|
+
def warning_area_type3
|
176
|
+
warning.find{|w| w.type == "気象警報・注意報(市町村等をまとめた地域等)"}
|
177
|
+
end
|
178
|
+
|
179
|
+
def warning_area_type4
|
180
|
+
warning.find{|w| w.type == "気象警報・注意報(市町村等)"}
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def detect_with_area(area, weather_alert_clusters: nil)
|
185
|
+
weather_alert_clusters ||= JMAFeed::WeatherAlert.clusters.keys
|
186
|
+
warning_item = detect_warning_item_with_area(area)
|
187
|
+
return nil unless warning_item
|
188
|
+
|
189
|
+
warning_alerts = weather_alert_clusters.map{|cluster|
|
190
|
+
warning_item.public_send(cluster)
|
191
|
+
}.compact
|
192
|
+
|
193
|
+
info_item = detect_info_item_with_area(area)
|
194
|
+
info_alerts = info_item && weather_alert_clusters.map{|cluster|
|
195
|
+
info_item.public_send(cluster)
|
196
|
+
}.compact
|
197
|
+
|
198
|
+
AreaAlert.new(
|
199
|
+
entry: self,
|
200
|
+
area: area,
|
201
|
+
weather_warnings: warning_alerts.map{|w|
|
202
|
+
WeatherWarning.new(w, info: info_alerts&.find{|i| i.code == w.code})
|
203
|
+
}
|
204
|
+
)
|
205
|
+
end
|
206
|
+
|
207
|
+
def detect_warning_item_with_area(area)
|
208
|
+
items = if area.is_a?(JMACode::AreaInformationCity)
|
209
|
+
body.warning_area_type4.item
|
210
|
+
else
|
211
|
+
if area.used_by.include?("area_forecast_type3_in_weather_alert")
|
212
|
+
body.warning_area_type3.item
|
213
|
+
elsif area.used_by.include?("area_forecast_type2_in_weather_alert")
|
214
|
+
body.warning_area_type2.item
|
215
|
+
elsif area.used_by.include?("area_forecast_type1_in_weather_alert")
|
216
|
+
body.warning_area_type1.item
|
217
|
+
else
|
218
|
+
nil
|
219
|
+
end
|
220
|
+
end
|
221
|
+
items&.find{_1.area.code == area.code}
|
222
|
+
end
|
223
|
+
|
224
|
+
def detect_info_item_with_area(area)
|
225
|
+
# NOTE: 当該電文で特別警報・警報・注意報の全てが解除される場合、MeteorologicalInfos 部は省略される。 (気象警報・注意報(H27)_解説資料.pdf > 3-3)
|
226
|
+
return nil unless body.meteorological_infos
|
227
|
+
|
228
|
+
if area.is_a?(JMACode::AreaInformationCity)
|
229
|
+
body.meteorological_infos.time_series_info.item.find{_1.area.code == area.code}
|
230
|
+
else
|
231
|
+
nil
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
class AreaAlert < Struct.new(:entry, :area, :weather_warnings, keyword_init: true)
|
236
|
+
end
|
237
|
+
|
238
|
+
class WeatherWarning < DelegateClass(WarningItemKind)
|
239
|
+
attr_reader :info
|
240
|
+
def initialize(warning, info:)
|
241
|
+
@warning = warning
|
242
|
+
@info = info
|
243
|
+
super(warning)
|
244
|
+
end
|
245
|
+
|
246
|
+
def cluster
|
247
|
+
weather_alert.cluster
|
248
|
+
end
|
249
|
+
|
250
|
+
def risk_level
|
251
|
+
weather_alert.risk_level
|
63
252
|
end
|
64
253
|
|
65
|
-
def
|
66
|
-
|
254
|
+
def attentions
|
255
|
+
attention&.note
|
67
256
|
end
|
68
257
|
|
69
|
-
def
|
70
|
-
|
258
|
+
def additions
|
259
|
+
addition&.note
|
71
260
|
end
|
72
261
|
|
73
|
-
def
|
74
|
-
|
262
|
+
def metrics
|
263
|
+
info&.weather_alert_metrics
|
75
264
|
end
|
76
265
|
end
|
77
266
|
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# 地震情報(震源・震度に関する情報)
|
2
|
+
# https://xml.kishou.go.jp/tec_material.html
|
3
|
+
# 電文毎の解説資料 > 解説資料セットzip > 地震火山関連_解説資料.pdf > (ウ)地震情報(震源・震度に関する情報)
|
4
|
+
#
|
5
|
+
class JMAFeed::VXSE53 < JMAFeed::ReportEntry
|
6
|
+
xml_node :head do
|
7
|
+
text_node :event_id, with_name: "EventID"
|
8
|
+
end
|
9
|
+
|
10
|
+
xml_node :body do
|
11
|
+
xml_node :earthquake, type: "JMAFeed::JMX::Earthquake"
|
12
|
+
|
13
|
+
xml_node :intensity do
|
14
|
+
xml_node :observation do
|
15
|
+
xml_node :code_define do
|
16
|
+
text_node :type, collection: true do
|
17
|
+
xml_attribute :xpath
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
text_node :max_int
|
22
|
+
|
23
|
+
xml_node_collection :pref do
|
24
|
+
text_node :name
|
25
|
+
text_node :code
|
26
|
+
xml_node :max_int, type: "JMAFeed::JMX::EarthquakeIntensity"
|
27
|
+
text_node :revise
|
28
|
+
xml_node_collection :area do
|
29
|
+
text_node :name
|
30
|
+
text_node :code
|
31
|
+
xml_node :max_int, type: "JMAFeed::JMX::EarthquakeIntensity"
|
32
|
+
text_node :revise
|
33
|
+
xml_node_collection :city do
|
34
|
+
text_node :name
|
35
|
+
text_node :code
|
36
|
+
xml_node :max_int, type: "JMAFeed::JMX::EarthquakeIntensity"
|
37
|
+
text_node :revise
|
38
|
+
text_node :condition
|
39
|
+
xml_node_collection :intensity_station do
|
40
|
+
text_node :name
|
41
|
+
text_node :code
|
42
|
+
xml_node :int, type: "JMAFeed::JMX::EarthquakeIntensity"
|
43
|
+
text_node :revise
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
xml_node :comments do
|
52
|
+
xml_node :forecast_comment do
|
53
|
+
xml_attribute :code_type
|
54
|
+
text_node :text
|
55
|
+
text_node :code
|
56
|
+
end
|
57
|
+
xml_node :var_comment do
|
58
|
+
xml_attribute :code_type
|
59
|
+
text_node :text
|
60
|
+
text_node :code
|
61
|
+
end
|
62
|
+
xml_node :free_form_comment do
|
63
|
+
text_node :text
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def detect_with_area(area)
|
69
|
+
pref = detect_pref_with_area(area)
|
70
|
+
return nil unless pref
|
71
|
+
|
72
|
+
earthquake = body.earthquake
|
73
|
+
comments = [
|
74
|
+
body.comments&.forecast_comment&.text,
|
75
|
+
body.comments&.var_comment&.text,
|
76
|
+
body.comments&.free_form_comment&.text,
|
77
|
+
].compact
|
78
|
+
if area.is_a?(JMACode::Prefecture)
|
79
|
+
AreaAlert.new(entry: self, area: area, intensity: pref, earthquake: earthquake, comments: comments)
|
80
|
+
else
|
81
|
+
local_area = detect_local_area_with_area(area, pref)
|
82
|
+
if local_area && area.is_a?(JMACode::AreaForecastLocalE)
|
83
|
+
AreaAlert.new(entry: self, area: area, intensity: local_area, earthquake: earthquake, comments: comments)
|
84
|
+
else
|
85
|
+
city = detect_city_with_area(area, local_area)
|
86
|
+
if city && area.is_a?(JMACode::AreaInformationCity)
|
87
|
+
AreaAlert.new(entry: self, area: area, intensity: city, earthquake: earthquake, comments: comments)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def detect_pref_with_area(area)
|
94
|
+
intensity = body.intensity
|
95
|
+
return nil unless intensity
|
96
|
+
|
97
|
+
prefs = intensity.observation.pref
|
98
|
+
pref_code = if area.is_a?(JMACode::Prefecture)
|
99
|
+
area.code
|
100
|
+
elsif area.is_a?(JMACode::AreaForecastLocalE)
|
101
|
+
area.prefecture_code
|
102
|
+
elsif area.is_a?(JMACode::AreaInformationCity)
|
103
|
+
area.prefecture_code
|
104
|
+
else
|
105
|
+
nil
|
106
|
+
end
|
107
|
+
|
108
|
+
prefs.find{|pr| pr.code == pref_code}
|
109
|
+
end
|
110
|
+
|
111
|
+
def detect_local_area_with_area(area, pref_node)
|
112
|
+
area_code = if area.is_a?(JMACode::AreaForecastLocalE)
|
113
|
+
area.code
|
114
|
+
elsif area.is_a?(JMACode::AreaInformationCity)
|
115
|
+
area.area_forecast_local_e_code
|
116
|
+
else
|
117
|
+
nil
|
118
|
+
end
|
119
|
+
|
120
|
+
pref_node.area.find{|ar| ar.code == area_code}
|
121
|
+
end
|
122
|
+
|
123
|
+
def detect_city_with_area(area, local_area_node)
|
124
|
+
city_code = if area.is_a?(JMACode::AreaInformationCity)
|
125
|
+
area.code
|
126
|
+
else
|
127
|
+
nil
|
128
|
+
end
|
129
|
+
|
130
|
+
local_area_node.city.find{|c| c.code == city_code}
|
131
|
+
end
|
132
|
+
|
133
|
+
class AreaAlert < Struct.new(:entry, :area, :intensity, :earthquake, :comments, keyword_init: true)
|
134
|
+
end
|
135
|
+
end
|
@@ -1,10 +1,13 @@
|
|
1
1
|
require "nokogiri"
|
2
|
-
require "giri"
|
3
2
|
|
4
|
-
class JMAFeed::ReportEntry <
|
3
|
+
class JMAFeed::ReportEntry < JMAFeed::BaseNode
|
5
4
|
class << self
|
6
5
|
def get(url)
|
7
6
|
xml = Net::HTTP.get(URI.parse(url))
|
7
|
+
build(xml)
|
8
|
+
end
|
9
|
+
|
10
|
+
def build(xml)
|
8
11
|
doc = Nokogiri::XML(xml)
|
9
12
|
new(doc.root)
|
10
13
|
end
|
@@ -25,16 +28,30 @@ class JMAFeed::ReportEntry < Giri::BaseNode
|
|
25
28
|
text_node :info_type
|
26
29
|
text_node :info_kind
|
27
30
|
text_node :info_kind_version
|
31
|
+
xml_node :headline do
|
32
|
+
text_node :text
|
33
|
+
end
|
28
34
|
end
|
29
35
|
end
|
30
36
|
|
31
37
|
require "jma_feed/report_entry/jmx/area"
|
38
|
+
require "jma_feed/report_entry/jmx/time_define"
|
32
39
|
require "jma_feed/report_entry/jmx/significancy"
|
33
40
|
require "jma_feed/report_entry/jmx/precipitation"
|
34
41
|
require "jma_feed/report_entry/jmx/water_level"
|
35
42
|
require "jma_feed/report_entry/jmx/discharge"
|
43
|
+
require "jma_feed/report_entry/jmx/wind_direction"
|
44
|
+
require "jma_feed/report_entry/jmx/wind_speed"
|
45
|
+
require "jma_feed/report_entry/jmx/wave_height"
|
46
|
+
require "jma_feed/report_entry/jmx/visibility"
|
47
|
+
require "jma_feed/report_entry/jmx/snow_fall_depth"
|
48
|
+
require "jma_feed/report_entry/jmx/humidity"
|
49
|
+
require "jma_feed/report_entry/jmx/tidal_level"
|
50
|
+
require "jma_feed/report_entry/jmx/earthquake"
|
51
|
+
require "jma_feed/report_entry/jmx/earthquake_intensity"
|
36
52
|
require "jma_feed/report_entry/vprn50"
|
37
53
|
require "jma_feed/report_entry/vpww54"
|
38
54
|
require "jma_feed/report_entry/vxko"
|
39
55
|
require "jma_feed/report_entry/vphw50"
|
40
56
|
require "jma_feed/report_entry/vptaii"
|
57
|
+
require "jma_feed/report_entry/vxse53"
|
data/lib/jma_feed/result.rb
CHANGED
@@ -13,52 +13,51 @@ class JMAFeed::Result
|
|
13
13
|
http_result.body
|
14
14
|
end
|
15
15
|
|
16
|
+
def modified?
|
17
|
+
http_result.kind_of?(Net::HTTPSuccess)
|
18
|
+
end
|
19
|
+
|
16
20
|
def last_modified
|
17
21
|
DateTime.parse(http_result["Last-Modified"])
|
18
22
|
end
|
19
23
|
|
20
24
|
def doc
|
21
|
-
@doc ||=
|
25
|
+
@doc ||= JMAFeed::ResultDoc.new(body)
|
22
26
|
end
|
23
27
|
|
24
|
-
def namespace
|
25
|
-
|
26
|
-
end
|
28
|
+
# def namespace
|
29
|
+
# {atom: doc.root.namespace.href}
|
30
|
+
# end
|
27
31
|
|
28
|
-
def text(name)
|
29
|
-
|
30
|
-
end
|
32
|
+
# def text(name)
|
33
|
+
# doc.xpath("/atom:feed/atom:#{name}", namespace).text
|
34
|
+
# end
|
31
35
|
|
32
36
|
def title
|
33
|
-
|
37
|
+
doc.title
|
34
38
|
end
|
35
39
|
|
36
40
|
def subtitle
|
37
|
-
|
41
|
+
doc.subtitle
|
38
42
|
end
|
39
43
|
|
40
44
|
def id
|
41
|
-
|
45
|
+
doc.id
|
42
46
|
end
|
43
47
|
|
44
48
|
def updated
|
45
|
-
|
49
|
+
doc.updated
|
46
50
|
end
|
47
51
|
|
48
52
|
def related
|
49
|
-
|
53
|
+
doc.related
|
50
54
|
end
|
51
55
|
|
52
56
|
def entries
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
updated: entry.xpath('atom:updated', namespace).text,
|
59
|
-
author: entry.xpath('atom:author/atom:name', namespace).text,
|
60
|
-
content: entry.xpath('atom:content', namespace).text,
|
61
|
-
)
|
62
|
-
end
|
57
|
+
doc.entries
|
58
|
+
end
|
59
|
+
|
60
|
+
def all_entries
|
61
|
+
doc.all_entries
|
63
62
|
end
|
64
63
|
end
|