zakuro 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +169 -0
  3. data/lib/zakuro/calculation/range/medieval_annual_range.rb +105 -0
  4. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +76 -0
  5. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +52 -0
  6. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +117 -0
  7. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +187 -0
  8. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +136 -0
  9. data/lib/zakuro/calculation/type/old_float.rb +69 -0
  10. data/lib/zakuro/version.rb +1 -1
  11. data/lib/zakuro/version/gihou/const/number.rb +55 -0
  12. data/lib/zakuro/version/gihou/const/remainder.rb +56 -0
  13. data/lib/zakuro/version/gihou/cycle/remainder.rb +61 -0
  14. data/lib/zakuro/version/gihou/cycle/solar_term.rb +34 -0
  15. data/lib/zakuro/version/gihou/gihou.rb +23 -2
  16. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +106 -0
  17. data/lib/zakuro/version/gihou/range/annual_range.rb +39 -0
  18. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +250 -0
  19. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +44 -0
  20. data/lib/zakuro/version/gihou/stella/lunar/location.rb +86 -0
  21. data/lib/zakuro/version/gihou/stella/lunar/value.rb +74 -0
  22. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +34 -0
  23. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +62 -0
  24. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +55 -0
  25. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +93 -0
  26. data/lib/zakuro/version/gihou/stella/solar/average.rb +97 -0
  27. data/lib/zakuro/version/gihou/stella/solar/interval.rb +108 -0
  28. data/lib/zakuro/version/gihou/stella/solar/location.rb +61 -0
  29. data/lib/zakuro/version/gihou/stella/solar/value.rb +36 -0
  30. data/lib/zakuro/version/senmyou/const/number.rb +1 -1
  31. data/lib/zakuro/version/senmyou/const/remainder.rb +7 -1
  32. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +4 -1
  33. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +11 -111
  34. data/lib/zakuro/version/senmyou/range/annual_range.rb +5 -77
  35. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +2 -3
  36. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +13 -28
  37. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +5 -28
  38. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +29 -29
  39. data/lib/zakuro/version/senmyou/stella/solar/average.rb +11 -89
  40. data/lib/zakuro/version/senmyou/stella/solar/location.rb +18 -121
  41. data/lib/zakuro/version/senmyou/stella/solar/value.rb +4 -103
  42. data/lib/zakuro/version/version_class_resolver.rb +4 -0
  43. metadata +28 -2
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../calculation/stella/solar/abstract_average'
4
+
5
+ require_relative '../../const/remainder'
6
+
7
+ require_relative '../../cycle/solar_term'
8
+
9
+ require_relative '../origin/winter_solstice'
10
+
11
+ require_relative './location'
12
+
13
+ # :nodoc:
14
+ module Zakuro
15
+ # :nodoc:
16
+ module Gihou
17
+ # :nodoc:
18
+ module Solar
19
+ #
20
+ # Average 平気(太陽軌道平均)
21
+ #
22
+ class Average < Calculation::Solar::AbstractAverage
23
+ #
24
+ # 初期化
25
+ #
26
+ # @param [Integer] western_year 西暦年
27
+ #
28
+ def initialize(western_year:)
29
+ solar_term = Average.first_solar_term(western_year: western_year)
30
+ super(solar_term: solar_term)
31
+ end
32
+
33
+ #
34
+ # 冬至から数えた1年データの月ごとに二十四節気を割り当てる
35
+ #
36
+ # @param [Array<Month>] annual_range 1年データ
37
+ #
38
+ # @return [Array<Month>] 1年データ
39
+ #
40
+ def set(annual_range:)
41
+ super(annual_range: annual_range)
42
+ end
43
+
44
+ #
45
+ # 計算開始する二十四節気を求める
46
+ #
47
+ # @param [Integer] western_year 西暦年
48
+ #
49
+ # @return [SolarTerm] 二十四節気
50
+ #
51
+ def self.first_solar_term(western_year:)
52
+ # 天正冬至
53
+ winter_solstice = Origin::WinterSolstice.get(western_year: western_year)
54
+
55
+ # 二十四節気(冬至)
56
+ solar_term = Cycle::SolarTerm.new(index: 0, remainder: winter_solstice)
57
+
58
+ first_solar_term_index = Average.calc_fist_solar_term_index(western_year: western_year)
59
+
60
+ # 対象の二十四節気まで戻す
61
+ solar_term.prev_by_index(first_solar_term_index)
62
+
63
+ solar_term
64
+ end
65
+
66
+ # :reek:TooManyStatements { max_statements: 6 }
67
+
68
+ #
69
+ # 計算開始する二十四節気番号を求める
70
+ #
71
+ # * 前提として入定気は冬至の手前にある
72
+ # * 例えば、定気が大雪であれば入定気は大雪の範囲内にある
73
+ # * 入定気は、定気の開始位置に重複しない限り、常に定気より後にある
74
+ # * 基本的に定気の一つ前から起算すれば、当時から求めた11月(閏10/閏11月)に二十四節気を割り当てられる
75
+ #
76
+ # @param [Integer] western_year 西暦年
77
+ #
78
+ # @return [Integer] 二十四節気番号
79
+ #
80
+ def self.calc_fist_solar_term_index(western_year:)
81
+ # 天正閏余
82
+ lunar_age = Origin::LunarAge.get(western_year: western_year)
83
+
84
+ solar_location = Solar::Location.new(lunar_age: lunar_age)
85
+ solar_location.run
86
+
87
+ solar_term_index = solar_location.index
88
+
89
+ # 入定気の一つ後の二十四節気まで戻す(ただし11月経朔が二十四節気上にある場合は戻さない)
90
+ solar_term_index += 1 unless solar_location.remainder == Cycle::Remainder.new(total: 0)
91
+
92
+ solar_term_index
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Gihou
7
+ # :nodoc:
8
+ module Solar
9
+ #
10
+ # Interval 入気定日加減数(二十四節気の間隔)
11
+ #
12
+ module Interval
13
+ #
14
+ # 気策の 15-292.5 を加減する
15
+ #
16
+ # @note 『日本暦日原典』は雨水と啓蟄が逆になっていたのでこれを改めた
17
+ #
18
+ # @return [Hash<Symbol, Cycle::Remainder>] 一覧
19
+ MAP = {
20
+ # 冬至(とうじ)・大雪(たいせつ)
21
+ touji: Cycle::Remainder.new(day: 14, minute: 910, second: 5), # -722
22
+ taisetsu: Cycle::Remainder.new(day: 14, minute: 910, second: 5),
23
+ # 小寒(しょうかん)・小雪(しょうせつ)
24
+ shoukan: Cycle::Remainder.new(day: 14, minute: 1014, second: 5), # -618
25
+ shousetsu: Cycle::Remainder.new(day: 14, minute: 1014, second: 5),
26
+ # 大寒(だいかん)・立冬(りっとう)
27
+ daikan: Cycle::Remainder.new(day: 14, minute: 1118, second: 5), # -514
28
+ rittou: Cycle::Remainder.new(day: 14, minute: 1118, second: 5),
29
+ # 立春(りっしゅん)・霜降(そうこう)
30
+ risshun: Cycle::Remainder.new(day: 14, minute: 1118, second: 5), # -514
31
+ soukou: Cycle::Remainder.new(day: 14, minute: 1118, second: 5),
32
+ # 雨水(うすい)・寒露(かんろ)
33
+ usui: Cycle::Remainder.new(day: 14, minute: 1014, second: 5), # -618
34
+ kanro: Cycle::Remainder.new(day: 14, minute: 1014, second: 5),
35
+ # 啓蟄(けいちつ)・秋分(しゅうぶん)
36
+ keichitsu: Cycle::Remainder.new(day: 14, minute: 910, second: 5), # -722
37
+ shuubun: Cycle::Remainder.new(day: 14, minute: 910, second: 5),
38
+ # 春分(しゅんぶん)・白露(はくろ)
39
+ shunbun: Cycle::Remainder.new(day: 15, minute: 1014, second: 5), # +722
40
+ hakuro: Cycle::Remainder.new(day: 15, minute: 1014, second: 5),
41
+ # 清明(せいめい)・処暑(しょしょ)
42
+ seimei: Cycle::Remainder.new(day: 15, minute: 910, second: 5), # +618
43
+ shosho: Cycle::Remainder.new(day: 15, minute: 910, second: 5),
44
+ # 穀雨(こくう)・立秋(りっしゅう)
45
+ kokuu: Cycle::Remainder.new(day: 15, minute: 806, second: 5), # +514
46
+ risshuu: Cycle::Remainder.new(day: 15, minute: 806, second: 5),
47
+ # 立夏(りっか)・大暑(たいしょ)
48
+ rikka: Cycle::Remainder.new(day: 15, minute: 806, second: 5), # +514
49
+ taisho: Cycle::Remainder.new(day: 15, minute: 806, second: 5),
50
+ # 小満(しょうまん)・小暑(しょうしょ)
51
+ shouman: Cycle::Remainder.new(day: 15, minute: 910, second: 5), # +618
52
+ shousho: Cycle::Remainder.new(day: 15, minute: 910, second: 5),
53
+ # 芒種(ぼうしゅ)・夏至(げし)
54
+ boushu: Cycle::Remainder.new(day: 15, minute: 1014, second: 5), # +722
55
+ geshi: Cycle::Remainder.new(day: 15, minute: 1014, second: 5)
56
+ }.freeze
57
+
58
+ # @return [Array<Remainder>] 索引
59
+ LIST = [
60
+ MAP[:touji], # 0
61
+ MAP[:shoukan], # 1
62
+ MAP[:daikan], # 2
63
+ MAP[:risshun], # 3
64
+ MAP[:usui], # 4
65
+ MAP[:keichitsu], # 5
66
+ MAP[:shunbun], # 6
67
+ MAP[:seimei], # 7
68
+ MAP[:kokuu], # 8
69
+ MAP[:rikka], # 9
70
+ MAP[:shouman], # 10
71
+ MAP[:boushu], # 11
72
+ MAP[:geshi], # 12
73
+ MAP[:shousho], # 13
74
+ MAP[:taisho], # 14
75
+ MAP[:risshuu], # 15
76
+ MAP[:shosho], # 16
77
+ MAP[:hakuro], # 17
78
+ MAP[:shuubun], # 18
79
+ MAP[:kanro], # 19
80
+ MAP[:soukou], # 20
81
+ MAP[:rittou], # 21
82
+ MAP[:shousetsu], # 22
83
+ MAP[:taisetsu] # 23
84
+ ].freeze
85
+
86
+ #
87
+ # 入気定日加減数を引き当てる
88
+ #
89
+ # @param [Integer] index 二十四節気番号
90
+ #
91
+ # @return [Cycle::Remainder] 入気定日加減数
92
+ #
93
+ def self.index_of(index)
94
+ LIST[index]
95
+ end
96
+
97
+ #
98
+ # 入気定日加減数の総数を返す
99
+ #
100
+ # @return [Integer] 入気定日加減数の総数
101
+ #
102
+ def self.size
103
+ LIST.size
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../calculation/stella/solar/abstract_location'
4
+
5
+ require_relative '../../const/remainder'
6
+
7
+ require_relative './interval'
8
+
9
+ # :nodoc:
10
+ module Zakuro
11
+ # :nodoc:
12
+ module Gihou
13
+ # :nodoc:
14
+ module Solar
15
+ #
16
+ # Location 入定気
17
+ #
18
+ class Location < Calculation::Solar::AbstractLocation
19
+ # @return [Cycle::Remainder] 弦
20
+ QUARTER = Const::Remainder::Solar::QUARTER
21
+
22
+ #
23
+ # 初期化
24
+ #
25
+ # @param [Cycle::Remainder] lunar_age 天正閏余(大余小余)
26
+ #
27
+ def initialize(lunar_age:)
28
+ super(lunar_age: lunar_age, quarter: QUARTER)
29
+ end
30
+
31
+ # :reek:UtilityFunction
32
+
33
+ #
34
+ # 二十四節気番号に対応する入気定日加減数を返す
35
+ #
36
+ # @note 継承のためクラスメソッドにしない
37
+ #
38
+ # @param [Integer] index 二十四節気番号
39
+ #
40
+ # @return [Cycle::Remainder] 入気定日加減数
41
+ #
42
+ def interval(index:)
43
+ Interval.index_of(index)
44
+ end
45
+
46
+ # :reek:UtilityFunction
47
+
48
+ #
49
+ # 入気定日加減数の要素数を返す
50
+ #
51
+ # @note 継承のためクラスメソッドにしない
52
+ #
53
+ # @return [Integer] 入気定日加減数の要素数
54
+ #
55
+ def interval_size
56
+ Interval.size
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../calculation/stella/solar/choukei_value'
4
+
5
+ require_relative '../../const/number'
6
+
7
+ require_relative './adjustment'
8
+
9
+ # :nodoc:
10
+ module Zakuro
11
+ # :nodoc:
12
+ module Gihou
13
+ # :nodoc:
14
+ module Solar
15
+ #
16
+ # Value 太陽補正値
17
+ #
18
+ module Value
19
+ #
20
+ # 太陽の運行による補正値を算出する
21
+ #
22
+ # @param [SolarTerm] solar_location 入定気
23
+ #
24
+ # @return [Integer] 補正値
25
+ #
26
+ def self.get(solar_location:)
27
+ remainder = solar_location.remainder
28
+
29
+ row = Adjustment.specify(index: solar_location.index)
30
+
31
+ Calculation::Solar::ChoukeiValue.get(remainder: remainder, row: row)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -18,7 +18,7 @@ module Zakuro
18
18
  module Cycle
