zakuro 0.2.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -1
  3. data/VERSION +1 -0
  4. data/doc/gengou.md +22 -22
  5. data/doc/operation/csv/month.csv +468 -202
  6. data/doc/operation/operation.xlsx +0 -0
  7. data/lib/zakuro/calculation/base/gengou.rb +82 -0
  8. data/lib/zakuro/calculation/base/linear_gengou.rb +76 -0
  9. data/lib/zakuro/calculation/base/operated_year.rb +104 -0
  10. data/lib/zakuro/calculation/base/year.rb +28 -13
  11. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +29 -29
  12. data/lib/zakuro/calculation/gengou/internal/counter.rb +129 -0
  13. data/lib/zakuro/calculation/gengou/internal/reserve/interval.rb +183 -0
  14. data/lib/zakuro/calculation/gengou/internal/reserve/list.rb +382 -0
  15. data/lib/zakuro/calculation/gengou/internal/reserve.rb +42 -0
  16. data/lib/zakuro/calculation/gengou/scroll.rb +262 -0
  17. data/lib/zakuro/calculation/monthly/first_day.rb +3 -2
  18. data/lib/zakuro/calculation/monthly/month.rb +49 -2
  19. data/lib/zakuro/calculation/monthly/operated_month.rb +49 -5
  20. data/lib/zakuro/calculation/range/full_range.rb +65 -103
  21. data/lib/zakuro/calculation/range/operated_range.rb +73 -23
  22. data/lib/zakuro/calculation/range/operated_solar_terms.rb +36 -17
  23. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +54 -0
  24. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +25 -21
  25. data/lib/zakuro/calculation/specifier/single_day.rb +13 -35
  26. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +9 -7
  27. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +19 -0
  28. data/lib/zakuro/calculation/summary/single.rb +5 -2
  29. data/lib/zakuro/calculation/version/internal/crawler.rb +51 -0
  30. data/lib/zakuro/calculation/version/internal/range.rb +39 -0
  31. data/lib/zakuro/calculation/version/version.rb +24 -0
  32. data/lib/zakuro/era/japan/calendar.rb +133 -0
  33. data/lib/zakuro/era/japan/gengou/parser.rb +95 -25
  34. data/lib/zakuro/era/japan/gengou/type.rb +148 -41
  35. data/lib/zakuro/era/japan/gengou/validator.rb +157 -52
  36. data/lib/zakuro/era/japan/gengou/yaml/set-001-until-south.yaml +1870 -0
  37. data/lib/zakuro/era/japan/gengou/yaml/set-002-from-north.yaml +810 -0
  38. data/lib/zakuro/era/japan/gengou/yaml/set-003-modern.yaml +50 -0
  39. data/lib/zakuro/era/japan/gengou.rb +5 -5
  40. data/lib/zakuro/era/japan/version.rb +151 -0
  41. data/lib/zakuro/era/{western.rb → western/calendar.rb} +0 -0
  42. data/lib/zakuro/merchant.rb +12 -3
  43. data/lib/zakuro/operation/month/parser.rb +1 -1
  44. data/lib/zakuro/operation/month/type.rb +59 -1
  45. data/lib/zakuro/operation/month/validator.rb +1 -1
  46. data/lib/zakuro/operation/yaml/month.yaml +8512 -0
  47. data/lib/zakuro/output/response.rb +5 -5
  48. data/lib/zakuro/tools/typeconv.rb +38 -0
  49. data/lib/zakuro/tools/typeof.rb +4 -1
  50. data/lib/zakuro/version/context.rb +25 -4
  51. data/lib/zakuro/version/daien/const/number.rb +55 -0
  52. data/lib/zakuro/version/daien/const/remainder.rb +53 -0
  53. data/lib/zakuro/version/daien/cycle/remainder.rb +85 -0
  54. data/lib/zakuro/version/daien/cycle/solar_term.rb +34 -0
  55. data/lib/zakuro/version/daien/daien.rb +11 -0
  56. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +106 -0
  57. data/lib/zakuro/version/daien/range/annual_range.rb +39 -0
  58. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +240 -0
  59. data/lib/zakuro/version/daien/stella/lunar/localization.rb +44 -0
  60. data/lib/zakuro/version/daien/stella/lunar/location.rb +80 -0
  61. data/lib/zakuro/version/daien/stella/lunar/value.rb +75 -0
  62. data/lib/zakuro/version/daien/stella/origin/average_november.rb +34 -0
  63. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +62 -0
  64. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +55 -0
  65. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +93 -0
  66. data/lib/zakuro/version/daien/stella/solar/average.rb +98 -0
  67. data/lib/zakuro/version/daien/stella/solar/interval.rb +108 -0
  68. data/lib/zakuro/version/daien/stella/solar/location.rb +61 -0
  69. data/lib/zakuro/version/daien/stella/solar/value.rb +36 -0
  70. data/lib/zakuro/version/genka/const/number.rb +43 -0
  71. data/lib/zakuro/version/genka/const/remainder.rb +33 -0
  72. data/lib/zakuro/version/genka/cycle/remainder.rb +92 -0
  73. data/lib/zakuro/version/genka/cycle/solar_term.rb +34 -0
  74. data/lib/zakuro/version/genka/genka.rb +1 -9
  75. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +95 -0
  76. data/lib/zakuro/version/genka/range/annual_range.rb +77 -0
  77. data/lib/zakuro/version/genka/stella/origin/first_term.rb +55 -0
  78. data/lib/zakuro/version/genka/stella/origin/january.rb +49 -0
  79. data/lib/zakuro/version/genka/stella/solar/average.rb +41 -0
  80. data/lib/zakuro/version/gihou/const/remainder.rb +0 -2
  81. data/lib/zakuro/version/gihou/cycle/remainder.rb +27 -6
  82. data/lib/zakuro/version/gihou/gihou.rb +1 -30
  83. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +1 -1
  84. data/lib/zakuro/version/gihou/stella/lunar/location.rb +2 -8
  85. data/lib/zakuro/version/gihou/stella/lunar/value.rb +3 -2
  86. data/lib/zakuro/version/gihou/stella/solar/average.rb +3 -3
  87. data/lib/zakuro/version/gregorio/gregorio.rb +1 -9
  88. data/lib/zakuro/version/houryaku/houryaku.rb +1 -9
  89. data/lib/zakuro/version/joukyou/joukyou.rb +1 -9
  90. data/lib/zakuro/version/kansei/kansei.rb +1 -9
  91. data/lib/zakuro/version/senmyou/const/remainder.rb +0 -2
  92. data/lib/zakuro/version/senmyou/cycle/remainder.rb +27 -6
  93. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +1 -1
  94. data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
  95. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +2 -8
  96. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +3 -2
  97. data/lib/zakuro/version/senmyou/stella/solar/average.rb +3 -3
  98. data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
  99. data/lib/zakuro/version/version_class_resolver.rb +8 -0
  100. data/zakuro.gemspec +1 -3
  101. metadata +50 -14
  102. data/lib/zakuro/calculation/base/multi_gengou.rb +0 -101
  103. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +0 -218
  104. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +0 -82
  105. data/lib/zakuro/era/japan/reki.rb +0 -91
  106. data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +0 -1121
  107. data/lib/zakuro/era/japan/yaml/set-002-from-north.yaml +0 -485
  108. data/lib/zakuro/era/japan/yaml/set-003-modern.yaml +0 -28
  109. data/lib/zakuro/version/abstract_version.rb +0 -29
  110. data/lib/zakuro/version/taien/taien.rb +0 -19
  111. data/lib/zakuro/version.rb +0 -7
  112. data/lib/zakuro/version_factory.rb +0 -59
