|
@@ -1,4 +1,6 @@
|
|
|
+import numpy as np
|
|
|
import json
|
|
|
+import matplotlib.pyplot as plt
|
|
|
|
|
|
# 假设数据文件名为 'betting_data.txt',每行为一个时间戳和JSON数据
|
|
|
file_path = '开奖记录.log'
|
|
@@ -25,6 +27,15 @@ class RoundInfo:
|
|
|
self.total_payout_by_settle = _total_payout_by_settle
|
|
|
|
|
|
|
|
|
+# json解析 RoundInfo
|
|
|
+class RoundInfoDecoder(json.JSONEncoder):
|
|
|
+ def default(self, obj):
|
|
|
+ if isinstance(obj, RoundInfo):
|
|
|
+ return f"{obj.key} odd结果:{obj.total_payout_by_bet_odd} 开奖结果:{obj.total_payout_by_settle} 一致数据可以保存用于分析"
|
|
|
+ # Let the base class default method raise the TypeError
|
|
|
+ return json.JSONEncoder.default(self, obj)
|
|
|
+
|
|
|
+
|
|
|
def process_settle(key, data):
|
|
|
global total_payout_by_settle, total_payout_by_bet_odd, result_option
|
|
|
player_settle = data["playerSettle"]
|
|
@@ -60,18 +71,75 @@ def save_and_clear(key):
|
|
|
if total_payout_by_settle == total_payout_by_bet_odd:
|
|
|
# print(f"{key} odd结果:{total_payout_by_bet_odd} 开奖结果:{total_payout_by_settle} 一致数据可以保存用于分析")
|
|
|
cacheRoundInfo.append(
|
|
|
- RoundInfo(key, result_option, options_pay_out, total_payout_by_bet_odd, total_payout_by_settle))
|
|
|
+ RoundInfo(key, result_option.copy(), options_pay_out.copy(), total_payout_by_bet_odd,
|
|
|
+ total_payout_by_settle))
|
|
|
bet_101 = 0
|
|
|
bet_102 = 0
|
|
|
total_payout_by_bet_odd = 0
|
|
|
total_payout_by_settle = 0
|
|
|
options_pay_out.clear()
|
|
|
+ result_option.clear()
|
|
|
+
|
|
|
+
|
|
|
+# 分析和绘图函数
|
|
|
+def analyze_group_positions(round_info_list, group1, group2):
|
|
|
+ # 存储每个中奖选项在排序后赔付列表中的位置
|
|
|
+ positions_group1 = []
|
|
|
+ positions_group2 = []
|
|
|
+
|
|
|
+ for info in round_info_list:
|
|
|
+ # 分别处理两组
|
|
|
+ group1_payouts = {k: info.options_pay_out[k] for k in group1 if k in info.options_pay_out}
|
|
|
+ group2_payouts = {k: info.options_pay_out[k] for k in group2 if k in info.options_pay_out}
|
|
|
+
|
|
|
+ # 排序
|
|
|
+ sorted_group1 = sorted(group1_payouts.items(), key=lambda x: x[1])
|
|
|
+ sorted_group2 = sorted(group2_payouts.items(), key=lambda x: x[1])
|
|
|
+
|
|
|
+ sorted_keys_group1 = [item[0] for item in sorted_group1]
|
|
|
+ sorted_keys_group2 = [item[0] for item in sorted_group2]
|
|
|
|
|
|
+ # 定位中奖选项
|
|
|
+ for res in info.result_option:
|
|
|
+ if res in sorted_keys_group1:
|
|
|
+ positions_group1.append(sorted_keys_group1.index(res) + 1)
|
|
|
+ if res in sorted_keys_group2:
|
|
|
+ positions_group2.append(sorted_keys_group2.index(res) + 1)
|
|
|
+
|
|
|
+ # 绘制两个组的结果
|
|
|
+ plt.figure(figsize=(12, 6))
|
|
|
+
|
|
|
+ plt.subplot(1, 2, 1)
|
|
|
+ # plt.hist(positions_group1, bins=len(group1), alpha=0.75, edgecolor='black', align='left', rwidth=0.5)
|
|
|
+ plt.hist(positions_group1, bins=np.arange(1, len(group1) + 2) - 0.5, alpha=0.75, edgecolor='black')
|
|
|
+
|
|
|
+ plt.xlabel('Position in Payout Sorting (Group 1)')
|
|
|
+ plt.ylabel('Frequency')
|
|
|
+ plt.title('Frequency of Winning Options in Group 1')
|
|
|
+ plt.xticks(np.arange(1, len(group1) + 1))
|
|
|
+
|
|
|
+ plt.subplot(1, 2, 2)
|
|
|
+ # plt.hist(positions_group2, bins=len(group2), alpha=0.75, edgecolor='black', align='left', rwidth=0.5)
|
|
|
+ plt.hist(positions_group2, bins=np.arange(1, len(group2) + 2) - 0.5, alpha=0.75, edgecolor='black')
|
|
|
+
|
|
|
+ plt.xlabel('Position in Payout Sorting (Group 2)')
|
|
|
+ plt.ylabel('Frequency')
|
|
|
+ plt.title('Frequency of Winning Options in Group 2')
|
|
|
+ plt.xticks(np.arange(1, len(group2) + 1))
|
|
|
+
|
|
|
+ plt.tight_layout()
|
|
|
+ plt.show()
|
|
|
|
|
|
def parse_data_from_file(_file_path):
|
|
|
clean_data(_file_path)
|
|
|
delete_wrong_data(_file_path)
|
|
|
- print(json.dumps(cacheRoundInfo))
|
|
|
+ # print(json.dumps(cacheRoundInfo, cls=RoundInfoDecoder))
|
|
|
+ # 定义两组选项
|
|
|
+ group1 = [101, 102, 103]
|
|
|
+ group2 = [301, 302, 303, 304, 305]
|
|
|
+
|
|
|
+ # 调用函数
|
|
|
+ analyze_group_positions(cacheRoundInfo, group1, group2)
|
|
|
|
|
|
|
|
|
def delete_wrong_data(_file_path):
|