british_suntimes 0.1.1 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 38a8f6343d904803f701d10d143f170abb35971e
4
- data.tar.gz: 3a9a693a25d25a83d320d8170040ee8135df2708
2
+ SHA256:
3
+ metadata.gz: 1216b26e7c62951c228d8cfa7f3fd731d53b08cad84802da98135541cc5e3f30
4
+ data.tar.gz: cfce6f3a0054424bca50e8a28c2e1c55ed9d25b77e190f3c16791c6a85a9bbe9
5
5
  SHA512:
6
- metadata.gz: ee040b326c73ca799e8afdad5e48ccb964ca0395d2c37e40616a803bc0efe5df2b4d86fd0cdd2436734b6c81fc3632674abff132718e09ffee60352228472c1a
7
- data.tar.gz: 3eae29293490f39a9fa195ac2569c12170b061f6c92d70343151b71a962532f81e292bbffb482cb4603011c087bdc59b71a9e9dd3be2e2872b8aba75d5ba09e6
6
+ metadata.gz: c71b48736907a9a093043573ff6dec821db92775b95681ce3098a31b38d19406ac8ae25912e3e647d97b183dd21cf82fbffee8dcee5f6c1fcfd33ac52b600678
7
+ data.tar.gz: 0b11a55f64a5b059af12711a10827d2a43a03efea137c8fa695760baace1c3e00395a320f519ed67ece3ceab9eea6f360aebfe8e4628d75fef9a076a0b6524df
checksums.yaml.gz.sig CHANGED
Binary file
@@ -3,22 +3,30 @@
3
3
  # file: british_suntimes.rb
4
4
 
5
5
 
6
+ require 'dynarex'
6
7
  require 'geocoder'
7
8
  require 'chronic_cron'
8
9
  require 'solareventcalculator'
9
10
 
11
+ require 'subunit'
12
+ require 'human_speakable'
13
+
10
14
 
11
15
 
12
16
  class BritishSuntimes
13
17
 
14
- attr_reader :to_h, :bst_start, :bst_end
18
+ attr_reader :to_h, :bst_start, :bst_end, :to_dx, :longest_day, :shortest_day
19
+
15
20
 
21
+ def initialize(year=Date.today.year.to_s, location: 'edinburgh',
22
+ debug: false)
16
23
 
17
- def initialize(year= Date.today.year.to_s, location: 'edinburgh')
24
+ @location, @debug = location, debug
18
25
 
19
26
  a = (Date.parse(year + ' Jan')...Date.parse(year.succ + ' Jan')).to_a
20
27
  g = Geocoder.search(location)
21
28
 
29
+ puts 'finding the times ...' if @debug
22
30
  times = a.inject({}) do |r, date|
23
31
 
24
32
  calc = SolarEventCalculator.new(date, *g[0].coordinates)
@@ -33,20 +41,82 @@ class BritishSuntimes
33
41
 
34
42
  # alter the times for British summertime
35
43
 
