jma_code 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/data/20240216-completed_AreaInformationCity-AreaForecastLocalM/AreaInformationCity.csv +2083 -0
  3. data/data/20240618-completed_Volcano-Earthquake/AreaForecastLocalE.csv +189 -0
  4. data/data/20240618-completed_Volcano-Earthquake/PointSeismicIntensity.csv +4565 -0
  5. data/lib/jma_code/area_forecast_local_e.rb +100 -0
  6. data/lib/jma_code/{area_forecast_local.rb → area_forecast_local_m.rb} +12 -7
  7. data/lib/jma_code/area_information_city.rb +35 -8
  8. data/lib/jma_code/point_seismic_intensity.rb +82 -0
  9. data/lib/jma_code/version.rb +1 -1
  10. data/lib/jma_code.rb +3 -1
  11. metadata +29 -24
  12. /data/data/{Volcano_Earthquake/20240618_AdditionalCommentEarthquake.csv → 20240618_Volcano-Earthquake/AdditionalCommentEarthquake.csv} +0 -0
  13. /data/data/{Volcano_Earthquake/20240618_AreaEpicenter.csv → 20240618_Volcano-Earthquake/AreaEpicenter.csv} +0 -0
  14. /data/data/{Volcano_Earthquake/20240618_AreaEpicenterAbbreviation.csv → 20240618_Volcano-Earthquake/AreaEpicenterAbbreviation.csv} +0 -0
  15. /data/data/{Volcano_Earthquake/20240618_AreaEpicenterDetail.csv → 20240618_Volcano-Earthquake/AreaEpicenterDetail.csv} +0 -0
  16. /data/data/{Volcano_Earthquake/20240618_AreaEpicenterSuppliment.csv → 20240618_Volcano-Earthquake/AreaEpicenterSuppliment.csv} +0 -0
  17. /data/data/{Volcano_Earthquake/20240618_AreaForecastEEW.csv → 20240618_Volcano-Earthquake/AreaForecastEEW.csv} +0 -0
  18. /data/data/{Volcano_Earthquake/20240618_AreaForecastLocalE_AreaInformationCity_PointRealtimeIntensity.csv → 20240618_Volcano-Earthquake/AreaForecastLocalE-AreaInformationCity-PointRealtimeIntensity.csv} +0 -0
  19. /data/data/{Volcano_Earthquake/20240618_AreaForecastLocalE_ AreaInformationCity_ PointSeismicIntensity.csv → 20240618_Volcano-Earthquake/AreaForecastLocalE-AreaInformationCity-PointSeismicIntensity.csv} +0 -0
  20. /data/data/{Volcano_Earthquake/20240618_AreaForecastLocalE_PointSeismicLgIntensity.csv → 20240618_Volcano-Earthquake/AreaForecastLocalE-PointSeismicLgIntensity.csv} +0 -0
  21. /data/data/{Volcano_Earthquake/20240618_AreaForecastLocalEEW.csv → 20240618_Volcano-Earthquake/AreaForecastLocalEEW.csv} +0 -0
  22. /data/data/{Volcano_Earthquake/20240618_AreaInformationPrefectureEarthquake.csv → 20240618_Volcano-Earthquake/AreaInformationPrefectureEarthquake.csv} +0 -0
  23. /data/data/{Volcano_Earthquake/20240618_AreaTsunami.csv → 20240618_Volcano-Earthquake/AreaTsunami.csv} +0 -0
  24. /data/data/{Volcano_Earthquake/20240618_CoastTsunami.csv → 20240618_Volcano-Earthquake/CoastTsunami.csv} +0 -0
  25. /data/data/{Volcano_Earthquake/20240618_EarthquakeForecast.csv → 20240618_Volcano-Earthquake/EarthquakeForecast.csv} +0 -0
  26. /data/data/{Volcano_Earthquake/20240618_EarthquakeInformation.csv → 20240618_Volcano-Earthquake/EarthquakeInformation.csv} +0 -0
  27. /data/data/{Volcano_Earthquake/20240618_EarthquakeWarning.csv → 20240618_Volcano-Earthquake/EarthquakeWarning.csv} +0 -0
  28. /data/data/{Volcano_Earthquake/20240618_PointTsunami.csv → 20240618_Volcano-Earthquake/PointTsunami.csv} +0 -0
  29. /data/data/{Volcano_Earthquake/20240618_PointVolcano.csv → 20240618_Volcano-Earthquake/PointVolcano.csv} +0 -0
  30. /data/data/{Volcano_Earthquake/20240618_TokaiInformation.csv → 20240618_Volcano-Earthquake/TokaiInformation.csv} +0 -0
  31. /data/data/{Volcano_Earthquake/20240618_TsunamiWarning.csv → 20240618_Volcano-Earthquake/TsunamiWarning.csv} +0 -0
  32. /data/data/{Volcano_Earthquake/20240618_VolcanicWarning.csv → 20240618_Volcano-Earthquake/VolcanicWarning.csv} +0 -0
