数据结构字典

Astrolabe、Palace、Star、Horoscope 每一个字段的类型与含义。

适合:开发者

这一页以序列化后的 JSON 字段名(camelCase)为准,它是三套绑定共用的契约。 各编程语言的命名换算:

命名示例
JSON / 绑定契约camelCaseisBodyPalace
Pythonsnake_caseis_body_palace
GoPascalCaseIsBodyPalace
Rustsnake_case,值为枚举is_body_palace

Astrolabe 星盘

排盘入口的返回值。

字段类型含义
genderstring性别,翻译文本
genderKeystring"male" / "female"
solarDatestring阳历生日,与入参一致
lunarDatestring农历生日的文字表示
chineseDatestring四柱干支展示串
rawDatesRawDates结构化的农历生日与四柱
timestring时辰名,如「寅时」
timeRangestring时辰时间段,如「03:00~05:00」
signstring星座
zodiacstring生肖,按年支
earthlyBranchOfSoulPalacestring命宫地支
earthlyBranchOfSoulPalaceKeystring命宫地支 key
earthlyBranchOfBodyPalacestring身宫地支
earthlyBranchOfBodyPalaceKeystring身宫地支 key
soulstring命主星
soulKeystring命主星 key
bodystring身主星
bodyKeystring身主星 key
fiveElementsClassstring五行局
fiveElementsClassKeystring五行局 key,如 water2nd
palacesPalace[12]十二宫,索引 0 是寅宫
timeIndexint出生时辰索引 0–12,保留原始传入值
fixLeapbool是否修正闰月
languagestring盘面语言
configConfig排盘配置

Palace 宫位

字段类型含义
indexint宫位在盘上的位置,0–11,0 是寅宫
namestring宫名
nameKeystring宫名 key,如 soulPalace
isBodyPalacebool是否身宫
isOriginalPalacebool是否来因宫
heavenlyStemstring宫干
heavenlyStemKeystring宫干 key
earthlyBranchstring宫支
earthlyBranchKeystring宫支 key
majorStarsStar[]主星
minorStarsStar[]辅星
adjectiveStarsStar[]杂耀
changsheng12 / changsheng12Keystring长生十二神
boshi12 / boshi12Keystring博士十二神
jiangqian12 / jiangqian12Keystring将前十二神
suiqian12 / suiqian12Keystring岁前十二神
mutagenStarKeysstring[4]本宫宫干化出的四颗星标识,顺序为禄、权、科、忌;受自定义四化表影响
decadalDecadal该宫掌管的大限
agesint[]小限经过该宫的虚岁列表

Star 星耀

字段类型含义
keystring星耀 key,如 ziweiMaj
namestring星名
typestringmajor / soft / tough / adjective / flower / helper / lucun / tianma
scopestringorigin / decadal / yearly / monthly / daily / hourly
brightnessstring亮度显示文本。主星与辅星恒有这个键,无亮度时为空串;杂耀与流耀整个键缺省
brightnessKeystring?亮度标识。无亮度时缺省(不是空串)
mutagenstring四化显示文本。十四主星与左辅右弼文昌文曲这 18 颗四化候选星恒有这个键,无四化时为空串;其余星整个键缺省
mutagenKeystring?四化标识。无四化时缺省

翻译字段与标识字段的缺省规则相反

brightness / mutagen 这两个翻译字段按星耀类别决定键在不在, 在的时候可能是空串;brightnessKey / mutagenKey 这两个标识字段 则是没值就整个键不出现。

所以「有没有亮度」要判断 brightnessKey 存在与否, 而不是判断 brightness 这个键在不在 —— 后者对所有主辅星都为真。

Decadal 大限

字段类型含义
range[int, int]起止虚岁,含两端
heavenlyStem / heavenlyStemKeystring大限天干
earthlyBranch / earthlyBranchKeystring大限地支

RawDates 结构化日期

字段类型含义
lunarDate.lunarYearint农历年
lunarDate.lunarMonthint农历月 1–12
lunarDate.lunarDayint农历日 1–30
lunarDate.isLeapbool是否闰月
chineseDate.yearly[string, string]年柱 [天干, 地支]
chineseDate.monthly[string, string]月柱
chineseDate.daily[string, string]日柱
chineseDate.hourly[string, string]时柱
chineseDate.yearlyKeys[string, string]年柱的语言无关 key
chineseDate.monthlyKeys[string, string]月柱的语言无关 key
chineseDate.dailyKeys[string, string]日柱的语言无关 key
chineseDate.hourlyKeys[string, string]时柱的语言无关 key

