ziwei-chart 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ziwei_chart-0.1.0/LICENSE +202 -0
- ziwei_chart-0.1.0/PKG-INFO +109 -0
- ziwei_chart-0.1.0/README.md +81 -0
- ziwei_chart-0.1.0/pyproject.toml +44 -0
- ziwei_chart-0.1.0/setup.cfg +4 -0
- ziwei_chart-0.1.0/src/ziwei_chart/__init__.py +103 -0
- ziwei_chart-0.1.0/src/ziwei_chart/calendar.py +160 -0
- ziwei_chart-0.1.0/src/ziwei_chart/data/60jiazi.json +62 -0
- ziwei_chart-0.1.0/src/ziwei_chart/data/6base_mainstar_location.json +171 -0
- ziwei_chart-0.1.0/src/ziwei_chart/data/sihua_config.json +62 -0
- ziwei_chart-0.1.0/src/ziwei_chart/data/wuhu_config.json +12 -0
- ziwei_chart-0.1.0/src/ziwei_chart/horoscope.py +134 -0
- ziwei_chart-0.1.0/src/ziwei_chart/models.py +343 -0
- ziwei_chart-0.1.0/src/ziwei_chart/natal.py +276 -0
- ziwei_chart-0.1.0/src/ziwei_chart/rules.py +70 -0
- ziwei_chart-0.1.0/src/ziwei_chart/schema/ziwei_chart.v1.json +365 -0
- ziwei_chart-0.1.0/src/ziwei_chart/solar_time.py +85 -0
- ziwei_chart-0.1.0/src/ziwei_chart.egg-info/PKG-INFO +109 -0
- ziwei_chart-0.1.0/src/ziwei_chart.egg-info/SOURCES.txt +25 -0
- ziwei_chart-0.1.0/src/ziwei_chart.egg-info/dependency_links.txt +1 -0
- ziwei_chart-0.1.0/src/ziwei_chart.egg-info/requires.txt +11 -0
- ziwei_chart-0.1.0/src/ziwei_chart.egg-info/top_level.txt +1 -0
- ziwei_chart-0.1.0/tests/test_custom_rules.py +40 -0
- ziwei_chart-0.1.0/tests/test_golden.py +164 -0
- ziwei_chart-0.1.0/tests/test_horoscope.py +95 -0
- ziwei_chart-0.1.0/tests/test_natal.py +77 -0
- ziwei_chart-0.1.0/tests/test_schema.py +56 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ziwei-chart
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Deterministic Zi Wei Dou Shu (紫微斗数) natal chart casting, outputting versioned JSON
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://github.com/suanqiu-oss/ziwei-chart
|
|
7
|
+
Project-URL: Source, https://github.com/suanqiu-oss/ziwei-chart
|
|
8
|
+
Project-URL: Issues, https://github.com/suanqiu-oss/ziwei-chart/issues
|
|
9
|
+
Keywords: ziwei,doushu,astrology,chart,purple-star
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: lunar-python>=1.3
|
|
21
|
+
Requires-Dist: tzdata; platform_system == "Windows"
|
|
22
|
+
Provides-Extra: solar
|
|
23
|
+
Requires-Dist: skyfield>=1.45; extra == "solar"
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
26
|
+
Requires-Dist: jsonschema>=4; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# ziwei-chart
|
|
30
|
+
|
|
31
|
+
确定性紫微斗数排盘库:输入出生时刻(可带经纬度换算真太阳时),输出生辰十二宫
|
|
32
|
+
安星、大限索引与流年/流月视图的带版本号 JSON(`ziwei_chart.v1`)。
|
|
33
|
+
不含任何 AI 解读与星曜释义文本。
|
|
34
|
+
|
|
35
|
+
纯 Python;日历后端为 [lunar-python](https://github.com/6tail/lunar-python)。
|
|
36
|
+
真太阳时(天文中天法)是可选依赖,需 `pip install ziwei-chart[solar]`。
|
|
37
|
+
|
|
38
|
+
## 安装
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install ziwei-chart # 基础(民用时间排盘)
|
|
42
|
+
pip install ziwei-chart[solar] # + 真太阳时(skyfield)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 使用
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from datetime import datetime
|
|
49
|
+
from zoneinfo import ZoneInfo
|
|
50
|
+
|
|
51
|
+
from ziwei_chart import BirthInput, CalendarRules, cast_chart
|
|
52
|
+
|
|
53
|
+
chart = cast_chart(BirthInput(
|
|
54
|
+
datetime=datetime(2004, 4, 25, 9, 20, tzinfo=ZoneInfo("Asia/Shanghai")),
|
|
55
|
+
gender="男",
|
|
56
|
+
longitude=116.39, # 可选;给了就换算真太阳时(需 [solar])
|
|
57
|
+
latitude=39.90,
|
|
58
|
+
))
|
|
59
|
+
chart.to_dict() # 本命盘(ziwei_chart.v1)
|
|
60
|
+
chart.horoscope(year=2026).to_dict() # 大限 + 流年
|
|
61
|
+
chart.horoscope(year=2026, month=3, is_leap=False).to_dict() # 流月
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
已有八字/农历串的应用可以走预算好的日历路径:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
chart = cast_chart(BirthInput(
|
|
68
|
+
gender="女",
|
|
69
|
+
bazi="甲申戊辰甲戌己巳",
|
|
70
|
+
lunar_date_str="2004-03-07 09:20:00",
|
|
71
|
+
))
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`BirthInput.datetime` 必须带 IANA 时区(如 `ZoneInfo("Asia/Shanghai")`)。
|
|
75
|
+
固定偏移的 `datetime.timezone(timedelta(hours=8))` 会被拒绝,因为真太阳时和
|
|
76
|
+
历史夏令时都要按时区名换算。
|
|
77
|
+
|
|
78
|
+
## 默认口径(流派差异参数化)
|
|
79
|
+
|
|
80
|
+
- `CalendarRules(day_rule="zi-early", time_rule="next-day")`:子初换日、
|
|
81
|
+
夜子归次日(与现行 suanqiu 口径一致)。可选 `day_rule="midnight" |
|
|
82
|
+
"solar-midnight"`、`time_rule="midnight" | "prev-day"`。
|
|
83
|
+
- 农历日期本身按民用午夜切日,不跟随日柱换日口径。
|
|
84
|
+
- 四化表可通过 `rules=` 注入自定义版本(如庚干派别分歧):
|
|
85
|
+
`cast_chart(inp, rules=RuleSet.default().with_sihua(my_table))`。
|
|
86
|
+
|
|
87
|
+
## 真太阳时星历
|
|
88
|
+
|
|
89
|
+
`[solar]` extra 依赖 skyfield;DE421 星历(约 17 MB)按以下顺序解析:
|
|
90
|
+
`eph_path` 参数 → 环境变量 `ZIWEI_CHART_EPHEMERIS` → 首次使用时自动下载到
|
|
91
|
+
用户缓存目录。
|
|
92
|
+
|
|
93
|
+
## 输出契约
|
|
94
|
+
|
|
95
|
+
顶层 `schema` 固定为 `ziwei_chart.v1`,JSON Schema 随包发布于
|
|
96
|
+
`ziwei_chart/schema/ziwei_chart.v1.json`。与旧实现的差异:
|
|
97
|
+
|
|
98
|
+
| 字段 | 处理 |
|
|
99
|
+
| --- | --- |
|
|
100
|
+
| `schema` / `input` | 新增;本命盘和大限/流年/流月视图都带 |
|
|
101
|
+
| `horoscope` | 新增,仅视图带:`mode`、`year`、`month`、`is_leap`、`age`,所在大限的 `age_range` / `year_range`,流月斗君元数据 `monthly` |
|
|
102
|
+
| `Star.property`、`Palace.palace_implication` | 删除(释义文本由应用层补回) |
|
|
103
|
+
| `decennial_age_index` 等 range 字符串键 | 改为 `[{start, end, palace_index, ...}]` 列表 |
|
|
104
|
+
|
|
105
|
+
字段有破坏性变更时升级到 v2。
|
|
106
|
+
|
|
107
|
+
## 许可证
|
|
108
|
+
|
|
109
|
+
Apache-2.0,全文见 `LICENSE`。规则表(四化、五虎遁、纳音、主星安星表)整理自公开资料,属传统排盘规则;不含第三方代码。
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# ziwei-chart
|
|
2
|
+
|
|
3
|
+
确定性紫微斗数排盘库:输入出生时刻(可带经纬度换算真太阳时),输出生辰十二宫
|
|
4
|
+
安星、大限索引与流年/流月视图的带版本号 JSON(`ziwei_chart.v1`)。
|
|
5
|
+
不含任何 AI 解读与星曜释义文本。
|
|
6
|
+
|
|
7
|
+
纯 Python;日历后端为 [lunar-python](https://github.com/6tail/lunar-python)。
|
|
8
|
+
真太阳时(天文中天法)是可选依赖,需 `pip install ziwei-chart[solar]`。
|
|
9
|
+
|
|
10
|
+
## 安装
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install ziwei-chart # 基础(民用时间排盘)
|
|
14
|
+
pip install ziwei-chart[solar] # + 真太阳时(skyfield)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 使用
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from datetime import datetime
|
|
21
|
+
from zoneinfo import ZoneInfo
|
|
22
|
+
|
|
23
|
+
from ziwei_chart import BirthInput, CalendarRules, cast_chart
|
|
24
|
+
|
|
25
|
+
chart = cast_chart(BirthInput(
|
|
26
|
+
datetime=datetime(2004, 4, 25, 9, 20, tzinfo=ZoneInfo("Asia/Shanghai")),
|
|
27
|
+
gender="男",
|
|
28
|
+
longitude=116.39, # 可选;给了就换算真太阳时(需 [solar])
|
|
29
|
+
latitude=39.90,
|
|
30
|
+
))
|
|
31
|
+
chart.to_dict() # 本命盘(ziwei_chart.v1)
|
|
32
|
+
chart.horoscope(year=2026).to_dict() # 大限 + 流年
|
|
33
|
+
chart.horoscope(year=2026, month=3, is_leap=False).to_dict() # 流月
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
已有八字/农历串的应用可以走预算好的日历路径:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
chart = cast_chart(BirthInput(
|
|
40
|
+
gender="女",
|
|
41
|
+
bazi="甲申戊辰甲戌己巳",
|
|
42
|
+
lunar_date_str="2004-03-07 09:20:00",
|
|
43
|
+
))
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`BirthInput.datetime` 必须带 IANA 时区(如 `ZoneInfo("Asia/Shanghai")`)。
|
|
47
|
+
固定偏移的 `datetime.timezone(timedelta(hours=8))` 会被拒绝,因为真太阳时和
|
|
48
|
+
历史夏令时都要按时区名换算。
|
|
49
|
+
|
|
50
|
+
## 默认口径(流派差异参数化)
|
|
51
|
+
|
|
52
|
+
- `CalendarRules(day_rule="zi-early", time_rule="next-day")`:子初换日、
|
|
53
|
+
夜子归次日(与现行 suanqiu 口径一致)。可选 `day_rule="midnight" |
|
|
54
|
+
"solar-midnight"`、`time_rule="midnight" | "prev-day"`。
|
|
55
|
+
- 农历日期本身按民用午夜切日,不跟随日柱换日口径。
|
|
56
|
+
- 四化表可通过 `rules=` 注入自定义版本(如庚干派别分歧):
|
|
57
|
+
`cast_chart(inp, rules=RuleSet.default().with_sihua(my_table))`。
|
|
58
|
+
|
|
59
|
+
## 真太阳时星历
|
|
60
|
+
|
|
61
|
+
`[solar]` extra 依赖 skyfield;DE421 星历(约 17 MB)按以下顺序解析:
|
|
62
|
+
`eph_path` 参数 → 环境变量 `ZIWEI_CHART_EPHEMERIS` → 首次使用时自动下载到
|
|
63
|
+
用户缓存目录。
|
|
64
|
+
|
|
65
|
+
## 输出契约
|
|
66
|
+
|
|
67
|
+
顶层 `schema` 固定为 `ziwei_chart.v1`,JSON Schema 随包发布于
|
|
68
|
+
`ziwei_chart/schema/ziwei_chart.v1.json`。与旧实现的差异:
|
|
69
|
+
|
|
70
|
+
| 字段 | 处理 |
|
|
71
|
+
| --- | --- |
|
|
72
|
+
| `schema` / `input` | 新增;本命盘和大限/流年/流月视图都带 |
|
|
73
|
+
| `horoscope` | 新增,仅视图带:`mode`、`year`、`month`、`is_leap`、`age`,所在大限的 `age_range` / `year_range`,流月斗君元数据 `monthly` |
|
|
74
|
+
| `Star.property`、`Palace.palace_implication` | 删除(释义文本由应用层补回) |
|
|
75
|
+
| `decennial_age_index` 等 range 字符串键 | 改为 `[{start, end, palace_index, ...}]` 列表 |
|
|
76
|
+
|
|
77
|
+
字段有破坏性变更时升级到 v2。
|
|
78
|
+
|
|
79
|
+
## 许可证
|
|
80
|
+
|
|
81
|
+
Apache-2.0,全文见 `LICENSE`。规则表(四化、五虎遁、纳音、主星安星表)整理自公开资料,属传统排盘规则;不含第三方代码。
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ziwei-chart"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Deterministic Zi Wei Dou Shu (紫微斗数) natal chart casting, outputting versioned JSON"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
keywords = ["ziwei", "doushu", "astrology", "chart", "purple-star"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.10",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"lunar-python>=1.3",
|
|
25
|
+
"tzdata; platform_system == 'Windows'",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/suanqiu-oss/ziwei-chart"
|
|
30
|
+
Source = "https://github.com/suanqiu-oss/ziwei-chart"
|
|
31
|
+
Issues = "https://github.com/suanqiu-oss/ziwei-chart/issues"
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
solar = ["skyfield>=1.45"]
|
|
35
|
+
dev = ["pytest>=7", "jsonschema>=4"]
|
|
36
|
+
|
|
37
|
+
[tool.setuptools.packages.find]
|
|
38
|
+
where = ["src"]
|
|
39
|
+
|
|
40
|
+
[tool.setuptools.package-data]
|
|
41
|
+
ziwei_chart = ["data/*.json", "schema/*.json"]
|
|
42
|
+
|
|
43
|
+
[tool.pytest.ini_options]
|
|
44
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""ziwei-chart: deterministic Zi Wei Dou Shu natal chart casting.
|
|
2
|
+
|
|
3
|
+
>>> from datetime import datetime
|
|
4
|
+
>>> from zoneinfo import ZoneInfo
|
|
5
|
+
>>> from ziwei_chart import BirthInput, cast_chart
|
|
6
|
+
>>> chart = cast_chart(BirthInput(
|
|
7
|
+
... datetime=datetime(2004, 4, 25, 9, 20, tzinfo=ZoneInfo("Asia/Shanghai")),
|
|
8
|
+
... gender="女"))
|
|
9
|
+
>>> chart.to_dict()["schema"]
|
|
10
|
+
'ziwei_chart.v1'
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from dataclasses import dataclass, field
|
|
15
|
+
from datetime import datetime
|
|
16
|
+
from typing import Literal
|
|
17
|
+
|
|
18
|
+
from .calendar import CalendarRules, resolve_calendar
|
|
19
|
+
from .models import Chart, HoroscopeChart
|
|
20
|
+
from .natal import build_natal_chart
|
|
21
|
+
from .rules import RuleSet
|
|
22
|
+
|
|
23
|
+
Gender = Literal["男", "女"]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass
|
|
27
|
+
class BirthInput:
|
|
28
|
+
"""Birth data for casting.
|
|
29
|
+
|
|
30
|
+
- ``datetime``: aware civil birth datetime with an IANA ZoneInfo.
|
|
31
|
+
- ``gender``: "男" or "女".
|
|
32
|
+
- ``longitude``/``latitude``: optional; when both are given the civil
|
|
33
|
+
time is converted to true solar time (requires the ``[solar]`` extra).
|
|
34
|
+
Place names are resolved by the caller.
|
|
35
|
+
- ``bazi``/``lunar_date_str``: optional precomputed calendar. When both
|
|
36
|
+
are provided they are used as-is and ``datetime`` may be None — this is
|
|
37
|
+
the path used by applications that keep their own calendar service.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
datetime: datetime | None = None
|
|
41
|
+
gender: Gender = "男"
|
|
42
|
+
longitude: float | None = None
|
|
43
|
+
latitude: float | None = None
|
|
44
|
+
bazi: str | None = None
|
|
45
|
+
lunar_date_str: str | None = None
|
|
46
|
+
calendar_rules: CalendarRules = field(default_factory=CalendarRules)
|
|
47
|
+
|
|
48
|
+
def __post_init__(self):
|
|
49
|
+
if self.gender not in ("男", "女"):
|
|
50
|
+
raise ValueError("紫微斗数暂不支持非二元性别")
|
|
51
|
+
has_precomputed = self.bazi is not None or self.lunar_date_str is not None
|
|
52
|
+
if has_precomputed and not (self.bazi and self.lunar_date_str):
|
|
53
|
+
raise ValueError("bazi and lunar_date_str must be provided together")
|
|
54
|
+
if not has_precomputed and self.datetime is None:
|
|
55
|
+
raise ValueError("either datetime or a precomputed bazi/lunar_date_str is required")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def cast_chart(birth_input: BirthInput, rules: RuleSet | None = None) -> Chart:
|
|
59
|
+
"""Cast the natal chart (and unlock horoscope views) from a BirthInput."""
|
|
60
|
+
rules = rules or RuleSet.default()
|
|
61
|
+
if birth_input.bazi and birth_input.lunar_date_str:
|
|
62
|
+
chart = cast_chart_from_calendar(
|
|
63
|
+
bazi=birth_input.bazi, lunar_date_str=birth_input.lunar_date_str,
|
|
64
|
+
gender=birth_input.gender, rules=rules,
|
|
65
|
+
)
|
|
66
|
+
if birth_input.datetime is not None:
|
|
67
|
+
chart.input_receipt["datetime"] = birth_input.datetime.isoformat()
|
|
68
|
+
return chart
|
|
69
|
+
|
|
70
|
+
calendar_info = resolve_calendar(
|
|
71
|
+
birth_input.datetime, birth_input.longitude, birth_input.latitude,
|
|
72
|
+
birth_input.calendar_rules,
|
|
73
|
+
)
|
|
74
|
+
chart = cast_chart_from_calendar(
|
|
75
|
+
bazi=calendar_info.bazi, lunar_date_str=calendar_info.lunar_date_str,
|
|
76
|
+
gender=birth_input.gender, rules=rules,
|
|
77
|
+
)
|
|
78
|
+
chart.calendar = calendar_info
|
|
79
|
+
chart.input_receipt.update(calendar_info.as_receipt())
|
|
80
|
+
if birth_input.datetime is not None:
|
|
81
|
+
chart.input_receipt["datetime"] = birth_input.datetime.isoformat()
|
|
82
|
+
if birth_input.longitude is not None and birth_input.latitude is not None:
|
|
83
|
+
chart.input_receipt["coordinates"] = [birth_input.latitude, birth_input.longitude]
|
|
84
|
+
return chart
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def cast_chart_from_calendar(bazi: str, lunar_date_str: str, gender: str,
|
|
88
|
+
rules: RuleSet | None = None) -> Chart:
|
|
89
|
+
"""Cast the natal chart from a precomputed bazi + lunar_date_str pair."""
|
|
90
|
+
return build_natal_chart(bazi=bazi, lunar_date_str=lunar_date_str,
|
|
91
|
+
gender=gender, rules=rules)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
__all__ = [
|
|
95
|
+
"BirthInput",
|
|
96
|
+
"CalendarRules",
|
|
97
|
+
"Chart",
|
|
98
|
+
"HoroscopeChart",
|
|
99
|
+
"RuleSet",
|
|
100
|
+
"cast_chart",
|
|
101
|
+
"cast_chart_from_calendar",
|
|
102
|
+
]
|
|
103
|
+
__version__ = "0.1.0"
|