@@ -0,0 +1,100 @@
1
+ module JMACode
2
+ using Blank
3
+
4
+ class AreaForecastLocalE < Struct.new(
5
+ :code, :name, :name_phonetic, :prefecture_code,
6
+ keyword_init: true
7
+ )
8
+ CSV_ROW_SEP = "\r\n"
9
+ NUM_HEADER_ROWS = 1
10
+ HEADERS = %i(
11
+ code
12
+ name
13
+ name_phonetic
14
+ prefecture_code
15
+ )
16
+
17
+ class << self
18
+ attr_accessor :data
19
+
20
+ def load_csv(version: "20240618-completed")
21
+ path = File.join(File.dirname(__FILE__), "../../data/#{version}_Volcano-Earthquake/AreaForecastLocalE.csv")
22
+ File.open(path) do |f|
23
+ csv = CSV.new(f, headers: HEADERS, row_sep: CSV_ROW_SEP)
24
+ yield(csv)
25
+ end
26
+ end
27
+
28
+ def load(**args)
29
+ load_csv(**args) do |csv|
30
+ csv.drop(NUM_HEADER_ROWS).map do |row|
31
+ build_by_csv_row(row)
32
+ end
33
+ end
34
+ end
35
+
36
+ def get
37
+ @data ||= load
38
+ end
39
+
40
+ def build_by_csv_row(row)
41
+ new(
42
+ code: row[:code],
43
+ name: row[:name],
44
+ name_phonetic: row[:name_phonetic],
45
+ prefecture_code: row[:prefecture_code],
46
+ )
47
+ end
48
+
49
+ def build_tree(areas=nil, cities=nil)
50
+ areas ||= get
51
+ cities ||= JMACode::AreaInformationCity.get
52
+
53
+ areas.group_by(&:prefecture).map{|pref, pref_areas|
54
+ [
55
+ block_given? ? yield(pref) : pref,
56
+ pref_areas.map{|a|
57
+ [
58
+ block_given? ? yield(a) : a,
59
+ a.area_information_cities.map{|c|
60
+ [
61
+ block_given? ? yield(c) : c,
62
+ nil
63
+ ]
64
+ }
65
+ ]
66
+ }
67
+ ]
68
+ }
69
+ end
70
+
71
+ def walk_tree(tree, &block)
72
+ tree.map do |area, children|
73
+ a = block.call(area)
74
+ c = if children.is_a?(Array) and children.present?
75
+ walk_tree(children, &block)
76
+ else
77
+ children
78
+ end
79
+ [a, c]
80
+ end
81
+ end
82
+ end
83
+
84
+ def prefecture
85
+ @prefecture ||= Prefecture.get.find{|pref| pref.code == prefecture_code}
86
+ end
87
+
88
+ def area_information_cities
89
+ @area_information_cities ||= AreaInformationCity.get.select{|x| x.area_forecast_local_e_code == code}
90
+ end
91
+
92
+ def to_csv_row
93
+ HEADERS.map do |k|
94
+ respond_to?(k) ?
95
+ public_send(k) :
96
+ nil
97
+ end
98
+ end
99
+ end
100
+ end
@@ -2,7 +2,7 @@
2
2
  module JMACode
