opentideconstants 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +132 -3
- data/lib/opentideconstants/bgzf.rb +436 -0
- data/lib/opentideconstants/cache.rb +559 -0
- data/lib/opentideconstants/cache_json.rb +67 -0
- data/lib/opentideconstants/canonical.rb +756 -0
- data/lib/opentideconstants/canonical_types.rb +2537 -0
- data/lib/opentideconstants/client.rb +1135 -0
- data/lib/opentideconstants/downloader.rb +400 -0
- data/lib/opentideconstants/errors.rb +210 -0
- data/lib/opentideconstants/fold.rb +24 -0
- data/lib/opentideconstants/historical_fingerprint.rb +58 -0
- data/lib/opentideconstants/http.rb +483 -0
- data/lib/opentideconstants/models.rb +635 -0
- data/lib/opentideconstants/name_fold.json +949 -0
- data/lib/opentideconstants/predict/astro.rb +85 -0
- data/lib/opentideconstants/predict/daily-facts.json +1 -0
- data/lib/opentideconstants/predict/daily.rb +62 -0
- data/lib/opentideconstants/predict/engine.rb +506 -0
- data/lib/opentideconstants/predict/harmonic.rb +228 -0
- data/lib/opentideconstants/predict/local.rb +49 -0
- data/lib/opentideconstants/predict/results.rb +357 -0
- data/lib/opentideconstants/predict/retained.rb +487 -0
- data/lib/opentideconstants/predict.rb +192 -0
- data/lib/opentideconstants/reader.rb +493 -0
- data/lib/opentideconstants/release.rb +1531 -0
- data/lib/opentideconstants/version.rb +15 -0
- data/lib/opentideconstants.rb +24 -3
- data/supported-formats.json +5 -0
- metadata +37 -5
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
require_relative "daily"
|
|
2
|
+
|
|
3
|
+
class OpenTideConstants
|
|
4
|
+
module Predict
|
|
5
|
+
class Sum
|
|
6
|
+
attr_accessor :mean
|
|
7
|
+
attr_reader :table
|
|
8
|
+
def initialize(table, constituents, amplitude: "amplitude_m", phase: "phase_deg", mean: 0.0, multiplier: 1.0, shift_hours: 0.0, daily: false)
|
|
9
|
+
@table, @mean, @years = table, mean, {}
|
|
10
|
+
@daily = daily ? DailyCorrection.new(constituents.map { |c| c.fetch("name") }) : nil
|
|
11
|
+
@days = {}
|
|
12
|
+
@terms = constituents.map do |constituent|
|
|
13
|
+
row = table.send(:row_for, constituent["name"])
|
|
14
|
+
speed = daily ? constituent.fetch("speed_deg_per_hour") : row["speed_deg_per_hour"]
|
|
15
|
+
[row, speed, multiplier * constituent.fetch(amplitude, 0.0), Predict.angle(constituent.fetch(phase, 0.0) + speed * shift_hours)]
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
def year_data(year)
|
|
19
|
+
@years.shift if @daily && !@years.key?(year) && @years.size >= 4
|
|
20
|
+
@years[year] ||= begin
|
|
21
|
+
index = @table.send(:index_for, year)
|
|
22
|
+
[Predict.year_start(year), @terms.map { |row, speed, amplitude, phase| [speed, row["f"][index] * amplitude, row["v0u_deg"][index] - phase, speed * RAD] }]
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
def daily?
|
|
26
|
+
!@daily.nil?
|
|
27
|
+
end
|
|
28
|
+
def day_data(seconds, year)
|
|
29
|
+
day = (seconds / 86400.0).floor * 86400
|
|
30
|
+
key = [day, year]
|
|
31
|
+
return @days[key] if @days.key?(key)
|
|
32
|
+
origin, terms = year_data(year)
|
|
33
|
+
p_day, values_day = @daily.at(day + 43200)
|
|
34
|
+
p_year, values_year = @daily.at((origin + Predict.year_start(year + 1)) / 2.0)
|
|
35
|
+
corrected = terms.each_with_index.map do |(speed, amplitude, argument, omega), index|
|
|
36
|
+
f, u, k = values_day[index]
|
|
37
|
+
fy, uy, = values_year[index]
|
|
38
|
+
raise UnsupportedError, "invalid daily annual factor" unless fy.finite? && fy > 0
|
|
39
|
+
[speed, amplitude * f / fy, argument + u - uy - k * (p_day - p_year), omega]
|
|
40
|
+
end
|
|
41
|
+
@days.shift if @days.size >= 16
|
|
42
|
+
@days[key] = [origin, corrected]
|
|
43
|
+
end
|
|
44
|
+
def value(seconds, year = nil, derivative = false, day: nil)
|
|
45
|
+
year ||= Predict.utc(seconds).year
|
|
46
|
+
origin, terms = @daily ? day_data(day || seconds, year) : year_data(year)
|
|
47
|
+
delta = (seconds - origin) / 3600.0
|
|
48
|
+
value = 0.0
|
|
49
|
+
terms.each do |speed, amplitude, argument, omega|
|
|
50
|
+
phase = Predict.angle(speed * delta + argument) * RAD
|
|
51
|
+
value += derivative ? -amplitude * omega * Math.sin(phase) : amplitude * Math.cos(phase)
|
|
52
|
+
end
|
|
53
|
+
derivative ? value : value + @mean
|
|
54
|
+
end
|
|
55
|
+
def bound(year, derivative, day: nil)
|
|
56
|
+
(@daily ? day_data(day, year) : year_data(year))[1].sum { |_, amplitude, _, omega| amplitude.abs * omega**(derivative ? 2 : 1) }
|
|
57
|
+
end
|
|
58
|
+
def error(year, a, b, derivative, day: nil)
|
|
59
|
+
origin, terms = @daily ? day_data(day, year) : year_data(year)
|
|
60
|
+
delta_max = [(a - origin).abs, (b - origin).abs].max / 3600.0
|
|
61
|
+
4.0 * 2.0**-52 * terms.sum { |_, amplitude, _, omega| amplitude.abs * (derivative ? omega : 1.0) * ((omega * delta_max).abs + 2.0 * Math::PI) }
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
module_function
|
|
65
|
+
def survivor(cluster, slack)
|
|
66
|
+
return nil if cluster.size.even?
|
|
67
|
+
return cluster[2 * ((cluster.size - 1) / 4)] if slack
|
|
68
|
+
wanted = cluster[0][1]
|
|
69
|
+
candidates = cluster.select { |c| c[1] == wanted }
|
|
70
|
+
wanted == "high" ? candidates.max_by { |c| [c[2], -c[0]] } : candidates.min_by { |c| [c[2], c[0]] }
|
|
71
|
+
end
|
|
72
|
+
def events(total, start, stop, slack: false)
|
|
73
|
+
unrounded_events(total, start, stop, slack: slack).select { |c| start <= (c[0] + 0.5).floor && (c[0] + 0.5).floor < stop }
|
|
74
|
+
end
|
|
75
|
+
def unrounded_events(total, start, stop, slack: false)
|
|
76
|
+
return [] if start == stop
|
|
77
|
+
return daily_events(total, start, stop) if total.daily? && !slack
|
|
78
|
+
first = (start / 360.0).floor * 360 - 3600
|
|
79
|
+
last = ((stop + 3600 - first) / 360.0).ceil * 360 + first
|
|
80
|
+
first.step(last, 360) { |point| total.table.send(:index_for, utc(point).year) }
|
|
81
|
+
derivative = !slack
|
|
82
|
+
roots = []
|
|
83
|
+
first.step(last - 1, 360) do |left|
|
|
84
|
+
year = utc(left).year
|
|
85
|
+
bound = total.bound(year, derivative)
|
|
86
|
+
value = ->(t) { total.value(t, year, derivative) }
|
|
87
|
+
subdivide = nil
|
|
88
|
+
subdivide = lambda do |a, b, fa, fb, depth|
|
|
89
|
+
margin = bound * ((b - a) / 3600.0) * (1.0 + 1e-9) + 2.0 * total.error(year, a, b, derivative) + 1e-12 * [1.0, bound].max
|
|
90
|
+
next if fa.abs + fb.abs > margin
|
|
91
|
+
if depth < 9
|
|
92
|
+
middle = (a + b) / 2.0
|
|
93
|
+
fm = value.call(middle)
|
|
94
|
+
subdivide.call(a, middle, fa, fm, depth + 1)
|
|
95
|
+
subdivide.call(middle, b, fm, fb, depth + 1)
|
|
96
|
+
next
|
|
97
|
+
end
|
|
98
|
+
falling = fa > 0 && fb <= 0
|
|
99
|
+
rising = fa < 0 && fb >= 0
|
|
100
|
+
next unless falling || rising
|
|
101
|
+
while b - a > 0.01
|
|
102
|
+
middle = (a + b) / 2.0
|
|
103
|
+
fm = value.call(middle)
|
|
104
|
+
if falling && fm > 0 || rising && fm < 0
|
|
105
|
+
a = middle
|
|
106
|
+
else
|
|
107
|
+
b = middle
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
root = (a + b) / 2.0
|
|
111
|
+
kind = slack ? (falling ? "slack_before_ebb" : "slack_before_flood") : (falling ? "high" : "low")
|
|
112
|
+
roots << [root, kind, slack ? 0.0 : total.value(root, year)]
|
|
113
|
+
end
|
|
114
|
+
subdivide.call(left, left + 360, value.call(left), value.call(left + 360), 0)
|
|
115
|
+
end
|
|
116
|
+
(utc(first).year + 1).upto(utc(last).year) do |new_year|
|
|
117
|
+
boundary = year_start(new_year)
|
|
118
|
+
next unless first < boundary && boundary < last
|
|
119
|
+
old = total.value(boundary, new_year - 1, derivative)
|
|
120
|
+
new_value = total.value(boundary, new_year, derivative)
|
|
121
|
+
next if old == 0 || new_value == 0 || (old > 0) == (new_value > 0)
|
|
122
|
+
left = roots.select { |c| c[0] <= boundary }.last
|
|
123
|
+
right = roots.find { |c| c[0] > boundary }
|
|
124
|
+
if left && right && right[0] - left[0] < 3600
|
|
125
|
+
loser = if slack then right else survivor([left, right, left], false) == left ? right : left end
|
|
126
|
+
roots.delete_at(roots.index(loser))
|
|
127
|
+
else
|
|
128
|
+
kind = slack ? (new_value > 0 ? "slack_before_flood" : "slack_before_ebb") : (old > 0 ? "high" : "low")
|
|
129
|
+
roots << [boundary, kind, slack ? 0.0 : total.value(boundary, new_year)]
|
|
130
|
+
end
|
|
131
|
+
roots.sort_by!(&:first)
|
|
132
|
+
end
|
|
133
|
+
kept, cluster = [], []
|
|
134
|
+
roots.each do |candidate|
|
|
135
|
+
if !cluster.empty? && candidate[0] - cluster[-1][0] >= 1.0
|
|
136
|
+
found = survivor(cluster, slack)
|
|
137
|
+
kept << found if found
|
|
138
|
+
cluster = []
|
|
139
|
+
end
|
|
140
|
+
cluster << candidate
|
|
141
|
+
end
|
|
142
|
+
found = survivor(cluster, slack)
|
|
143
|
+
kept << found if found
|
|
144
|
+
kept
|
|
145
|
+
end
|
|
146
|
+
def daily_events(total, start, stop)
|
|
147
|
+
first = (start / 360.0).floor * 360 - 3600
|
|
148
|
+
last = ((stop + 3600 - first) / 360.0).ceil * 360 + first
|
|
149
|
+
boundaries = [first]
|
|
150
|
+
boundary = (first / 86400.0).floor * 86400 + 86400
|
|
151
|
+
while boundary < last
|
|
152
|
+
boundaries << boundary
|
|
153
|
+
boundary += 86400
|
|
154
|
+
end
|
|
155
|
+
boundaries << last
|
|
156
|
+
roots = []
|
|
157
|
+
boundaries.each_cons(2) do |segment_start, segment_end|
|
|
158
|
+
year = utc(segment_start).year
|
|
159
|
+
day = segment_start
|
|
160
|
+
bound = total.bound(year, true, day: day)
|
|
161
|
+
value = ->(t) { total.value(t, year, true, day: day) }
|
|
162
|
+
subdivide = nil
|
|
163
|
+
subdivide = lambda do |a, b, fa, fb, depth|
|
|
164
|
+
margin = bound * ((b - a) / 3600.0) * (1.0 + 1e-9) + 2.0 * total.error(year, a, b, true, day: day) + 1e-12 * [1.0, bound].max
|
|
165
|
+
next if fa.abs + fb.abs > margin
|
|
166
|
+
if depth < 9
|
|
167
|
+
middle = (a + b) / 2.0
|
|
168
|
+
fm = value.call(middle)
|
|
169
|
+
subdivide.call(a, middle, fa, fm, depth + 1)
|
|
170
|
+
subdivide.call(middle, b, fm, fb, depth + 1)
|
|
171
|
+
next
|
|
172
|
+
end
|
|
173
|
+
falling = fa > 0 && fb <= 0
|
|
174
|
+
rising = fa < 0 && fb >= 0
|
|
175
|
+
next unless falling || rising
|
|
176
|
+
next if (a == segment_start && fa == 0.0) || (b == segment_end && fb == 0.0)
|
|
177
|
+
while b - a > 0.01
|
|
178
|
+
middle = (a + b) / 2.0
|
|
179
|
+
fm = value.call(middle)
|
|
180
|
+
if falling && fm > 0 || rising && fm < 0
|
|
181
|
+
a = middle
|
|
182
|
+
else
|
|
183
|
+
b = middle
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
root = (a + b) / 2.0
|
|
187
|
+
next unless root > segment_start && root < segment_end
|
|
188
|
+
roots << [root, falling ? "high" : "low", total.value(root, year, false, day: day)]
|
|
189
|
+
end
|
|
190
|
+
left = segment_start
|
|
191
|
+
while left < segment_end
|
|
192
|
+
right = [left + 360, segment_end].min
|
|
193
|
+
subdivide.call(left, right, value.call(left), value.call(right), 0)
|
|
194
|
+
left = right
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
boundaries[1...-1].each do |point|
|
|
198
|
+
left_year = utc(point - 1).year
|
|
199
|
+
right_year = utc(point).year
|
|
200
|
+
left_day = point - 1
|
|
201
|
+
left_height = total.value(point, left_year, false, day: left_day)
|
|
202
|
+
right_height = total.value(point, right_year, false, day: point)
|
|
203
|
+
left_derivative = total.value(point, left_year, true, day: left_day)
|
|
204
|
+
right_derivative = total.value(point, right_year, true, day: point)
|
|
205
|
+
next unless left_height == right_height && left_derivative == 0.0 && right_derivative == 0.0
|
|
206
|
+
before = total.value(point - 0.01, left_year, true, day: left_day)
|
|
207
|
+
after = total.value(point + 0.01, right_year, true, day: point)
|
|
208
|
+
next unless before * after < 0
|
|
209
|
+
roots << [point, before > 0 ? "high" : "low", right_height]
|
|
210
|
+
end
|
|
211
|
+
roots.sort_by!(&:first)
|
|
212
|
+
kept, cluster = [], []
|
|
213
|
+
roots.each do |candidate|
|
|
214
|
+
if !cluster.empty? && candidate[0] - cluster[-1][0] >= 1.0
|
|
215
|
+
found = survivor(cluster, false)
|
|
216
|
+
kept << found if found
|
|
217
|
+
cluster = []
|
|
218
|
+
end
|
|
219
|
+
cluster << candidate
|
|
220
|
+
end
|
|
221
|
+
found = survivor(cluster, false)
|
|
222
|
+
kept << found if found
|
|
223
|
+
kept
|
|
224
|
+
end
|
|
225
|
+
private_class_method :daily_events
|
|
226
|
+
private_class_method :unrounded_events
|
|
227
|
+
end
|
|
228
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
class OpenTideConstants
|
|
2
|
+
module Predict
|
|
3
|
+
module_function
|
|
4
|
+
def localize(result, tz)
|
|
5
|
+
zone = tz == "station" ? result.timezone : tz
|
|
6
|
+
unless zone.is_a?(String) && zone.size <= 255 && zone.match?(/\A[A-Za-z0-9_+\-]+(?:\/[A-Za-z0-9_+\-]+)*\z/) && !zone.start_with?("posix/", "right/") && !%w[posixrules localtime Factory].include?(zone)
|
|
7
|
+
raise UnknownTimeZoneError.new("unknown time zone #{zone.inspect}", zone: zone)
|
|
8
|
+
end
|
|
9
|
+
begin
|
|
10
|
+
require "tzinfo"
|
|
11
|
+
rescue LoadError
|
|
12
|
+
raise LocalTimeUnavailableError, "install tzinfo for local time"
|
|
13
|
+
end
|
|
14
|
+
begin
|
|
15
|
+
rules = TZInfo::Timezone.get(zone)
|
|
16
|
+
rescue TZInfo::InvalidTimezoneIdentifier
|
|
17
|
+
raise UnknownTimeZoneError.new("unknown time zone #{zone}", zone: zone)
|
|
18
|
+
end
|
|
19
|
+
version = nil
|
|
20
|
+
source = TZInfo::DataSource.get
|
|
21
|
+
if source.is_a?(TZInfo::DataSources::RubyDataSource)
|
|
22
|
+
version = TZInfo::Data::Version::TZDATA if defined?(TZInfo::Data::Version::TZDATA)
|
|
23
|
+
elsif source.respond_to?(:zoneinfo_dir)
|
|
24
|
+
root = source.zoneinfo_dir
|
|
25
|
+
%w[tzdata.zi +VERSION].each do |name|
|
|
26
|
+
begin
|
|
27
|
+
first = File.open(File.join(root, name), &:readline).strip
|
|
28
|
+
version = name == "tzdata.zi" ? first.delete_prefix("# version ") : first
|
|
29
|
+
break
|
|
30
|
+
rescue SystemCallError, EOFError
|
|
31
|
+
next
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
items = result.items.map do |item|
|
|
36
|
+
wall = rules.to_local(item.time)
|
|
37
|
+
offset = wall.utc_offset
|
|
38
|
+
magnitude = offset.abs
|
|
39
|
+
suffix = format("%s%02d:%02d", offset >= 0 ? "+" : "-", magnitude / 3600, magnitude % 3600 / 60)
|
|
40
|
+
suffix += format(":%02d", magnitude % 60) unless (magnitude % 60).zero?
|
|
41
|
+
stamp = wall.strftime("%Y-%m-%dT%H:%M:%S") + suffix
|
|
42
|
+
fields = item.instance_variables.reject { |v| v == :@_local }.to_h { |v| [v.to_s.delete_prefix("@").to_sym, item.instance_variable_get(v)] }
|
|
43
|
+
item.class.new(**fields.merge(local_time: stamp, utc_offset_s: offset, _local: wall.freeze))
|
|
44
|
+
end
|
|
45
|
+
fields = result.instance_variables.reject { |v| v == :@_local }.to_h { |v| [v.to_s.delete_prefix("@").to_sym, result.instance_variable_get(v)] }
|
|
46
|
+
result.class.new(**fields.merge(items: items, tz: zone, tz_version: version))
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
class OpenTideConstants
|
|
2
|
+
class HeightPoint
|
|
3
|
+
attr_reader :time, :height_m, :local_time, :utc_offset_s, :units
|
|
4
|
+
def initialize(time: nil, height_m: nil, local_time: nil, utc_offset_s: nil, _local: nil, units: "meters")
|
|
5
|
+
@time = Util.deep_freeze(time)
|
|
6
|
+
@height_m = Util.deep_freeze(height_m)
|
|
7
|
+
@local_time = Util.deep_freeze(local_time)
|
|
8
|
+
@utc_offset_s = Util.deep_freeze(utc_offset_s)
|
|
9
|
+
@units = Util.deep_freeze(units)
|
|
10
|
+
@_local = _local
|
|
11
|
+
freeze
|
|
12
|
+
end
|
|
13
|
+
def height
|
|
14
|
+
units == "meters" || height_m.nil? ? height_m : height_m / 0.3048
|
|
15
|
+
end
|
|
16
|
+
def local_time_object
|
|
17
|
+
@_local
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
class Extreme
|
|
21
|
+
attr_reader :time, :type, :height_m, :local_time, :utc_offset_s, :units
|
|
22
|
+
def initialize(time: nil, type: nil, height_m: nil, local_time: nil, utc_offset_s: nil, _local: nil, units: "meters")
|
|
23
|
+
@time = Util.deep_freeze(time)
|
|
24
|
+
@type = Util.deep_freeze(type)
|
|
25
|
+
@height_m = Util.deep_freeze(height_m)
|
|
26
|
+
@local_time = Util.deep_freeze(local_time)
|
|
27
|
+
@utc_offset_s = Util.deep_freeze(utc_offset_s)
|
|
28
|
+
@units = Util.deep_freeze(units)
|
|
29
|
+
@_local = _local
|
|
30
|
+
freeze
|
|
31
|
+
end
|
|
32
|
+
def height
|
|
33
|
+
units == "meters" || height_m.nil? ? height_m : height_m / 0.3048
|
|
34
|
+
end
|
|
35
|
+
def local_time_object
|
|
36
|
+
@_local
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
class CurrentPoint
|
|
40
|
+
attr_reader :time, :velocity_major_ms, :velocity_minor_ms, :speed_ms, :direction_deg, :local_time, :utc_offset_s, :units
|
|
41
|
+
def initialize(time: nil, velocity_major_ms: nil, velocity_minor_ms: nil, speed_ms: nil, direction_deg: nil, local_time: nil, utc_offset_s: nil, _local: nil, units: "m/s")
|
|
42
|
+
@time = Util.deep_freeze(time)
|
|
43
|
+
@velocity_major_ms = Util.deep_freeze(velocity_major_ms)
|
|
44
|
+
@velocity_minor_ms = Util.deep_freeze(velocity_minor_ms)
|
|
45
|
+
@speed_ms = Util.deep_freeze(speed_ms)
|
|
46
|
+
@direction_deg = Util.deep_freeze(direction_deg)
|
|
47
|
+
@local_time = Util.deep_freeze(local_time)
|
|
48
|
+
@utc_offset_s = Util.deep_freeze(utc_offset_s)
|
|
49
|
+
@units = Util.deep_freeze(units)
|
|
50
|
+
@_local = _local
|
|
51
|
+
freeze
|
|
52
|
+
end
|
|
53
|
+
def velocity_major
|
|
54
|
+
units == "m/s" || velocity_major_ms.nil? ? velocity_major_ms : velocity_major_ms / (1852.0 / 3600.0)
|
|
55
|
+
end
|
|
56
|
+
def velocity_minor
|
|
57
|
+
units == "m/s" || velocity_minor_ms.nil? ? velocity_minor_ms : velocity_minor_ms / (1852.0 / 3600.0)
|
|
58
|
+
end
|
|
59
|
+
def speed
|
|
60
|
+
units == "m/s" || speed_ms.nil? ? speed_ms : speed_ms / (1852.0 / 3600.0)
|
|
61
|
+
end
|
|
62
|
+
def local_time_object
|
|
63
|
+
@_local
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
class CurrentEvent
|
|
67
|
+
attr_reader :time, :type, :velocity_ms, :direction_deg, :local_time, :utc_offset_s, :units
|
|
68
|
+
def initialize(time: nil, type: nil, velocity_ms: nil, direction_deg: nil, local_time: nil, utc_offset_s: nil, _local: nil, units: "m/s")
|
|
69
|
+
@time = Util.deep_freeze(time)
|
|
70
|
+
@type = Util.deep_freeze(type)
|
|
71
|
+
@velocity_ms = Util.deep_freeze(velocity_ms)
|
|
72
|
+
@direction_deg = Util.deep_freeze(direction_deg)
|
|
73
|
+
@local_time = Util.deep_freeze(local_time)
|
|
74
|
+
@utc_offset_s = Util.deep_freeze(utc_offset_s)
|
|
75
|
+
@units = Util.deep_freeze(units)
|
|
76
|
+
@_local = _local
|
|
77
|
+
freeze
|
|
78
|
+
end
|
|
79
|
+
def velocity
|
|
80
|
+
units == "m/s" || velocity_ms.nil? ? velocity_ms : velocity_ms / (1852.0 / 3600.0)
|
|
81
|
+
end
|
|
82
|
+
def local_time_object
|
|
83
|
+
@_local
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
class HeightSeries
|
|
87
|
+
attr_reader :items, :requested_profile, :resolved_profile, :selection_status, :selection_evidence, :source, :station_id, :timezone, :method, :set_id, :convention_id, :astro_table_id, :reference_station_id, :reference_bin, :datum, :datum_name, :datum_kind, :datum_uncertainty_m, :tz, :tz_version, :release, :algorithm, :offset_id, :offset_source, :offset_source_version, :historical_offsets, :current_validity, :current_accuracy, :reference_set_id, :reference_source_version, :reference_2020_equivalence, :source_note, :units
|
|
88
|
+
def initialize(requested_profile: nil, resolved_profile: nil, selection_status: nil, selection_evidence: nil, source: nil, items: [], station_id: nil, timezone: nil, method: nil, set_id: nil, convention_id: nil, astro_table_id: nil, reference_station_id: nil, reference_bin: nil, datum: nil, datum_name: nil, datum_kind: nil, datum_uncertainty_m: nil, tz: nil, tz_version: nil, release: nil, algorithm: nil, offset_id: nil, offset_source: nil, offset_source_version: nil, historical_offsets: false, current_validity: nil, current_accuracy: nil, reference_set_id: nil, reference_source_version: nil, reference_2020_equivalence: nil, source_note: nil, _local: nil, units: "meters")
|
|
89
|
+
@requested_profile = Util.deep_freeze(requested_profile)
|
|
90
|
+
@resolved_profile = Util.deep_freeze(resolved_profile)
|
|
91
|
+
@selection_status = Util.deep_freeze(selection_status)
|
|
92
|
+
@selection_evidence = Util.deep_freeze(selection_evidence)
|
|
93
|
+
@source = Util.deep_freeze(source)
|
|
94
|
+
@items = Util.deep_freeze(items)
|
|
95
|
+
@station_id = Util.deep_freeze(station_id)
|
|
96
|
+
@timezone = Util.deep_freeze(timezone)
|
|
97
|
+
@method = Util.deep_freeze(method)
|
|
98
|
+
@set_id = Util.deep_freeze(set_id)
|
|
99
|
+
@convention_id = Util.deep_freeze(convention_id)
|
|
100
|
+
@astro_table_id = Util.deep_freeze(astro_table_id)
|
|
101
|
+
@reference_station_id = Util.deep_freeze(reference_station_id)
|
|
102
|
+
@reference_bin = Util.deep_freeze(reference_bin)
|
|
103
|
+
@datum = Util.deep_freeze(datum)
|
|
104
|
+
@datum_name = Util.deep_freeze(datum_name)
|
|
105
|
+
@datum_kind = Util.deep_freeze(datum_kind)
|
|
106
|
+
@datum_uncertainty_m = Util.deep_freeze(datum_uncertainty_m)
|
|
107
|
+
@tz = Util.deep_freeze(tz)
|
|
108
|
+
@tz_version = Util.deep_freeze(tz_version)
|
|
109
|
+
@release = Util.deep_freeze(release)
|
|
110
|
+
@algorithm = Util.deep_freeze(algorithm)
|
|
111
|
+
@offset_id = Util.deep_freeze(offset_id)
|
|
112
|
+
@offset_source = Util.deep_freeze(offset_source)
|
|
113
|
+
@offset_source_version = Util.deep_freeze(offset_source_version)
|
|
114
|
+
@historical_offsets = Util.deep_freeze(historical_offsets)
|
|
115
|
+
@current_validity = Util.deep_freeze(current_validity)
|
|
116
|
+
@current_accuracy = Util.deep_freeze(current_accuracy)
|
|
117
|
+
@reference_set_id = Util.deep_freeze(reference_set_id)
|
|
118
|
+
@reference_source_version = Util.deep_freeze(reference_source_version)
|
|
119
|
+
@reference_2020_equivalence = Util.deep_freeze(reference_2020_equivalence)
|
|
120
|
+
@source_note = Util.deep_freeze(source_note)
|
|
121
|
+
@units = Util.deep_freeze(units)
|
|
122
|
+
@_local = _local
|
|
123
|
+
freeze
|
|
124
|
+
end
|
|
125
|
+
def to_local(tz = 'station')
|
|
126
|
+
Predict.localize(self, tz)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
class ExtremeList
|
|
130
|
+
attr_reader :items, :requested_profile, :resolved_profile, :selection_status, :selection_evidence, :source, :station_id, :timezone, :method, :set_id, :convention_id, :astro_table_id, :reference_station_id, :reference_bin, :datum, :datum_name, :datum_kind, :datum_uncertainty_m, :tz, :tz_version, :release, :algorithm, :offset_id, :offset_source, :offset_source_version, :historical_offsets, :current_validity, :current_accuracy, :reference_set_id, :reference_source_version, :reference_2020_equivalence, :source_note, :units
|
|
131
|
+
def initialize(requested_profile: nil, resolved_profile: nil, selection_status: nil, selection_evidence: nil, source: nil, items: [], station_id: nil, timezone: nil, method: nil, set_id: nil, convention_id: nil, astro_table_id: nil, reference_station_id: nil, reference_bin: nil, datum: nil, datum_name: nil, datum_kind: nil, datum_uncertainty_m: nil, tz: nil, tz_version: nil, release: nil, algorithm: nil, offset_id: nil, offset_source: nil, offset_source_version: nil, historical_offsets: false, current_validity: nil, current_accuracy: nil, reference_set_id: nil, reference_source_version: nil, reference_2020_equivalence: nil, source_note: nil, _local: nil, units: "meters")
|
|
132
|
+
@requested_profile = Util.deep_freeze(requested_profile)
|
|
133
|
+
@resolved_profile = Util.deep_freeze(resolved_profile)
|
|
134
|
+
@selection_status = Util.deep_freeze(selection_status)
|
|
135
|
+
@selection_evidence = Util.deep_freeze(selection_evidence)
|
|
136
|
+
@source = Util.deep_freeze(source)
|
|
137
|
+
@items = Util.deep_freeze(items)
|
|
138
|
+
@station_id = Util.deep_freeze(station_id)
|
|
139
|
+
@timezone = Util.deep_freeze(timezone)
|
|
140
|
+
@method = Util.deep_freeze(method)
|
|
141
|
+
@set_id = Util.deep_freeze(set_id)
|
|
142
|
+
@convention_id = Util.deep_freeze(convention_id)
|
|
143
|
+
@astro_table_id = Util.deep_freeze(astro_table_id)
|
|
144
|
+
@reference_station_id = Util.deep_freeze(reference_station_id)
|
|
145
|
+
@reference_bin = Util.deep_freeze(reference_bin)
|
|
146
|
+
@datum = Util.deep_freeze(datum)
|
|
147
|
+
@datum_name = Util.deep_freeze(datum_name)
|
|
148
|
+
@datum_kind = Util.deep_freeze(datum_kind)
|
|
149
|
+
@datum_uncertainty_m = Util.deep_freeze(datum_uncertainty_m)
|
|
150
|
+
@tz = Util.deep_freeze(tz)
|
|
151
|
+
@tz_version = Util.deep_freeze(tz_version)
|
|
152
|
+
@release = Util.deep_freeze(release)
|
|
153
|
+
@algorithm = Util.deep_freeze(algorithm)
|
|
154
|
+
@offset_id = Util.deep_freeze(offset_id)
|
|
155
|
+
@offset_source = Util.deep_freeze(offset_source)
|
|
156
|
+
@offset_source_version = Util.deep_freeze(offset_source_version)
|
|
157
|
+
@historical_offsets = Util.deep_freeze(historical_offsets)
|
|
158
|
+
@current_validity = Util.deep_freeze(current_validity)
|
|
159
|
+
@current_accuracy = Util.deep_freeze(current_accuracy)
|
|
160
|
+
@reference_set_id = Util.deep_freeze(reference_set_id)
|
|
161
|
+
@reference_source_version = Util.deep_freeze(reference_source_version)
|
|
162
|
+
@reference_2020_equivalence = Util.deep_freeze(reference_2020_equivalence)
|
|
163
|
+
@source_note = Util.deep_freeze(source_note)
|
|
164
|
+
@units = Util.deep_freeze(units)
|
|
165
|
+
@_local = _local
|
|
166
|
+
freeze
|
|
167
|
+
end
|
|
168
|
+
def to_local(tz = 'station')
|
|
169
|
+
Predict.localize(self, tz)
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
class CurrentSeries
|
|
173
|
+
attr_reader :items, :requested_profile, :resolved_profile, :selection_status, :selection_evidence, :source, :station_id, :timezone, :method, :set_id, :convention_id, :astro_table_id, :reference_station_id, :reference_bin, :datum, :datum_name, :datum_kind, :datum_uncertainty_m, :bin_number, :tz, :tz_version, :release, :algorithm, :units
|
|
174
|
+
def initialize(requested_profile: nil, resolved_profile: nil, selection_status: nil, selection_evidence: nil, source: nil, items: [], station_id: nil, timezone: nil, method: nil, set_id: nil, convention_id: nil, astro_table_id: nil, reference_station_id: nil, reference_bin: nil, datum: nil, datum_name: nil, datum_kind: nil, datum_uncertainty_m: nil, bin_number: nil, tz: nil, tz_version: nil, release: nil, algorithm: nil, _local: nil, units: "m/s")
|
|
175
|
+
@requested_profile = Util.deep_freeze(requested_profile)
|
|
176
|
+
@resolved_profile = Util.deep_freeze(resolved_profile)
|
|
177
|
+
@selection_status = Util.deep_freeze(selection_status)
|
|
178
|
+
@selection_evidence = Util.deep_freeze(selection_evidence)
|
|
179
|
+
@source = Util.deep_freeze(source)
|
|
180
|
+
@items = Util.deep_freeze(items)
|
|
181
|
+
@station_id = Util.deep_freeze(station_id)
|
|
182
|
+
@timezone = Util.deep_freeze(timezone)
|
|
183
|
+
@method = Util.deep_freeze(method)
|
|
184
|
+
@set_id = Util.deep_freeze(set_id)
|
|
185
|
+
@convention_id = Util.deep_freeze(convention_id)
|
|
186
|
+
@astro_table_id = Util.deep_freeze(astro_table_id)
|
|
187
|
+
@reference_station_id = Util.deep_freeze(reference_station_id)
|
|
188
|
+
@reference_bin = Util.deep_freeze(reference_bin)
|
|
189
|
+
@datum = Util.deep_freeze(datum)
|
|
190
|
+
@datum_name = Util.deep_freeze(datum_name)
|
|
191
|
+
@datum_kind = Util.deep_freeze(datum_kind)
|
|
192
|
+
@datum_uncertainty_m = Util.deep_freeze(datum_uncertainty_m)
|
|
193
|
+
@bin_number = Util.deep_freeze(bin_number)
|
|
194
|
+
@tz = Util.deep_freeze(tz)
|
|
195
|
+
@tz_version = Util.deep_freeze(tz_version)
|
|
196
|
+
@release = Util.deep_freeze(release)
|
|
197
|
+
@algorithm = Util.deep_freeze(algorithm)
|
|
198
|
+
@units = Util.deep_freeze(units)
|
|
199
|
+
@_local = _local
|
|
200
|
+
freeze
|
|
201
|
+
end
|
|
202
|
+
def to_local(tz = 'station')
|
|
203
|
+
Predict.localize(self, tz)
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
class CurrentEventList
|
|
207
|
+
attr_reader :items, :requested_profile, :resolved_profile, :selection_status, :selection_evidence, :source, :station_id, :timezone, :method, :set_id, :convention_id, :astro_table_id, :reference_station_id, :reference_bin, :datum, :datum_name, :datum_kind, :datum_uncertainty_m, :bin_number, :omitted_event_types, :tz, :tz_version, :release, :algorithm, :units
|
|
208
|
+
def initialize(requested_profile: nil, resolved_profile: nil, selection_status: nil, selection_evidence: nil, source: nil, items: [], station_id: nil, timezone: nil, method: nil, set_id: nil, convention_id: nil, astro_table_id: nil, reference_station_id: nil, reference_bin: nil, datum: nil, datum_name: nil, datum_kind: nil, datum_uncertainty_m: nil, bin_number: nil, omitted_event_types: nil, tz: nil, tz_version: nil, release: nil, algorithm: nil, _local: nil, units: "m/s")
|
|
209
|
+
@requested_profile = Util.deep_freeze(requested_profile)
|
|
210
|
+
@resolved_profile = Util.deep_freeze(resolved_profile)
|
|
211
|
+
@selection_status = Util.deep_freeze(selection_status)
|
|
212
|
+
@selection_evidence = Util.deep_freeze(selection_evidence)
|
|
213
|
+
@source = Util.deep_freeze(source)
|
|
214
|
+
@items = Util.deep_freeze(items)
|
|
215
|
+
@station_id = Util.deep_freeze(station_id)
|
|
216
|
+
@timezone = Util.deep_freeze(timezone)
|
|
217
|
+
@method = Util.deep_freeze(method)
|
|
218
|
+
@set_id = Util.deep_freeze(set_id)
|
|
219
|
+
@convention_id = Util.deep_freeze(convention_id)
|
|
220
|
+
@astro_table_id = Util.deep_freeze(astro_table_id)
|
|
221
|
+
@reference_station_id = Util.deep_freeze(reference_station_id)
|
|
222
|
+
@reference_bin = Util.deep_freeze(reference_bin)
|
|
223
|
+
@datum = Util.deep_freeze(datum)
|
|
224
|
+
@datum_name = Util.deep_freeze(datum_name)
|
|
225
|
+
@datum_kind = Util.deep_freeze(datum_kind)
|
|
226
|
+
@datum_uncertainty_m = Util.deep_freeze(datum_uncertainty_m)
|
|
227
|
+
@bin_number = Util.deep_freeze(bin_number)
|
|
228
|
+
@omitted_event_types = Util.deep_freeze(omitted_event_types)
|
|
229
|
+
@tz = Util.deep_freeze(tz)
|
|
230
|
+
@tz_version = Util.deep_freeze(tz_version)
|
|
231
|
+
@release = Util.deep_freeze(release)
|
|
232
|
+
@algorithm = Util.deep_freeze(algorithm)
|
|
233
|
+
@units = Util.deep_freeze(units)
|
|
234
|
+
@_local = _local
|
|
235
|
+
freeze
|
|
236
|
+
end
|
|
237
|
+
def to_local(tz = 'station')
|
|
238
|
+
Predict.localize(self, tz)
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
class DatumPredictionBinding
|
|
242
|
+
attr_reader :chart_datum, :status, :limitations
|
|
243
|
+
def initialize(chart_datum: nil, status:, limitations: [])
|
|
244
|
+
@chart_datum = Util.deep_freeze(chart_datum)
|
|
245
|
+
@status = Util.deep_freeze(status)
|
|
246
|
+
@limitations = Util.deep_freeze(limitations)
|
|
247
|
+
freeze
|
|
248
|
+
end
|
|
249
|
+
def to_h
|
|
250
|
+
{"chart_datum" => chart_datum, "status" => status, "limitations" => limitations}
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
class DatumDeclaration
|
|
254
|
+
attr_reader :scope, :set_id, :source, :source_record_id, :source_version, :disposition,
|
|
255
|
+
:licence_id, :upstream_licence_id, :published_set_ids, :field_path, :candidate, :provenance
|
|
256
|
+
def initialize(scope:, set_id: nil, source: nil, source_record_id: nil, source_version: nil, disposition: nil,
|
|
257
|
+
licence_id: nil, upstream_licence_id: nil, published_set_ids: [], field_path:, candidate:, provenance: nil)
|
|
258
|
+
@scope = Util.deep_freeze(scope)
|
|
259
|
+
@set_id = Util.deep_freeze(set_id)
|
|
260
|
+
@source = Util.deep_freeze(source)
|
|
261
|
+
@source_record_id = Util.deep_freeze(source_record_id)
|
|
262
|
+
@source_version = Util.deep_freeze(source_version)
|
|
263
|
+
@disposition = Util.deep_freeze(disposition)
|
|
264
|
+
@licence_id = Util.deep_freeze(licence_id)
|
|
265
|
+
@upstream_licence_id = Util.deep_freeze(upstream_licence_id)
|
|
266
|
+
@published_set_ids = Util.deep_freeze(published_set_ids)
|
|
267
|
+
@field_path = Util.deep_freeze(field_path)
|
|
268
|
+
@candidate = Util.deep_freeze(candidate)
|
|
269
|
+
@provenance = Util.deep_freeze(provenance)
|
|
270
|
+
freeze
|
|
271
|
+
end
|
|
272
|
+
def to_h
|
|
273
|
+
{"scope" => scope, "set_id" => set_id, "source" => source, "source_record_id" => source_record_id,
|
|
274
|
+
"source_version" => source_version, "disposition" => disposition, "licence_id" => licence_id,
|
|
275
|
+
"upstream_licence_id" => upstream_licence_id, "published_set_ids" => published_set_ids,
|
|
276
|
+
"field_path" => field_path, "candidate" => candidate, "provenance" => provenance}
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
class DatumAlternativePath
|
|
280
|
+
attr_reader :kind, :set_id, :offset_id, :reference_station_id, :chart_datum, :datum, :qualifications
|
|
281
|
+
def initialize(kind:, set_id: nil, offset_id: nil, reference_station_id: nil, chart_datum: nil, datum: nil, qualifications: [])
|
|
282
|
+
@kind = Util.deep_freeze(kind)
|
|
283
|
+
@set_id = Util.deep_freeze(set_id)
|
|
284
|
+
@offset_id = Util.deep_freeze(offset_id)
|
|
285
|
+
@reference_station_id = Util.deep_freeze(reference_station_id)
|
|
286
|
+
@chart_datum = Util.deep_freeze(chart_datum)
|
|
287
|
+
@datum = Util.deep_freeze(datum)
|
|
288
|
+
@qualifications = Util.deep_freeze(qualifications)
|
|
289
|
+
freeze
|
|
290
|
+
end
|
|
291
|
+
def to_h
|
|
292
|
+
{"kind" => kind, "set_id" => set_id, "offset_id" => offset_id, "reference_station_id" => reference_station_id,
|
|
293
|
+
"chart_datum" => chart_datum, "datum" => datum, "qualifications" => qualifications}
|
|
294
|
+
end
|
|
295
|
+
end
|
|
296
|
+
class DatumSources
|
|
297
|
+
attr_reader :station_id, :selected_set_id, :prediction_binding, :declarations, :alternative_paths
|
|
298
|
+
def initialize(station_id:, selected_set_id: nil, prediction_binding:, declarations: [], alternative_paths: [])
|
|
299
|
+
@station_id = Util.deep_freeze(station_id)
|
|
300
|
+
@selected_set_id = Util.deep_freeze(selected_set_id)
|
|
301
|
+
@prediction_binding = Util.deep_freeze(prediction_binding)
|
|
302
|
+
@declarations = Util.deep_freeze(declarations)
|
|
303
|
+
@alternative_paths = Util.deep_freeze(alternative_paths)
|
|
304
|
+
freeze
|
|
305
|
+
end
|
|
306
|
+
def to_h
|
|
307
|
+
{"station_id" => station_id, "selected_set_id" => selected_set_id, "prediction_binding" => prediction_binding.to_h,
|
|
308
|
+
"declarations" => declarations.map(&:to_h), "alternative_paths" => alternative_paths.map(&:to_h)}
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
class DatumInfo
|
|
312
|
+
attr_reader :set_id, :zero, :zero_name, :chart_datum, :msl_offset_m, :levels
|
|
313
|
+
def initialize(set_id: nil, zero: nil, zero_name: nil, chart_datum: nil, msl_offset_m: nil, levels: [], _local: nil)
|
|
314
|
+
@set_id = Util.deep_freeze(set_id)
|
|
315
|
+
@zero = Util.deep_freeze(zero)
|
|
316
|
+
@zero_name = Util.deep_freeze(zero_name)
|
|
317
|
+
@chart_datum = Util.deep_freeze(chart_datum)
|
|
318
|
+
@msl_offset_m = Util.deep_freeze(msl_offset_m)
|
|
319
|
+
@levels = Util.deep_freeze(levels)
|
|
320
|
+
@_local = _local
|
|
321
|
+
freeze
|
|
322
|
+
end
|
|
323
|
+
end
|
|
324
|
+
class DatumLevel
|
|
325
|
+
attr_reader :key, :value_m, :above_chart_m, :kind, :method, :source_name, :epoch, :data_span, :control_station_id, :control_set_id, :control_source_id, :uncertainty_m, :uncertainty_basis, :flags, :fallback
|
|
326
|
+
def initialize(key: nil, value_m: nil, above_chart_m: nil, kind: nil, method: nil, source_name: nil, epoch: nil, data_span: nil, control_station_id: nil, control_set_id: nil, control_source_id: nil, uncertainty_m: nil, uncertainty_basis: nil, flags: [], fallback: nil, _local: nil)
|
|
327
|
+
@key = Util.deep_freeze(key)
|
|
328
|
+
@value_m = Util.deep_freeze(value_m)
|
|
329
|
+
@above_chart_m = Util.deep_freeze(above_chart_m)
|
|
330
|
+
@kind = Util.deep_freeze(kind)
|
|
331
|
+
@method = Util.deep_freeze(method)
|
|
332
|
+
@source_name = Util.deep_freeze(source_name)
|
|
333
|
+
@epoch = Util.deep_freeze(epoch)
|
|
334
|
+
@data_span = Util.deep_freeze(data_span)
|
|
335
|
+
@control_station_id = Util.deep_freeze(control_station_id)
|
|
336
|
+
@control_set_id = Util.deep_freeze(control_set_id)
|
|
337
|
+
@control_source_id = Util.deep_freeze(control_source_id)
|
|
338
|
+
@uncertainty_m = Util.deep_freeze(uncertainty_m)
|
|
339
|
+
@uncertainty_basis = Util.deep_freeze(uncertainty_basis)
|
|
340
|
+
@flags = Util.deep_freeze(flags)
|
|
341
|
+
@fallback = fallback.nil? ? nil : Util.deep_freeze(JSON.parse(JSON.generate(fallback)))
|
|
342
|
+
@_local = _local
|
|
343
|
+
freeze
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
class Ranges
|
|
347
|
+
attr_reader :mn, :gt, :dhq, :dlq
|
|
348
|
+
def initialize(mn: nil, gt: nil, dhq: nil, dlq: nil, _local: nil)
|
|
349
|
+
@mn = Util.deep_freeze(mn)
|
|
350
|
+
@gt = Util.deep_freeze(gt)
|
|
351
|
+
@dhq = Util.deep_freeze(dhq)
|
|
352
|
+
@dlq = Util.deep_freeze(dlq)
|
|
353
|
+
@_local = _local
|
|
354
|
+
freeze
|
|
355
|
+
end
|
|
356
|
+
end
|
|
357
|
+
end
|