36
- d1 = ChronicCron.new('last sunday in March at 1am',
44
+ @bst_start = ChronicCron.new('last sunday in March at 1am',
37
45
  Time.local(year)).to_date
38
- d2 = ChronicCron.new('last sunday in October at 2am',
46
+ @bst_end = ChronicCron.new('last sunday in October at 2am',
39
47
  Time.local(year)).to_date
40
48
 
41
- @bst_start, @bst_end = d1, d2
42
49
 
43
- (d1...d2).to_a.each do |d|
50
+ (@bst_start...@bst_end).to_a.each do |d|
44
51
  t1, t2 = times[d.strftime("%d %b")].map {|x| Time.parse(x)}
45
52
  t1 += 60 * 60; t2 += 60 * 60
46
53
  times[d.strftime("%d %b")] = [t1.strftime("%H:%M"), t2.strftime("%H:%M")]
47
54
  end
48
55
 
49
- @to_h = times
56
+ @year, @location, @to_h = year, location, times
57
+ puts 'buklding @to_dx' if @debug
58
+ @to_dx = build_dx()
59
+
60
+ end
61
+
62
+ # exports the sun times to a raw Dynarex file
63
+ #
64
+ def export(filename=@location + "-suntimes-#{@year}.txt")
65
+ File.write filename, @to_dx.to_s
66
+ end
67
+
68
+ private
69
+
70
+ def build_dx()
71
+
72
+ dx = Dynarex.new 'times[title, tags, desc, bst_start, ' +
73
+ 'bst_end, longest_day, shortest_day]/day(date, sunrise, sunset)'
74
+ dx.title = @location + " sunrise sunset times " + @year
75
+ dx.tags = @location + " times sunrise sunset %s" % [@year]
76
+ dx.delimiter = ' # '
77
+ dx.bst_start, dx.bst_end = @bst_start.to_s, @bst_end.to_s
78
+ dx.desc = 'Adjusted for British summertime'
79
+
80
+ @to_h.each {|k,v| dx.create({date: k, sunrise: v[0], sunset: v[1]}) }
81
+
82
+ a = dx.all.map do |x|
83
+ Time.parse(x.date + ' ' + x.sunset) - Time.parse(x.date + ' ' + x.sunrise)
84
+ end
85
+
86
+ shortest, longest = a.minmax.map {|x| dx.all[a.index(x)]}
87
+ @longest_day = dx.longest_day = longest.date
88
+ @shortest_day = dx.shortest_day = shortest.date
89
+
90
+ dx
91
+ end
92
+
93
+ end
94
+
95
+ class BritishSuntimesAgent < BritishSuntimes
96
+ using HumanSpeakable
97
+ using Ordinals
98
+
99
+
100
+ def longest_day()
101
+
102
+ d = super()
103
+ days = (Date.parse(d) - Date.today).to_i
104
+ sunrise, sunset = to_dx().to_h[d]
105
+
106
+ t1 = Time.parse(d + ' ' + sunrise)
107
+ t2 = Time.parse(d + ' ' + sunset)
108
+
109
+ su = Subunit.new(units={minutes:60, hours:60}, seconds: (t2 - t1).to_i)
110
+ duration = su.to_s omit: [:seconds]
111
+
112
+ d2 = Date.parse(d)
113
+ day = d2.strftime("#{d2.day.ordinal} %B")
114
+
115
+ s = d2.humanize
116
+ msg = s[0].upcase + s[1..-1] + ", the longest day of the year, #%s \
117
+ will enjoy %s of sunshine. The sun will rise at %sam \
118
+ and set at %spm." % [@location, duration, t1.strftime("%-I:%M"), \
119
+ t2.strftime("%-I:%M")]
50
120
 
51
121
  end
52
122
 
data.tar.gz.sig CHANGED
@@ -1,2 +1 @@
1
- l ����s��1˪xNca�'�+Nnes��d'���Q���=��(oEB����f=v9���B�%}LTz$�S�b-����ґ��%�/���T� G��vû��Ɯ3���:�H��wİ��B4��
2
- �3�ͬ����4@���'��qK�u׈��0|��1;�2:Fc�*RkF�>���~tO�����&�>�b�K���,��V��u���+�����ӆ#�weQ|���a ����V;�x
1
+ �%����DX�z?�mM�Q�V� �B�Z@�Y��)��9����q���l�f����/���s�e�k�}���&Sw�C�!5�y�d��7iQ!����VyA'����(JB�G����F���ǔ��%w�Q.��Z��El8� �AW�D��hoJ���ls��{�|-���=��ʼ��/�F�Rd({���ro$y�Ҩ(�\I��]�z�=�XHخ�Tp}9��޴�{T�ZJ%n�� ��]�\��Z�@�)}*xB���h� c
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: british_suntimes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,68 +10,93 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDXjCCAkagAwIBAgIBATANBgkqhkiG9w0BAQUFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTgwMzA4MjMyMjA5WhcN
15
- MTkwMzA4MjMyMjA5WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCiAALr
17
- RUV3gWaErxprpgvbKvK0BXBDbt7bg2g6yT4k7VmZLg3jSxIcYw4kg5OUQou+Rawo
18
- geosw2OlYPwhWk/Mi6BSUOk8oxPplPBjSiFeAVPllcl+c/wDVPBOw5UIyAORRtqO
19
- /jPjpOSU/rWsI29+TlyW3xJyrygZQq7Qt6FyxNn0d4JNi5muCfhDeW0eoYA7SP2p
20
- U8HH/wNn2ywYALtsLBGAVsgPvklyjJPVWiRSyIvvsjzbw7A5FShZyzHjks5vYesi
21
- 81j3L+nXsKdUxAJvTsF7pla3R38S77Ofzpu0e+/oLe9YcsyfJ8mEMHaQ8ZQpwT/d
22
- XYVXASZE0nF0MV+/AgMBAAGjgYowgYcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw
23
- HQYDVR0OBBYEFJswy1odtxLSCTl/h63FVI/I+bZHMCYGA1Ud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IFICATE-----
33
- date: 2018-03-09 00:00:00.000000000 Z
38
+ date: 2022-02-07 00:00:00.000000000 Z
34
39
  dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: dynarex
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.9'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 1.9.2
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '1.9'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 1.9.2
35
60
  - !ruby/object:Gem::Dependency
