zakuro 0.1.5 → 0.5.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/README.md +17 -1
  3. data/doc/gengou.md +22 -22
  4. data/doc/operation/csv/month.csv +468 -202
  5. data/doc/operation/operation.xlsx +0 -0
  6. data/lib/zakuro/calculation/base/operated_year.rb +114 -0
  7. data/lib/zakuro/calculation/base/year.rb +3 -0
  8. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +29 -29
  9. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +169 -0
  10. data/lib/zakuro/calculation/monthly/first_day.rb +1 -1
  11. data/lib/zakuro/calculation/monthly/operated_month.rb +47 -3
  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 +8512 -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 +85 -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/genka/const/number.rb +43 -0
  45. data/lib/zakuro/version/genka/const/remainder.rb +33 -0
  46. data/lib/zakuro/version/genka/cycle/remainder.rb +92 -0
  47. data/lib/zakuro/version/genka/cycle/solar_term.rb +34 -0
  48. data/lib/zakuro/version/genka/genka.rb +19 -2
  49. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +95 -0
  50. data/lib/zakuro/version/genka/range/annual_range.rb +77 -0
  51. data/lib/zakuro/version/genka/stella/origin/first_term.rb +55 -0
  52. data/lib/zakuro/version/genka/stella/origin/january.rb +49 -0
  53. data/lib/zakuro/version/genka/stella/solar/average.rb +41 -0
  54. data/lib/zakuro/version/gihou/const/number.rb +55 -0
  55. data/lib/zakuro/version/gihou/const/remainder.rb +54 -0
  56. data/lib/zakuro/version/gihou/cycle/remainder.rb +82 -0
  57. data/lib/zakuro/version/gihou/cycle/solar_term.rb +34 -0
  58. data/lib/zakuro/version/gihou/gihou.rb +23 -2
  59. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +106 -0
  60. data/lib/zakuro/version/gihou/range/annual_range.rb +39 -0
  61. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +250 -0
  62. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +44 -0
  63. data/lib/zakuro/version/gihou/stella/lunar/location.rb +80 -0
  64. data/lib/zakuro/version/gihou/stella/lunar/value.rb +75 -0
  65. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +34 -0
  66. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +62 -0
  67. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +55 -0
  68. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +93 -0
  69. data/lib/zakuro/version/gihou/stella/solar/average.rb +97 -0
  70. data/lib/zakuro/version/gihou/stella/solar/interval.rb +108 -0
  71. data/lib/zakuro/version/gihou/stella/solar/location.rb +61 -0
  72. data/lib/zakuro/version/gihou/stella/solar/value.rb +36 -0
  73. data/lib/zakuro/version/senmyou/const/number.rb +1 -1
  74. data/lib/zakuro/version/senmyou/const/remainder.rb +7 -3
  75. data/lib/zakuro/version/senmyou/cycle/remainder.rb +27 -6
  76. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +4 -1
  77. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +12 -112
  78. data/lib/zakuro/version/senmyou/range/annual_range.rb +5 -77
  79. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +2 -3
  80. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +13 -34
  81. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +8 -30
  82. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +29 -29
  83. data/lib/zakuro/version/senmyou/stella/solar/average.rb +14 -92
  84. data/lib/zakuro/version/senmyou/stella/solar/location.rb +18 -121
  85. data/lib/zakuro/version/senmyou/stella/solar/value.rb +4 -103
  86. data/lib/zakuro/version/version_class_resolver.rb +12 -0
  87. data/lib/zakuro/version.rb +1 -1
  88. data/lib/zakuro/version_factory.rb +1 -1
  89. metadata +61 -7
  90. data/lib/zakuro/version/taien/taien.rb +0 -19
@@ -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 Gihou
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 Gihou
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 Gihou
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 Gihou
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 Gihou
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 Gihou
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 Gihou
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: +3.9546, per_day: -0.0372), # 冬至(とうじ)
54
+ shoukan: Row.new(stack: +54.0, per_term: +3.4091, per_day: -0.0372), # 小寒(しょうかん)
55
+ daikan: Row.new(stack: +100.0, per_term: +2.8636, per_day: -0.0372), # 大寒(だいかん)
56
+ risshun: Row.new(stack: +138.0, per_term: +2.3181, per_day: +0.0372), # 立春(りっしゅん)
57
+ usui: Row.new(stack: +176.0, per_term: +2.8636, per_day: +0.0372), # 雨水(うすい)
58
+ keichitsu: Row.new(stack: +222.0, per_term: +3.4091, per_day: +0.0372), # 啓蟄(けいちつ)
59
+ shunbun: Row.new(stack: +276.0, per_term: -3.7220, per_day: +0.0329), # 春分(しゅんぶん)
60
+ seimei: Row.new(stack: +222.0, per_term: -3.2086, per_day: +0.0329), # 清明(せいめい)
61
+ kokuu: Row.new(stack: +176.0, per_term: -2.6952, per_day: +0.0329), # 穀雨(こくう)
62
+ rikka: Row.new(stack: +138.0, per_term: -2.1818, per_day: -0.0329), # 立夏(りっか)
63
+ shouman: Row.new(stack: +100.0, per_term: -2.6952, per_day: -0.0329), # 小満(しょうまん)
64
+ boushu: Row.new(stack: +54.0, per_term: -3.2086, per_day: -0.0329), # 芒種(ぼうしゅ)
65
+ geshi: Row.new(stack: 0.0, per_term: -3.7220, per_day: +0.0329), # 夏至(げし)
66
+ shousho: Row.new(stack: -54.0, per_term: -3.2086, per_day: +0.0329), # 小暑(しょうしょ)
67
+ taisho: Row.new(stack: -100.0, per_term: -2.6952, per_day: +0.0329), # 大暑(たいしょ)
68
+ risshuu: Row.new(stack: -138.0, per_term: -2.1818, per_day: -0.0329), # 立秋(りっしゅう)
69
+ shosho: Row.new(stack: -176.0, per_term: -2.6952, per_day: -0.0329), # 処暑(しょしょ)
70
+ hakuro: Row.new(stack: -222.0, per_term: -3.2086, per_day: -0.0329), # 白露(はくろ)
71
+ shuubun: Row.new(stack: -276.0, per_term: +3.9546, per_day: -0.0372), # 秋分(しゅうぶん)
72
+ kanro: Row.new(stack: -222.0, per_term: +3.4091, per_day: -0.0372), # 寒露(かんろ)
73
+ soukou: Row.new(stack: -176.0, per_term: +2.8636, per_day: -0.0372), # 霜降(そうこう)
74
+ rittou: Row.new(stack: -138.0, per_term: +2.3181, per_day: +0.0372), # 立冬(りっとう)
75
+ shousetsu: Row.new(stack: -100.0, per_term: +2.8636, per_day: +0.0372), # 小雪(しょうせつ)
76
+ taisetsu: Row.new(stack: -54.0, per_term: +3.4091, per_day: +0.0372) # 大雪(たいせつ)
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
@@ -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_first_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_first_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.day.zero?
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