19
19
  # @return [Integer] 統法(1日=8400分)
20
20
  DAY = 8400
21
- # @return [Integer] 暦周(1近日点)
21
+ # @return [Float] 暦周(1近点月)
22
22
  ANOMALISTIC_MONTH = 231_458.19
23
23
  # @return [Integer] 朔望月
24
24
  SYNODIC_MONTH = 248_057
@@ -20,6 +20,9 @@ module Zakuro
20
20
  module Solar
21
21
  # @return [Cycle::Remainder] 気策(24分の1年)
22
22
  SOLAR_TERM_AVERAGE = Cycle::Remainder.new(day: 15, minute: 1835, second: 5)
23
+ #
24
+ # @note 章月 248057 = 29-4457
25
+ #
23
26
  # @return [Cycle::Remainder] 弦(1分=8秒)
24
27
  QUARTER = Cycle::Remainder.new(day: 7, minute: 3214, second: 2)
25
28
  end
@@ -29,11 +32,14 @@ module Zakuro
29
32
  #
30
33
  module Lunar
31
34
  # @return [Cycle::LunarRemainder] 暦中日
32
- # @note ANOMALISTIC_MONTH の半分に相当する
35
+ # @note ANOMALISTIC_MONTH (1近点月)の半分に相当する
33
36
  HALF_ANOMALISTIC_MONTH = \
