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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jma_feed/atom/eqvol.rb +7 -0
  3. data/lib/jma_feed/atom/extra.rb +7 -0
  4. data/lib/jma_feed/atom/other.rb +7 -0
  5. data/lib/jma_feed/atom/regular.rb +7 -0
  6. data/lib/jma_feed/atom.rb +70 -0
  7. data/lib/jma_feed/entity/weather_alert/metrics_item.rb +14 -0
  8. data/lib/jma_feed/entity/weather_alert.rb +348 -0
  9. data/lib/jma_feed/node/base_node.rb +4 -0
  10. data/lib/jma_feed/report.rb +14 -1
  11. data/lib/jma_feed/report_entry/jmx/discharge.rb +4 -0
  12. data/lib/jma_feed/report_entry/jmx/earthquake.rb +22 -0
  13. data/lib/jma_feed/report_entry/jmx/earthquake_intensity.rb +14 -0
  14. data/lib/jma_feed/report_entry/jmx/humidity.rb +20 -0
  15. data/lib/jma_feed/report_entry/jmx/precipitation.rb +13 -0
  16. data/lib/jma_feed/report_entry/jmx/significancy.rb +14 -0
  17. data/lib/jma_feed/report_entry/jmx/snow_fall_depth.rb +20 -0
  18. data/lib/jma_feed/report_entry/jmx/tidal_level.rb +20 -0
  19. data/lib/jma_feed/report_entry/jmx/time_define.rb +18 -0
  20. data/lib/jma_feed/report_entry/jmx/visibility.rb +20 -0
  21. data/lib/jma_feed/report_entry/jmx/water_level.rb +4 -0
  22. data/lib/jma_feed/report_entry/jmx/wave_height.rb +20 -0
  23. data/lib/jma_feed/report_entry/jmx/wind_direction.rb +20 -0
  24. data/lib/jma_feed/report_entry/jmx/wind_speed.rb +20 -0
  25. data/lib/jma_feed/report_entry/vphw50.rb +4 -4
  26. data/lib/jma_feed/report_entry/vprn50.rb +5 -4
  27. data/lib/jma_feed/report_entry/vpww54.rb +221 -32
  28. data/lib/jma_feed/report_entry/vxse53.rb +135 -0
  29. data/lib/jma_feed/report_entry.rb +19 -2
  30. data/lib/jma_feed/result.rb +21 -22
  31. data/lib/jma_feed/result_doc.rb +53 -0
  32. data/lib/jma_feed/result_entry.rb +24 -1
  33. data/lib/jma_feed/version.rb +1 -1
  34. data/lib/jma_feed.rb +10 -3
  35. metadata +26 -8
  36. data/lib/jma_feed/api.rb +0 -48
  37. data/lib/jma_feed/entity/alert.rb +0 -176
