zakuro 0.1.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/doc/gengou.md +22 -22
  3. data/doc/operation/csv/month.csv +447 -202
  4. data/doc/operation/operation.xlsx +0 -0
  5. data/lib/zakuro/calculation/base/operated_year.rb +114 -0
  6. data/lib/zakuro/calculation/base/year.rb +3 -0
  7. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +44 -19
  8. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +169 -0
  9. data/lib/zakuro/calculation/monthly/first_day.rb +1 -1
  10. data/lib/zakuro/calculation/monthly/operated_month.rb +47 -3
  11. data/lib/zakuro/calculation/range/full_range.rb +1 -1
  12. data/lib/zakuro/calculation/range/medieval_annual_range.rb +105 -0
  13. data/lib/zakuro/calculation/range/operated_range.rb +61 -16
  14. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +78 -0
  15. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +71 -0
  16. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +117 -0
  17. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +187 -0
  18. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +136 -0
  19. data/lib/zakuro/calculation/type/old_float.rb +69 -0
  20. data/lib/zakuro/era/japan/reki.rb +1 -1
  21. data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +22 -22
  22. data/lib/zakuro/operation/month/type.rb +58 -0
  23. data/lib/zakuro/operation/yaml/month.yaml +7840 -0
  24. data/lib/zakuro/version/context.rb +1 -1
  25. data/lib/zakuro/version/daien/const/number.rb +55 -0
  26. data/lib/zakuro/version/daien/const/remainder.rb +53 -0
  27. data/lib/zakuro/version/daien/cycle/remainder.rb +59 -0
  28. data/lib/zakuro/version/daien/cycle/solar_term.rb +34 -0
  29. data/lib/zakuro/version/daien/daien.rb +36 -0
  30. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +106 -0
  31. data/lib/zakuro/version/daien/range/annual_range.rb +39 -0
  32. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +240 -0
  33. data/lib/zakuro/version/daien/stella/lunar/localization.rb +44 -0
  34. data/lib/zakuro/version/daien/stella/lunar/location.rb +80 -0
  35. data/lib/zakuro/version/daien/stella/lunar/value.rb +75 -0
  36. data/lib/zakuro/version/daien/stella/origin/average_november.rb +34 -0
  37. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +62 -0
  38. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +55 -0
  39. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +93 -0
  40. data/lib/zakuro/version/daien/stella/solar/average.rb +98 -0
  41. data/lib/zakuro/version/daien/stella/solar/interval.rb +108 -0
  42. data/lib/zakuro/version/daien/stella/solar/location.rb +61 -0
  43. data/lib/zakuro/version/daien/stella/solar/value.rb +36 -0
  44. data/lib/zakuro/version/gihou/const/number.rb +55 -0
  45. data/lib/zakuro/version/gihou/const/remainder.rb +54 -0
  46. data/lib/zakuro/version/gihou/cycle/remainder.rb +56 -0
  47. data/lib/zakuro/version/gihou/cycle/solar_term.rb +34 -0
  48. data/lib/zakuro/version/gihou/gihou.rb +23 -2
  49. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +106 -0
  50. data/lib/zakuro/version/gihou/range/annual_range.rb +39 -0
  51. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +250 -0
  52. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +44 -0
  53. data/lib/zakuro/version/gihou/stella/lunar/location.rb +80 -0
  54. data/lib/zakuro/version/gihou/stella/lunar/value.rb +75 -0
  55. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +34 -0
  56. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +62 -0
  57. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +55 -0
  58. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +93 -0
  59. data/lib/zakuro/version/gihou/stella/solar/average.rb +97 -0
  60. data/lib/zakuro/version/gihou/stella/solar/interval.rb +108 -0
  61. data/lib/zakuro/version/gihou/stella/solar/location.rb +61 -0
  62. data/lib/zakuro/version/gihou/stella/solar/value.rb +36 -0
  63. data/lib/zakuro/version/senmyou/const/number.rb +51 -0
  64. data/lib/zakuro/version/senmyou/const/remainder.rb +47 -0
  65. data/lib/zakuro/version/senmyou/cycle/remainder.rb +5 -12
  66. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +4 -1
  67. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +36 -155
  68. data/lib/zakuro/version/senmyou/range/annual_range.rb +7 -135
  69. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +237 -0
  70. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +44 -0
  71. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +87 -0
  72. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +67 -0
  73. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +34 -0
  74. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +62 -0
  75. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +55 -0
  76. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +93 -0
  77. data/lib/zakuro/version/senmyou/stella/solar/average.rb +97 -0
  78. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +103 -0
  79. data/lib/zakuro/version/senmyou/stella/solar/location.rb +61 -0
  80. data/lib/zakuro/version/senmyou/stella/solar/value.rb +39 -0
  81. data/lib/zakuro/version/version_class_resolver.rb +8 -0
  82. data/lib/zakuro/version.rb +1 -1
  83. data/lib/zakuro/version_factory.rb +1 -1
  84. metadata +62 -8
  85. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +0 -332
  86. data/lib/zakuro/version/senmyou/stella/solar_average.rb +0 -169
  87. data/lib/zakuro/version/senmyou/stella/solar_location.rb +0 -213
  88. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +0 -213
  89. data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +0 -106
  90. data/lib/zakuro/version/taien/taien.rb +0 -19
