|
@@ -0,0 +1,125 @@
|
|
|
+from yixue import Configs
|
|
|
+from yixue.Models import BaZi, MBTIItem, MBTISet
|
|
|
+
|
|
|
+
|
|
|
+def calc(bazi: BaZi):
|
|
|
+ ss_per = __calc_shishen_power_percentage__(bazi)
|
|
|
+ wx_per = __calc_wuxing_power_percentage__(bazi)
|
|
|
+ bazi.mbti = {}
|
|
|
+ for key in Configs.config_mbti_key_list: # key=外向、内向
|
|
|
+ st = MBTISet()
|
|
|
+ st.key = key
|
|
|
+ st.items = []
|
|
|
+ for ss in Configs.config_shishen_list:
|
|
|
+ power = ss_per[ss]
|
|
|
+ items = Configs.get_value2(Configs.config_mbti, ss, key)
|
|
|
+ for item in items:
|
|
|
+ mbti = MBTIItem()
|
|
|
+ mbti.key = key
|
|
|
+ mbti.shishen = ss
|
|
|
+ mbti.wuxing = None
|
|
|
+ mbti.desc = item["desc"]
|
|
|
+ mbti.state = item["state"]
|
|
|
+ param = item["state"]
|
|
|
+ mbti.power = power
|
|
|
+ mbti.score = power * param
|
|
|
+ st.items.append(mbti)
|
|
|
+
|
|
|
+ for wx in Configs.config_wuxing_list:
|
|
|
+ power = wx_per[wx]
|
|
|
+ items = Configs.get_value2(Configs.config_mbti, wx, key)
|
|
|
+ for item in items:
|
|
|
+ mbti = MBTIItem()
|
|
|
+ mbti.key = key
|
|
|
+ mbti.wuxing = wx
|
|
|
+ mbti.shishen = None
|
|
|
+ mbti.desc = item["desc"]
|
|
|
+ mbti.state = item["state"]
|
|
|
+ param = item["state"]
|
|
|
+ mbti.power = power
|
|
|
+ mbti.score = power * param
|
|
|
+ st.items.append(mbti)
|
|
|
+
|
|
|
+ __calc_score_in_set__(st)
|
|
|
+ bazi.mbti[key] = st
|
|
|
+ __calc_percentages__(["外向", "内向"], bazi)
|
|
|
+ __calc_percentages__(["感觉", "直觉"], bazi)
|
|
|
+ __calc_percentages__(["思考", "情感"], bazi)
|
|
|
+ __calc_percentages__(["判断", "知觉"], bazi)
|
|
|
+
|
|
|
+
|
|
|
+def __calc_percentages__(keys: [str], bazi: BaZi):
|
|
|
+ total = 0
|
|
|
+ for key in keys:
|
|
|
+ st = bazi.mbti[key]
|
|
|
+ total += st.total_score
|
|
|
+
|
|
|
+ for key in keys:
|
|
|
+ st = bazi.mbti[key]
|
|
|
+ st.percentage = round(st.total_score * 100 / total, 0)
|
|
|
+
|
|
|
+
|
|
|
+def __calc_score_in_set__(st: MBTISet):
|
|
|
+ st.total_score = 0
|
|
|
+ st.score_detail = {}
|
|
|
+ for ss in Configs.config_shishen_list:
|
|
|
+ st.score_detail[ss] = 0
|
|
|
+ for wx in Configs.config_wuxing_list:
|
|
|
+ st.score_detail[wx] = 0
|
|
|
+ for item in st.items:
|
|
|
+ st.total_score += item.score
|
|
|
+ if item.shishen is not None:
|
|
|
+ st.score_detail[item.shishen] += item.score
|
|
|
+ if item.wuxing is not None:
|
|
|
+ st.score_detail[item.wuxing] += item.score
|
|
|
+
|
|
|
+
|
|
|
+def __calc_shishen_power_percentage__(bazi: BaZi):
|
|
|
+ total = 0
|
|
|
+ ss_power = {}
|
|
|
+ ss_per = {}
|
|
|
+ keys = [ss for ss in Configs.config_shishen_list]
|
|
|
+ for key in ["官杀", "财星", "印绶", "食伤", "比劫"]:
|
|
|
+ keys.append(key)
|
|
|
+
|
|
|
+ for key in keys:
|
|
|
+ ss_power[key] = 0
|
|
|
+ ss_per[key] = 0
|
|
|
+
|
|
|
+ for ss in Configs.config_shishen_list:
|
|
|
+ step = bazi.power_steps[ss]
|
|
|
+ amount = bazi.counter.power_raw[ss]
|
|
|
+ power = step * amount
|
|
|
+ total += power
|
|
|
+ ss_power[ss] = power
|
|
|
+ if ss in ["官", "杀"]:
|
|
|
+ ss_power["官杀"] += power
|
|
|
+ elif ss in ["财", "才"]:
|
|
|
+ ss_power["财星"] += power
|
|
|
+ elif ss in ["印", "枭"]:
|
|
|
+ ss_power["印绶"] += power
|
|
|
+ elif ss in ["食", "伤"]:
|
|
|
+ ss_power["食伤"] += power
|
|
|
+ elif ss in ["比", "劫"]:
|
|
|
+ ss_power["比劫"] += power
|
|
|
+
|
|
|
+ for ss in keys:
|
|
|
+ ss_per[ss] = round(ss_power[ss] * 100 / total, 0)
|
|
|
+ return ss_per
|
|
|
+
|
|
|
+
|
|
|
+def __calc_wuxing_power_percentage__(bazi: BaZi):
|
|
|
+ total = 0
|
|
|
+ wx_power = {}
|
|
|
+ wx_per = {}
|
|
|
+ for wx in Configs.config_wuxing_list:
|
|
|
+ step = bazi.power_steps[wx]
|
|
|
+ amount = bazi.counter.power_raw[wx]
|
|
|
+ power = step * amount
|
|
|
+ total += power
|
|
|
+ wx_power[wx] = power
|
|
|
+
|
|
|
+ for wx in Configs.config_wuxing_list:
|
|
|
+ wx_per[wx] = round(wx_power[wx] * 100 / total, 0)
|
|
|
+
|
|
|
+ return wx_per
|