@@ -0,0 +1,53 @@
1
+ class JMAFeed::ResultDoc
2
+ attr_reader :doc
3
+
4
+ def initialize(body)
5
+ @body = body
6
+ @doc = Nokogiri::XML(body)
7
+ end
8
+
9
+ def namespace
10
+ {atom: doc.root.namespace.href}
11
+ end
12
+
13
+ def text(name)
14
+ doc.xpath("/atom:feed/atom:#{name}", namespace).text
15
+ end
16
+
17
+ def title
18
+ text('title')
19
+ end
20
+
21
+ def subtitle
22
+ text('subtitle')
23
+ end
24
+
25
+ def id
26
+ text('id')
27
+ end
28
+
29
+ def updated
30
+ DateTime.parse(text('updated'))
31
+ end
32
+
33
+ def related
34
+ text('link[@rel="related"]/@href')
35
+ end
36
+
37
+ def all_entries
38
+ @all_entries ||= doc.xpath('/atom:feed/atom:entry', namespace).map do |entry|
39
+ JMAFeed::ResultEntry.new(
40
+ title: entry.xpath('atom:title', namespace).text,
41
+ link: entry.xpath('atom:link/@href', namespace).text,
42
+ id: entry.xpath('atom:id', namespace).text,
43
+ updated: entry.xpath('atom:updated', namespace).text,
44
+ author: entry.xpath('atom:author/atom:name', namespace).text,
45
+ content: entry.xpath('atom:content', namespace).text,
46
+ )
47
+ end
48
+ end
49
+
50
+ def entries
51
+ all_entries.uniq(&:identity)
52
+ end
53
+ end
@@ -9,16 +9,39 @@ class JMAFeed::ResultEntry < Struct.new(
9
9
  time, number, report_code, report_area_code = identifier.split('_')
10
10
  end
11
11
 
12
+ # 気象警報・注意報(H27)_解説資料.pdf
13
+ # ---------------
14
+ # 「前回電文」とは、参照中の電文(当該電文)と、
15
+ # - 情報名称(Control/Title)
16
+ # - 運用種別(Control/Status)
17
+ # - 発信官署(Control/EditorialOffice)
18
+ # が同一である電文の中で、発表時刻(Head/ReportDateTime)が当該電文の直近過去である電文を指す。
19
+ #
20
+ # idに記載されるファイル名アンダースコア区切りの2番目がStatusを意味しているのかどうかは2024Aug時点で不明
21
+ # Status="通常" の電文しか取得できておらず確証はないが、この値をidに含んでいる可能性が高いと見切っての実装
22
+ def identity
23
+ [report_code, report_status, report_area_code].join('_')
24
+ end
25
+
12
26
  def report_code
13
27
  @report_code ||= identifier_components[2]
14
28
  end
15
29
 
16
30
  def report
17
31
  return nil if report_code.nil?
18
- @report ||= JMAFeed::Report.latest.detect{_1.has_code?(report_code)}
32
+ @report ||= JMAFeed::Report.get.detect{_1.has_code?(report_code)}
19
33
  end
20
34
 
21
35
  def report_area_code
22
36
  @report_area_code ||= identifier_components[3]
23
37
  end
38
+
39
+ def report_status
40
+ @report_status ||= identifier_components[1]
41
+ end
42
+
43
+ def get_report_entry!
44
+ return unless report
45
+ report.report_entry_class.get(id)
46
+ end
24
47
  end
@@ -1,3 +1,3 @@
1
1
  module JMAFeed
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/jma_feed.rb CHANGED
@@ -8,10 +8,17 @@ end
8
8
 
9
9
  require "jma_feed/version"
10
10
  require "jma_feed/report"
11
- require "jma_feed/result_entry"
12
11
  require "jma_feed/result"
13
- require "jma_feed/api"
14
- require "jma_feed/entity/alert"
12
+ require "jma_feed/result_doc"
13
+ require "jma_feed/result_entry"
14
+ require "jma_feed/atom"
15
+ require "jma_feed/atom/extra"
16
+ require "jma_feed/atom/regular"
17
+ require "jma_feed/atom/eqvol"
18
+ require "jma_feed/atom/other"
19
+ require "jma_feed/node/base_node"
20
+ require "jma_feed/entity/weather_alert"
21
+ require "jma_feed/entity/weather_alert/metrics_item"
15
22
  require "jma_feed/entity/risk_level"
16
23
 
17
24
  require "jma_feed/report_entry"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jma_feed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - metheglin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-05 00:00:00.000000000 Z
11
+ date: 2024-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -44,28 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.0.3
47
+ version: 0.0.6
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.0.3
54
+ version: 0.0.6
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: giri
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.0.3
61
+ version: 0.0.4
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.0.3
68
+ version: 0.0.4
69
69
  description: JMA Feed
70
70
  email: pigmybank@gmail.com
71
71
  executables: []
@@ -75,22 +75,40 @@ files:
75
75
  - README.md
76
76
  - data/jmaxml_20240216_format_v1_3_hyo1.csv
77
77
  - lib/jma_feed.rb
78
- - lib/jma_feed/api.rb
79
- - lib/jma_feed/entity/alert.rb
78
+ - lib/jma_feed/atom.rb
79
+ - lib/jma_feed/atom/eqvol.rb
80
+ - lib/jma_feed/atom/extra.rb
81
+ - lib/jma_feed/atom/other.rb
82
+ - lib/jma_feed/atom/regular.rb
80
83
  - lib/jma_feed/entity/risk_level.rb
84
+ - lib/jma_feed/entity/weather_alert.rb
85
+ - lib/jma_feed/entity/weather_alert/metrics_item.rb
86
+ - lib/jma_feed/node/base_node.rb
81
87
  - lib/jma_feed/report.rb
82
88
  - lib/jma_feed/report_entry.rb
83
89
  - lib/jma_feed/report_entry/jmx/area.rb
84
90
  - lib/jma_feed/report_entry/jmx/discharge.rb
91
+ - lib/jma_feed/report_entry/jmx/earthquake.rb
92
+ - lib/jma_feed/report_entry/jmx/earthquake_intensity.rb
93
+ - lib/jma_feed/report_entry/jmx/humidity.rb
85
94
  - lib/jma_feed/report_entry/jmx/precipitation.rb
86
95
  - lib/jma_feed/report_entry/jmx/significancy.rb
96
+ - lib/jma_feed/report_entry/jmx/snow_fall_depth.rb
97
+ - lib/jma_feed/report_entry/jmx/tidal_level.rb
98
+ - lib/jma_feed/report_entry/jmx/time_define.rb
99
+ - lib/jma_feed/report_entry/jmx/visibility.rb
87
100
  - lib/jma_feed/report_entry/jmx/water_level.rb
101
+ - lib/jma_feed/report_entry/jmx/wave_height.rb
102
+ - lib/jma_feed/report_entry/jmx/wind_direction.rb
103
+ - lib/jma_feed/report_entry/jmx/wind_speed.rb
88
104
  - lib/jma_feed/report_entry/vphw50.rb
89
105
  - lib/jma_feed/report_entry/vprn50.rb
90
106
  - lib/jma_feed/report_entry/vptaii.rb
91
107
  - lib/jma_feed/report_entry/vpww54.rb
92
108
  - lib/jma_feed/report_entry/vxko.rb
109
+ - lib/jma_feed/report_entry/vxse53.rb
93
110
  - lib/jma_feed/result.rb
111
+ - lib/jma_feed/result_doc.rb
94
112
  - lib/jma_feed/result_entry.rb
95
113
  - lib/jma_feed/version.rb
96
114
  homepage: https://rubygems.org/gems/jma_feed
data/lib/jma_feed/api.rb DELETED
@@ -1,48 +0,0 @@
1
- require "net/http"
2
-
3
- class JMAFeed::Api
4
- def initialize
5
- end
6
-
7
- def get_feed_regular(if_modified_since: nil, &block)
8
- res = execute(:get, "https://www.data.jma.go.jp/developer/xml/feed/regular.xml", headers: {
9
- "If-Modified-Since" => if_modified_since ?
10
- if_modified_since.httpdate :
11
- nil
12
- }, &block)
13
- JMAFeed::Result.new(res)
14
- end
15
-
16
- def get_feed_extra(if_modified_since: nil, &block)
17
- res = execute(:get, "https://www.data.jma.go.jp/developer/xml/feed/extra.xml", headers: {
18
- "If-Modified-Since" => if_modified_since ?
19
- if_modified_since.httpdate :
20
- nil
21
- }, &block)
22
- JMAFeed::Result.new(res)
23
- end
24
-
25
- def execute(verb, uri, query: nil, body: nil, headers: {})
26
- uri = uri.is_a?(URI::HTTP) ? uri : URI.parse(uri)
27
- request = build_request(verb, uri, query: query, body: body)
28
- headers.each {|k,v| request[k] = v}
29
- res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
30
- yield(request, http) if block_given?
31
- # http.read_timeout = 30 # sec
32
- http.request(request)
33
- end
34
- end
35
-
36
- def build_request(verb, uri, query: nil, body: nil, headers: {})
37
- if query
38
- uri.query = URI.encode_www_form(query)
39
- end
40
- request = "Net::HTTP::#{verb.to_s.camelize}".constantize.new(uri)
41
-
42
- if body
43
- request.body = body
44
- end
45
-
46
- request
47
- end
48
- end
@@ -1,176 +0,0 @@
1
- class JMAFeed::Alert < Struct.new(:code, :name, :risk_level, :cluster, keyword_init: true)
2
- # 気象警報・注意(H27)_解説資料.pdf > 別表1
3
- # https://www.jma.go.jp/jma/kishou/know/bosai/warning_kind.html
4
- LIST = {
5
- "00" => {
6
- name: "解除",
7
- risk_level: :level5,
8
- cluster: :clear,
9
- },
10
- "02" => {
11
- name: "暴風雪警報",
12
- risk_level: :level3,
13
- cluster: :snowstorm,
14
- },
15
- "03" => {
16
- name: "大雨警報",
17
- risk_level: :level3,
18
- cluster: :heavy_rain,
19
- },
20
- "04" => {
21
- name: "洪水警報",
22
- risk_level: :level3,
23
- cluster: :flood,
24
- },
25
- "05" => {
26
- name: "暴風警報",
27
- risk_level: :level3,
28
- cluster: :storm,
29
- },
30
- "06" => {
31
- name: "大雪警報",
32
- risk_level: :level3,
33
- cluster: :heavy_snow,
34
- },
35
- "07" => {
36
- name: "波浪警報",
37
- risk_level: :level3,
38
- cluster: :high_wave,
39
- },
40
- "08" => {
41
- name: "高潮警報",
42
- risk_level: :level3,
43
- cluster: :storm_surge,
44
- },
45
- "10" => {
46
- name: "大雨注意報",
47
- risk_level: :level2,
48
- cluster: :heavy_rain,
49
- },
50
- "12" => {
51
- name: "大雪注意報",
52
- risk_level: :level2,
53
- cluster: :heavy_snow,
54
- },
55
- "13" => {
56
- name: "風雪注意報",
57
- risk_level: :level2,
58
- cluster: :snowstorm,
59
- },
60
- "14" => {
61
- name: "雷注意報",
62
- risk_level: :level2,
63
- cluster: :thunderstorm,
64
- },
65
- "15" => {
66
- name: "強風注意報",
67
- risk_level: :level2,
68
- cluster: :storm,
69
- },
70
- "16" => {
71
- name: "波浪注意報",
72
- risk_level: :level2,
73
- cluster: :high_wave,
74
- },
75
- "17" => {
76
- name: "融雪注意報",
77
- risk_level: :level2,
78
- cluster: :snow_melting,
79
- },
80
- "18" => {
81
- name: "洪水注意報",
82
- risk_level: :level2,
83
- cluster: :flood,
84
- },
85
- "19" => {
86
- name: "高潮注意報",
87
- risk_level: :level2,
88
- cluster: :storm_surge,
89
- },
90
- "20" => {
91
- name: "濃霧注意報",
92
- risk_level: :level2,
93
- cluster: :dense_fog,
94
- },
95
- "21" => {
96
- name: "乾燥注意報",
97
- risk_level: :level2,
98
- cluster: :dry_air,
99
- },
100
-
101
- "22" => {
102
- name: "なだれ注意報",
103
- risk_level: :level2,
104
- cluster: :avalanche,
105
- },
106
- "23" => {
107
- name: "低温注意報",
108
- risk_level: :level2,
109
- cluster: :low_temperature,
110
- },
111
- "24" => {
112
- name: "霜注意報",
113
- risk_level: :level2,
114
- cluster: :frost,
115
- },
116
- "25" => {
117
- name: "着氷注意報",
118
- risk_level: :level2,
119
- cluster: :ice_accretion,
120
- },
121
- "26" => {
122
- name: "着雪注意報",
123
- risk_level: :level2,
124
- cluster: :snow_accretion,
125
- },
126
- "27" => {
127
- name: "その他の注意",
128
- risk_level: :level2,
129
- cluster: :other,
130
- },
131
-
132
- "32" => {
133
- name: "暴風雪特別警報",
134
- risk_level: :level5,
135
- cluster: :snowstorm,
136
- },
137
- "33" => {
138
- name: "大雨特別警報",
139
- risk_level: :level5,
140
- cluster: :heavy_rain,
141
- },
142
- "35" => {
143
- name: "暴風特別警報",
144
- risk_level: :level5,
145
- cluster: :storm,
146
- },
147
- "36" => {
148
- name: "大雪特別警報",
149
- risk_level: :level5,
150
- cluster: :heavy_snow,
151
- },
152
- "37" => {
153
- name: "波浪特別警報",
154
- risk_level: :level5,
155
- cluster: :high_wave,
156
- },
157
- "38" => {
158
- name: "高潮特別警報",
159
- risk_level: :level5,
160
- cluster: :storm_surge,
161
- },
162
- }
163
-
164
- # def self.clusters
165
- # LIST.map{|k,v| v[:cluster]}.uniq
166
- # end
167
-
168
- def self.clusters
169
- # LIST.map{|k,v| v[:cluster]}.uniq
170
- all.group_by(&:cluster)
171
- end
172
-
173
- def self.all
174
- @all ||= LIST.map{|k,v| new(v.merge(code: k.to_s))}
175
- end
176
- end