34
37
  Cycle::LunarRemainder.new(day: 13, minute: 6529, second: 9.5)
35
38
  # @return [Cycle::LunarRemainder] 入暦上限
36
39
  LIMIT = Cycle::LunarRemainder.new(day: 14, minute: 6529, second: 0)
40
+ #
41
+ # @note 章月 248057 = 29-4457
42
+ #
37
43
  # @return [Cycle::LunarRemainder] 弦(1分=100秒)
38
44
  QUARTER = Cycle::LunarRemainder.new(day: 7, minute: 3214, second: 25)
39
45
  end
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../../../calculation/cycle/abstract_solar_term'
4
+
5
+ require_relative '../const/remainder'
6
+
4
7
  require_relative './remainder'
5
8
 
6
9
  # :nodoc:
@@ -14,7 +17,7 @@ module Zakuro
14
17
  #
15
18
  class SolarTerm < Calculation::Cycle::AbstractSolarTerm
16
19
  # @return [Remainder] 気策(24分の1年)
17
- SOLAR_TERM_AVERAGE = Remainder.new(day: 15, minute: 1835, second: 5)
20
+ SOLAR_TERM_AVERAGE = Const::Remainder::Solar::SOLAR_TERM_AVERAGE
18
21
 
19
22
  #
20
23
  # 初期化
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../../output/logger'
3
+ require_relative '../../../calculation/monthly/abstract_lunar_phase'
4
4
 
