RubySunrise 0.1.0 → 0.1.1
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.
- data/lib/{sunrise.rb → solareventcalculator.rb} +39 -39
- data/rubysunrise.gemspec +1 -1
- data/test/sunrisetest.rb +10 -11
- data/test/sunsettest.rb +10 -11
- metadata +3 -3
@@ -13,18 +13,14 @@ class SolarEventCalculator
|
|
13
13
|
@longitude = longitude
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def compute_lnghour
|
17
17
|
lngHour = @longitude / BigDecimal.new("15")
|
18
18
|
lngHour.round(4)
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
|
23
|
-
longHour.
|
24
|
-
end
|
25
|
-
|
26
|
-
def compute_set_longitude_hour
|
27
|
-
longHour = @date.yday + ((BigDecimal.new("18") - compute_longitude_hour) / BigDecimal.new("24"))
|
21
|
+
def compute_longitude_hour(isSunrise)
|
22
|
+
minuend = (isSunrise) ? BigDecimal.new("6") : BigDecimal.new("18")
|
23
|
+
longHour = @date.yday + ((minuend - compute_lnghour) / BigDecimal.new("24"))
|
28
24
|
longHour.round(4)
|
29
25
|
end
|
30
26
|
|
@@ -85,17 +81,12 @@ class SolarEventCalculator
|
|
85
81
|
cosLocalHour.round(4)
|
86
82
|
end
|
87
83
|
|
88
|
-
def
|
84
|
+
def compute_local_hour_angle(cosSunLocalHour, isSunrise)
|
89
85
|
acosH = BigDecimal.new(Math.acos(cosSunLocalHour).to_s)
|
90
|
-
|
91
|
-
localHourAngle = localHourAngle / BigDecimal.new("15")
|
92
|
-
localHourAngle.round(4)
|
93
|
-
end
|
86
|
+
acosHDegrees = rads_as_degrees(acosH)
|
94
87
|
|
95
|
-
|
96
|
-
|
97
|
-
acosH = rads_as_degrees(acosH)
|
98
|
-
localHourAngle = acosH / BigDecimal.new("15")
|
88
|
+
localHourAngle = (isSunrise) ? BigDecimal.new("360") - acosHDegrees : acosHDegrees
|
89
|
+
localHourAngle = localHourAngle / BigDecimal.new("15")
|
99
90
|
localHourAngle.round(4)
|
100
91
|
end
|
101
92
|
|
@@ -111,11 +102,11 @@ class SolarEventCalculator
|
|
111
102
|
utcTime.round(4)
|
112
103
|
end
|
113
104
|
|
114
|
-
def
|
115
|
-
longHour =
|
116
|
-
|
105
|
+
def compute_utc_solar_event(zenith, isSunrise)
|
106
|
+
longHour = compute_lnghour
|
107
|
+
eventLongHour = compute_longitude_hour(isSunrise)
|
117
108
|
|
118
|
-
meanAnomaly = compute_sun_mean_anomaly(
|
109
|
+
meanAnomaly = compute_sun_mean_anomaly(eventLongHour)
|
119
110
|
sunTrueLong = compute_sun_true_longitude(meanAnomaly)
|
120
111
|
cosineSunLocalHour = compute_cosine_sun_local_hour(sunTrueLong, zenith)
|
121
112
|
|
@@ -123,8 +114,8 @@ class SolarEventCalculator
|
|
123
114
|
return nil
|
124
115
|
end
|
125
116
|
|
126
|
-
sunLocalHour =
|
127
|
-
localMeanTime = compute_local_mean_time(sunTrueLong, longHour,
|
117
|
+
sunLocalHour = compute_local_hour_angle(cosineSunLocalHour, isSunrise)
|
118
|
+
localMeanTime = compute_local_mean_time(sunTrueLong, longHour, eventLongHour, sunLocalHour)
|
128
119
|
|
129
120
|
timeParts = localMeanTime.to_s('F').split('.')
|
130
121
|
mins = BigDecimal.new("." + timeParts[1]) * BigDecimal.new("60")
|
@@ -135,27 +126,36 @@ class SolarEventCalculator
|
|
135
126
|
Time.gm(@date.year, @date.mon, @date.mday, hours, pad_minutes(mins.to_i))
|
136
127
|
end
|
137
128
|
|
138
|
-
def
|
139
|
-
|
140
|
-
|
129
|
+
def compute_utc_civil_sunrise
|
130
|
+
compute_utc_solar_event(96, true)
|
131
|
+
end
|
141
132
|
|
142
|
-
|
143
|
-
|
144
|
-
|
133
|
+
def compute_utc_civil_sunset
|
134
|
+
compute_utc_solar_event(96, false)
|
135
|
+
end
|
145
136
|
|
146
|
-
|
147
|
-
|
148
|
-
|
137
|
+
def compute_utc_official_sunrise
|
138
|
+
compute_utc_solar_event(90.8333, true)
|
139
|
+
end
|
149
140
|
|
150
|
-
|
151
|
-
|
141
|
+
def compute_utc_official_sunset
|
142
|
+
compute_utc_solar_event(90.8333, false)
|
143
|
+
end
|
152
144
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
hours = timeParts[0]
|
145
|
+
def compute_utc_nautical_sunrise
|
146
|
+
compute_utc_solar_event(102, true)
|
147
|
+
end
|
157
148
|
|
158
|
-
|
149
|
+
def compute_utc_nautical_sunset
|
150
|
+
compute_utc_solar_event(102, false)
|
151
|
+
end
|
152
|
+
|
153
|
+
def compute_utc_astronomical_sunrise
|
154
|
+
compute_utc_solar_event(108, true)
|
155
|
+
end
|
156
|
+
|
157
|
+
def compute_utc_astronomical_sunset
|
158
|
+
compute_utc_solar_event(108, false)
|
159
159
|
end
|
160
160
|
|
161
161
|
def pad_minutes(minutes)
|
data/rubysunrise.gemspec
CHANGED
data/test/sunrisetest.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require '../lib/solareventcalculator'
|
2
2
|
|
3
3
|
describe SolarEventCalculator, "test the math for home" do
|
4
4
|
|
@@ -8,11 +8,11 @@ describe SolarEventCalculator, "test the math for home" do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "returns correct longitude hour" do
|
11
|
-
@calc.
|
11
|
+
@calc.compute_lnghour.should eql(BigDecimal.new("-5.0523"))
|
12
12
|
end
|
13
13
|
|
14
14
|
it "returns correct longitude hour" do
|
15
|
-
@calc.
|
15
|
+
@calc.compute_longitude_hour(true).should eql(BigDecimal.new("306.4605"))
|
16
16
|
end
|
17
17
|
|
18
18
|
it "returns correct sunrise mean anomaly" do
|
@@ -44,7 +44,7 @@ describe SolarEventCalculator, "test the math for home" do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "returns correct sunrise local hour angle" do
|
47
|
-
@calc.
|
47
|
+
@calc.compute_local_hour_angle(BigDecimal.new("0.0791"), true).should eql(BigDecimal.new("18.3025"))
|
48
48
|
end
|
49
49
|
|
50
50
|
it "returns correct sunrise local mean time" do
|
@@ -56,19 +56,19 @@ describe SolarEventCalculator, "test the math for home" do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it "returns correct civil sunrise time" do
|
59
|
-
@calc.
|
59
|
+
@calc.compute_utc_civil_sunrise.should eql(Time.gm(@date.year, @date.mon, @date.mday, 11, 4))
|
60
60
|
end
|
61
61
|
|
62
62
|
it "returns correct official sunrise time" do
|
63
|
-
@calc.
|
63
|
+
@calc.compute_utc_official_sunrise.should eql(Time.gm(@date.year, @date.mon, @date.mday, 11, 33))
|
64
64
|
end
|
65
65
|
|
66
66
|
it "returns correct nautical sunrise time" do
|
67
|
-
@calc.
|
67
|
+
@calc.compute_utc_nautical_sunrise.should eql(Time.gm(@date.year, @date.mon, @date.mday, 10, 32))
|
68
68
|
end
|
69
69
|
|
70
70
|
it "returns correct astronomical sunrise time" do
|
71
|
-
@calc.
|
71
|
+
@calc.compute_utc_astronomical_sunrise.should eql(Time.gm(@date.year, @date.mon, @date.mday, 10, 1))
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -77,13 +77,12 @@ describe SolarEventCalculator, "test the math for areas where there could be no
|
|
77
77
|
it "returns correct time" do
|
78
78
|
date = Date.parse('2008-04-25') #25 April 2008
|
79
79
|
calc = SolarEventCalculator.new(date, BigDecimal.new("64.8378"), BigDecimal.new("-147.7164"))
|
80
|
-
calc.
|
80
|
+
calc.compute_utc_nautical_sunrise.should eql(nil)
|
81
81
|
end
|
82
82
|
|
83
83
|
it "returns correct time" do
|
84
84
|
date = Date.parse('2008-04-25') #25 April 2008
|
85
85
|
calc = SolarEventCalculator.new(date, BigDecimal.new("64.8378"), BigDecimal.new("-147.7164"))
|
86
|
-
calc.
|
86
|
+
calc.compute_utc_nautical_sunrise.should eql(nil)
|
87
87
|
end
|
88
88
|
end
|
89
|
-
|
data/test/sunsettest.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require '../lib/solareventcalculator'
|
2
2
|
|
3
3
|
describe SolarEventCalculator, "Test the sunset algorithm" do
|
4
4
|
|
@@ -8,11 +8,11 @@ describe SolarEventCalculator, "Test the sunset algorithm" do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "returns correct longitude hour" do
|
11
|
-
@calc.
|
11
|
+
@calc.compute_lnghour.should eql(BigDecimal.new("-5.0523"))
|
12
12
|
end
|
13
13
|
|
14
14
|
it "returns correct longitude hour" do
|
15
|
-
@calc.
|
15
|
+
@calc.compute_longitude_hour(false).should eql(BigDecimal.new("306.9605"))
|
16
16
|
end
|
17
17
|
|
18
18
|
it "returns correct sunset mean anomaly" do
|
@@ -44,7 +44,7 @@ describe SolarEventCalculator, "Test the sunset algorithm" do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "returns correct sunset local hour angle" do
|
47
|
-
@calc.
|
47
|
+
@calc.compute_local_hour_angle(BigDecimal.new("0.0815"), false).should eql(BigDecimal.new("5.6883"))
|
48
48
|
end
|
49
49
|
|
50
50
|
it "returns correct sunset local mean time" do
|
@@ -56,19 +56,19 @@ describe SolarEventCalculator, "Test the sunset algorithm" do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it "returns correct civil sunset time" do
|
59
|
-
@calc.
|
59
|
+
@calc.compute_utc_civil_sunset.should eql(Time.gm(@date.year, @date.mon, @date.mday, 22, 28))
|
60
60
|
end
|
61
61
|
|
62
62
|
it "returns correct official sunset time" do
|
63
|
-
@calc.
|
63
|
+
@calc.compute_utc_official_sunset.should eql(Time.gm(@date.year, @date.mon, @date.mday, 21, 59))
|
64
64
|
end
|
65
65
|
|
66
66
|
it "returns correct nautical sunset time" do
|
67
|
-
@calc.
|
67
|
+
@calc.compute_utc_nautical_sunset.should eql(Time.gm(@date.year, @date.mon, @date.mday, 23, 0))
|
68
68
|
end
|
69
69
|
|
70
70
|
it "returns correct astronomical sunset time" do
|
71
|
-
@calc.
|
71
|
+
@calc.compute_utc_astronomical_sunset.should eql(Time.gm(@date.year, @date.mon, @date.mday, 23, 31))
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -77,13 +77,12 @@ describe SolarEventCalculator, "test the math for areas where the sun doesn't se
|
|
77
77
|
it "returns correct time" do
|
78
78
|
date = Date.parse('2008-04-25') #25 April 2008
|
79
79
|
calc = SolarEventCalculator.new(date, BigDecimal.new("64.8378"), BigDecimal.new("-147.7164"))
|
80
|
-
calc.
|
80
|
+
calc.compute_utc_nautical_sunset.should eql(nil)
|
81
81
|
end
|
82
82
|
|
83
83
|
it "returns correct time" do
|
84
84
|
date = Date.parse('2008-04-25') #25 April 2008
|
85
85
|
calc = SolarEventCalculator.new(date, BigDecimal.new("64.8378"), BigDecimal.new("-147.7164"))
|
86
|
-
calc.
|
86
|
+
calc.compute_utc_nautical_sunset.should eql(nil)
|
87
87
|
end
|
88
88
|
end
|
89
|
-
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mike Reedell / LuckyCatLabs
|
@@ -28,7 +28,7 @@ extra_rdoc_files: []
|
|
28
28
|
|
29
29
|
files:
|
30
30
|
- rubysunrise.gemspec
|
31
|
-
- lib/
|
31
|
+
- lib/solareventcalculator.rb
|
32
32
|
has_rdoc: true
|
33
33
|
homepage: http://www.luckycatlabs.com
|
34
34
|
licenses: []
|