zakuro 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/lib/zakuro/calculation/base/multi_gengou.rb +101 -0
  3. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +218 -0
  4. data/lib/zakuro/calculation/base/year.rb +107 -0
  5. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +471 -0
  6. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +173 -0
  7. data/lib/zakuro/calculation/cycle/zodiac.rb +106 -0
  8. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +169 -0
  9. data/lib/zakuro/calculation/monthly/first_day.rb +45 -0
  10. data/lib/zakuro/calculation/monthly/initialized_month.rb +125 -0
  11. data/lib/zakuro/calculation/monthly/month.rb +187 -0
  12. data/lib/zakuro/calculation/monthly/month_label.rb +88 -0
  13. data/lib/zakuro/calculation/monthly/operated_month.rb +209 -0
  14. data/lib/zakuro/calculation/range/full_range.rb +210 -0
  15. data/lib/zakuro/calculation/range/medieval_annual_range.rb +105 -0
  16. data/lib/zakuro/calculation/range/operated_range.rb +144 -0
  17. data/lib/zakuro/calculation/range/operated_solar_terms.rb +201 -0
  18. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +82 -0
  19. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +146 -0
  20. data/lib/zakuro/calculation/specifier/single_day.rb +109 -0
  21. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +76 -0
  22. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +52 -0
  23. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +117 -0
  24. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +187 -0
  25. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +136 -0
  26. data/lib/zakuro/calculation/summary/single.rb +129 -0
  27. data/lib/zakuro/calculation/type/old_float.rb +69 -0
  28. data/lib/zakuro/merchant.rb +2 -2
  29. data/lib/zakuro/operation/month/parser.rb +1 -1
  30. data/lib/zakuro/operation/month/type.rb +5 -10
  31. data/lib/zakuro/output/error.rb +7 -6
  32. data/lib/zakuro/output/logger.rb +50 -49
  33. data/lib/zakuro/output/response.rb +145 -144
  34. data/lib/zakuro/tools/typeof.rb +2 -2
  35. data/lib/zakuro/version.rb +1 -1
  36. data/lib/zakuro/version/abstract_version.rb +1 -1
  37. data/lib/zakuro/version/context.rb +23 -0
  38. data/lib/zakuro/version/gihou/const/number.rb +55 -0
  39. data/lib/zakuro/version/gihou/const/remainder.rb +56 -0
  40. data/lib/zakuro/version/gihou/cycle/remainder.rb +61 -0
  41. data/lib/zakuro/version/gihou/cycle/solar_term.rb +34 -0
  42. data/lib/zakuro/version/gihou/gihou.rb +23 -2
  43. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +106 -0
  44. data/lib/zakuro/version/gihou/range/annual_range.rb +39 -0
  45. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +250 -0
  46. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +44 -0
  47. data/lib/zakuro/version/gihou/stella/lunar/location.rb +86 -0
  48. data/lib/zakuro/version/gihou/stella/lunar/value.rb +74 -0
  49. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +34 -0
  50. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +62 -0
  51. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +55 -0
  52. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +93 -0
  53. data/lib/zakuro/version/gihou/stella/solar/average.rb +97 -0
  54. data/lib/zakuro/version/gihou/stella/solar/interval.rb +108 -0
  55. data/lib/zakuro/version/gihou/stella/solar/location.rb +61 -0
  56. data/lib/zakuro/version/gihou/stella/solar/value.rb +36 -0
  57. data/lib/zakuro/version/senmyou/const/number.rb +51 -0
  58. data/lib/zakuro/version/senmyou/const/remainder.rb +49 -0
  59. data/lib/zakuro/version/senmyou/cycle/remainder.rb +61 -0
  60. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +34 -0
  61. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +80 -195
  62. data/lib/zakuro/version/senmyou/range/annual_range.rb +25 -170
  63. data/lib/zakuro/version/senmyou/senmyou.rb +10 -4
  64. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +237 -0
  65. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +44 -0
  66. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +93 -0
  67. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +66 -0
  68. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +34 -0
  69. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +62 -0
  70. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +55 -0
  71. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +93 -0
  72. data/lib/zakuro/version/senmyou/stella/solar/average.rb +97 -0
  73. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +103 -0
  74. data/lib/zakuro/version/senmyou/stella/solar/location.rb +61 -0
  75. data/lib/zakuro/version/senmyou/stella/solar/value.rb +39 -0
  76. data/lib/zakuro/version/version_class_resolver.rb +66 -0
  77. data/lib/zakuro/version_factory.rb +2 -2
  78. metadata +64 -24
  79. data/lib/zakuro/cycle/abstract_remainder.rb +0 -456
  80. data/lib/zakuro/cycle/zodiac.rb +0 -103
  81. data/lib/zakuro/version/senmyou/base/era.rb +0 -83
  82. data/lib/zakuro/version/senmyou/base/multi_gengou.rb +0 -98
  83. data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +0 -217
  84. data/lib/zakuro/version/senmyou/base/remainder.rb +0 -60
  85. data/lib/zakuro/version/senmyou/base/solar_term.rb +0 -86
  86. data/lib/zakuro/version/senmyou/base/year.rb +0 -104
  87. data/lib/zakuro/version/senmyou/monthly/first_day.rb +0 -44
  88. data/lib/zakuro/version/senmyou/monthly/initialized_month.rb +0 -48
  89. data/lib/zakuro/version/senmyou/monthly/month.rb +0 -181
  90. data/lib/zakuro/version/senmyou/monthly/month_label.rb +0 -87
  91. data/lib/zakuro/version/senmyou/monthly/operated_month.rb +0 -167
  92. data/lib/zakuro/version/senmyou/range/full_range.rb +0 -324
  93. data/lib/zakuro/version/senmyou/range/operated_range.rb +0 -126
  94. data/lib/zakuro/version/senmyou/range/operated_solar_terms.rb +0 -181
  95. data/lib/zakuro/version/senmyou/specifier/single_day_specifier.rb +0 -102
  96. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +0 -332
  97. data/lib/zakuro/version/senmyou/stella/solar_average.rb +0 -214
  98. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +0 -394
  99. data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +0 -106
  100. data/lib/zakuro/version/senmyou/summary/single.rb +0 -125
