Files
bocai/PyModel/batch_predict_betting_v7.py
2026-01-22 18:02:21 +08:00

165 lines
6.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
import os
import sys
from datetime import datetime, timedelta
current_dir = os.path.dirname(os.path.abspath(__file__))
# 如果当前目录不在sys.path中就添加进去避免重复添加
if current_dir not in sys.path:
sys.path.append(current_dir)
from predict_model_v6 import LotteryPredictorV6
SUM12_ODDS = {
3: 41.9, 4: 41.9, 18: 41.9, 19: 41.9,
5: 20.38, 6: 20.38, 16: 20.38, 17: 20.38,
7: 13.51, 8: 13.51, 14: 13.51, 15: 13.51,
9: 9.7, 10: 9.7, 12: 9.7, 13: 9.7,
11: 8.1
}
# 玩法1.1 赔率映射
SIZE_ODDS = {"冠亚大": 2.1, "冠亚小": 1.7}
ODD_EVEN_ODDS = {"冠亚单": 1.7, "冠亚双": 2.1}
NUM_DETAIL_ODDS = 1.9199 * 20
# NUM_DETAIL_ODDS = {"大": 1.9199, "小": 1.9199, "单": 1.9199, "双": 1.9199}
# 玩法2.1/2.2/3 固定赔率
RANK_GLH_ODDS = 1.9199 * 10 # 玩法2.2
NUM_POS_ODDS = 9.599 * 10 # 玩法3
# 总赔率
TOTAL_ODDS = 0
SUM12_ODDS_TOTAL = sum(SUM12_ODDS.values())
SIZE_ODDS_TOTAL = sum(SIZE_ODDS.values())
ODD_EVEN_ODDS_TOTAL = sum(ODD_EVEN_ODDS.values())
TOTAL_ODDS += SUM12_ODDS_TOTAL + SIZE_ODDS_TOTAL + ODD_EVEN_ODDS_TOTAL
TOTAL_ODDS += round(NUM_DETAIL_ODDS + RANK_GLH_ODDS + NUM_POS_ODDS, 4)
# TOTAL_ODDS += round(NUM_DETAIL_ODDS * 20 + RANK_GLH_ODDS * 10 + NUM_POS_ODDS * 10, 4)
EMPTY_TIME_WINDOWS = [
"06:05:00", "06:10:00", "06:15:00", "06:20:00", "06:25:00", "06:30:00", "06:35:00", "06:40:00", "06:45:00",
"06:50:00", "06:55:00", "07:00:00",
]
print(f"总赔率: {TOTAL_ODDS}")
# 生成预测数据
def generate_time_series(start_str, end_str):
start = datetime.strptime(start_str, '%Y-%m-%d %H:%M:%S')
end = datetime.strptime(end_str, '%Y-%m-%d %H:%M:%S')
current = start
series = []
while current <= end:
series.append(current)
current += timedelta(minutes=5)
return series
def main():
predictor = LotteryPredictorV6('data_test_predict/aggregated_stats_v7.json')
with open("full_history_time_performance.json", "r", encoding="utf-8") as f:
time_windows = json.load(f)
# start_time = "2025-01-01 07:05:00"
# end_time = "2026-01-19 06:00:00"
start_time = "2026-01-20 07:05:00"
end_time = "2026-01-21 06:00:00"
time_series = generate_time_series(start_time, end_time)
total_budget = 20.0
results = []
for dt in time_series:
date_str = dt.strftime('%Y-%m-%d')
time_str = dt.strftime('%H:%M:%S')
raw = predictor.predict(date_str, time_str)
# 收集所有潜在押注项及其原始概率
candidates = [] # (type, pos/key, sub_key, prob)
# 1. Result (数字位置) - 每个位置选 Top 3, 门槛 0.11
for i in range(10):
# if time_str not in EMPTY_TIME_WINDOWS and time_windows["accuracy"][time_str] < 0.6248:
# break
pos_key = f'pos_{i}'
probs = raw['digital_pos'][pos_key]
sorted_p = sorted(probs.items(), key=lambda x: x[1], reverse=True)
for val, p in sorted_p[:5]:
if p >= 0.1055:
# if p >= 0.1055:
candidates.append(('result', i, val, p))
# 2. Result Detail (单双大小) - 互斥, 门槛 0.53
for i in range(10):
pos_key = f'pos_{i}'
for cat in ['big_small', 'odd_even']:
probs = raw['pos_detail'][pos_key][cat]
sorted_p = sorted(probs.items(), key=lambda x: x[1], reverse=True)
best_opt, best_p = sorted_p[0]
if best_p >= 0.53068:
candidates.append(('result_detail', i, best_opt, best_p))
# 3. Winner - 门槛 0.08
for val, p in raw['winner_prob'].items():
if p >= 0.08582:
candidates.append(('winner', None, val, p))
# 4. GD1 & GD2 - 互斥, 门槛 0.53
for cat in ['direct_gd1', 'direct_gd2']:
probs = raw[cat]
sorted_p = sorted(probs.items(), key=lambda x: x[1], reverse=True)
best_opt, best_p = sorted_p[0]
if best_p >= 0.53068:
candidates.append(('gd', cat, best_opt, best_p))
# 5. GLH (龙虎) - 进取型, 无门槛 (取优势方)
for i in range(5):
pos_key = f'pos_{i}'
probs = raw['glh_pos'][pos_key]
sorted_p = sorted(probs.items(), key=lambda x: x[1], reverse=True)
best_opt, best_p = sorted_p[0]
if best_p >= 0.53068:
candidates.append(('glh', i, best_opt, best_p))
# 动态资金分配: 金额 = (概率 / 总概率和) * 500
total_prob_sum = sum(c[3] for c in candidates)
entry = {
"id": dt.strftime('%Y%m%d%H%M'),
"time": dt.strftime('%Y-%m-%d %H:%M:%S'),
"result": {i: {str(n): None for n in range(1, 11)} for i in range(10)},
"result_detail": {i: {"": None, "": None, "": None, "": None} for i in range(10)},
"winner": {},
"GD1": {"冠亚大": None, "冠亚小": None},
"GD2": {"冠亚单": None, "冠亚双": None},
"GLH_result": {}
}
if total_prob_sum > 0:
for c_type, key, sub_key, prob in candidates:
# bet_amount = round((prob / total_prob_sum) * total_budget, 2)
if c_type == 'result':
# entry['result'][key][sub_key] = 10
entry['result'][key][sub_key] = round((NUM_POS_ODDS / TOTAL_ODDS) * total_budget, 2)
elif c_type == 'result_detail':
entry['result_detail'][key][sub_key] = round((NUM_DETAIL_ODDS / TOTAL_ODDS) * total_budget, 2)
elif c_type == 'winner':
entry['winner'][sub_key] = round((SUM12_ODDS[int(sub_key)] / TOTAL_ODDS) * total_budget, 2)
elif c_type == 'gd':
# key is 'direct_gd1' or 'direct_gd2'
field = 'GD1' if key == 'direct_gd1' else 'GD2'
_odd = SIZE_ODDS_TOTAL if key == 'direct_gd1' else ODD_EVEN_ODDS_TOTAL
entry[field][sub_key] = round((_odd / TOTAL_ODDS) * total_budget, 2)
elif c_type == 'glh':
entry['GLH_result'][f"pos_{key}_{sub_key}"] = round((RANK_GLH_ODDS / TOTAL_ODDS) * total_budget, 2)
results.append(entry)
with open('data_test_predict/betting_predictions_final_1_20.json', 'w', encoding='utf-8') as f:
# with open('data_test_predict/betting_predictions_final_502.json', 'w', encoding='utf-8') as f:
# with open('data_test_predict/betting_predictions_final_501.json', 'w', encoding='utf-8') as f:
json.dump(results, f, ensure_ascii=False, indent=2)
print(f"Generated {len(results)} predictions.")
if __name__ == "__main__":
main()