zakuro 0.7.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +48 -13
- data/VERSION +1 -1
- data/doc/dropped_date.md +93 -0
- data/doc/error.md +45 -0
- data/doc/operation/csv/month.csv +100 -79
- data/doc/operation/operation.xlsx +0 -0
- data/lib/zakuro/calculation/base/day.rb +52 -0
- data/lib/zakuro/calculation/base/gengou.rb +5 -5
- data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
- data/lib/zakuro/calculation/base/operated_year.rb +26 -24
- data/lib/zakuro/calculation/base/year.rb +7 -7
- data/lib/zakuro/calculation/cycle/abstract_remainder.rb +55 -47
- data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +28 -24
- data/lib/zakuro/calculation/cycle/zodiac.rb +22 -20
- data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +38 -29
- data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
- data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
- data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +16 -16
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +58 -35
- data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +3 -3
- data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +111 -113
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +6 -6
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +7 -9
- data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +22 -20
- data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
- data/lib/zakuro/calculation/era/version/version.rb +12 -10
- data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
- data/lib/zakuro/calculation/monthly/const.rb +18 -0
- data/lib/zakuro/calculation/monthly/initialized_month.rb +40 -38
- data/lib/zakuro/calculation/monthly/month.rb +17 -17
- data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
- data/lib/zakuro/calculation/monthly/operated_month.rb +37 -86
- data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
- data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
- data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
- data/lib/zakuro/calculation/range/abstract_full_range.rb +40 -25
- data/lib/zakuro/calculation/range/abstract_operation_range.rb +111 -109
- data/lib/zakuro/calculation/range/dated_full_range.rb +1 -1
- data/lib/zakuro/calculation/range/dated_operation_range.rb +1 -1
- data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
- data/lib/zakuro/calculation/range/named_full_range.rb +1 -1
- data/lib/zakuro/calculation/range/named_operation_range.rb +1 -1
- data/lib/zakuro/calculation/range/operated_solar_term.rb +220 -0
- data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
- data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
- data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
- data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
- data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
- data/lib/zakuro/calculation/stella/solar/abstract_location.rb +7 -5
- data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
- data/lib/zakuro/calculation/summary/internal/day.rb +42 -0
- data/lib/zakuro/calculation/summary/internal/month.rb +32 -11
- data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
- data/lib/zakuro/calculation/summary/internal/option.rb +101 -0
- data/lib/zakuro/calculation/summary/japan/range.rb +145 -118
- data/lib/zakuro/calculation/summary/japan/single.rb +87 -87
- data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +57 -50
- data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
- data/lib/zakuro/calculation/summary/western/range.rb +95 -92
- data/lib/zakuro/calculation/summary/western/single.rb +78 -76
- data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +123 -119
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +63 -56
- data/lib/zakuro/calculation/type/old_float.rb +2 -2
- data/lib/zakuro/calculation/type/optional.rb +46 -0
- data/lib/zakuro/condition.rb +142 -92
- data/lib/zakuro/context/context.rb +44 -0
- data/lib/zakuro/context/option.rb +119 -0
- data/lib/zakuro/context/version_class_resolver.rb +112 -0
- data/lib/zakuro/era/japan/calendar.rb +35 -33
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +8 -4
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +117 -118
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +7 -5
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +20 -14
- data/lib/zakuro/era/japan/gengou/alignment.rb +27 -25
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +51 -34
- data/lib/zakuro/era/japan/gengou/resource/type.rb +45 -37
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +34 -32
- data/lib/zakuro/era/japan/gengou.rb +28 -26
- data/lib/zakuro/era/japan/version.rb +18 -16
- data/lib/zakuro/era/western/calendar.rb +104 -88
- data/lib/zakuro/exception/case/pattern.rb +39 -3
- data/lib/zakuro/exception/case/preset.rb +2 -2
- data/lib/zakuro/exception/exception.rb +17 -15
- data/lib/zakuro/exception/zakuro_error.rb +19 -1
- data/lib/zakuro/gateway/locale/date.rb +2 -2
- data/lib/zakuro/gateway/locale/range.rb +3 -3
- data/lib/zakuro/gateway/range.rb +3 -3
- data/lib/zakuro/gateway/single.rb +14 -3
- data/lib/zakuro/merchant.rb +79 -9
- data/lib/zakuro/operation/month/parser.rb +252 -249
- data/lib/zakuro/operation/month/type.rb +17 -8
- data/lib/zakuro/operation/month/validator.rb +148 -144
- data/lib/zakuro/operation/operation.rb +38 -36
- data/lib/zakuro/operation/yaml/month.yaml +955 -281
- data/lib/zakuro/output/response.rb +107 -141
- data/lib/zakuro/result/data/option/abstract_option.rb +37 -0
- data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
- data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
- data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
- data/lib/zakuro/result/data/single_day.rb +9 -1
- data/lib/zakuro/result/operation/month/annotation.rb +2 -2
- data/lib/zakuro/result/operation/month/history.rb +2 -2
- data/lib/zakuro/result/operation/month.rb +31 -0
- data/lib/zakuro/result/operation.rb +39 -0
- data/lib/zakuro/result/result.rb +3 -3
- data/lib/zakuro/tools/stringifier.rb +67 -42
- data/lib/zakuro/tools/typeconv.rb +17 -15
- data/lib/zakuro/tools/typeof.rb +15 -13
- data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
- data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
- data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -37
- data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -47
- data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
- data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
- data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
- data/lib/zakuro/version/genka/cycle/remainder.rb +4 -4
- data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
- data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
- data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
- data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
- data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
- data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -37
- data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -47
- data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
- data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
- data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
- data/lib/zakuro/version/senmyou/const/remainder.rb +7 -1
- data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
- data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +10 -10
- data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
- data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -36
- data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -34
- data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
- data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
- data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
- metadata +27 -7
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -218
- data/lib/zakuro/result/operation/month/bundle.rb +0 -36
- data/lib/zakuro/result/operation/operation.rb +0 -44
- data/lib/zakuro/version/context.rb +0 -44
- data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -10,6 +10,9 @@ module Zakuro
|
|
10
10
|
# AbstractAverage 平気(太陽軌道平均)
|
11
11
|
#
|
12
12
|
class AbstractAverage
|
13
|
+
# @return [Cycle::AbstractSolarTerm] 入定気
|
14
|
+
attr_reader :solar_term
|
15
|
+
|
13
16
|
#
|
14
17
|
# 初期化
|
15
18
|
#
|
@@ -41,30 +44,32 @@ module Zakuro
|
|
41
44
|
|
42
45
|
# :reek:TooManyStatements { max_statements: 7 }
|
43
46
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
47
|
+
class << self
|
48
|
+
#
|
49
|
+
# 月内(当月朔日から当月末日(来月朔日の前日)の間)に二十四節気があるか
|
50
|
+
# @note 大余60で一巡するため 以下2パターンがある
|
51
|
+
# * current_month <= next_month : (二十四節気) >= current_month && (二十四節気) < next_month
|
52
|
+
# * current_month > next_month : (二十四節気) >= current_month || (二十四節気) < next_month
|
53
|
+
#
|
54
|
+
# @param [Cycle::AbstractRemainder] solar_term 二十四節気
|
55
|
+
# @param [Cycle::AbstractRemainder] current_month 月初
|
56
|
+
# @param [Cycle::AbstractRemainder] next_month 月末
|
57
|
+
#
|
58
|
+
# @return [True] 対象の二十四節気がある
|
59
|
+
# @return [False] 対象の二十四節気がない
|
60
|
+
#
|
61
|
+
def in_solar_term?(solar_term:, current_month:, next_month:)
|
62
|
+
# 大余で比較する
|
63
|
+
target_time = solar_term.day
|
64
|
+
current_month_time = current_month.day
|
65
|
+
next_month_time = next_month.day
|
66
|
+
current_month_over = (target_time >= current_month_time)
|
67
|
+
next_month_under = (target_time < next_month_time)
|
64
68
|
|
65
|
-
|
69
|
+
return current_month_over && next_month_under if current_month_time <= next_month_time
|
66
70
|
|
67
|
-
|
71
|
+
current_month_over || next_month_under
|
72
|
+
end
|
68
73
|
end
|
69
74
|
|
70
75
|
private
|
@@ -83,8 +88,8 @@ module Zakuro
|
|
83
88
|
# * 閏月は1回しか設定しない
|
84
89
|
# * 最大2回設定する(中気・節気)
|
85
90
|
(0..3).each do |_index|
|
86
|
-
in_range =
|
87
|
-
solar_term:
|
91
|
+
in_range = self.class.in_solar_term?(
|
92
|
+
solar_term: solar_term.remainder, current_month: current_month.remainder,
|
88
93
|
next_month: next_month.remainder
|
89
94
|
)
|
90
95
|
|
@@ -97,7 +102,7 @@ module Zakuro
|
|
97
102
|
next
|
98
103
|
end
|
99
104
|
|
100
|
-
current_month.add_term(term:
|
105
|
+
current_month.add_term(term: solar_term.clone)
|
101
106
|
next_solar_term
|
102
107
|
|
103
108
|
# 定気は最大2つまで
|
@@ -109,7 +114,7 @@ module Zakuro
|
|
109
114
|
# 次の二十四節気に移る
|
110
115
|
#
|
111
116
|
def next_solar_term
|
112
|
-
|
117
|
+
solar_term.next_term!
|
113
118
|
end
|
114
119
|
end
|
115
120
|
end
|
@@ -58,7 +58,7 @@ module Zakuro
|
|
58
58
|
# 弦の分だけ太陽地点を進める
|
59
59
|
#
|
60
60
|
def add_quarter
|
61
|
-
|
61
|
+
remainder.add!(quarter)
|
62
62
|
end
|
63
63
|
|
64
64
|
#
|
@@ -105,6 +105,8 @@ module Zakuro
|
|
105
105
|
#
|
106
106
|
# 初回の入定気を定める
|
107
107
|
#
|
108
|
+
# @raise [ArgumentError] 引数エラー
|
109
|
+
#
|
108
110
|
def define_first
|
109
111
|
# 入定気の起算方法
|
110
112
|
# 概要:
|
@@ -149,12 +151,12 @@ module Zakuro
|
|
149
151
|
def prev(index:)
|
150
152
|
interval = interval(index: index)
|
151
153
|
if remainder > interval
|
152
|
-
|
154
|
+
remainder.sub!(interval)
|
153
155
|
return
|
154
156
|
end
|
155
157
|
|
156
158
|
# 入定気が確定する
|
157
|
-
@remainder = interval.sub(
|
159
|
+
@remainder = interval.sub(remainder)
|
158
160
|
@index = index
|
159
161
|
end
|
160
162
|
|
@@ -163,7 +165,7 @@ module Zakuro
|
|
163
165
|
#
|
164
166
|
def next_index
|
165
167
|
@index += 1
|
166
|
-
@index = 0 if
|
168
|
+
@index = 0 if index >= interval_size
|
167
169
|
end
|
168
170
|
|
169
171
|
#
|
@@ -174,7 +176,7 @@ module Zakuro
|
|
174
176
|
# 現在の二十四節気に留まる
|
175
177
|
return if remainder < interval
|
176
178
|
|
177
|
-
|
179
|
+
remainder.sub!(interval)
|
178
180
|
|
179
181
|
next_index
|
180
182
|
|
@@ -15,121 +15,121 @@ module Zakuro
|
|
15
15
|
# @return [Output::Logger] ロガー
|
16
16
|
LOGGER = Output::Logger.new(location: 'solar_choukei')
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
18
|
+
class << self
|
19
|
+
#
|
20
|
+
# 補正値を返す
|
21
|
+
#
|
22
|
+
# @param [Cycle::AbstractRemainder] remainder 大余小余
|
23
|
+
# @param [Adjustment::Row] row 24気損益眺朒(ちょうじく)数
|
24
|
+
#
|
25
|
+
# @return [Integer] 補正値
|
26
|
+
#
|
27
|
+
def get(remainder:, row:)
|
28
|
+
# 損益率/眺朒(ちょうじく)数
|
29
|
+
# パラメータ:
|
30
|
+
# a: 眺朒(ちょうじく)数の初日の値
|
31
|
+
# b: 損益率初日の値
|
32
|
+
# c: 損益率の毎日の差
|
33
|
+
# n: 定気の日から数えた日数
|
34
|
+
|
35
|
+
# LOGGER.debug("row.per_day: #{row.per_day}")
|
36
|
+
# LOGGER.debug("row.stack: #{row.stack}")
|
37
|
+
|
38
|
+
day_stack = calc_day_stack(remainder: remainder, row: row)
|
39
|
+
|
40
|
+
# LOGGER.debug("day_stack: #{day_stack}")
|
41
|
+
|
42
|
+
month_stack = calc_month_stack(row: row, day: remainder.day)
|
43
|
+
|
44
|
+
# LOGGER.debug("month_stack: #{month_stack}")
|
45
|
+
|
46
|
+
# 冬至であれば眺朒数がプラスになり続けて損益率が「益」で、小雪であればマイナスの眺朒数がプラスされ続けて「損」
|
47
|
+
month_stack + day_stack
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
#
|
53
|
+
# 損益率を求める
|
54
|
+
#
|
55
|
+
# @param [Remainder] remainder 入定気
|
56
|
+
# @param [Adjustment::Row] row 24気損益眺朒(ちょうじく)数
|
57
|
+
#
|
58
|
+
# @return [Integer] 損益率
|
59
|
+
#
|
60
|
+
def calc_day_stack(remainder:, row:)
|
61
|
+
ratio = calc_ratio(day: remainder.day, per_term: row.per_term, per_day: row.per_day)
|
62
|
+
|
63
|
+
# LOGGER.debug("ratio.sign: #{ratio.sign}")
|
64
|
+
# LOGGER.debug("ratio.abs: #{ratio.abs}")
|
65
|
+
|
66
|
+
calc_day_stack_from_ratio(
|
67
|
+
ratio: ratio, minute: remainder.minute, limit: remainder.base_day
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# 大余に対応する損益率を求める
|
73
|
+
# 損益率 = b + n * c
|
74
|
+
#
|
75
|
+
# @param [Integer] day 大余
|
76
|
+
# @param [Integer] per_term 眺朒(ちょうじく)数
|
77
|
+
# @param [Integer] per_day 毎日差
|
78
|
+
#
|
79
|
+
# @return [Type::OldFloat] 大余に対応する損益率
|
80
|
+
#
|
81
|
+
def calc_ratio(day:, per_term:, per_day:)
|
82
|
+
ratio = Type::OldFloat.new(per_term + day * per_day)
|
83
|
+
# 小数点以下は無視する
|
84
|
+
ratio.floor!
|
85
|
+
|
86
|
+
ratio
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# 小余を含めた損益率を求める
|
91
|
+
#
|
92
|
+
# @param [Integer] sign 正負(大余に対応する損益率)
|
93
|
+
# @param [Integer] ratio 大余に対応する損益率
|
94
|
+
# @param [Integer] minute 小余
|
95
|
+
#
|
96
|
+
# @return [Integer] 小余を含めた損益率
|
97
|
+
#
|
98
|
+
def calc_day_stack_from_ratio(ratio:, minute:, limit:)
|
99
|
+
minute_stack = ratio.abs * minute
|
100
|
+
day_stack = (minute_stack / limit).floor
|
101
|
+
# 四捨五入
|
102
|
+
# NOTE 資料では「この余りが4200をこえていれば切り上げる」とあり「>=」とした
|
103
|
+
# 1612年の7月(慶長17年7月)が境界値4200だが、繰り上げを行なっていたため
|
104
|
+
day_stack += 1 if minute_stack % limit >= (limit / 2)
|
105
|
+
day_stack *= ratio.sign
|
106
|
+
|
107
|
+
day_stack
|
108
|
+
end
|
109
|
+
|
110
|
+
#
|
111
|
+
# 眺朒(ちょうじく)数を求める
|
112
|
+
# 眺朒(ちょうじく)数 = a + (n * b) + (1/2)n(n-1)c
|
113
|
+
#
|
114
|
+
# @param [Adjustment::Row] row 24気損益眺朒(ちょうじく)数
|
115
|
+
# @param [Integer] day 大余
|
116
|
+
#
|
117
|
+
# @return [Integer] 眺朒(ちょうじく)数
|
118
|
+
#
|
119
|
+
def calc_month_stack(row:, day:)
|
120
|
+
# row.stack: 眺朒(ちょうじく)積
|
121
|
+
# row.per_term: 眺朒(ちょうじく)数
|
122
|
+
# row.per_day: 毎日差
|
123
|
+
month_stack = Type::OldFloat.new(
|
124
|
+
row.stack + day * row.per_term + \
|
125
|
+
(1 / 2.0) * (day * (day - 1) * row.per_day)
|
126
|
+
)
|
127
|
+
# 切り捨て(プラスマイナスに関わらず小数点以下切り捨て)
|
128
|
+
month_stack.floor!
|
129
|
+
|
130
|
+
month_stack.get
|
131
|
+
end
|
47
132
|
end
|
48
|
-
|
49
|
-
#
|
50
|
-
# 損益率を求める
|
51
|
-
#
|
52
|
-
# @param [Remainder] remainder 入定気
|
53
|
-
# @param [Adjustment::Row] row 24気損益眺朒(ちょうじく)数
|
54
|
-
#
|
55
|
-
# @return [Integer] 損益率
|
56
|
-
#
|
57
|
-
def self.calc_day_stack(remainder:, row:)
|
58
|
-
ratio = calc_ratio(day: remainder.day, per_term: row.per_term, per_day: row.per_day)
|
59
|
-
|
60
|
-
# LOGGER.debug("ratio.sign: #{ratio.sign}")
|
61
|
-
# LOGGER.debug("ratio.abs: #{ratio.abs}")
|
62
|
-
|
63
|
-
calc_day_stack_from_ratio(
|
64
|
-
ratio: ratio, minute: remainder.minute, limit: remainder.base_day
|
65
|
-
)
|
66
|
-
end
|
67
|
-
private_class_method :calc_day_stack
|
68
|
-
|
69
|
-
#
|
70
|
-
# 大余に対応する損益率を求める
|
71
|
-
# 損益率 = b + n * c
|
72
|
-
#
|
73
|
-
# @param [Integer] day 大余
|
74
|
-
# @param [Integer] per_term 眺朒(ちょうじく)数
|
75
|
-
# @param [Integer] per_day 毎日差
|
76
|
-
#
|
77
|
-
# @return [Type::OldFloat] 大余に対応する損益率
|
78
|
-
#
|
79
|
-
def self.calc_ratio(day:, per_term:, per_day:)
|
80
|
-
ratio = Type::OldFloat.new(per_term + day * per_day)
|
81
|
-
# 小数点以下は無視する
|
82
|
-
ratio.floor!
|
83
|
-
|
84
|
-
ratio
|
85
|
-
end
|
86
|
-
private_class_method :calc_ratio
|
87
|
-
|
88
|
-
#
|
89
|
-
# 小余を含めた損益率を求める
|
90
|
-
#
|
91
|
-
# @param [Integer] sign 正負(大余に対応する損益率)
|
92
|
-
# @param [Integer] ratio 大余に対応する損益率
|
93
|
-
# @param [Integer] minute 小余
|
94
|
-
#
|
95
|
-
# @return [Integer] 小余を含めた損益率
|
96
|
-
#
|
97
|
-
def self.calc_day_stack_from_ratio(ratio:, minute:, limit:)
|
98
|
-
minute_stack = ratio.abs * minute
|
99
|
-
day_stack = (minute_stack / limit).floor
|
100
|
-
# 四捨五入
|
101
|
-
# NOTE 資料では「この余りが4200をこえていれば切り上げる」とあり「>=」とした
|
102
|
-
# 1612年の7月(慶長17年7月)が境界値4200だが、繰り上げを行なっていたため
|
103
|
-
day_stack += 1 if minute_stack % limit >= (limit / 2)
|
104
|
-
day_stack *= ratio.sign
|
105
|
-
|
106
|
-
day_stack
|
107
|
-
end
|
108
|
-
private_class_method :calc_day_stack_from_ratio
|
109
|
-
|
110
|
-
#
|
111
|
-
# 眺朒(ちょうじく)数を求める
|
112
|
-
# 眺朒(ちょうじく)数 = a + (n * b) + (1/2)n(n-1)c
|
113
|
-
#
|
114
|
-
# @param [Adjustment::Row] row 24気損益眺朒(ちょうじく)数
|
115
|
-
# @param [Integer] day 大余
|
116
|
-
#
|
117
|
-
# @return [Integer] 眺朒(ちょうじく)数
|
118
|
-
#
|
119
|
-
def self.calc_month_stack(row:, day:)
|
120
|
-
# row.stack: 眺朒(ちょうじく)積
|
121
|
-
# row.per_term: 眺朒(ちょうじく)数
|
122
|
-
# row.per_day: 毎日差
|
123
|
-
month_stack = Type::OldFloat.new(
|
124
|
-
row.stack + day * row.per_term + \
|
125
|
-
(1 / 2.0) * (day * (day - 1) * row.per_day)
|
126
|
-
)
|
127
|
-
# 切り捨て(プラスマイナスに関わらず小数点以下切り捨て)
|
128
|
-
month_stack.floor!
|
129
|
-
|
130
|
-
month_stack.get
|
131
|
-
end
|
132
|
-
private_class_method :calc_month_stack
|
133
133
|
end
|
134
134
|
end
|
135
135
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../calculation/base/day'
|
4
|
+
require_relative '../../../era/western/calendar'
|
5
|
+
|
6
|
+
# :nodoc:
|
7
|
+
module Zakuro
|
8
|
+
# :nodoc:
|
9
|
+
module Calculation
|
10
|
+
# :nodoc:
|
11
|
+
module Summary
|
12
|
+
#
|
13
|
+
# Day 特定日
|
14
|
+
#
|
15
|
+
module Day
|
16
|
+
class << self
|
17
|
+
#
|
18
|
+
# 日を取得する
|
19
|
+
#
|
20
|
+
# @param [Month] month 月
|
21
|
+
# @param [Western::Calendar] date 現在西暦日
|
22
|
+
#
|
23
|
+
# @return [Calculation::Base::Day] 特定日
|
24
|
+
#
|
25
|
+
def get(month:, date: Western::Calendar.new)
|
26
|
+
first_date = month.western_date
|
27
|
+
days = date - first_date
|
28
|
+
remainder = month.remainder
|
29
|
+
remainder = remainder.add(
|
30
|
+
# 常に参照元のRemainderクラスで生成する
|
31
|
+
remainder.class.new(day: days, minute: 0, second: 0)
|
32
|
+
)
|
33
|
+
|
34
|
+
Calculation::Base::Day.new(
|
35
|
+
number: days + 1, western_date: date, remainder: remainder
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
require_relative '../../../output/response'
|
4
4
|
|
5
|
+
require_relative './day'
|
6
|
+
require_relative './option'
|
7
|
+
|
5
8
|
# :nodoc:
|
6
9
|
module Zakuro
|
7
10
|
# :nodoc:
|
@@ -12,6 +15,8 @@ module Zakuro
|
|
12
15
|
# Month 特定月
|
13
16
|
#
|
14
17
|
class Month
|
18
|
+
# @return [Context::Context] 暦コンテキスト
|
19
|
+
attr_reader :context
|
15
20
|
# @return [Western::Calendar] 西暦開始日
|
16
21
|
attr_reader :start_date
|
17
22
|
# @return [Western::Calendar] 西暦終了日
|
@@ -24,12 +29,14 @@ module Zakuro
|
|
24
29
|
#
|
25
30
|
# 初期化
|
26
31
|
#
|
32
|
+
# @param [Context::Context] context 暦コンテキスト
|
27
33
|
# @param [Western::Calendar] start_date 西暦開始日
|
28
34
|
# @param [Western::Calendar] last_date 西暦終了日
|
29
35
|
# @param [Base::Year] year 年
|
30
36
|
# @param [Monthly::Month] month 月
|
31
37
|
#
|
32
|
-
def initialize(start_date:, last_date:, year:, month:)
|
38
|
+
def initialize(context:, start_date:, last_date:, year:, month:)
|
39
|
+
@context = context
|
33
40
|
@start_date = start_date
|
34
41
|
@last_date = last_date
|
35
42
|
@year = year
|
@@ -43,19 +50,14 @@ module Zakuro
|
|
43
50
|
#
|
44
51
|
def get
|
45
52
|
result = []
|
46
|
-
first_date =
|
53
|
+
first_date = month.western_date.clone
|
47
54
|
|
48
|
-
(0
|
55
|
+
(0..month.days).each do |index|
|
49
56
|
current_date = first_date.clone + index
|
50
57
|
|
51
58
|
next unless include?(date: current_date)
|
52
59
|
|
53
|
-
day =
|
54
|
-
param: Output::Response::SingleDay::Param.new(
|
55
|
-
year: @year, month: @month,
|
56
|
-
date: current_date, days: index
|
57
|
-
)
|
58
|
-
)
|
60
|
+
day = single_day(current_date: current_date)
|
59
61
|
|
60
62
|
result.push(day)
|
61
63
|
end
|
@@ -72,12 +74,31 @@ module Zakuro
|
|
72
74
|
# @return [False] 含まない
|
73
75
|
#
|
74
76
|
def include?(date:)
|
75
|
-
return false if date <
|
77
|
+
return false if date < start_date
|
76
78
|
|
77
|
-
return false if date >
|
79
|
+
return false if date > last_date
|
78
80
|
|
79
81
|
true
|
80
82
|
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
#
|
87
|
+
# 1日データを取得する
|
88
|
+
#
|
89
|
+
# @param [Western::Calendar] current_date 現在西暦日
|
90
|
+
#
|
91
|
+
# @return [Result::Data::SingleDay] 1日データ
|
92
|
+
#
|
93
|
+
def single_day(current_date:)
|
94
|
+
day = Day.get(month: month, date: current_date)
|
95
|
+
|
96
|
+
options = Option.create(month: month, day: day)
|
97
|
+
|
98
|
+
Output::Response::SingleDay.create(
|
99
|
+
year: year, month: month, day: day, options: options
|
100
|
+
)
|
101
|
+
end
|
81
102
|
end
|
82
103
|
end
|
83
104
|
end
|
@@ -12,86 +12,87 @@ module Zakuro
|
|
12
12
|
# Operation 運用情報
|
13
13
|
#
|
14
14
|
module Operation
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
class << self
|
16
|
+
#
|
17
|
+
# 運用情報を生成する
|
18
|
+
#
|
19
|
+
# @param [Result::Data::SingleDay] calc_date 和暦日(計算値)
|
20
|
+
#
|
21
|
+
# @return [Result::Operation] 運用情報
|
22
|
+
#
|
23
|
+
def create(calc_date: Result::Data::SingleDay.new)
|
24
|
+
first_day = calc_date.month.first_day.western_date
|
25
|
+
operation_history = Zakuro::Operation.specify_history(western_date: first_day)
|
25
26
|
|
26
|
-
|
27
|
+
operation_month = create_operation_month(operation_history: operation_history)
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
Result::Operation.new(
|
30
|
+
operated: !operation_history.invalid?, month: operation_month, original: calc_date
|
31
|
+
)
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
# 月履歴集約情報を生成する
|
35
|
-
#
|
36
|
-
# @param [Operation::MonthHistory] operation_history 変更履歴(月)
|
37
|
-
#
|
38
|
-
# @return [Result::Operation::Month::Bundle] 月履歴集約情報
|
39
|
-
#
|
40
|
-
def self.create_operation_month(operation_history: Operation::MonthHistory.new)
|
41
|
-
return Result::Operation::Month::Bundle.new if operation_history.invalid?
|
34
|
+
private
|
42
35
|
|
43
|
-
|
44
|
-
|
45
|
-
|
36
|
+
#
|
37
|
+
# 月履歴集約情報を生成する
|
38
|
+
#
|
39
|
+
# @param [Operation::MonthHistory] operation_history 変更履歴(月)
|
40
|
+
#
|
41
|
+
# @return [Result::Operation::Month] 月履歴情報
|
42
|
+
#
|
43
|
+
def create_operation_month(operation_history: Operation::MonthHistory.new)
|
44
|
+
return Result::Operation::Month.new if operation_history.invalid?
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
)
|
51
|
-
end
|
52
|
-
private_class_method :create_operation_month
|
46
|
+
parent_operation_history = Zakuro::Operation.specify_history_by_id(
|
47
|
+
id: operation_history.parent_id
|
48
|
+
)
|
53
49
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
# @return [Result::Operation::Month::History] 月別履歴情報
|
60
|
-
#
|
61
|
-
def self.create_operation_month_history(operation_history: Operation::MonthHistory.new)
|
62
|
-
return Result::Operation::Month::History.new if operation_history.invalid?
|
50
|
+
Result::Operation::Month.new(
|
51
|
+
current: create_operation_month_history(operation_history: operation_history),
|
52
|
+
parent: create_operation_month_history(operation_history: parent_operation_history)
|
53
|
+
)
|
54
|
+
end
|
63
55
|
|
64
|
-
|
56
|
+
#
|
57
|
+
# 月別履歴情報を生成する
|
58
|
+
#
|
59
|
+
# @param [Operation::MonthHistory] operation_history 変更履歴(月)
|
60
|
+
#
|
61
|
+
# @return [Result::Operation::Month::History] 月別履歴情報
|
62
|
+
#
|
63
|
+
def create_operation_month_history(operation_history: Operation::MonthHistory.new)
|
64
|
+
return Result::Operation::Month::History.new if operation_history.invalid?
|
65
65
|
|
66
|
-
|
67
|
-
Result::Operation::Month::History.new(
|
68
|
-
id: operation_history.id, western_date: operation_history.western_date.format,
|
69
|
-
page: reference.page, number: reference.number, annotations: annotations
|
70
|
-
)
|
71
|
-
end
|
72
|
-
private_class_method :create_operation_month_history
|
66
|
+
annotations = create_annnotations(operation_history: operation_history)
|
73
67
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
#
|
79
|
-
# @return [Array<Result::Operation::Month::Annotation>] 注釈
|
80
|
-
#
|
81
|
-
def self.create_annnotations(operation_history: Operation::MonthHistory.new)
|
82
|
-
annotations = []
|
83
|
-
operation_history.annotations.each do |annotation|
|
84
|
-
annotations.push(
|
85
|
-
Result::Operation::Month::Annotation.new(
|
86
|
-
description: annotation.description,
|
87
|
-
note: annotation.note
|
88
|
-
)
|
68
|
+
reference = operation_history.reference
|
69
|
+
Result::Operation::Month::History.new(
|
70
|
+
id: operation_history.id, western_date: operation_history.western_date.format,
|
71
|
+
page: reference.page, number: reference.number, annotations: annotations
|
89
72
|
)
|
90
73
|
end
|
91
74
|
|
92
|
-
|
75
|
+
#
|
76
|
+
# 注釈情報を生成する
|
77
|
+
#
|
78
|
+
# @param [Operation::MonthHistory] operation_history 変更履歴(月)
|
79
|
+
#
|
80
|
+
# @return [Array<Result::Operation::Month::Annotation>] 注釈
|
81
|
+
#
|
82
|
+
def create_annnotations(operation_history: Operation::MonthHistory.new)
|
83
|
+
annotations = []
|
84
|
+
operation_history.annotations.each do |annotation|
|
85
|
+
annotations.push(
|
86
|
+
Result::Operation::Month::Annotation.new(
|
87
|
+
description: annotation.description,
|
88
|
+
note: annotation.note
|
89
|
+
)
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
annotations
|
94
|
+
end
|
93
95
|
end
|
94
|
-
private_class_method :create_annnotations
|
95
96
|
end
|
96
97
|
end
|
97
98
|
end
|