tranzito_utils 1.2.1 → 1.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91051949d5689eb724426c9dc4c233f2b6f71eb0d411d63ca0037676b8338cea
4
- data.tar.gz: 9380a70b1a4e798be1ee05d4b183d03f939abc194d0ea0e1d536fd7efe2bf851
3
+ metadata.gz: 2e21a51b8176d00af57ccad00580020c4734331290167b89151126a9a5f86ff9
4
+ data.tar.gz: b9ac19e2a024ff05c5bc9e4fb4e4840553238b5255aee85ef88b820031072f79
5
5
  SHA512:
6
- metadata.gz: a618433b4284b261862e73f4bde3ef116012f1dfb2cbc415837027f4c07abb4569b92de1d75dec6fc678d6f0244c0d467c1044bcdde524e674ee0ea2268e5d53
7
- data.tar.gz: e2e8649aeadce46d8885a3d401021694a7eaae01ffe418ef0358b450f45c423789a59446e4cf16e5d06e764eb8cba8d4bea93d154f934137443bcf4d5881e70f
6
+ metadata.gz: c2977b2f4c56eeb4449d01e9911bbe70907e0a58071973e610826be3fa233a751ebdc4b37193f4301ee95bc2a73c17c87b219bf6c13c0dff49b749ff8d4d9cca
7
+ data.tar.gz: baffd85526162bfd191afc173aa62f128adbcc854f814abe51482b5b77eed02615cdb7ead17d07d127c49f66e233b37354af7733d7729b7a3cd01d02fdbe68af
@@ -3,6 +3,7 @@
3
3
  - count ||= defined?(collection.total_count) ? collection.total_count : collection.count
4
4
  - skip_total ||= false
5
5
  - skip_pagination ||= false
6
+ - paginate_params ||= {}
6
7
  -# override added to convert Created to Imported - for clarity in payroll_times
7
8
  - humanized_time_range_column_override ||= nil
8
9
 
@@ -25,7 +26,7 @@
25
26
  = humanized_time_range(@time_range)
26
27
  - unless skip_pagination
27
28
  .pagination-flex.justify-content-md-end{class: (skip_total ? "col-12" : "col-md-7")}
28
- = paginate collection, outer_window: 1
29
+ = paginate collection, outer_window: 1, params: paginate_params
29
30
  - if count > @per_page.to_i
30
31
  - per_pages = [10, 25, 50, 100, @per_page.to_i].uniq.sort
31
32
  = select_tag :per_page_select, options_for_select(per_pages.map { |i| ["#{i} / page", i] }, selected: @per_page), { class: "form-control per-page-select" }
@@ -29,7 +29,7 @@ module TranzitoUtils
29
29
  end
30
30
 
31
31
  def sortable_search_params
32
- search_param_keys = params.keys.select { |k| k.to_s.start_with?(/search_/) }
32
+ search_param_keys = params.keys.select { |k| k.to_s.start_with?("search_") }
33
33
  params.permit(*(DEFAULT_SEARCH_KEYS | TranzitoUtils::DEFAULT[:additional_search_keys] | search_param_keys))
34
34
  end
35
35
 