36
61
  name: geocoder
37
62
  requirement: !ruby/object:Gem::Requirement
38
63
  requirements:
39
64
  - - "~>"
40
65
  - !ruby/object:Gem::Version
41
- version: '1.4'
66
+ version: '1.7'
42
67
  - - ">="
43
68
  - !ruby/object:Gem::Version
44
- version: 1.4.6
69
+ version: 1.7.3
45
70
  type: :runtime
46
71
  prerelease: false
47
72
  version_requirements: !ruby/object:Gem::Requirement
48
73
  requirements:
49
74
  - - "~>"
50
75
  - !ruby/object:Gem::Version
51
- version: '1.4'
76
+ version: '1.7'
52
77
  - - ">="
53
78
  - !ruby/object:Gem::Version
54
- version: 1.4.6
79
+ version: 1.7.3
55
80
  - !ruby/object:Gem::Dependency
56
81
  name: chronic_cron
57
82
  requirement: !ruby/object:Gem::Requirement
58
83
  requirements:
59
84
  - - "~>"
60
85
  - !ruby/object:Gem::Version
61
- version: '0.3'
86
+ version: '0.7'
62
87
  - - ">="
63
88
  - !ruby/object:Gem::Version
64
- version: 0.3.7
89
+ version: 0.7.1
65
90
  type: :runtime
66
91
  prerelease: false
67
92
  version_requirements: !ruby/object:Gem::Requirement
68
93
  requirements:
69
94
  - - "~>"
70
95
  - !ruby/object:Gem::Version
71
- version: '0.3'
96
+ version: '0.7'
72
97
  - - ">="
73
98
  - !ruby/object:Gem::Version
74
- version: 0.3.7
99
+ version: 0.7.1
75
100
  - !ruby/object:Gem::Dependency
76
101
  name: RubySunrise
77
102
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +106,7 @@ dependencies:
81
106
  version: '0.3'
82
107
  - - ">="
83
108
  - !ruby/object:Gem::Version
84
- version: 0.3.1
109
+ version: 0.3.3
85
110
  type: :runtime
86
111
  prerelease: false
87
112
  version_requirements: !ruby/object:Gem::Requirement
@@ -91,9 +116,49 @@ dependencies:
91
116
  version: '0.3'
92
117
  - - ">="
93
118
  - !ruby/object:Gem::Version
94
- version: 0.3.1
119
+ version: 0.3.3
120
+ - !ruby/object:Gem::Dependency
121
+ name: subunit
122
+ requirement: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: '0.8'
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: 0.8.5
130
+ type: :runtime
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '0.8'
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: 0.8.5
140
+ - !ruby/object:Gem::Dependency
141
+ name: human_speakable
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: 0.2.0
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '0.2'
150
+ type: :runtime
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: 0.2.0
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.2'
95
160
  description:
96
- email: james@jamesrobertson.eu
161
+ email: digital.robertson@gmail.com
97
162
  executables: []
98
163
  extensions: []
99
164
  extra_rdoc_files: []
@@ -119,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
184
  version: '0'
120
185
  requirements: []
121
186
  rubyforge_project:
122
- rubygems_version: 2.6.13
187
+ rubygems_version: 2.7.10
123
188
  signing_key:
124
189
  specification_version: 4
125
190
  summary: Generates the British sunrise and sunset times.
metadata.gz.sig CHANGED
Binary file