@@ -1,126 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './full_range'
4
- require_relative './operated_solar_terms'
5
- require_relative '../../../operation/operation'
6
- require_relative '../monthly/operated_month'
7
-
8
- # :nodoc:
9
- module Zakuro
10
- # :nodoc:
11
- module Senmyou
12
- #
13
- # OperatedRange 運用結果範囲
14
- #
15
- # 何らかの理由により、計算された暦とは異なる運用結果である場合、その結果に合わせて計算結果を上書きする
16
- class OperatedRange
17
- # @return [Array<Year>] 年データ(完全範囲)
18
- attr_reader :years
19
- # @return [OperatedSolarTerms] 運用時二十四節気
20
- attr_reader :operated_solar_terms
21
-
22
- #
23
- # 初期化
24
- #
25
- # @param [Array<Year>] years 年データ(完全範囲)
26
- #
27
- def initialize(years: [])
28
- @years = years
29
- @operated_solar_terms = OperatedSolarTerms.new(years: @years)
30
- @operated_solar_terms.create
31
- end
32
-
33
- #
34
- # 運用結果範囲を取得する
35
- #
36
- # @return [Array<Year>] 運用結果範囲
37
- #
38
- def get
39
- rewrite
40
- end
41
-
42
- #
43
- # 運用結果に書き換える
44
- #
45
- # @return [Array<Year>] 運用結果範囲
46
- #
47
- def rewrite
48
- operated_years = []
49
-
50
- years.each do |year|
51
- operated_year = OperatedRange.rewrite_year(
52
- year: year, operated_solar_terms: @operated_solar_terms
53
- )
54
- operated_years.push(operated_year)
55
- end
56
-
57
- operated_years
58
- end
59
-
60
- #
61
- # 年を書き換える
62
- #
63
- # @param [Year] year 年
64
- # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
65
- #
66
- # @return [Year] 年
67
- #
68
- def self.rewrite_year(year:, operated_solar_terms:)
69
- result = Year.new(multi_gengou: year.multi_gengou, new_year_date: year.new_year_date)
70
- year.months.each do |month|
71
- result.push(month: resolve_month(
72
- month: month, operated_solar_terms: operated_solar_terms
73
- ))
74
- end
75
-
76
- result.commit
77
-
78
- result
79
- end
80
-
81
- #
82
- # 履歴情報の有無に応じた月にする
83
- #
84
- # @param [Month] month 月
85
- # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
86
- #
87
- # @return [Month] 月
88
- #
89
- def self.resolve_month(month:, operated_solar_terms:)
90
- history = Operation.specify_history(western_date: month.western_date)
91
-
92
- return month if history.invalid?
93
-
94
- OperatedRange.rewrite_month(
95
- month: month, history: history, operated_solar_terms: operated_solar_terms
96
- )
97
- end
98
-
99
- #
100
- # 月を運用結果に書き換える
101
- #
102
- # @param [Month] month 月
103
- # @param [Operation::MonthHistory] history 変更履歴
104
- # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
105
- #
106
- # @return [Month] 月(運用結果)
107
- #
108
- def self.rewrite_month(month:, history:, operated_solar_terms:)
109
- return month unless month.western_date == history.western_date
110
-
111
- operated_month = OperatedMonth.new(
112
- month_label: month.month_label, first_day: month.first_day,
113
- solar_terms: month.solar_terms, history: history,
114
- operated_solar_terms: operated_solar_terms
115
- )
116
-
117
- operated_month.rewrite
118
-
119
- Month.new(
120
- month_label: operated_month.month_label, first_day: operated_month.first_day,
121
- solar_terms: operated_month.solar_terms
122
- )
123
- end
124
- end
125
- end
126
- end
@@ -1,181 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './full_range'
4
- require_relative '../../../operation/operation'
5
- require_relative '../monthly/month'
6
-
7
- # TODO: solar_termの中はsrc/destだが、yamlはcalc/actual。統一したい。
8
-
9
- # :nodoc:
10
- module Zakuro
11
- # :nodoc:
12
- module Senmyou
13
- #
14
- # OperatedSolarTerm 運用時二十四節気
15
- #
16
- class OperatedSolarTerms
17
- # @return [Array<Year>] 完全範囲(年データ)
18
- attr_reader :years
19
- # @return [Hash<String, SolarTerm>] 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
20
- #
21
- # * 移動元の二十四節気:無効な大余小余あり(削除対象)
22
- # * 移動先の二十四節気:移動元からの二十四節気(追加対象)
23
- #
24
- attr_reader :directions
25
-
26
- #
27
- # 初期化
28
- #
29
- # @param [Array<Year>] years 完全範囲(年データ)
30
- #
31
- def initialize(years: [])
32
- @years = years
33
- @directions = {}
34
- end
35
-
36
- #
37
- # データ生成する
38
- #
39
- # @return [<Type>] <description>
40
- #
41
- def create
42
- @directions = create_directions
43
- end
44
-
45
- #
46
- # 二十四節気を取得する
47
- #
48
- # @param [Western::Calendar] western_date 月初日の西暦日
49
- #
50
- # @return [True] 対象あり
51
- # @return [False] 対象なし
52
- # @return [SolarTerm] 二十四節気
53
- #
54
- def get(western_date: Western::Calendar.new)
55
- solar_term = @directions.fetch(western_date.format, SolarTerm.new)
56
-
57
- # 合致しない場合
58
- return false, SolarTerm.new if solar_term.empty?
59
-
60
- # 合致した上で、二十四節気が移動元(削除対象)の場合
61
- # 合致した上で、二十四節気が移動先(追加対象)の場合
62
- [true, solar_term]
63
- end
64
-
65
- #
66
- # 二十四節気の移動元/移動先を生成する
67
- #
68
- # @return [Hash<String, SolarTerm>] 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
69
- #
70
- def create_directions
71
- directions = {}
72
-
73
- years.each do |year|
74
- OperatedSolarTerms.create_directions_with_months(
75
- directions: directions, months: year.months
76
- )
77
- end
78
-
79
- directions
80
- end
81
-
82
- # :reek:TooManyStatements { max_statements: 6 }
83
-
84
- #
85
- # 年内の全ての月の移動方向を作成する
86
- #
87
- # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
88
- # @param [Array<Month>] months 年内の全ての月
89
- #
90
- def self.create_directions_with_months(directions: {}, months: [])
91
- months.each do |month|
92
- history = Operation.specify_history(western_date: month.western_date)
93
-
94
- next if history.invalid?
95
-
96
- direction = history.diffs.solar_term
97
-
98
- next if direction.invalid?
99
-
100
- OperatedSolarTerms.create_directions_each_month(
101
- directions: directions, direction: direction, month: month
102
- )
103
- end
104
- end
105
-
106
- #
107
- # 月毎の移動方向を作成する
108
- #
109
- # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
110
- # @param [Operation::SolarTerm::Diretion] 二十四節気(移動)
111
- # @param [Month] 月
112
- #
113
- def self.create_directions_each_month(directions: {},
114
- direction: Operation::SolarTerm::Diretion.new,
115
- month: Month.new)
116
-
117
- month.solar_terms.each do |solar_term|
118
- OperatedSolarTerms.push_source(directions: directions, direction: direction,
119
- solar_term: solar_term)
120
- end
121
- OperatedSolarTerms.push_destination(directions: directions,
122
- destination: direction.destination)
123
- end
124
-
125
- #
126
- # 移動先に有効な二十四節気(差し替える二十四節気)を指定する
127
- #
128
- # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
129
- # @param [Operation::SolarTerm::Direction] source 二十四節気(移動)
130
- # @param [SolarTerm] solar_term 二十四節気(計算値)
131
- #
132
- def self.push_source(directions: {}, direction: Operation::SolarTerm::Direction.new,
133
- solar_term: SolarTerm.new)
134
- source = direction.source
135
-
136
- return if source.invalid?
137
-
138
- return unless source.index == solar_term.index
139
-
140
- # 移動先に移動元の二十四節気を指定する
141
- directions[source.to.format] = OperatedSolarTerms.created_source(
142
- direction: direction, solar_term: solar_term
143
- )
144
- end
145
-
146
- #
147
- # 移動先に有効な二十四節気(差し替える二十四節気)を生成する
148
- #
149
- # @param [Operation::SolarTerm::Direction] source 二十四節気(移動)
150
- # @param [SolarTerm] solar_term 二十四節気(計算値)
151
- #
152
- # @return [SolarTerm] 二十四節気(運用値)
153
- #
154
- def self.created_source(direction: Operation::SolarTerm::Direction.new,
155
- solar_term: SolarTerm.new)
156
- operated_solar_term = solar_term.clone
157
-
158
- unless direction.invalid_days?
159
- # 二十四節気の大余をずらす
160
- operated_solar_term.remainder.add!(
161
- Remainder.new(day: direction.days, minute: 0, second: 0)
162
- )
163
- end
164
-
165
- operated_solar_term
166
- end
167
-
168
- #
169
- # 移動元に無効な二十四節気(連番のみ指定)を指定する
170
- #
171
- # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
172
- # @param [Operation::SolarTerm::Destination] destination 二十四節気(移動先)
173
- #
174
- def self.push_destination(directions: {}, destination: Operation::SolarTerm::Destination.new)
175
- return if destination.invalid?
176
-
177
- directions[destination.from.format] = SolarTerm.new(index: destination.index)
178
- end
179
- end
180
- end
181
- end
@@ -1,102 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../../era/western'
4
- require_relative '../range/full_range'
5
- require_relative '../base/multi_gengou_roller'
6
- require_relative '../base/year'
7
- require_relative '../../../output/response'
8
- require_relative '../../../output/logger'
9
-
10
- # :nodoc:
11
- module Zakuro
12
- # :nodoc:
13
- module Senmyou
14
- #
15
- # SingleDaySpecifier 一日検索
16
- #
17
- module SingleDaySpecifier
18
- # @return [Logger] ロガー
19
- LOGGER = Logger.new(location: 'specifier')
20
-
21
- #
22
- # 取得する
23
- #
24
- # @param [Array<Year>] yeas 範囲
25
- # @param [Western::Calendar] date 西暦日
26
- #
27
- # @return [Result::Data::SingleDay] 和暦日
28
- #
29
- def self.get(years: [], date: Western::Calendar.new)
30
- year = specify_year(years: years, date: date)
31
-
32
- year = transfer(year: year, date: date)
33
-
34
- month = specify_month(year: year, date: date)
35
- first_date = month.western_date
36
-
37
- Response::SingleDay.save_single_day(
38
- param: Response::SingleDay::Param.new(
39
- year: year, month: month,
40
- date: date, days: date - first_date
41
- )
42
- )
43
- end
44
-
45
- #
46
- # 年を特定する
47
- #
48
- # @param [Array<Year>] years 範囲
49
- # @param [Western::Calendar] date 西暦日
50
- #
51
- # @return [Year] 対象年
52
- #
53
- def self.specify_year(years:, date:)
54
- years.reverse_each do |year|
55
- return year if date >= year.new_year_date
56
- end
57
-
58
- raise ArgumentError, "invalid year range. date: #{date.format}"
59
- end
60
- private_class_method :specify_year
61
-
62
- #
63
- # 改元する
64
- #
65
- # @param [Year] year 年
66
- # @param [Western::Calendar] date 西暦日
67
- #
68
- # @return [Year] 改元後の年
69
- #
70
- def self.transfer(year:, date:)
71
- multi_gengou = MultiGengouRoller.transfer(multi_gengou: year.multi_gengou, date: date)
72
- Year.new(multi_gengou: multi_gengou, new_year_date: year.new_year_date,
73
- months: year.months, total_days: year.total_days)
74
- end
75
- private_class_method :transfer
76
-
77
- # :reek:TooManyStatements { max_statements: 7 }
78
-
79
- #
80
- # 月を特定する
81
- #
82
- # @param [Year] year 年
83
- # @param [Western::Calendar] date 西暦日
84
- #
85
- # @return [Month] 対象月
86
- #
87
- def self.specify_month(year:, date:)
88
- months = year.months
89
-
90
- current_month = months[0]
91
- months.each do |month|
92
- return current_month if month.western_date > date
93
-
94
- current_month = month
95
- end
96
-
97
- current_month
98
- end
99
- private_class_method :specify_month
100
- end
101
- end
102
- end
@@ -1,332 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # :nodoc:
4
- module Zakuro
5
- # :nodoc:
6
- module Senmyou
7
- #
8
- # LunarOrbit 月軌道
9
- #
10
- module LunarOrbit
11
- # @return [Integer] 暦周(1近日点)
12
- ANOMALISTIC_MONTH = 231_458.19
13
- # @return [Integer] 暦中日
14
- # @note ANOMALISTIC_MONTH の半分に相当する
15
- HALF_ANOMALISTIC_MONTH = \
16
- LunarRemainder.new(day: 13, minute: 6529, second: 9.5)
17
-
18
- #
19
- # Adjustment 補正値情報
20
- #
21
- module Adjustment
22
- #
23
- # Item 補正値
24
- #
25
- class Item
26
- # @return [Integer] 損益率
27
- attr_reader :per
28
- # @return [Integer] 眺朒(ちょうじく)積
29
- attr_reader :stack
30
-
31
- #
32
- # 初期化
33
- #
34
- # @param [Integer] per 損益率
35
- # @param [Integer] stack 眺朒(ちょうじく)積
36
- #
37
- def initialize(per:, stack:)
38
- @per = per
39
- @stack = stack
40
- end
41
-
42
- #
43
- # 文字化
44
- #
45
- # @return [String] 文字
46
- #
47
- def to_s
48
- "per:#{@per}, stack:#{@stack}"
49
- end
50
- end
51
-
52
- # @return [Array<Item>] 月の補正値
53
- # @note キーは複合キーであり、以下のパターンに対応する
54
- # * 進退
55
- # * forward: 進(遠地点より数える)
56
- # * back: 退(近地点より数える)
57
- # * 入暦(1-14)
58
- # * 小余(0-8400)
59
- LIST = {
60
- forward_01_0000_8400: Item.new(per: +830, stack: 0),
61
- forward_02_0000_8400: Item.new(per: +726, stack: +830),
62
- forward_03_0000_8400: Item.new(per: +606, stack: +1556),
63
- forward_04_0000_8400: Item.new(per: +471, stack: +2162),
64
- forward_05_0000_8400: Item.new(per: +337, stack: +2633),
65
- forward_06_0000_8400: Item.new(per: +202, stack: +2970),
66
- forward_07_0000_7465: Item.new(per: +53, stack: +3172),
67
- forward_07_7465_8400: Item.new(per: -7, stack: +3225), # +3172 + 53(初益)
68
- forward_08_0000_8400: Item.new(per: -82, stack: +3218),
69
- forward_09_0000_8400: Item.new(per: -224, stack: +3136),
70
- forward_10_0000_8400: Item.new(per: -366, stack: +2912),
71
- forward_11_0000_8400: Item.new(per: -509, stack: +2546),
72
- forward_12_0000_8400: Item.new(per: -643, stack: +2037),
73
- forward_13_0000_8400: Item.new(per: -748, stack: +1394),
74
- forward_14_0000_6529: Item.new(per: -646, stack: +646), # 14日の小余は常に6529以下
75
- back_01_0000_8400: Item.new(per: -830, stack: 0),
76
- back_02_0000_8400: Item.new(per: -726, stack: -830),
77
- back_03_0000_8400: Item.new(per: -598, stack: -1556),
78
- back_04_0000_8400: Item.new(per: -464, stack: -2154),
79
- back_05_0000_8400: Item.new(per: -329, stack: -2618),
80
- back_06_0000_8400: Item.new(per: -195, stack: -2947),
81
- back_07_0000_7465: Item.new(per: -53, stack: -3142),
82
- back_07_7465_8400: Item.new(per: +7, stack: -3195), # -3142 - 53(初益)
83
- back_08_0000_8400: Item.new(per: +82, stack: -3188),
84
- back_09_0000_8400: Item.new(per: +225, stack: -3106),
85
- back_10_0000_8400: Item.new(per: +366, stack: -2881),
86
- back_11_0000_8400: Item.new(per: +501, stack: -2515),
87
- back_12_0000_8400: Item.new(per: +628, stack: -2014),
88
- back_13_0000_8400: Item.new(per: +740, stack: -1386),
89
- back_14_0000_6529: Item.new(per: +646, stack: -646) # 14日の小余は常に6529以下
90
- }.freeze
91
- end
92
-
93
- #
94
- # 月の運行による補正値を算出する
95
- #
96
- # @param [Remainder] remainder_month 月の大余小余
97
- # @param [True, False] is_forward 進(遠地点より数える)/退(近地点より数える)
98
- #
99
- # @return [Integer] 補正値
100
- #
101
- def self.calc_moon_orbit_value(remainder_month:, is_forward:)
102
- valid?(remainder: remainder_month)
103
-
104
- day, minute = make_calculable_remainder_value(remainder: remainder_month)
105
-
106
- # 引き当て
107
- adjustment, diff, minute = specify_moon_adjustment(
108
- is_forward: is_forward, day: day, minute: minute
109
- )
110
- day = make_cumulative_value_for_days(per: adjustment.per,
111
- denominator: diff, minute: minute)
112
-
113
- adjustment.stack + day
114
- end
115
-
116
- #
117
- # 大余小余を検証する
118
- #
119
- # @param [Remainder] remainder 大余小余
120
- #
121
- # @return [True] 正しい(月の位相計算に使う大余小余)
122
- # @return [True] 正しくない
123
- #
124
- def self.valid?(remainder:)
125
- return if remainder.is_a?(LunarRemainder)
126
-
127
- raise ArgumentError, "unmatch parameter type: #{remainder.class}"
128
- end
129
- private_class_method :valid?
130
-
131
- #
132
- # 大余小余を計算可能な値にする
133
- # @note 大余の秒(second)は使わない
134
- #
135
- # @param [LunarRemainder] remainder 大余小余
136
- #
137
- # @return [Integer] 大余
138
- # @return [Integer] 小余
139
- #
140
- def self.make_calculable_remainder_value(remainder:)
141
- day = remainder.day
142
- minute = remainder.minute + (remainder.second / 100)
143
- minute = minute.floor
144
-
145
- [day, minute]
146
- end
147
- private_class_method :make_calculable_remainder_value
148
-
149
- # :reek:TooManyStatements { max_statements: 9 }
150
-
151
- #
152
- # 累計値(大余)を作成する
153
- #
154
- # @param [Integer] per 入暦(1-14)
155
- # @param [Integer] denominator 小余の分母
156
- # @param [Integer] minute 小余
157
- #
158
- # @return [Integer] 累計値(大余)
159
- #
160
- def self.make_cumulative_value_for_days(per:, denominator:, minute:)
161
- remainder_minute = (per * minute).to_f
162
- day = remainder_minute / denominator
163
- # 切り捨て(プラスマイナスに関わらず小数点以下切り捨て)
164
- day = day.negative? ? day.ceil : day.floor
165
- sign = remainder_minute.negative? ? -1 : 1
166
- remainder_day = (sign * remainder_minute) % denominator
167
- # 四捨五入(8400ならその半分の4200以上を繰り上げる)
168
- day += sign if remainder_day >= (denominator / 2)
169
-
170
- day
171
- end
172
- private_class_method :make_cumulative_value_for_days
173
-
174
- # :reek:TooManyStatements { max_statements: 9 }
175
-
176
- #
177
- # 月軌道の補正に必要な基本値を引き当てる
178
- #
179
- # @note 戻り値は calc_moon_orbit_value で使用する
180
- #
181
- # @param [True, False] is_forward 進(遠地点より数える)/退(近地点より数える)
182
- # @param [Integer] day 大余
183
- # @param [Integer] minute 小余
184
- #
185
- # @return [Adjustment::Item] 補正値
186
- # @return [Integer] (小余を処理する時の)分母
187
- # @return [Integer] 小余の下げ幅
188
- #
189
- def self.specify_moon_adjustment(is_forward:, day:, minute:)
190
- prefix = { true => 'forward', false => 'back' }[is_forward]
191
-
192
- targets = Adjustment::LIST.select \
193
- { |key, _| key.match(/^#{prefix}_#{format('%<day>02d', day: day)}_.*/) }
194
-
195
- targets.each do |key, value|
196
- # NOTE: 境界値は上から順に引き当てた方を返す(7日の境界値7465は上のキーで返す)
197
- matched, diff = \
198
- extract_data_from_moon_adjustment_key(key, minute)
199
- # 小余の下げ幅
200
- calc_minute = (day == 7 && minute > 7465 ? minute - 7465 : minute)
201
- return value, diff, calc_minute if matched
202
- end
203
-
204
- [nil, nil, nil]
205
- end
206
- private_class_method :specify_moon_adjustment
207
-
208
- #
209
- # 補正値を引き当てる
210
- #
211
- # @param [String] key 補正値のキー
212
- # @param [Integer] minute 小余
213
- #
214
- # @return [Adjustment::Item] 補正値
215
- # @return [Integer] (小余を処理する時の)分母
216
- #
217
- def self.extract_data_from_moon_adjustment_key(key, minute)
218
- matched = key.match(/([0-9]{4})_([0-9]{4})$/)
219
- start = matched[1].to_i
220
- finish = matched[2].to_i
221
-
222
- matched = minute >= start && minute <= finish
223
- [matched, (finish - start)]
224
- end
225
- private_class_method :extract_data_from_moon_adjustment_key
226
-
227
- # :reek:ControlParameter and :reek:BooleanParameter
228
- # :reek:LongParameterList { max_params: 4 }
229
-
230
- #
231
- # 月地点を計算する
232
- #
233
- # @param [LunarRemainder] remainder 初回(昨年冬至), 前回計算結果(入暦)
234
- # @param [Integer] western_year 西暦年
235
- # @param [True, False] is_forward 進(遠地点より数える)/退(近地点より数える)
236
- # @param [True, False] first 初回計算, 次回以降計算
237
- #
238
- # @return [LunarRemainder] 入暦
239
- # @return [True] 進(遠地点より数える)
240
- # @return [False] 退(近地点より数える)
241
- #
242
- def self.calc_moon_point(remainder:, western_year:,
243
- is_forward: true, first: true)
244
- if first
245
- return calc_first_moon_point(winter_solstice_age: remainder,
246
- western_year: western_year)
247
- end
248
- calc_following_moon_point(remainder: remainder, is_forward: is_forward)
249
- end
250
-
251
- # :reek:TooManyStatements { max_statements: 7 }
252
-
253
- #
254
- # 入暦(月の遠地点から数えた日数/近地点から数えた日数)を求める
255
- #
256
- # 天正冬至(入暦前回未計算)を求める
257
- #
258
- # @param [Remainder] winter_solstice_age 昨年冬至
259
- # @param [Integer] western_year 西暦年
260
- #
261
- # @return [LunarRemainder] 入暦
262
- # @return [True] 進(遠地点より数える)
263
- # @return [False] 退(近地点より数える)
264
- #
265
- def self.calc_first_moon_point(winter_solstice_age:, western_year:)
266
- # 積年の開始から対象年までの年数
267
- total_year = \
268
- WinterSolstice::TOTAL_YEAR + western_year - WinterSolstice::BEGIN_YEAR
269
-
270
- # 通積分 - 天正閏余
271
- total_day = \
272
- total_year * WinterSolstice::YEAR - winter_solstice_age.to_minute
273
-
274
- remainder_month = \
275
- LunarRemainder.new(total: (total_day % ANOMALISTIC_MONTH))
276
-
277
- remainder_month, is_forward = decrease_moon_point(
278
- remainder_month: remainder_month,
279
- remainder_limit: HALF_ANOMALISTIC_MONTH, is_forward: true
280
- )
281
-
282
- remainder_month.add!(Remainder.new(day: 1, minute: 0, second: 0))
283
-
284
- [remainder_month, is_forward]
285
- end
286
- private_class_method :calc_first_moon_point
287
-
288
- #
289
- # 入暦(月の遠地点から数えた日数/近地点から数えた日数)を求める
290
- #
291
- # 前回計算結果を補正する
292
- #
293
- # @param [LunarRemainder] remainder 前回計算結果(入暦)
294
- # @param [True, False] is_forward 進(遠地点より数える)/退(近地点より数える)
295
- #
296
- # @return [LunarRemainder] 入暦
297
- # @return [True] 進(遠地点より数える)
298
- # @return [False] 退(近地点より数える)
299
- #
300
- def self.calc_following_moon_point(remainder:, is_forward:)
301
- # 前回計算結果を引き継いた場合、暦中日ではなく損益眺朒(ちょうじく)数の上限とする
302
- remainder_month, is_forward = \
303
- decrease_moon_point(
304
- remainder_month: remainder,
305
- remainder_limit: Remainder.new(day: 14, minute: 6529, second: 0),
306
- is_forward: is_forward
307
- )
308
-
309
- [remainder_month, is_forward]
310
- end
311
- private_class_method :calc_following_moon_point
312
-
313
- #
314
- # 月地点を減算する
315
- #
316
- # @param [LunarRemainder] remainder_month 大余小余
317
- # @param [Remainder] remainder_limit 大余小余の上限(最大の入暦)
318
- # @param [True, False] is_forward 進(遠地点より数える)/退(近地点より数える)
319
- #
320
- # @return [LunarRemainder] 大余小余の減算結果(上限値超えした場合)
321
- # @return [True] 進(遠地点より数える)
322
- # @return [False] 退(近地点より数える)
323
- #
324
- def self.decrease_moon_point(remainder_month:, remainder_limit:, is_forward:)
325
- return remainder_month, is_forward if remainder_month < remainder_limit
326
-
327
- [remainder_month.sub(HALF_ANOMALISTIC_MONTH), !is_forward]
328
- end
329
- private_class_method :decrease_moon_point
330
- end
331
- end
332
- end