cpdundon_cli_app_take3 0.3.0 → 0.4.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/bin/bin_current +6 -0
- data/lib/calc_current.rb +99 -0
- data/lib/cli.rb +2 -2
- data/lib/cli_current.rb +121 -0
- data/lib/config.rb +6 -4
- data/lib/cpdundon_cli_app_take3.rb +2 -0
- data/lib/cpdundon_cli_app_take3/version.rb +1 -1
- data/lib/noaa_soap.rb +8 -3
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8747d93fdbefa5c663566af241e89f3372d242dc0ae5c84869fd34aeb7de36df
|
4
|
+
data.tar.gz: bfedcf261b3646e023e50100112c12c2e3b71d69d3ea9eadd3bbc850cc7a516d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34adc7972f13db9fa45e86ae4484bbd3f2e3671cebac643e1e0f428a85ec486c29c7bd835623d25ae4a50c9ab7ae468c249bc6d6f5534a8c60dfbcda1c31e74a
|
7
|
+
data.tar.gz: 04d7585f2d165093e0c9fdda89b74ce7f1670d3c4bb6fc6faf05dc0aaf3e01dd74c8389f854b84aa7b074daa6cde7bf0f2bd28f98b6a7c78bef582b77977364e
|
data/bin/bin_current
ADDED
data/lib/calc_current.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require_relative './config'
|
2
|
+
|
3
|
+
# ========================================================
|
4
|
+
# This is proof of concept code. It can be extended
|
5
|
+
# to allow for a great deal more realistic take on
|
6
|
+
# estuary currents. CPD - 12-May-2018
|
7
|
+
# ========================================================
|
8
|
+
|
9
|
+
class CalcCurrent
|
10
|
+
|
11
|
+
include Math
|
12
|
+
attr_reader :depth_delta
|
13
|
+
|
14
|
+
Gamma = 0.005 #Tanh scale factor
|
15
|
+
Depth = 25 #Meters
|
16
|
+
Estuary_Width = 1000 #Meters
|
17
|
+
Estuary_Length = 115000 #Meters
|
18
|
+
Shaft_Radius = 5000 #Meters
|
19
|
+
Meters_Knots = 1.94384 #Meter/Sec to Knots
|
20
|
+
SixMin_Secs = 360
|
21
|
+
|
22
|
+
@@static_data = []
|
23
|
+
@@tanh_fac = nil
|
24
|
+
|
25
|
+
def self.static
|
26
|
+
@@static_data
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.tanh_fac
|
30
|
+
@@tanh_fac
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
return if self.class.static.size != 0
|
35
|
+
@@tanh_fac = tanh_normalization_factor
|
36
|
+
static_bootstrap
|
37
|
+
end
|
38
|
+
|
39
|
+
def calc_surface_current(location, depth_delta = nil)
|
40
|
+
@depth_delta = depth_delta / SixMin_Secs if !!depth_delta
|
41
|
+
|
42
|
+
return "Missisng Depth Delta information." if !!!self.depth_delta
|
43
|
+
|
44
|
+
depth = depth_from_loc(location) # this maps location to a depth from radial tdc in the river channel.
|
45
|
+
|
46
|
+
stat = self.class.static
|
47
|
+
rdh = stat.select { |e| e.depth == depth.to_i }[0]
|
48
|
+
|
49
|
+
surf_current = self.depth_delta * rdh.normalized_tanh * Estuary_Length
|
50
|
+
|
51
|
+
rdu = RiverData_Surf.new
|
52
|
+
rdu.tdc_radius = Shaft_Radius
|
53
|
+
rdu.c_velocity_ms = surf_current
|
54
|
+
rdu.c_velocity_kts = surf_current * Meters_Knots
|
55
|
+
rdu.surf_loc = location
|
56
|
+
rdu.surf_radius = rdh.depth_radius
|
57
|
+
|
58
|
+
rdu
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
def tanh_normalization_factor
|
63
|
+
tnf = 0
|
64
|
+
(0..Depth).each do |i|
|
65
|
+
tnf += tanh(Gamma * i)
|
66
|
+
end
|
67
|
+
tnf
|
68
|
+
end
|
69
|
+
|
70
|
+
def static_bootstrap
|
71
|
+
(0..Depth).each do |i|
|
72
|
+
rdh = RiverData_Shaft.new
|
73
|
+
rdh.depth = Depth - i
|
74
|
+
rdh.height = i
|
75
|
+
rdh.depth_radius = Shaft_Radius - i
|
76
|
+
rdh.normalized_tanh = tanh(Gamma * i) / self.class.tanh_fac
|
77
|
+
self.class.static << rdh
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def depth_from_loc(loc)
|
82
|
+
r_tdc = Shaft_Radius - Depth
|
83
|
+
|
84
|
+
r_tdc2 = r_tdc ** 2
|
85
|
+
l2 = loc ** 2
|
86
|
+
r_loc = sqrt(r_tdc2 + l2)
|
87
|
+
depth = (r_loc - r_tdc).floor
|
88
|
+
depth
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
class RiverData_Shaft
|
94
|
+
attr_accessor :depth, :height, :depth_radius, :normalized_tanh
|
95
|
+
end
|
96
|
+
|
97
|
+
class RiverData_Surf
|
98
|
+
attr_accessor :surf_radius, :surf_loc, :c_velocity_ms, :c_velocity_kts, :tdc_radius
|
99
|
+
end
|
data/lib/cli.rb
CHANGED
@@ -91,8 +91,8 @@ private
|
|
91
91
|
wl_data = gwl.pull_data(self.tideID)
|
92
92
|
wv_data = gwv.pull_data(self.windID)
|
93
93
|
|
94
|
-
wl = NOAA_SOAP.most_recent(wl_data)
|
95
|
-
wv = NOAA_SOAP.most_recent(wv_data)
|
94
|
+
wl = NOAA_SOAP.most_recent(wl_data)[0]
|
95
|
+
wv = NOAA_SOAP.most_recent(wv_data)[0]
|
96
96
|
|
97
97
|
puts "Using #{self.windLocation}:"
|
98
98
|
puts "Wind station time is #{wv[:time_stamp]} GMT:"
|
data/lib/cli_current.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
require_relative './config'
|
2
|
+
|
3
|
+
class CLICurrent
|
4
|
+
|
5
|
+
attr_accessor :windID, :tideID, :windLocation, :tideLocation
|
6
|
+
|
7
|
+
def initialize ()
|
8
|
+
@windID = nil
|
9
|
+
@tideID = nil
|
10
|
+
@windLocation = nil
|
11
|
+
@tideLocation = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def main()
|
15
|
+
input = nil
|
16
|
+
|
17
|
+
input = decision("tide")
|
18
|
+
return input if input == "exit"
|
19
|
+
|
20
|
+
input = current_cycle
|
21
|
+
input
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def decision(flag)
|
26
|
+
input = nil
|
27
|
+
iCaptured = nil
|
28
|
+
puts
|
29
|
+
puts "================================="
|
30
|
+
puts "'Exit' will stop data collection."
|
31
|
+
puts "================================="
|
32
|
+
|
33
|
+
if flag.strip.downcase == "winds"
|
34
|
+
stations = GetActiveStations.winds
|
35
|
+
else
|
36
|
+
stations = GetActiveStations.water_level
|
37
|
+
end
|
38
|
+
|
39
|
+
stations = stations.sort {|x,y| x.name <=> y.name}
|
40
|
+
|
41
|
+
sz = stations.size
|
42
|
+
until (input == "exit" || iCaptured)
|
43
|
+
puts
|
44
|
+
puts "Enter the index number of the #{flag.upcase} station you want to use."
|
45
|
+
(1..sz).each do |i|
|
46
|
+
puts "#{i}. Station named '#{stations[i-1].name}'."
|
47
|
+
end
|
48
|
+
puts
|
49
|
+
puts "Enter the index number of the #{flag.upcase} station you want to use."
|
50
|
+
input = gets.strip.downcase
|
51
|
+
iCaptured = (input == input.to_i.to_s) && input.to_i > 0 && input.to_i <= sz
|
52
|
+
end
|
53
|
+
|
54
|
+
if input != "exit" && flag == "winds"
|
55
|
+
sta = stations[input.to_i - 1]
|
56
|
+
self.windLocation = sta.name
|
57
|
+
self.windID = sta.iD
|
58
|
+
elsif input != "exit"
|
59
|
+
sta = stations[input.to_i - 1]
|
60
|
+
self.tideLocation = sta.name
|
61
|
+
self.tideID = sta.iD
|
62
|
+
end
|
63
|
+
|
64
|
+
input
|
65
|
+
end
|
66
|
+
|
67
|
+
def current_cycle()
|
68
|
+
input = nil
|
69
|
+
puts
|
70
|
+
puts "======================================="
|
71
|
+
puts "'Exit' will terminate this application."
|
72
|
+
puts "======================================="
|
73
|
+
puts
|
74
|
+
|
75
|
+
|
76
|
+
gwl = GetWaterLevel.new
|
77
|
+
wl_data = gwl.pull_data(self.tideID)
|
78
|
+
wl_chg_data = NOAA_SOAP.most_recent(wl_data, 2)
|
79
|
+
wl_delta_6min = wl_chg_data[0][:wl].to_f - wl_chg_data[1][:wl].to_f
|
80
|
+
t = wl_chg_data[0][:time_stamp]
|
81
|
+
|
82
|
+
cc = CalcCurrent.new
|
83
|
+
|
84
|
+
until (input == "exit") do
|
85
|
+
puts "Enter your location in meters away from center channel (-500...500)."
|
86
|
+
puts "OR..."
|
87
|
+
puts "Enter 'New' to query NOAA for the latest water level measurement."
|
88
|
+
puts
|
89
|
+
puts "***The NOAA Service Updates Every 6 Minutes***"
|
90
|
+
puts
|
91
|
+
|
92
|
+
input = gets.strip.downcase
|
93
|
+
puts
|
94
|
+
|
95
|
+
if input == input.to_i.to_s && input.to_i >= -500 && input.to_i <= 500
|
96
|
+
|
97
|
+
rdu = cc.calc_surface_current(input.to_i, wl_delta_6min)
|
98
|
+
return "Error" if rdu.class != RiverData_Surf
|
99
|
+
|
100
|
+
kts = rdu.c_velocity_kts
|
101
|
+
|
102
|
+
puts "Using #{self.tideLocation} at #{t.slice(0, t.length-5)} GMT:"
|
103
|
+
puts "The 6 minute water level difference is #{'%.3f' %wl_delta_6min} meters:"
|
104
|
+
puts "The current #{input} meter(s) away from center channel is #{'%.2f' %kts} knots."
|
105
|
+
end
|
106
|
+
|
107
|
+
if input == "new"
|
108
|
+
gwl = GetWaterLevel.new
|
109
|
+
wl_data = gwl.pull_data(self.tideID)
|
110
|
+
wl_chg_data = NOAA_SOAP.most_recent(wl_data, 2)
|
111
|
+
wl_delta_6min = wl_chg_data[0][:wl].to_f - wl_chg_data[1][:wl].to_f
|
112
|
+
t = wl_chg_data[0][:time_stamp]
|
113
|
+
puts
|
114
|
+
puts "The new data has a time stamp of #{t.slice(0, t.length-5)} GMT."
|
115
|
+
end
|
116
|
+
|
117
|
+
puts
|
118
|
+
end
|
119
|
+
input
|
120
|
+
end
|
121
|
+
end
|
data/lib/config.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
require_relative './gmt'
|
2
1
|
require_relative './noaa_soap'
|
2
|
+
require_relative './cli'
|
3
|
+
require_relative './cli_current'
|
4
|
+
require_relative './gmt'
|
3
5
|
require_relative './get_water_level'
|
4
6
|
require_relative './get_wind'
|
5
7
|
require_relative './get_active_stations'
|
6
|
-
require_relative './cli'
|
7
8
|
require_relative './station'
|
9
|
+
require_relative './calc_current'
|
8
10
|
|
9
|
-
require 'time'
|
10
|
-
require 'savon'
|
11
11
|
require 'nokogiri'
|
12
|
+
require 'savon'
|
13
|
+
require 'time'
|
data/lib/noaa_soap.rb
CHANGED
@@ -3,9 +3,14 @@ require_relative './config'
|
|
3
3
|
class NOAA_SOAP
|
4
4
|
attr_reader :client
|
5
5
|
|
6
|
-
def self.most_recent(data)
|
7
|
-
|
8
|
-
d
|
6
|
+
def self.most_recent(data, count = 1)
|
7
|
+
rtn = []
|
8
|
+
d = data.sort { |x,y| y[:time_stamp] <=> x[:time_stamp] }
|
9
|
+
|
10
|
+
(1..count).each do |i|
|
11
|
+
rtn << d[i - 1]
|
12
|
+
end
|
13
|
+
rtn
|
9
14
|
end
|
10
15
|
|
11
16
|
def initialize(wsdl)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cpdundon_cli_app_take3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher P. Dundon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -83,10 +83,13 @@ files:
|
|
83
83
|
- README.md
|
84
84
|
- Rakefile
|
85
85
|
- bin/bin
|
86
|
+
- bin/bin_current
|
86
87
|
- bin/console
|
87
88
|
- bin/setup
|
88
89
|
- cpdundon_cli_app_take3.gemspec
|
90
|
+
- lib/calc_current.rb
|
89
91
|
- lib/cli.rb
|
92
|
+
- lib/cli_current.rb
|
90
93
|
- lib/config.rb
|
91
94
|
- lib/cpdundon_cli_app_take3.rb
|
92
95
|
- lib/cpdundon_cli_app_take3/version.rb
|