@@ -0,0 +1,240 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../const/number'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Daien
9
+ # :nodoc:
10
+ module Lunar
11
+ #
12
+ # Adjustment 補正値情報
13
+ #
14
+ module Adjustment
15
+ # 『歴代天文律暦等志彙編 七』中華書房 p.2230
16
+ #
17
+ # 遠/近の地点での中間
18
+ #
19
+ # @return [Hash<Integer>] 遠/近の地点での中間
20
+ DAY_LIMIT = {
21
+ 7 => 2701,
22
+ 14 => 2363,
23
+ 21 => 2024,
24
+ 28 => 1686
25
+ }.freeze
26
+
27
+ #
28
+ # Row 行情報
29
+ #
30
+ class Row
31
+ # @return [Integer] 入暦(1-14)
32
+ attr_reader :day
33
+ # @return [Range] 小余範囲
34
+ attr_reader :range
35
+ # @return [Value] 補正値
36
+ attr_reader :value
37
+
38
+ #
39
+ # 初期化
40
+ #
41
+ # @param [Integer] day 入暦(1-14)
42
+ # @param [Range] range 小余範囲
43
+ # @param [Value] value 補正値
44
+ #
45
+ def initialize(day:, range:, value:)
46
+ @day = day
47
+ @range = range
48
+ @value = value
49
+ end
50
+
51
+ # :reek:ControlParameter
52
+
53
+ #
54
+ # 一致するか
55
+ #
56
+ # @param [Integer] day 入暦(1-14)
57
+ # @param [Integer] minute 小余
58
+ #
59
+ # @return [True] 一致
60
+ # @return [False] 不一致
61
+ #
62
+ def match?(day:, minute:)
63
+ return false unless @day == day
64
+
65
+ return false unless @range.include?(minute: minute)
66
+
67
+ true
68
+ end
69
+
70
+ #
71
+ # 分母を返す
72
+ #
73
+ # @return [Integer] 分母
74
+ #
75
+ def denominator
76
+ @range.denominator
77
+ end
78
+ end
79
+
80
+ #
81
+ # Range 小余範囲
82
+ #
83
+ class Range
84
+ # @return [Integer] 下限
85
+ MIN = 0
86
+ # @return [Integer] 上限
87
+ MAX = Const::Number::Cycle::DAY
88
+
89
+ # @return [Integer] 下限
90
+ attr_reader :min
91
+ # @return [Integer] 上限
92
+ attr_reader :max
93
+
94
+ #
95
+ # 初期化
96
+ #
97
+ # @param [Integer] min 下限
98
+ # @param [Integer] max 上限
99
+ #
100
+ def initialize(min: MIN, max: MAX)
101
+ @min = min
102
+ @max = max
103
+ end
104
+
105
+ #
106
+ # 含まれるか
107
+ #
108
+ # @param [Integer] minute 小余
109
+ #
110
+ # @return [True] 含まれる
111
+ # @return [False] 含まれない
112
+ #
113
+ def include?(minute:)
114
+ minute >= @min && minute <= @max
115
+ end
116
+
117
+ #
118
+ # 分母を返す
119
+ #
120
+ # @return [Integer] 分母
121
+ #
122
+ def denominator
123
+ @max - @min
124
+ end
125
+ end
126
+
127
+ #
128
+ # Value 補正値
129
+ #
130
+ class Value
131
+ # @return [Integer] 増減率
132
+ attr_reader :per
133
+ # @return [Integer] 遅速積
134
+ attr_reader :stack
135
+
136
+ #
137
+ # 初期化
138
+ #
139
+ # @param [Integer] per 増減率
140
+ # @param [Integer] stack 遅速積
141
+ #
142
+ def initialize(per:, stack:)
143
+ @per = per
144
+ @stack = stack
145
+ end
146
+
147
+ #
148
+ # 文字化
149
+ #
150
+ # @return [String] 文字
151
+ #
152
+ def to_s
153
+ "per:#{@per}, stack:#{@stack}"
154
+ end
155
+ end
156
+
157
+ # rubocop:disable Layout/LineLength
158
+
159
+ # 『歴代天文律暦等志彙編 七』中華書房 p.2228-2230
160
+ #
161
+ # @note 7日、14日、21日、28日の小余は DAY_LIMIT を参照のこと
162
+ #
163
+ # @return [Array<Row>] 月の補正値情報
164
+ #
165
+ LIST = [
166
+ Row.new(day: 1, range: Range.new, value: Value.new(per: +297, stack: 0)),
167
+ Row.new(day: 2, range: Range.new, value: Value.new(per: +259, stack: +297)),
168
+ Row.new(day: 3, range: Range.new, value: Value.new(per: +220, stack: +556)),
169
+ Row.new(day: 4, range: Range.new, value: Value.new(per: +180, stack: +776)),
170
+ Row.new(day: 5, range: Range.new, value: Value.new(per: +139, stack: +956)),
171
+ Row.new(day: 6, range: Range.new, value: Value.new(per: +97, stack: +1095)),
172
+ Row.new(day: 7, range: Range.new(max: DAY_LIMIT[7]), value: Value.new(per: +48, stack: +1192)),
173
+ Row.new(day: 7, range: Range.new(min: DAY_LIMIT[7]), value: Value.new(per: -6, stack: +1240)), # stack: +1192 + 48
174
+ Row.new(day: 8, range: Range.new, value: Value.new(per: -64, stack: +1234)),
175
+ Row.new(day: 9, range: Range.new, value: Value.new(per: -106, stack: +1170)),
176
+ Row.new(day: 10, range: Range.new, value: Value.new(per: -148, stack: +1064)),
177
+ Row.new(day: 11, range: Range.new, value: Value.new(per: -189, stack: +916)),
178
+ Row.new(day: 12, range: Range.new, value: Value.new(per: -229, stack: +727)),
179
+ Row.new(day: 13, range: Range.new, value: Value.new(per: -267, stack: +498)),
180
+ Row.new(day: 14, range: Range.new(max: DAY_LIMIT[14]), value: Value.new(per: -231, stack: +231)),
181
+ Row.new(day: 14, range: Range.new(min: DAY_LIMIT[14]), value: Value.new(per: -66, stack: 0)), # stack: +232 - 231
182
+ Row.new(day: 15, range: Range.new, value: Value.new(per: -289, stack: -66)),
183
+ Row.new(day: 16, range: Range.new, value: Value.new(per: -250, stack: -355)),
184
+ Row.new(day: 17, range: Range.new, value: Value.new(per: -211, stack: -605)),
185
+ Row.new(day: 18, range: Range.new, value: Value.new(per: -171, stack: -816)),
186
+ Row.new(day: 19, range: Range.new, value: Value.new(per: -130, stack: -987)),
187
+ Row.new(day: 20, range: Range.new, value: Value.new(per: -87, stack: -1117)),
188
+ Row.new(day: 21, range: Range.new(max: DAY_LIMIT[21]), value: Value.new(per: -36, stack: -1204)),
189
+ Row.new(day: 21, range: Range.new(min: DAY_LIMIT[21]), value: Value.new(per: +18, stack: -1240)), # stack: -1204 - 36
190
+ Row.new(day: 22, range: Range.new, value: Value.new(per: +73, stack: -1222)),
191
+ Row.new(day: 23, range: Range.new, value: Value.new(per: +116, stack: -1149)),
192
+ Row.new(day: 24, range: Range.new, value: Value.new(per: +157, stack: -1033)),
193
+ Row.new(day: 25, range: Range.new, value: Value.new(per: +198, stack: -876)),
194
+ Row.new(day: 26, range: Range.new, value: Value.new(per: +237, stack: -678)),
195
+ Row.new(day: 27, range: Range.new, value: Value.new(per: +276, stack: -441)),
196
+ Row.new(day: 28, range: Range.new(max: DAY_LIMIT[28]), value: Value.new(per: +165, stack: -165))
197
+ ].freeze
198
+ # rubocop:enable Layout/LineLength
199
+
200
+ #
201
+ # 月軌道の補正に必要な基本値を引き当てる
202
+ #
203
+ # @param [True, False] forward 進(遠地点より数える)/退(近地点より数える)
204
+ # @param [Integer] day 大余
205
+ # @param [Integer] minute 小余
206
+ #
207
+ # @return [Row] 補正値
208
+ #
209
+ def self.specify(day:, minute:)
210
+ LIST.each do |row|
211
+ # NOTE: 範囲が重複している場合、最初に引き当てたほうを優先する
212
+ return row if row.match?(day: day, minute: minute)
213
+ end
214
+
215
+ raise ArgumentError.new, "invalid parameter: #{day}/#{minute}"
216
+ end
217
+
218
+ # :reek:ControlParameter
219
+
220
+ #
221
+ # 小余の下げ幅を求める
222
+ #
223
+ # @param [Integer] day 大余
224
+ # @param [Integer] minute 小余
225
+ #
226
+ # @return [Integer] 小余の下げ幅
227
+ #
228
+ def self.minus_minute(day:, minute:)
229
+ limit = DAY_LIMIT.fetch(day, -1)
230
+ # 該当なし
231
+ return minute if limit == -1
232
+
233
+ return minute unless minute > limit
234
+
235
+ minute - limit
236
+ end
237
+ end
238
+ end
239
+ end
240
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../const/number'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Daien
9
+ # :nodoc:
10
+ module Lunar
11
+ #
12
+ # Localization 入暦特定
13
+ #
14
+ module Localization
15
+ # @return [Integer] 1近点月
16
+ ANOMALISTIC_MONTH = Const::Number::Cycle::ANOMALISTIC_MONTH
17
+ # @return [Integer] 積年
18
+ TOTAL_YEAR = Const::Number::Stack::TOTAL_YEAR
19
+ # @return [Integer] 開始年
20
+ BEGIN_YEAR = Const::Number::Stack::BEGIN_YEAR
21
+ # @return [Integer] 年
22
+ YEAR = Const::Number::Cycle::YEAR
23
+
24
+ #
25
+ # 対象年の最初の入暦を求める
26
+ #
27
+ # @param [Remainder] lunar_age 天正閏余
28
+ # @param [Integer] western_year 西暦年
29
+ #
30
+ # @return [Cycle::LunarRemainder] 入暦
31
+ #
32
+ def self.first_remainder(lunar_age:, western_year:)
33
+ # 積年の開始から対象年までの年数
34
+ total_year = TOTAL_YEAR + western_year - BEGIN_YEAR
35
+
36
+ # 通積分 - 天正閏余
37
+ total_day = total_year * YEAR - lunar_age.to_minute
38
+
39
+ Cycle::LunarRemainder.new(total: (total_day % ANOMALISTIC_MONTH))
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../calculation/stella/lunar/abstract_location'
4
+
5
+ require_relative '../../const/remainder'
6
+
7
+ require_relative './localization'
8
+
9
+ # :nodoc:
10
+ module Zakuro
11
+ # :nodoc:
12
+ module Daien
13
+ # :nodoc:
14
+ module Lunar
15
+ #
16
+ # Location 入暦
17
+ #
18
+ class Location < Calculation::Lunar::AbstractLocation
19
+ # @return [Cycle::LunarRemainder] 1近点月
20
+ ANOMALISTIC_MONTH = Const::Remainder::Lunar::ANOMALISTIC_MONTH
21
+ # @return [Cycle::LunarRemainder] 弦
22
+ QUARTER = Const::Remainder::Lunar::QUARTER
23
+
24
+ #
25
+ # 初期化
26
+ #
27
+ # @param [Cycle::LunarRemainder] lunar_age 天正閏余(大余小余)
28
+ # @param [Integer] western_year 西暦年
29
+ #
30
+ def initialize(lunar_age:, western_year:)
31
+ super(lunar_age: lunar_age, western_year: western_year)
32
+ end
33
+
34
+ #
35
+ # 入暦を計算する
36
+ #
37
+ def run
38
+ if calculated
39
+ decrease(limit: ANOMALISTIC_MONTH)
40
+ return
41
+ end
42
+
43
+ first
44
+ end
45
+
46
+ #
47
+ # 弦の分だけ月地点を進める
48
+ #
49
+ def add_quarter
50
+ remainder.add!(QUARTER)
51
+ end
52
+
53
+ private
54
+
55
+ #
56
+ # 初回計算
57
+ #
58
+ def first
59
+ @remainder = Localization.first_remainder(
60
+ lunar_age: remainder, western_year: western_year
61
+ )
62
+ decrease(limit: ANOMALISTIC_MONTH)
63
+
64
+ @calculated = true
65
+ end
66
+
67
+ #
68
+ # 大余小余に合わせて減算する(折り返す)
69
+ #
70
+ # @param [Cycle::LunarRemainder] limit 上限
71
+ #
72
+ def decrease(limit:)
73
+ return if remainder < limit
74
+
75
+ remainder.sub!(limit)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../calculation/stella/lunar/choukei_value'
4
+
5
+ require_relative '../../cycle/remainder'
6
+
7
+ require_relative './adjustment'
8
+
9
+ # :nodoc:
10
+ module Zakuro
11
+ # :nodoc:
12
+ module Daien
13
+ # :nodoc:
14
+ module Lunar
15
+ #
16
+ # Value 月補正値
17
+ #
18
+ module Value
19
+ # @return [Output::Logger] ロガー
20
+ LOGGER = Output::Logger.new(location: 'lunar_value')
21
+
22
+ # :reek:TooManyStatements { max_statements: 9 }
23
+
24
+ #
25
+ # 月の運行による補正値を算出する
26
+ #
27
+ # @param [Cycle::LunarRemainder] remainder 月の大余小余
28
+ #
29
+ # @return [Integer] 補正値
30
+ #
31
+ def self.get(remainder:)
32
+ valid?(remainder: remainder)
33
+
34
+ day, minute = Calculation::Lunar::ChoukeiValue.remainder_without_second(
35
+ remainder: remainder
36
+ )
37
+
38
+ # 引き当て
39
+ row = Adjustment.specify(day: day, minute: minute)
40
+
41
+ value = row.value
42
+
43
+ # LOGGER.debug("value.per: #{value.per}")
44
+ # LOGGER.debug("row.denominator: #{row.denominator}")
45
+ # LOGGER.debug("value.stack: #{value.stack}")
46
+
47
+ minus_minute = Adjustment.minus_minute(day: day, minute: minute)
48
+
49
+ day = Calculation::Lunar::ChoukeiValue.rounded_day(
50
+ per: value.per, denominator: row.denominator, minute: minus_minute
51
+ )
52
+
53
+ # LOGGER.debug("day: #{day}")
54
+
55
+ value.stack + day
56
+ end
57
+
58
+ #
59
+ # 大余小余を検証する
60
+ #
61
+ # @param [Cycle::LunarRemainder] remainder 大余小余
62
+ #
63
+ # @return [True] 正しい(月の位相計算に使う大余小余)
64
+ # @return [True] 正しくない
65
+ #
66
+ def self.valid?(remainder:)
67
+ return if remainder.is_a?(Cycle::LunarRemainder)
68
+
69
+ raise ArgumentError, "unmatch parameter type: #{remainder.class}"
70
+ end
71
+ private_class_method :valid?
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './lunar_age'
4
+ require_relative './winter_solstice'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Daien
10
+ # :nodoc:
11
+ module Origin
12
+ #
13
+ # AverageNovember 11月経
14
+ #
15
+ module AverageNovember
16
+ #
17
+ # 11月経朔(冬至が含まれる月の1日)を求める
18
+ #
19
+ # @param [Integer] western_year 西暦年
20
+ #
21
+ # @return [Remainder] 11月経朔
22
+ #
23
+ def self.get(western_year:)
24
+ # 冬至
25
+ winter_solstice = WinterSolstice.get(western_year: western_year)
26
+ # 天正閏余
27
+ lunar_age = LunarAge.get(western_year: western_year)
28
+
29
+ winter_solstice.sub(lunar_age)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../output/logger'
4
+
5
+ require_relative '../../const/number'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Daien
11
+ # :nodoc:
12
+ module Origin
13
+ #
14
+ # LunarAge 天正閏余
15
+ #
16
+ module LunarAge
17
+ # @return [Integer] 朔望月
18
+ SYNODIC_MONTH = Const::Number::Cycle::SYNODIC_MONTH
19
+ # @return [Integer] 一年
20
+ YEAR = Const::Number::Cycle::YEAR
21
+ # @return [Integer] 積年
22
+ TOTAL_YEAR = Const::Number::Stack::TOTAL_YEAR
23
+ # @return [Integer] 暦の開始年
24
+ BEGIN_YEAR = Const::Number::Stack::BEGIN_YEAR
25
+
26
+ # @return [Output::Logger] ロガー
27
+ LOGGER = Output::Logger.new(location: 'lunar_age')
28
+
29
+ # :reek:TooManyStatements { max_statements: 7 }
30
+
31
+ #
32
+ # 対象年の天正閏余(冬至より前にある11月経朔との差 = 月齢)を算出する
33
+ # 太陽と月の運動による補正値を算出し、その補正結果を返す
34
+ #
35
+ # @param [Integer] western_year 西暦年
36
+ #
37
+ # @return [Remainder] 天正閏余
38
+ #
39
+ def self.get(western_year:)
40
+ # 積年の開始から対象年までの年数
41
+ total = TOTAL_YEAR + western_year - BEGIN_YEAR
42
+
43
+ # 12朔望月に対する1年の余り(単位:分)
44
+ remainder_minute = YEAR - (SYNODIC_MONTH * 12)
45
+
46
+ # 朔望月に含まれなかった余り(単位:年)
47
+ remainder_year = total % SYNODIC_MONTH
48
+
49
+ LOGGER.debug("[01]: #{remainder_year}")
50
+
51
+ # 天正閏余
52
+ lunar_age = remainder_minute * remainder_year % SYNODIC_MONTH
53
+
54
+ LOGGER.debug("[02]: #{lunar_age}")
55
+
56
+ # 大余・小余に変換する
57
+ Cycle::Remainder.new(total: lunar_age)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../output/logger'
4
+
5
+ require_relative '../../const/number'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Daien
11
+ # :nodoc:
12
+ module Origin
13
+ #
14
+ # WinterSolstice 冬至
15
+ #
16
+ module WinterSolstice
17
+ # @return [Integer] 通余
18
+ REMAINDER_ALL_YEAR = Const::Number::Derivation::REMAINDER_ALL_YEAR
19
+ # @return [Integer] 60日
20
+ SIXTY_DAYS = Const::Number::Derivation::SIXTY_DAYS
21
+ # @return [Integer] 積年
22
+ TOTAL_YEAR = Const::Number::Stack::TOTAL_YEAR
23
+ # @return [Integer] 暦の開始年
24
+ BEGIN_YEAR = Const::Number::Stack::BEGIN_YEAR
25
+
26
+ # @return [Output::Logger] ロガー
27
+ LOGGER = Output::Logger.new(location: 'winter_solstice')
28
+
29
+ # :reek:TooManyStatements { max_statements: 6 }
30
+
31
+ #
32
+ # 対象年の前年の冬至を求める
33
+ #
34
+ # @param [Integer] western_year 西暦年
35
+ #
36
+ # @return [Remainder] 前年の冬至
37
+ #
38
+ def self.get(western_year:)
39
+ # 積年の開始から対象年までの年数
40
+ total = TOTAL_YEAR + western_year - BEGIN_YEAR
41
+ remainder_year = total % SIXTY_DAYS
42
+
43
+ LOGGER.debug("[01]:#{remainder_year}")
44
+
45
+ # 通余を使う
46
+ winter_solstice_minute = (remainder_year * REMAINDER_ALL_YEAR) % SIXTY_DAYS
47
+
48
+ LOGGER.debug("[02]:#{winter_solstice_minute}")
49
+
50
+ Cycle::Remainder.new(total: winter_solstice_minute)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../cycle/solar_term'
4
+
5
+ require_relative '../../const/number'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Daien
11
+ # :nodoc:
12
+ module Solar
13
+ #
14
+ # Adjustment 24気損益眺朒(ちょうじく)数
15
+ #
16
+ module Adjustment
17
+ #
18
+ # Row 行データ
19
+ #
20
+ class Row
21
+ # @return [Integer] 眺朒(ちょうじく)積
22
+ attr_reader :stack
23
+ # @return [Integer] 眺朒(ちょうじく)数
24
+ attr_reader :per_term
25
+ # @return [Integer] 毎日差
26
+ attr_reader :per_day
27
+
28
+ #
29
+ # 初期化
30
+ #
31
+ # @param [Integer] stack 眺朒(ちょうじく)積
32
+ # @param [Integer] per_term 眺朒(ちょうじく)数
33
+ # @param [Integer] per_day 毎日差
34
+ #
35
+ def initialize(stack:, per_term:, per_day:)
36
+ @stack = stack
37
+ @per_term = per_term
38
+ @per_day = per_day
39
+ end
40
+
41
+ #
42
+ # 文字化
43
+ #
44
+ # @return [String] 文字
45
+ #
46
+ def to_s
47
+ "stack:#{@stack}, per_term:#{@per_term}, per_day:#{@per_day}"
48
+ end
49
+ end
50
+
51
+ # @return [Array<Row>] 24気損益眺朒(ちょうじく)数
52
+ MAP = {
53
+ touji: Row.new(stack: 0.0, per_term: +13.4524, per_day: -0.1886), # 冬至(とうじ)
54
+ shoukan: Row.new(stack: +176.0, per_term: +10.5564, per_day: -0.1634), # 小寒(しょうかん)
55
+ daikan: Row.new(stack: +314.0, per_term: +8.0408, per_day: -0.1446), # 大寒(だいかん)
56
+ risshun: Row.new(stack: +418.0, per_term: +5.8160, per_day: -0.1318), # 立春(りっしゅん)
57
+ usui: Row.new(stack: +491.0, per_term: +3.7987, per_day: -0.1240), # 雨水(うすい)
58
+ keichitsu: Row.new(stack: +535.0, per_term: +1.9265, per_day: -0.1240), # 啓蟄(けいちつ)
59
+ shunbun: Row.new(stack: +551.0, per_term: -0.2048, per_day: -0.1178), # 春分(しゅんぶん)
60
+ seimei: Row.new(stack: +535.0, per_term: -1.9968, per_day: -0.1190), # 清明(せいめい)
61
+ kokuu: Row.new(stack: +491.0, per_term: -3.7956, per_day: -0.1240), # 穀雨(こくう)
62
+ rikka: Row.new(stack: +418.0, per_term: -5.6626, per_day: -0.1324), # 立夏(りっか)
63
+ shouman: Row.new(stack: +314.0, per_term: -7.6555, per_day: -0.1436), # 小満(しょうまん)
64
+ boushu: Row.new(stack: +176.0, per_term: -9.9405, per_day: -0.1436), # 芒種(ぼうしゅ)
65
+ geshi: Row.new(stack: 0.0, per_term: -12.0819, per_day: +0.1436), # 夏至(げし)
66
+ shousho: Row.new(stack: -176.0, per_term: -9.7018, per_day: +0.1324), # 小暑(しょうしょ)
67
+ taisho: Row.new(stack: -314.0, per_term: -7.5450, per_day: +0.1240), # 大暑(たいしょ)
68
+ risshuu: Row.new(stack: -418.0, per_term: -5.5634, per_day: +0.1190), # 立秋(りっしゅう)
69
+ shosho: Row.new(stack: -491.0, per_term: -3.7038, per_day: +0.1178), # 処暑(しょしょ)
70
+ hakuro: Row.new(stack: -535.0, per_term: -1.8954, per_day: +0.1178), # 白露(はくろ)
71
+ shuubun: Row.new(stack: -551.0, per_term: +0.1783, per_day: +0.1240), # 秋分(しゅうぶん)
72
+ kanro: Row.new(stack: -535.0, per_term: +2.0042, per_day: +0.1318), # 寒露(かんろ)
73
+ soukou: Row.new(stack: -491.0, per_term: +3.8950, per_day: +0.1446), # 霜降(そうこう)
74
+ rittou: Row.new(stack: -418.0, per_term: +5.9214, per_day: +0.1634), # 立冬(りっとう)
75
+ shousetsu: Row.new(stack: -314.0, per_term: +8.1610, per_day: +0.1886), # 小雪(しょうせつ)
76
+ taisetsu: Row.new(stack: -176.0, per_term: +10.9010, per_day: +0.1886) # 大雪(たいせつ)
77
+ }.freeze
78
+
79
+ #
80
+ # 24気損益眺朒(ちょうじく)数の行データを特定する
81
+ #
82
+ # @param [Integer] index 連番(二十四節気)
83
+ #
84
+ # @return [Row] 行データ
85
+ #
86
+ def self.specify(index:)
87
+ key = Cycle::SolarTerm::ORDER[index]
88
+ Adjustment::MAP[key].clone
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end