5
5
  require_relative '../const/remainder'
6
6
 
@@ -21,108 +21,32 @@ module Zakuro
21
21
  #
22
22
  # LunarPhase 月の位相
23
23
  #
24
- class LunarPhase
24
+ class LunarPhase < Calculation::Monthly::AbstractLunarPhase
25
25
  # @return [Cycle::Remainder] 弦
26
26
  QUARTER = Const::Remainder::Solar::QUARTER
27
27
 
28
- # @return [Output::Logger] ロガー
29
- LOGGER = Output::Logger.new(location: 'lunar_phase')
30
-
31
- # @return [Array<String>] 月内の弦
32
- PHASE_INDEXES = %w[朔日 上弦 望月 下弦].freeze
33
-
34
- # @return [Remainder]] 経
35
- attr_reader :average_remainder
36
- # @return [SolarTerm] 二十四節気(入定気)
37
- attr_reader :solar_term
38
- # @return [Integer] 弦
39
- attr_reader :phase_index
40
-
41
28
  #
42
29
  # 初期化
43
30
  #
44
31
  # @param [Integer] western_year 西暦年
45
32
  #
46
33
  def initialize(western_year:)
47
- # 経
48
- @average_remainder = Origin::AverageNovember.get(western_year: western_year)
49
34
  # 天正閏余