3
3
  using Blank
4
4
 
5
- class AreaForecastLocal < Struct.new(
5
+ class AreaForecastLocalM < Struct.new(
6
6
  :code, :name, :name_phonetic,
7
7
  :belonging_local_code_in_weather_alert,
8
8
  :belonging_local_code_in_tornado_alert,
@@ -156,20 +156,20 @@ module JMACode
156
156
  end
157
157
 
158
158
  def area_information_cities
159
- @area_information_cities ||= AreaInformationCity.get.select{|x| x.area_forecast_local_code == code}
159
+ @area_information_cities ||= AreaInformationCity.get.select{|x| x.area_forecast_local_m_code == code}
160
160
  end
161
161
 
162
162
  def belonging_local_in_weather_alert
163
163
  return nil if belonging_local_code_in_weather_alert.blank?
164
164
  @belonging_local_in_weather_alert ||= begin
165
- AreaForecastLocal.get.find{|a| a.code == belonging_local_code_in_weather_alert}
165
+ AreaForecastLocalM.get.find{|a| a.code == belonging_local_code_in_weather_alert}
166
166
  end
167
167
  end
168
168
 
169
169
  def belonging_local_in_tornado_alert
170
170
  return nil if belonging_local_code_in_tornado_alert.blank?
171
171
  @belonging_local_in_tornado_alert ||= begin
172
- AreaForecastLocal.get.find{|a| a.code == belonging_local_code_in_tornado_alert}
172
+ AreaForecastLocalM.get.find{|a| a.code == belonging_local_code_in_tornado_alert}
173
173
  end
174
174
  end
175
175
 
@@ -192,9 +192,14 @@ module JMACode
192
192
 
193
193
  def to_csv_row
194
194
  HEADERS.map do |k|
195
- respond_to?(k) ?
196
- public_send(k) :
197
- nil
195
+ if respond_to?(k)
196
+ public_send(k)
197
+ else
198
+ if k.to_s.start_with?("used_by_")
199
+ x = k.to_s.sub('used_by_', '').to_sym
200
+ used_by.include?(x) ? '1' : nil
201
+ end
202
+ end
198
203
  end
199
204
  end
200
205
  end
@@ -4,7 +4,9 @@ module JMACode
4
4
 
5
5
  class AreaInformationCity < Struct.new(
6
6
  :code, :long_name, :alt_name, :alt_name_phonetic,
7
- :area_forecast_local_code, :used_by,
7
+ :area_forecast_local_m_code,
8
+ :area_forecast_local_e_code,
9
+ :used_by,
8
10
  keyword_init: true
9
11
  )
10
12
  CSV_ROW_SEP = "\r\n"
@@ -14,7 +16,7 @@ module JMACode
14
16
  long_name
15
17
  name_used_by_weather
16
18
  name_phonetic_used_by_weather
17
- area_forecast_local_code
19
+ area_forecast_local_m_code
18
20
  used_by_weather
19
21
  used_by_tornado
20
22
  used_by_storm_surge
@@ -29,12 +31,13 @@ module JMACode
29
31
  name_phonetic_used_by_uv
30
32
  name_used_by_rainstorm
31
33
  name_phonetic_used_by_rainstorm
34
+ area_forecast_local_e_code
32
35
  )
33
36
 
34
37
  class << self
35
38
  attr_accessor :data
36
39
 
37
- def load_csv(version: "20240216")
40
+ def load_csv(version: "20240216-completed")
38
41
  path = File.join(File.dirname(__FILE__), "../../data/#{version}_AreaInformationCity-AreaForecastLocalM/AreaInformationCity.csv")
39
42
  File.open(path) do |f|
40
43
  csv = CSV.new(f, headers: HEADERS, row_sep: CSV_ROW_SEP)
@@ -74,7 +77,8 @@ module JMACode
74
77
  long_name: row[:long_name],
75
78
  alt_name: alt_name,
76
79
  alt_name_phonetic: alt_name_phonetic,
77
- area_forecast_local_code: row[:area_forecast_local_code],
80
+ area_forecast_local_m_code: row[:area_forecast_local_m_code],
81
+ area_forecast_local_e_code: row[:area_forecast_local_e_code],
78
82
  used_by: [
79
83
  row[:used_by_weather] == '1' ? :weather : nil,
80
84
  row[:used_by_tornado] == '1' ? :tornado : nil,
@@ -103,12 +107,35 @@ module JMACode
103
107
  @prefecture_code ||= code[0, 2]
104
108
  end
105
109
 
106
- def area_forecast_local
107
- @area_forecast_local ||= AreaForecastLocal.get.find{|x| x.code == area_forecast_local_code}
110
+ def area_forecast_local_m
111
+ @area_forecast_local_m ||= AreaForecastLocalM.get.find{|x| x.code == area_forecast_local_m_code}
112
+ end
113
+
114
+ def area_forecast_local_e
115
+ @area_forecast_local_e ||= AreaForecastLocalE.get.find{|x| x.code == area_forecast_local_e_code}
108
116
  end
109
117
 
110
118
  def child_of?(area_or_city)
111
- area_forecast_local_code == area_or_city.code
119
+ area_forecast_local_m_code == area_or_city.code
120
+ end
121
+
122
+ def to_csv_row
123
+ HEADERS.map do |k|
124
+ if respond_to?(k)
125
+ public_send(k)
126
+ else
127
+ if k.to_s.start_with?("used_by_")
128
+ x = k.to_s.sub('used_by_', '').to_sym
129
+ used_by.include?(x) ? '1' : nil
130
+ elsif k.to_s.start_with?("name_used_by_")
131
+ x = k.to_s.sub('name_used_by_', '').to_sym
132
+ used_by.include?(x) ? alt_name : nil
133
+ elsif k.to_s.start_with?("name_phonetic_used_by_")
134
+ x = k.to_s.sub('name_phonetic_used_by_', '').to_sym
135
+ used_by.include?(x) ? alt_name_phonetic : nil
136
+ end
137
+ end
138
+ end
112
139
  end
113
140
 
114
141
  def to_h
@@ -116,7 +143,7 @@ module JMACode
116
143
  code: code,
117
144
  name: name,
118
145
  name_phonetic: name_phonetic,
119
- area_forecast_local_code: area_forecast_local_code,
146
+ area_forecast_local_m_code: area_forecast_local_m_code,
120
147
  used_by: used_by,
121
148
  }
122
149
  end
@@ -0,0 +1,82 @@
1
+ module JMACode
2
+ using Blank
3
+
4
+ class PointSeismicIntensity < Struct.new(
5
+ :code, :name, :name_phonetic,
6
+ :area_information_city_code,
7
+ :used_by,
8
+ keyword_init: true
9
+ )
10
+ CSV_ROW_SEP = "\r\n"
11
+ NUM_HEADER_ROWS = 1
12
+ HEADERS = %i(
13
+ code
14
+ name
15
+ name_phonetic
16
+ area_information_city_code
17
+ used_by_regular_seismic_intensity
18
+ used_by_realtime_seismic_intensity
19
+ used_by_long_seismic_intensity
20
+ )
21
+
22
+ class << self
23
+ attr_accessor :data
24
+
25
+ def load_csv(version: "20240618-completed")
26
+ path = File.join(File.dirname(__FILE__), "../../data/#{version}_Volcano-Earthquake/PointSeismicIntensity.csv")
27
+ File.open(path) do |f|
28
+ csv = CSV.new(f, headers: HEADERS, row_sep: CSV_ROW_SEP)
29
+ yield(csv)
30
+ end
31
+ end
32
+
33
+ def load(**args)
34
+ load_csv(**args) do |csv|
35
+ csv.drop(NUM_HEADER_ROWS).map do |row|
36
+ build_by_csv_row(row)
37
+ end
38
+ end
39
+ end
40
+
41
+ def get
42
+ @data ||= load
43
+ end
44
+
45
+ def build_by_csv_row(row)
46
+ used_by_fields = HEADERS.select{|n| n.to_s.start_with?('used_by_')}
47
+ new(
48
+ code: row[:code],
49
+ name: row[:name],
50
+ name_phonetic: row[:name_phonetic],
51
+ area_information_city_code: row[:area_information_city_code],
52
+ used_by: used_by_fields.select{|f| row[f] == '1'}.map{|f| f.to_s.sub(/\Aused_by_/, '').to_sym}
53
+ )
54
+ end
55
+ end
56
+
57
+ # def prefecture_code
58
+ # @prefecture_code ||= code[0, 2]
59
+ # end
60
+
61
+ # def prefecture
62
+ # @prefecture ||= Prefecture.get.find{|pref| pref.code == prefecture_code}
63
+ # end
64
+
65
+ def area_information_city
66
+ @area_information_city ||= AreaInformationCity.get.find{|x| x.code == area_information_city_code}
67
+ end
68
+
69
+ def to_csv_row
70
+ HEADERS.map do |k|
71
+ if respond_to?(k)
72
+ public_send(k)
73
+ else
74
+ if k.to_s.start_with?("used_by_")
75
+ x = k.to_s.sub('used_by_', '').to_sym
76
+ used_by.include?(x) ? '1' : nil
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -1,3 +1,3 @@
1
1
  module JMACode
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/jma_code.rb CHANGED
@@ -7,9 +7,11 @@ require "jma_code/river_office"
7
7
  require "jma_code/point_amedas"
8
8
  require "jma_code/area_flood_forecast"
9
9
  require "jma_code/area_information_city"
10
- require "jma_code/area_forecast_local"
10
+ require "jma_code/area_forecast_local_m"
11
11
  require "jma_code/area_marine"
12
12
  require "jma_code/area_river"
13
+ require "jma_code/area_forecast_local_e"
14
+ require "jma_code/point_seismic_intensity"
13
15
 
14
16
  module JMACode
15
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jma_code
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
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-09 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
@@ -38,6 +38,7 @@ files:
38
38
  - data/20230105_AreaFloodForecast.csv
39
39
  - data/20230105_AreaRiver.csv
40
40
  - data/20240216-completed_AreaInformationCity-AreaForecastLocalM/AreaForecastLocalM(コード表).csv
41
+ - data/20240216-completed_AreaInformationCity-AreaForecastLocalM/AreaInformationCity.csv
41
42
  - data/20240216_AreaInformationCity-AreaForecastLocalM/AreaForecastLocalM(コード表).csv
42
43
  - data/20240216_AreaInformationCity-AreaForecastLocalM/AreaForecastLocalM(関係表 竜巻注意情報.csv
43
44
  - data/20240216_AreaInformationCity-AreaForecastLocalM/AreaForecastLocalM(関係表 警報・注意報.csv
@@ -46,36 +47,40 @@ files:
46
47
  - data/20240325_PointAmedas/ame_master.csv
47
48
  - data/20240325_PointAmedas/snow_master.csv
48
49
  - data/20240418_WaterLevelStation.csv
49
- - data/Volcano_Earthquake/20240618_AdditionalCommentEarthquake.csv
50
- - data/Volcano_Earthquake/20240618_AreaEpicenter.csv
51
- - data/Volcano_Earthquake/20240618_AreaEpicenterAbbreviation.csv
52
- - data/Volcano_Earthquake/20240618_AreaEpicenterDetail.csv
53
- - data/Volcano_Earthquake/20240618_AreaEpicenterSuppliment.csv
54
- - data/Volcano_Earthquake/20240618_AreaForecastEEW.csv
55
- - data/Volcano_Earthquake/20240618_AreaForecastLocalEEW.csv
56
- - data/Volcano_Earthquake/20240618_AreaForecastLocalE_ AreaInformationCity_ PointSeismicIntensity.csv
57
- - data/Volcano_Earthquake/20240618_AreaForecastLocalE_AreaInformationCity_PointRealtimeIntensity.csv
58
- - data/Volcano_Earthquake/20240618_AreaForecastLocalE_PointSeismicLgIntensity.csv
59
- - data/Volcano_Earthquake/20240618_AreaInformationPrefectureEarthquake.csv
60
- - data/Volcano_Earthquake/20240618_AreaTsunami.csv
61
- - data/Volcano_Earthquake/20240618_CoastTsunami.csv
62
- - data/Volcano_Earthquake/20240618_EarthquakeForecast.csv
63
- - data/Volcano_Earthquake/20240618_EarthquakeInformation.csv
64
- - data/Volcano_Earthquake/20240618_EarthquakeWarning.csv
65
- - data/Volcano_Earthquake/20240618_PointTsunami.csv
66
- - data/Volcano_Earthquake/20240618_PointVolcano.csv
67
- - data/Volcano_Earthquake/20240618_TokaiInformation.csv
68
- - data/Volcano_Earthquake/20240618_TsunamiWarning.csv
69
- - data/Volcano_Earthquake/20240618_VolcanicWarning.csv
50
+ - data/20240618-completed_Volcano-Earthquake/AreaForecastLocalE.csv
51
+ - data/20240618-completed_Volcano-Earthquake/PointSeismicIntensity.csv
52
+ - data/20240618_Volcano-Earthquake/AdditionalCommentEarthquake.csv
53
+ - data/20240618_Volcano-Earthquake/AreaEpicenter.csv
54
+ - data/20240618_Volcano-Earthquake/AreaEpicenterAbbreviation.csv
55
+ - data/20240618_Volcano-Earthquake/AreaEpicenterDetail.csv
56
+ - data/20240618_Volcano-Earthquake/AreaEpicenterSuppliment.csv
57
+ - data/20240618_Volcano-Earthquake/AreaForecastEEW.csv
58
+ - data/20240618_Volcano-Earthquake/AreaForecastLocalE-AreaInformationCity-PointRealtimeIntensity.csv
59
+ - data/20240618_Volcano-Earthquake/AreaForecastLocalE-AreaInformationCity-PointSeismicIntensity.csv
60
+ - data/20240618_Volcano-Earthquake/AreaForecastLocalE-PointSeismicLgIntensity.csv
61
+ - data/20240618_Volcano-Earthquake/AreaForecastLocalEEW.csv
62
+ - data/20240618_Volcano-Earthquake/AreaInformationPrefectureEarthquake.csv
63
+ - data/20240618_Volcano-Earthquake/AreaTsunami.csv
64
+ - data/20240618_Volcano-Earthquake/CoastTsunami.csv
65
+ - data/20240618_Volcano-Earthquake/EarthquakeForecast.csv
66
+ - data/20240618_Volcano-Earthquake/EarthquakeInformation.csv
67
+ - data/20240618_Volcano-Earthquake/EarthquakeWarning.csv
68
+ - data/20240618_Volcano-Earthquake/PointTsunami.csv
69
+ - data/20240618_Volcano-Earthquake/PointVolcano.csv
70
+ - data/20240618_Volcano-Earthquake/TokaiInformation.csv
71
+ - data/20240618_Volcano-Earthquake/TsunamiWarning.csv
72
+ - data/20240618_Volcano-Earthquake/VolcanicWarning.csv
70
73
  - lib/jma_code.rb
71
74
  - lib/jma_code/area_flood_forecast.rb
72
- - lib/jma_code/area_forecast_local.rb
75
+ - lib/jma_code/area_forecast_local_e.rb
76
+ - lib/jma_code/area_forecast_local_m.rb
73
77
  - lib/jma_code/area_information_city.rb
74
78
  - lib/jma_code/area_marine.rb
75
79
  - lib/jma_code/area_river.rb
76
80
  - lib/jma_code/entity/area_forecast_type.rb
77
81
  - lib/jma_code/ext/blank.rb
78
82
  - lib/jma_code/point_amedas.rb
83
+ - lib/jma_code/point_seismic_intensity.rb
79
84
  - lib/jma_code/prefecture.rb
80
85
  - lib/jma_code/river_office.rb
81
86
  - lib/jma_code/version.rb