@@ -0,0 +1,85 @@
1
+ class SolarPositionCalculator
2
+ LATITUDE_RANGE = (-90..90)
3
+ LONGITUDE_RANGE = (-180..180)
4
+
5
+ attr_reader :latitude, :longitude, :timezone
6
+
7
+ def initialize(latitude, longitude, timezone)
8
+ validate_latitude(latitude)
9
+ validate_longitude(longitude)
10
+ @latitude = latitude
11
+ @longitude = longitude
12
+ @timezone = timezone
13
+ end
14
+
15
+ def sunrise_time(date)
16
+ calculate_sun_time(date, :sunrise)
17
+ end
18
+
19
+ def sunset_time(date)
20
+ calculate_sun_time(date, :sunset)
21
+ end
22
+
23
+ private
24
+
25
+ def calculate_sun_time(date, type)
26
+ validate_date(date)
27
+ utc_time = calculate_utc_time(date, type)
28
+ utc_to_timezone(date, utc_time)
29
+ end
30
+
31
+ def calculate_utc_time(date, type)
32
+ time = Time.new(date.year, date.month, date.day, 12, 0, 0, timezone)
33
+ gamma = calculate_gamma(time)
34
+ eqtime = calculate_eqtime(gamma)
35
+
36
+ decl = calculate_decl(gamma)
37
+ ha = calculate_ha(decl)
38
+ calculate_sun_time_utc(ha, eqtime, type)
39
+ end
40
+
41
+ def calculate_sun_time_utc(ha, eqtime, type)
42
+ if type == :sunrise
43
+ 720 - 4 * (longitude + ha * 180 / Math::PI) - eqtime
44
+ else
45
+ 720 - 4 * (longitude - ha * 180 / Math::PI) - eqtime
46
+ end
47
+ end
48
+
49
+ def calculate_gamma(time)
50
+ 2 * Math::PI / (leap_year?(time.year) ? 366 : 365) * (time.yday - 1 + (time.hour - 12) / 24.0)
51
+ end
52
+
53
+ def calculate_eqtime(gamma)
54
+ 229.18 * (0.000075 + 0.001868 * Math.cos(gamma) - 0.032077 * Math.sin(gamma) - 0.014615 * Math.cos(2 * gamma) - 0.040849 * Math.sin(2 * gamma))
55
+ end
56
+
57
+ def calculate_decl(gamma)
58
+ 0.006918 - 0.399912 * Math.cos(gamma) + 0.070257 * Math.sin(gamma) - 0.006758 * Math.cos(2 * gamma) + 0.000907 * Math.sin(2 * gamma) - 0.002697 * Math.cos(3 * gamma) + 0.00148 * Math.sin(3 * gamma)
59
+ end
60
+
61
+ def calculate_ha(decl)
62
+ Math.acos(Math.cos(Math::PI / 180 * 90.833) / (Math.cos(Math::PI / 180 * latitude) * Math.cos(decl)) - Math.tan(Math::PI / 180 * latitude) * Math.tan(decl))
63
+ end
64
+
65
+ def utc_to_timezone(date, utc_time)
66
+ response = Time.parse("#{date} #{Time.at(utc_time * 60).utc.strftime("%H:%M:%S")}") + timezone * 3600
67
+ response.strftime("%H:%M:%S")
68
+ end
69
+
70
+ def leap_year?(year)
71
+ year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)
72
+ end
73
+
74
+ def validate_latitude(latitude)
75
+ raise ArgumentError, "Latitude should be between -90 and 90 degrees" unless LATITUDE_RANGE.include?(latitude)
76
+ end
77
+
78
+ def validate_longitude(longitude)
79
+ raise ArgumentError, "Longitude should be between -180 and 180 degrees" unless LONGITUDE_RANGE.include?(longitude)
80
+ end
81
+
82
+ def validate_date(date)
83
+ raise ArgumentError, "Invalid date" unless date.is_a?(Date)
84
+ end
85
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TranzitoUtils
4
- VERSION = "1.2.1"
4
+ VERSION = "1.3.1"
5
5
  end
@@ -21,4 +21,5 @@ require "tranzito_utils/helpers/sortable_helper"
21
21
  require "tranzito_utils/helpers/helpers"
22
22
  require "tranzito_utils/services/time_parser"
23
23
  require "tranzito_utils/services/normalize"
24
+ require "tranzito_utils/services/solar_position_calculator"
24
25
  require "tranzito_utils/gem"
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tranzito_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - willbarrettdev
8
8
  - sethherr
9
9
  - hafiz-ahmed
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-03-07 00:00:00.000000000 Z
13
+ date: 2024-03-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -112,6 +112,7 @@ files:
112
112
  - lib/tranzito_utils/helpers/helpers.rb
113
113
  - lib/tranzito_utils/helpers/sortable_helper.rb
114
114
  - lib/tranzito_utils/services/normalize.rb
115
+ - lib/tranzito_utils/services/solar_position_calculator.rb
115
116
  - lib/tranzito_utils/services/time_parser.rb
116
117
  - lib/tranzito_utils/version.rb
117
118
  homepage: https://github.com/Tranzito/tranzito_utils
@@ -120,7 +121,7 @@ licenses:
120
121
  metadata:
121
122
  homepage_uri: https://github.com/Tranzito/tranzito_utils
122
123
  source_code_uri: https://github.com/Tranzito/tranzito_utils
123
- post_install_message:
124
+ post_install_message:
124
125
  rdoc_options: []
125
126
  require_paths:
126
127
  - lib
@@ -135,8 +136,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
136
  - !ruby/object:Gem::Version
136
137
  version: '0'
137
138
  requirements: []
138
- rubygems_version: 3.1.2
139
- signing_key:
139
+ rubygems_version: 3.3.26
140
+ signing_key:
140
141
  specification_version: 4
141
142
  summary: Ruby gem contain several modules mainly containing the helpers, concerns
142
143
  and services for personal use by Tranzito