四柱里的干支是未本地化的原文(任何盘面语言下都是中文),做判断请用 *Keys。 把 *Keys 交给 translate_chinese_date 即可得到按语言翻译的展示串, 与顶层 chineseDate 字段逐字一致。

Config 配置

字段取值默认
yearDividenormal / exactnormal
horoscopeDividenormal / exactnormal
ageDividenormal / birthdaynormal
dayDivideforward / currentforward
algorithmdefault / zhongzhoudefault
astroTypeheaven / earth / humanheaven

另有两个只进不出的输入键,用于替换内置数据表:

输入键取值
mutagens{天干标识: [四个星耀标识]},顺序为禄权科忌,必须四项
brightness{星耀标识: [十二个亮度标识]},第一项是寅宫,必须十二项,无亮度处传空串

这两个键不会回显在星盘的 config —— 它们是排盘的输入配置, 不属于排盘结果,加进 DTO 会破坏与 JS iztro 的字段契约。 要留档就自己存那份配置。

含义见 Config 详解

Horoscope 运限

字段类型含义
solarDatestring目标阳历日期
lunarDatestring目标农历日期
decadalHoroscopeScope大限,未起运时为童限
ageHoroscopeScope小限,带 nominalAge
yearlyHoroscopeScope流年,带 yearlyDecStar
monthlyHoroscopeScope流月
dailyHoroscopeScope流日
hourlyHoroscopeScope流时

HoroscopeScope 运限层级

字段类型含义
indexint该运限所在盘上位置 0–11
namestring层级名,翻译文本
heavenlyStem / heavenlyStemKeystring该运限天干
earthlyBranch / earthlyBranchKeystring该运限地支
palaceNamesstring[12]以该运限位置为命宫重排的宫名,按盘上位置排列
palaceNameKeysstring[12]同上的 key 形式
mutagenstring[4]四化星名,顺序为禄、权、科、忌
mutagenKeysstring[4]同上的 key 形式
starsStar[][12]?流耀在十二宫的分布(外层十二项对应宫位,内层是该宫的流耀列表),无流耀的层级缺省
nominalAgeint?虚岁,仅小限有
yearlyDecStarYearlyDecStar?仅流年有

YearlyDecStar 流年十二神

字段类型含义
suiqian12 / suiqian12Keysstring[12]按流年支起的岁前十二神,索引即宫位索引
jiangqian12 / jiangqian12Keysstring[12]按流年支起的将前十二神

Rust 侧的 base 层

Rust 里 ageyearly 的通用字段收在 .base 下(AgeItem { base, nominal_age }), 序列化时用 #[serde(flatten)] 展平,所以 JSON 与 Python / Go 侧看到的是平铺结构。

完整 JSON 样例

by_solar("2000-8-16", 2, female) 的真实输出(顶层,省略 palaces 的十二项):

{
  "gender": "女",
  "genderKey": "female",
  "solarDate": "2000-8-16",
  "lunarDate": "二〇〇〇年七月十七",
  "chineseDate": "庚辰 甲申 丙午 庚寅",
  "rawDates": {
    "lunarDate": { "lunarYear": 2000, "lunarMonth": 7, "lunarDay": 17, "isLeap": false },
    "chineseDate": {
      "yearly": ["庚", "辰"], "monthly": ["甲", "申"],
      "daily": ["丙", "午"], "hourly": ["庚", "寅"],
      "yearlyKeys": ["gengHeavenly", "chenEarthly"],
      "monthlyKeys": ["jiaHeavenly", "shenEarthly"],
      "dailyKeys": ["bingHeavenly", "wuEarthly"],
      "hourlyKeys": ["gengHeavenly", "yinEarthly"]
    }
  },
  "time": "寅时",
  "timeRange": "03:00~05:00",
  "sign": "狮子座",
  "zodiac": "龙",
  "earthlyBranchOfSoulPalace": "午", "earthlyBranchOfSoulPalaceKey": "wuEarthly",
  "earthlyBranchOfBodyPalace": "戌", "earthlyBranchOfBodyPalaceKey": "xuEarthly",
  "soul": "破军", "soulKey": "pojunMaj",
  "body": "文昌", "bodyKey": "wenchangMin",
  "fiveElementsClass": "木三局", "fiveElementsClassKey": "wood3rd",
  "palaces": [ /* 12 项 */ ],
  "timeIndex": 2,
  "fixLeap": true,
  "language": "zh-CN",
  "config": {
    "yearDivide": "normal", "horoscopeDivide": "normal",
    "ageDivide": "normal", "dayDivide": "forward",
    "algorithm": "default", "astroType": "heaven"
  }
}