@@ -1,213 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # :nodoc:
4
- module Zakuro
5
- # :nodoc:
6
- module Senmyou
7
- #
8
- # SolarLocation 入定気演算
9
- #
10
- # 入定気とは、太陽がどの二十四節気に属するか、またその二十四節気の開始点からどれだけ離れているかを示す
11
- #
12
- module SolarLocation
13
- #
14
- # Interval 入気定日加減数(二十四節気の間隔)
15
- #
16
- module Interval
17
- # @return [Hash<Symbol, Remainder>] 一覧
18
- LIST = {
19
- # 冬至(とうじ)・大雪(たいせつ)
20
- touji: Cycle::Remainder.new(day: 14, minute: 4235, second: 5),
21
- taisetsu: Cycle::Remainder.new(day: 14, minute: 4235, second: 5),
22
- # 小寒(しょうかん)・小雪(しょうせつ)
23
- shoukan: Cycle::Remainder.new(day: 14, minute: 5235, second: 5),
24
- shousetsu: Cycle::Remainder.new(day: 14, minute: 5235, second: 5),
25
- # 大寒(だいかん)・立冬(りっとう)
26
- daikan: Cycle::Remainder.new(day: 14, minute: 6235, second: 5),
27
- rittou: Cycle::Remainder.new(day: 14, minute: 6235, second: 5),
28
- # 立春(りっしゅん)・霜降(そうこう)
29
- risshun: Cycle::Remainder.new(day: 14, minute: 7235, second: 5),
30
- soukou: Cycle::Remainder.new(day: 14, minute: 7235, second: 5),
31
- # 雨水(うすい)・寒露(かんろ)
32
- usui: Cycle::Remainder.new(day: 15, minute: 35, second: 5),
33
- kanro: Cycle::Remainder.new(day: 15, minute: 35, second: 5),
34
- # 啓蟄(けいちつ)・秋分(しゅうぶん)
35
- keichitsu: Cycle::Remainder.new(day: 15, minute: 1235, second: 5),
36
- shuubun: Cycle::Remainder.new(day: 15, minute: 1235, second: 5),
37
- # 春分(しゅんぶん)・白露(はくろ)
38
- shunbun: Cycle::Remainder.new(day: 15, minute: 2435, second: 5),
39
- hakuro: Cycle::Remainder.new(day: 15, minute: 2435, second: 5),
40
- # 清明(せいめい)・処暑(しょしょ)
41
- seimei: Cycle::Remainder.new(day: 15, minute: 3635, second: 5),
42
- shosho: Cycle::Remainder.new(day: 15, minute: 3635, second: 5),
43
- # 穀雨(こくう)・立秋(りっしゅう)
44
- kokuu: Cycle::Remainder.new(day: 15, minute: 4835, second: 5),
45
- risshuu: Cycle::Remainder.new(day: 15, minute: 4835, second: 5),
46
- # 立夏(りっか)・大暑(たいしょ)
47
- rikka: Cycle::Remainder.new(day: 15, minute: 5835, second: 5),
48
- taisho: Cycle::Remainder.new(day: 15, minute: 5835, second: 5),
49
- # 小満(しょうまん)・小暑(しょうしょ)
50
- shouman: Cycle::Remainder.new(day: 15, minute: 6835, second: 5),
51
- shousho: Cycle::Remainder.new(day: 15, minute: 6835, second: 5),
52
- # 芒種(ぼうしゅ)・夏至(げし)
53
- boushu: Cycle::Remainder.new(day: 15, minute: 7835, second: 5),
54
- geshi: Cycle::Remainder.new(day: 15, minute: 7835, second: 5)
55
- }.freeze
56
-
57
- # @return [Array<Remainder>] 索引
58
- INDEXES = [
59
- LIST[:touji], # 0
60
- LIST[:shoukan], # 1
61
- LIST[:daikan], # 2
62
- LIST[:risshun], # 3
63
- LIST[:usui], # 4
64
- LIST[:keichitsu], # 5
65
- LIST[:shunbun], # 6
66
- LIST[:seimei], # 7
67
- LIST[:kokuu], # 8
68
- LIST[:rikka], # 9
69
- LIST[:shouman], # 10
70
- LIST[:boushu], # 11
71
- LIST[:geshi], # 12
72
- LIST[:shousho], # 13
73
- LIST[:taisho], # 14
74
- LIST[:risshuu], # 15
75
- LIST[:shosho], # 16
76
- LIST[:hakuro], # 17
77
- LIST[:shuubun], # 18
78
- LIST[:kanro], # 19
79
- LIST[:soukou], # 20
80
- LIST[:rittou], # 21
81
- LIST[:shousetsu], # 22
82
- LIST[:taisetsu] # 23
83
- ].freeze
84
- end
85
-
86
- #
87
- # 入定気を計算する
88
- #
89
- # * 定気(index)の指定がない場合は、11月の入定気を求める
90
- # * 定気(index)の指定がある場合は、大余小余から適切な入定気を再計算する
91
- #
92
- # @param [SolarTerm] solar_term 入定気
93
- #
94
- # @return [SolarTerm] 入定気
95
- #
96
- def self.get(solar_term:)
97
- if solar_term.invalid?
98
- return calc_first_solar_term(
99
- winter_solstice_age: solar_term.remainder
100
- )
101
- end
102
-
103
- calc_next_solar_term_recursively(
104
- solar_term: solar_term
105
- )
106
- end
107
-
108
- # :reek:TooManyStatements { max_statements: 7 }
109
-
110
- #
111
- # 入定気(定気の開始点からの日時)と属する定気を計算する
112
- #
113
- # @param [Remainder] winter_solstice_age 天正冬至
114
- #
115
- # @return [SolarTerm] 二十四節気
116
- # SolarTerm.remainder : 入定気(定気の開始点からの日時)
117
- # SolarTerm.index : 定気
118
- #
119
- def self.calc_first_solar_term(winter_solstice_age:)
120
- # 入定気の起算方法
121
- # 概要:
122
- # * 太陽の運行による補正値は、二十四節気の気ごとに定められる
123
- # * 11月経朔の前にある気を求め、それから11月経朔との間隔を求める
124
- # * 気ごとの補正値と、気から11月経朔までにかかる補正値を求める
125
- # 前提:
126
- # * 11月経朔に関わる二十四節気は、時系列から順に、小雪・大雪・冬至である
127
- # * 小雪〜大雪の間隔は小雪定数で、大雪〜冬至の間隔は大雪定数で決められている(24気損益眺朒(ちょうじく)数のこと)
128
- # * 11月経朔は、この小雪〜冬至の間のいずれかにある
129
- # 計算:
130
- # 2パターンある
131
- # (a) 大雪〜冬至にある場合
132
- # *「大雪定数 >= 天正閏余」の場合を指す
133
- # * * NOTE 資料では「より大きい(>)」とされるが、大雪そのものの場合は大雪から起算すべき
134
- # * この場合は、大雪〜経朔の間隔を求める
135
- # (b) 小雪〜大雪にある場合
136
- # *「大雪定数 < 天正閏余」の場合を指す
137
- # * この場合は、小雪〜経朔の間隔を求める
138
-
139
- # NOTE: 上記パターンとは別に、稀だが立冬のパターンも存在する
140
- # この場合は比較方法はそのままに立冬〜経朔の間隔を求める
141
-
142
- rest = winter_solstice_age.clone
143
- # 大雪(23)/小雪(22)/立冬(21)
144
- [23, 22, 21].each do |index|
145
- solar_term = prev_solar_term(winter_solstice_age: rest, index: index)
146
-
147
- if solar_term.invalid?
148
- rest = solar_term.remainder
149
- next
150
- end
151
-
152
- return solar_term
153
- end
154
-
155
- # 立冬(21)を超える天正閏余は成立し得ない(1朔望月をはるかに超えることになる)
156
- raise ArgumentError.new, 'invalid winster solstice age'
157
- end
158
- private_class_method :calc_first_solar_term
159
-
160
- #
161
- # 入気定日加減数で入定気を遡る
162
- #
163
- # @param [Remainder] winter_solstice_age 天正冬至
164
- # @param [Integer] index 二十四節気の連番
165
- #
166
- # @return [SolarTerm] 二十四節気
167
- # SolarTerm.remainder : 入定気(定気の開始点からの日時)
168
- # SolarTerm.index : 定気(範囲外であれば-1とする)
169
- #
170
- def self.prev_solar_term(winter_solstice_age:, index:)
171
- interval = Interval::INDEXES[index]
172
- if winter_solstice_age > interval
173
- # 入定気が確定しない(さらに前の定気まで遡れる)
174
- return Cycle::SolarTerm.new(
175
- remainder: winter_solstice_age.sub(interval),
176
- index: -1
177
- )
178
- end
179
-
180
- # 入定気が確定する
181
- Cycle::SolarTerm.new(
182
- remainder: interval.sub(winter_solstice_age),
183
- index: index
184
- )
185
- end
186
- private_class_method :prev_solar_term
187
-
188
- # :reek:TooManyStatements { max_statements: 8 }
189
-
190
- #
191
- # 次の二十四節気を計算する
192
- #
193
- # @param [SolarTerm] solar_term 今回の二十四節気
194
- #
195
- # @return [SolarTerm] 次回の二十四節気
196
- #
197
- def self.calc_next_solar_term_recursively(solar_term:)
198
- remainder = solar_term.remainder
199
- index = solar_term.index
200
- interval = Interval::INDEXES[index]
201
- return solar_term if remainder < interval
202
-
203
- remainder.sub!(interval)
204
- index += 1
205
- index = 0 if index >= Interval::INDEXES.size
206
- calc_next_solar_term_recursively(
207
- solar_term: Cycle::SolarTerm.new(remainder: remainder, index: index)
208
- )
209
- end
210
- private_class_method :calc_next_solar_term_recursively
211
- end
212
- end
213
- end
@@ -1,213 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../cycle/solar_term'
4
-
5
- # :nodoc:
6
- module Zakuro
7
- # :nodoc:
8
- module Senmyou
9
- #
10
- # SolarOrbit 太陽軌道
11
- #
12
- module SolarOrbit
13
- # @return [Integer] 統法(1日=8400分)
14
- DAY = 8400
15
-
16
- #
17
- # 24気損益眺朒(ちょうじく)数
18
- #
19
- module Adjustment
20
- #
21
- # Item 24気損益眺朒(ちょうじく)数
22
- #
23
- class Item
24
- # @return [Integer] 眺朒(ちょうじく)積
25
- attr_reader :stack
26
- # @return [Integer] 眺朒(ちょうじく)数
27
- attr_reader :per_term
28
- # @return [Integer] 毎日差
29
- attr_reader :per_day
30
-
31
- #
32
- # 初期化
33
- #
34
- # @param [Integer] stack 眺朒(ちょうじく)積
35
- # @param [Integer] per_term 眺朒(ちょうじく)数
36
- # @param [Integer] per_day 毎日差
37
- #
38
- def initialize(stack:, per_term:, per_day:)
39
- @stack = stack
40
- @per_term = per_term
41
- @per_day = per_day
42
- end
43
-
44
- #
45
- # 文字化
46
- #
47
- # @return [String] 文字
48
- #
49
- def to_s
50
- "stack:#{@stack}, per_term:#{@per_term}, per_day:#{@per_day}"
51
- end
52
- end
53
-
54
- # @return [Array<Item>] 24気損益眺朒(ちょうじく)数
55
- LIST = {
56
- touji: Item.new(stack: 0.0, per_term: +33.4511, per_day: -0.3695), # 冬至(とうじ)
57
- shoukan: Item.new(stack: +449.0, per_term: +28.0389, per_day: -0.3606), # 小寒(しょうかん)
58
- daikan: Item.new(stack: +823.0, per_term: +22.6998, per_day: -0.3519), # 大寒(だいかん)
59
- risshun: Item.new(stack: +1122.0, per_term: +17.8923, per_day: -0.4068), # 立春(りっしゅん)
60
- usui: Item.new(stack: +1346.0, per_term: +11.7966, per_day: -0.3998), # 雨水(うすい)
61
- keichitsu: Item.new(stack: +1481.0, per_term: +5.7986, per_day: -0.3998), # 啓蟄(けいちつ)
62
- shunbun: Item.new(stack: +1526.0, per_term: -0.2433, per_day: -0.3779), # 春分(しゅんぶん)
63
- seimei: Item.new(stack: +1481.0, per_term: -6.1254, per_day: -0.3634), # 清明(せいめい)
64
- kokuu: Item.new(stack: +1346.0, per_term: -12.2048, per_day: -0.2987), # 穀雨(こくう)
65
- rikka: Item.new(stack: +1122.0, per_term: -16.9060, per_day: -0.2919), # 立夏(りっか)
66
- shouman: Item.new(stack: +823.0, per_term: -21.5362, per_day: -0.2854), # 小満(しょうまん)
67
- boushu: Item.new(stack: +449.0, per_term: -26.0498, per_day: -0.2854), # 芒種(ぼうしゅ)
68
- geshi: Item.new(stack: 0.0, per_term: -30.3119, per_day: +0.2854), # 夏至(げし)
69
- shousho: Item.new(stack: -449.0, per_term: -25.8126, per_day: +0.2919), # 小暑(しょうしょ)
70
- taisho: Item.new(stack: -823.0, per_term: -21.2454, per_day: +0.2987), # 大暑(たいしょ)
71
- risshuu: Item.new(stack: -1122.0, per_term: -17.0296, per_day: +0.3634), # 立秋(りっしゅう)
72
- shosho: Item.new(stack: -1346.0, per_term: -11.4744, per_day: +0.3779), # 処暑(しょしょ)
73
- hakuro: Item.new(stack: -1481.0, per_term: -5.6429, per_day: +0.3779), # 白露(はくろ)
74
- shuubun: Item.new(stack: -1526.0, per_term: +0.1432, per_day: +0.3998), # 秋分(しゅうぶん)
75
- kanro: Item.new(stack: -1481.0, per_term: +6.1488, per_day: +0.4068), # 寒露(かんろ)
76
- soukou: Item.new(stack: -1346.0, per_term: +12.6336, per_day: +0.3519), # 霜降(そうこう)
77
- rittou: Item.new(stack: -1122.0, per_term: +17.8043, per_day: +0.3606), # 立冬(りっとう)
78
- shousetsu: Item.new(stack: -823.0, per_term: +23.0590, per_day: +0.3695), # 小雪(しょうせつ)
79
- taisetsu: Item.new(stack: -449.0, per_term: +28.4618, per_day: +0.3695) # 大雪(たいせつ)
80
- }.freeze
81
- end
82
-
83
- #
84
- # 太陽の運行による補正値を算出する
85
- #
86
- # @param [SolarTerm] solar_term 入定気
87
- #
88
- # @return [Integer] 補正値
89
- #
90
- def self.calc_sun_orbit_value(solar_term:)
91
- remainder = solar_term.remainder
92
-
93
- adjustment = specify_solar_term_adjustment(index: solar_term.index)
94
- # 損益率/眺朒(ちょうじく)数
95
- # パラメータ:
96
- # a: 眺朒(ちょうじく)数の初日の値
97
- # b: 損益率初日の値
98
- # c: 損益率の毎日の差
99
- # n: 定気の日から数えた日数
100
-
101
- day_stack = calc_day_stack(remainder: remainder, adjustment: adjustment)
102
-
103
- month_stack = calc_month_stack(stack: adjustment.stack, day: remainder.day,
104
- per_term: adjustment.per_term, per_day:
105
- adjustment.per_day)
106
-
107
- # 冬至であれば眺朒数がプラスになり続けて損益率が「益」で、小雪であればマイナスの眺朒数がプラスされ続けて「損」
108
- month_stack + day_stack
109
- end
110
-
111
- #
112
- # 損益率を求める
113
- #
114
- # @param [Remainder] remainder 入定気
115
- # @param [Adjustment::Item] adjustment 24気損益眺朒(ちょうじく)数
116
- #
117
- # @return [Integer] 損益率
118
- #
119
- def self.calc_day_stack(remainder:, adjustment:)
120
- per_term = adjustment.per_term
121
- per_day = adjustment.per_day
122
- sign, ratio = calc_ratio(day: remainder.day, per_term: per_term, per_day: per_day)
123
-
124
- calc_day_stack_from_ratio(sign: sign, ratio: ratio,
125
- minute: remainder.minute)
126
- end
127
- private_class_method :calc_day_stack
128
-
129
- #
130
- # 24気損益眺朒(ちょうじく)数を特定する
131
- #
132
- # @param [Integer] index 連番(二十四節気)
133
- #
134
- # @return [Adjustment::Item] 24気損益眺朒(ちょうじく)数
135
- #
136
- def self.specify_solar_term_adjustment(index:)
137
- key = Cycle::SolarTerm::ORDER[index]
138
- Adjustment::LIST[key].clone
139
- end
140
- private_class_method :specify_solar_term_adjustment
141
-
142
- # :reek:TooManyStatements { max_statements: 6 }
143
-
144
- #
145
- # 大余に対応する損益率を求める
146
- # 損益率 = b + n * c
147
- #
148
- # @param [Integer] day 大余
149
- # @param [Integer] per_term 眺朒(ちょうじく)数
150
- # @param [Integer] per_day 毎日差
151
- #
152
- # @return [Integer] 正負
153
- # @return [Integer] 大余に対応する損益率
154
- #
155
- def self.calc_ratio(day:, per_term:, per_day:)
156
- ratio = per_term + day * per_day
157
- sign = 1
158
- if ratio.negative?
159
- sign = -1
160
- ratio *= sign
161
- end
162
- # 小数点以下は無視する
163
- ratio = ratio.floor
164
-
165
- [sign, ratio]
166
- end
167
- private_class_method :calc_ratio
168
-
169
- #
170
- # 小余を含めた損益率を求める
171
- #
172
- # @param [Integer] sign 正負(大余に対応する損益率)
173
- # @param [Integer] ratio 大余に対応する損益率
174
- # @param [Integer] minute 小余
175
- #
176
- # @return [Integer] 小余を含めた損益率
177
- #
178
- def self.calc_day_stack_from_ratio(sign:, ratio:, minute:)
179
- minute_stack = ratio * minute
180
- day_stack = (minute_stack / DAY).floor
181
- # 四捨五入
182
- # NOTE 資料では「この余りが4200をこえていれば切り上げる」とあり「>=」とした
183
- # 1612年の7月(慶長17年7月)が境界値4200だが、繰り上げを行なっていたため
184
- day_stack += 1 if minute_stack % DAY >= (DAY / 2)
185
- day_stack *= sign
186
-
187
- day_stack
188
- end
189
- private_class_method :calc_day_stack_from_ratio
190
-
191
- # :reek:LongParameterList { max_params: 4 }
192
-
193
- #
194
- # 眺朒(ちょうじく)数を求める
195
- # 眺朒(ちょうじく)数 = a + (n * b) + (1/2)n(n-1)c
196
- #
197
- # @param [Integer] stack 眺朒(ちょうじく)積
198
- # @param [Integer] day 大余
199
- # @param [Integer] per_term 眺朒(ちょうじく)数
200
- # @param [Integer] per_day 毎日差f
201
- #
202
- # @return [Integer] 眺朒(ちょうじく)数
203
- #
204
- def self.calc_month_stack(stack:, day:, per_term:, per_day:)
205
- month_stack = stack + day * per_term + \
206
- (1 / 2.0) * (day * (day - 1) * per_day)
207
- # 切り捨て(プラスマイナスに関わらず小数点以下切り捨て)
208
- month_stack.negative? ? month_stack.ceil : month_stack.floor
209
- end
210
- private_class_method :calc_month_stack
211
- end
212
- end
213
- end
@@ -1,106 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../../output/logger'
4
-
5
- # :nodoc:
6
- module Zakuro
7
- # :nodoc:
8
- module Senmyou
9
- # :reek:TooManyConstants
10
-
11
- #
12
- # WinterSolstice 冬至
13
- #
14
- module WinterSolstice
15
- # @return [Integer] 統法(1日=8400分)
16
- DAY = 8400
17
- # @return [Integer] 朔望月
18
- SYNODIC_MONTH = 248_057
19
- # @return [Integer] 一年
20
- YEAR = 3_068_055
21
- # @return [Integer] 通余: (YEAR - DAY * 12 * 30) = 44055
22
- REMAINDER_ALL_YEAR = 44_055
23
- # @return [Integer] 旬周(60日) 8400 * 60
24
- SIXTY_DAYS = 504_000
25
- # @return [Integer] 積年(甲子夜半朔旦冬至〜暦の開始前)
26
- TOTAL_YEAR = 7_070_138
27
- # @return [Integer] 暦の開始年(長慶2年)
28
- BEGIN_YEAR = 822
29
-
30
- # @return [Output::Logger] ロガー
31
- LOGGER = Output::Logger.new(location: 'winter_solstice')
32
-
33
- # :reek:TooManyStatements { max_statements: 6 }
34
-
35
- #
36
- # 対象年の前年の冬至を求める
37
- #
38
- # @param [Integer] western_year 西暦年
39
- #
40
- # @return [Remainder] 前年の冬至
41
- #
42
- def self.calc(western_year:)
43
- # 積年の開始から対象年までの年数
44
- total = TOTAL_YEAR + western_year - BEGIN_YEAR
45
- remainder_year = total % SIXTY_DAYS
46
-
47
- LOGGER.debug("[a01]:#{remainder_year}")
48
-
49
- # 通余を使う
50
- winter_solstice_minute = (remainder_year * REMAINDER_ALL_YEAR) % SIXTY_DAYS
51
-
52
- LOGGER.debug("[a02]:#{winter_solstice_minute}")
53
-
54
- Cycle::Remainder.new(total: winter_solstice_minute)
55
- end
56
-
57
- # :reek:TooManyStatements { max_statements: 7 }
58
-
59
- #
60
- # 対象年の天正閏余(冬至より前にある11月経朔との差 = 月齢)を算出する
61
- # 太陽と月の運動による補正値を算出し、その補正結果を返す
62
- #
63
- # @param [Integer] western_year 西暦年
64
- #
65
- # @return [Remainder] 天正閏余
66
- #
67
- def self.calc_moon_age(western_year:)
68
- # 積年の開始から対象年までの年数
69
- total = TOTAL_YEAR + western_year - BEGIN_YEAR
70
-
71
- # 12朔望月に対する1年の余り(単位:分)
72
- remainder_minute = YEAR - (SYNODIC_MONTH * 12)
73
-
74
- # 朔望月に含まれなかった余り(単位:年)
75
- remainder_year = total % SYNODIC_MONTH
76
-
77
- LOGGER.debug("[b01]: #{remainder_year}")
78
-
79
- # 天正閏余
80
- winter_solstice_age = remainder_minute * remainder_year % SYNODIC_MONTH
81
-
82
- LOGGER.debug("[b02]: #{winter_solstice_age}")
83
-
84
- # 大余・小余に変換する
85
- Cycle::Remainder.new(total: winter_solstice_age)
86
- end
87
-
88
- #
89
- # 11月経朔(冬至が含まれる月の1日)を求める
90
- #
91
- # @param [Integer] western_year 西暦年
92
- #
93
- # @return [Remainder] 11月経朔
94
- #
95
- def self.calc_averaged_last_november_1st(western_year:)
96
- # 冬至
97
- winter_solstice = calc(western_year: western_year)
98
- # 天正閏余
99
- winter_solstice_age = calc_moon_age(western_year: western_year)
100
-
101
- # 11月経朔
102
- winter_solstice.sub(winter_solstice_age)
103
- end
104
- end
105
- end
106
- end