50
35
  lunar_age = Origin::LunarAge.get(western_year: western_year)
51
- # 入定気
52
- @solar_location = Solar::Location.new(lunar_age: lunar_age)
53
- # 入暦
54
- @lunar_location = Lunar::Location.new(
55
- western_year: western_year,
56
- lunar_age: Cycle::LunarRemainder.new(total: 0).add!(lunar_age)
57
- )
58
-
59
- # 弦
60
- @phase_index = 0
61
- end
62
-
63
- #
64
- # 次の弦に進める
65
- #
66
- # @return [Remainder] 定朔
67
- #
68
- def next_phase
69
- adjusted = current_remainder
70
-
71
- add_quarter_moon_size
72
36
 
73
- adjusted
74
- end
75
-
76
- #
77
- # 次の月に進める
78
- # @note 進めた後の月の定朔ではなく、当月のものを返却する
79
- #
80
- # @return [Remainder] 当月初の定朔
81
- #
82
- def next_month
83
- result = nil
84
- PHASE_INDEXES.each_with_index do |_phase, index|
85
- adjust = next_phase
86
- result = adjust if index.zero?
87
- end
88
-
89
- result
37
+ super(
38
+ quater: QUARTER,
39
+ average_remainder: Origin::AverageNovember.get(western_year: western_year),
40
+ solar_location: Solar::Location.new(lunar_age: lunar_age),
41
+ lunar_location: Lunar::Location.new(
42
+ western_year: western_year,
43
+ lunar_age: Cycle::LunarRemainder.new(total: 0).add!(lunar_age)
44
+ )
45
+ )
90
46
  end
91
47
 
92
48
  private
93
49
 
94
- #
95
- # 次の弦に進める
96
- #
97
- # @return [Integer] 弦
98
- #
99
- def next_phase_index
100
- @phase_index += 1
101
- @phase_index = 0 if @phase_index >= PHASE_INDEXES.size
102
- @phase_index
103
- end
104
-
105
- #
106
- # 朔月(月初)であるか
107
- #
108
- # @return [True] 朔月である
109
- # @return [False] 朔月ではない
110
- #
111
- def first_phase?
112
- @phase_index.zero?
113
- end
114
-
115
- #
116
- # 朔月のみログ出力する
117
- #
118
- # @param [String] messages メッセージ(可変長)
119
- #
120
- def debug(*messages)
121
- return unless first_phase?
122
-
123
- LOGGER.debug(*messages)
124
- end
125
-
126
50
  # :reek:TooManyStatements { max_statements: 6 }
127
51
 
128
52
  #
@@ -144,22 +68,6 @@ module Zakuro
144
68
  adjusted
145
69
  end
146
70
 
147
- #
148
- # 補正値を得る
149
- #
150
- # @return [Integer] 補正値
151
- #
152
- def correction_value
153
- sun = correction_solar_value
154
- moon = correction_moon_value
155
-
156
- sum = sun + moon
157
-
158
- debug("sun: #{sun}", "moon: #{moon}", "sun + moon : #{sum}")
159
-
160
- sum
161
- end
162
-
163
71
  #
164
72
  # 太陽運動の補正値を得る
165
73
  #
@@ -191,14 +99,6 @@ module Zakuro
191
99
 
192
100
  Lunar::Value.get(remainder: remainder, forward: forward)
193
101
  end
194
-
195
- def add_quarter_moon_size
196
- @average_remainder.add!(QUARTER)
197
- @solar_location.add_quarter
198
- @lunar_location.add_quarter
199
-
200
- next_phase_index
201
- end
202
102
  end
203
103
  end
204
104
  end