一个宫的样例

同一张盘的命宫(palacesindex 为 4 的那一项):

{
  "index": 4,
  "name": "命宫", "nameKey": "soulPalace",
  "isBodyPalace": false, "isOriginalPalace": false,
  "heavenlyStem": "壬", "heavenlyStemKey": "renHeavenly",
  "earthlyBranch": "午", "earthlyBranchKey": "wuEarthly",
  "majorStars": [
    { "key": "ziweiMaj", "name": "紫微", "type": "major", "scope": "origin",
      "brightness": "庙", "brightnessKey": "miao", "mutagen": "" }
  ],
  "minorStars": [
    { "key": "wenquMin", "name": "文曲", "type": "soft", "scope": "origin",
      "brightness": "陷", "brightnessKey": "xian", "mutagen": "" }
  ],
  "adjectiveStars": [
    { "key": "fengge", "name": "凤阁", "type": "adjective", "scope": "origin" },
    { "key": "tianfu", "name": "天福", "type": "adjective", "scope": "origin" },
    { "key": "jielu",  "name": "截路", "type": "adjective", "scope": "origin" },
    { "key": "feilian", "name": "蜚廉", "type": "adjective", "scope": "origin" },
    { "key": "nianjie", "name": "年解", "type": "helper", "scope": "origin" }
  ],
  "changsheng12": "衰",   "changsheng12Key": "shuai",
  "boshi12": "青龙",      "boshi12Key": "qinglong",
  "jiangqian12": "灾煞",  "jiangqian12Key": "zhaisha",
  "suiqian12": "丧门",    "suiqian12Key": "sangmen",
  "mutagenStarKeys": ["tianliangMaj", "ziweiMaj", "zuofuMin", "wuquMaj"],
  "decadal": {
    "range": [3, 12],
    "heavenlyStem": "壬", "heavenlyStemKey": "renHeavenly",
    "earthlyBranch": "午", "earthlyBranchKey": "wuEarthly"
  },
  "ages": [5, 17, 29, 41, 53, 65, 77, 89, 101, 113]
}

紫微与文曲都有 mutagen: "" —— 它们是四化候选星,这一盘上没被化到, 所以键在但值为空,mutagenKey 则整个缺省。五颗杂耀连 brightness 键都没有。

*Key 字段是什么

每个会被翻译的字段旁边都有一个同名加 Key 后缀的伴生字段, 取值是 iztro 的 i18n 键名,与盘面语言无关:

{ "name": "紫微", "key": "ziweiMaj", "brightness": "庙", "brightnessKey": "miao" }

翻译字段给人看,标识字段给代码用。星耀的标识字段直接叫 key(没有 nameKey), 其余一律是「原字段名 + Key」;数组形式的用复数 KeysmutagenKeyspalaceNameKeysyearlyKeys)。

*Key / key 系列、genderKeytimeIndexfixLeaplanguageconfig 是 x-iztro 相对 JS iztro 的扩展;其余字段与 iztro 的 JSON.stringify 输出逐键逐值一致,由绑定契约测试守着。判断逻辑请用标识字段,见 key 契约

导出 JSON

Python 侧有现成的导出方法,输出即上面这份契约:

chart.to_dict()          # dict
chart.to_json(indent=2)  # str

不要用 dataclasses.asdict

AstrolabePalaceStar 之间有回指引用(宫位持有所属星盘), asdict() 会递归进去直到 RecursionError。要 JSON 就用 to_json()

本页目录