调整脚本
This commit is contained in:
@@ -10,19 +10,43 @@ data_dirs = ['data_test_dir']
|
|||||||
all_records = []
|
all_records = []
|
||||||
|
|
||||||
for d in data_dirs:
|
for d in data_dirs:
|
||||||
if not os.path.exists(d): continue
|
print(f"Processing directory: {d}")
|
||||||
for f in os.listdir(d):
|
if not os.path.exists(d):
|
||||||
|
print(f"Directory {d} does not exist")
|
||||||
|
continue
|
||||||
|
print(f"Found directory: {d}")
|
||||||
|
files = os.listdir(d)
|
||||||
|
print(f"Files in directory: {files}")
|
||||||
|
for f in files:
|
||||||
if f.endswith('.json') and f != 'stat_result.json':
|
if f.endswith('.json') and f != 'stat_result.json':
|
||||||
with open(os.path.join(d, f), 'r') as file:
|
file_path = os.path.join(d, f)
|
||||||
try:
|
print(f"Processing file: {file_path}")
|
||||||
all_records.extend(json.load(file))
|
try:
|
||||||
except:
|
with open(file_path, 'r', encoding='utf-8') as file:
|
||||||
continue
|
data = json.load(file)
|
||||||
|
print(f"Loaded {len(data)} records from {f}")
|
||||||
|
if len(data) > 0:
|
||||||
|
print(f"First record keys: {list(data[0].keys())}")
|
||||||
|
all_records.extend(data)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error processing {file_path}: {str(e)}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
print(f"Total records loaded: {len(all_records)}")
|
||||||
df = pd.DataFrame(all_records)
|
df = pd.DataFrame(all_records)
|
||||||
df = df.drop_duplicates(subset=['id'], keep='last')
|
print(f"DataFrame columns: {list(df.columns)}")
|
||||||
df['time'] = pd.to_datetime(df['time'])
|
if 'id' in df.columns:
|
||||||
print(f"Total unique records: {len(df)}")
|
df = df.drop_duplicates(subset=['id'], keep='last')
|
||||||
|
print(f"Total unique records after deduplication: {len(df)}")
|
||||||
|
else:
|
||||||
|
print("No 'id' column found in DataFrame")
|
||||||
|
if 'time' in df.columns:
|
||||||
|
df['time'] = pd.to_datetime(df['time'])
|
||||||
|
print(f"Total unique records: {len(df)}")
|
||||||
|
else:
|
||||||
|
print("No 'time' column found in DataFrame")
|
||||||
|
print("Sample of first 5 records:")
|
||||||
|
print(df.head())
|
||||||
|
|
||||||
|
|
||||||
# 2. 极速统计函数
|
# 2. 极速统计函数
|
||||||
@@ -88,7 +112,18 @@ output_data = {
|
|||||||
'last_updated': last_date.strftime('%Y-%m-%d %H:%M:%S')
|
'last_updated': last_date.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
}
|
}
|
||||||
|
|
||||||
with open('data_test_predict/aggregated_stats_v7.json', 'w') as f:
|
# 创建data_test_predict目录(如果不存在)
|
||||||
|
predict_dir = 'data_test_predict'
|
||||||
|
if not os.path.exists(predict_dir):
|
||||||
|
print(f"Creating directory: {predict_dir}")
|
||||||
|
os.makedirs(predict_dir)
|
||||||
|
else:
|
||||||
|
print(f"Directory {predict_dir} already exists")
|
||||||
|
|
||||||
|
# 保存结果
|
||||||
|
output_file = os.path.join(predict_dir, 'aggregated_stats_v7.json')
|
||||||
|
print(f"Saving results to: {output_file}")
|
||||||
|
with open(output_file, 'w') as f:
|
||||||
json.dump(output_data, f)
|
json.dump(output_data, f)
|
||||||
|
|
||||||
print(f"Stats V7 generated with 100-day window. Last data point: {last_date}")
|
print(f"Stats V7 generated with 100-day window. Last data point: {last_date}")
|
||||||
1
PyModel/data_test_predict/aggregated_stats_v7.json
Normal file
1
PyModel/data_test_predict/aggregated_stats_v7.json
Normal file
File diff suppressed because one or more lines are too long
56858
PyModel/data_test_predict/betting_predictions_final_1_20.json
Normal file
56858
PyModel/data_test_predict/betting_predictions_final_1_20.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -33,6 +33,11 @@ public class BetSchedule {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CompletedTodayRepository completedTodayRepository;
|
private CompletedTodayRepository completedTodayRepository;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
BetSchedule betSchedule = new BetSchedule();
|
||||||
|
betSchedule.placeBet();
|
||||||
|
}
|
||||||
|
|
||||||
// 每天早上7.07分开始,每5分钟执行一次到第二天早上6点结束(7:07, 7:12, 7:17...23:57, 0:02, 0:07...5:57)
|
// 每天早上7.07分开始,每5分钟执行一次到第二天早上6点结束(7:07, 7:12, 7:17...23:57, 0:02, 0:07...5:57)
|
||||||
// @Scheduled(cron = "0 7/5 7-23,0-6 * * ?")
|
// @Scheduled(cron = "0 7/5 7-23,0-6 * * ?")
|
||||||
public void placeBet() {
|
public void placeBet() {
|
||||||
@@ -55,51 +60,51 @@ public class BetSchedule {
|
|||||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||||
);
|
);
|
||||||
|
|
||||||
LoginInfoResult loginInfo = loginInfoRepository.findFirstByOrderByCreateTimeDesc().orElse(null);
|
// LoginInfoResult loginInfo = loginInfoRepository.findFirstByOrderByCreateTimeDesc().orElse(null);
|
||||||
if (loginInfo == null) {
|
// if (loginInfo == null) {
|
||||||
System.out.println(currentTime + " - 未找到登录信息,跳过执行");
|
// System.out.println(currentTime + " - 未找到登录信息,跳过执行");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// 检查onOff字段是否为1(开启状态)
|
// // 检查onOff字段是否为1(开启状态)
|
||||||
if (loginInfo.getOnOff() != 1) {
|
// if (loginInfo.getOnOff() != 1) {
|
||||||
System.out.println(currentTime + " - 投注功能未开启,跳过执行");
|
// System.out.println(currentTime + " - 投注功能未开启,跳过执行");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// 检查winNum和loseNum字段是否合理
|
// // 检查winNum和loseNum字段是否合理
|
||||||
Integer winNum = loginInfo.getWinNum();
|
// Integer winNum = loginInfo.getWinNum();
|
||||||
Integer loseNum = loginInfo.getLoseNum();
|
// Integer loseNum = loginInfo.getLoseNum();
|
||||||
|
//
|
||||||
if (winNum != null || loseNum != null) {
|
// if (winNum != null || loseNum != null) {
|
||||||
// 根据LoginInfo的startTime 查询CompletedToday的resultAmount总和 判断是否达到 winNum 和 loseNum的值
|
// // 根据LoginInfo的startTime 查询CompletedToday的resultAmount总和 判断是否达到 winNum 和 loseNum的值
|
||||||
Date startTime = loginInfo.getStartTime();
|
// Date startTime = loginInfo.getStartTime();
|
||||||
if (startTime != null) {
|
// if (startTime != null) {
|
||||||
Double totalResultAmount = completedTodayRepository.sumResultAmountByCreateTimeAfter(startTime);
|
// Double totalResultAmount = completedTodayRepository.sumResultAmountByCreateTimeAfter(startTime);
|
||||||
if (totalResultAmount != null) {
|
// if (totalResultAmount != null) {
|
||||||
System.out.println(" - 今日盈亏总和: " + totalResultAmount);
|
// System.out.println(" - 今日盈亏总和: " + totalResultAmount);
|
||||||
|
//
|
||||||
// 判断是否达到止盈点
|
// // 判断是否达到止盈点
|
||||||
if (totalResultAmount >= winNum) {
|
// if (totalResultAmount >= winNum) {
|
||||||
System.out.println(currentTime + " - 已达到止盈点 " + winNum + ",跳过执行");
|
// System.out.println(currentTime + " - 已达到止盈点 " + winNum + ",跳过执行");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// 判断是否达到止亏点
|
// // 判断是否达到止亏点
|
||||||
if (totalResultAmount <= -loseNum) {
|
// if (totalResultAmount <= -loseNum) {
|
||||||
System.out.println(currentTime + " - 已达到止亏点 " + loseNum + ",跳过执行");
|
// System.out.println(currentTime + " - 已达到止亏点 " + loseNum + ",跳过执行");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
System.out.println(currentTime + " - 开始执行投注...");
|
System.out.println(currentTime + " - 开始执行投注...");
|
||||||
System.out.println(" - 投注设置: 止盈点=" + winNum + ", 止亏点=" + loseNum + ", 状态=" + (loginInfo.getOnOff() == 1 ? "开启" : "关闭"));
|
// System.out.println(" - 投注设置: 止盈点=" + winNum + ", 止亏点=" + loseNum + ", 状态=" + (loginInfo.getOnOff() == 1 ? "开启" : "关闭"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 执行投注逻辑
|
// 执行投注逻辑
|
||||||
executeBet(loginInfo);
|
executeBet(null);
|
||||||
|
|
||||||
System.out.println(currentTime + " - 投注执行完成");
|
System.out.println(currentTime + " - 投注执行完成");
|
||||||
|
|
||||||
@@ -120,32 +125,42 @@ public class BetSchedule {
|
|||||||
// 4. 记录投注结果
|
// 4. 记录投注结果
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 1. 从json文件中获取投注号码
|
// 1. 从json文件中获取投注数据
|
||||||
System.out.println(" - 从json文件中获取投注号码...");
|
System.out.println(" - 从json文件中获取投注数据...");
|
||||||
JSONObject betData = readBetDataFromJson();
|
JSONArray betDataArray = readBetDataFromJson();
|
||||||
JSONArray betNumbers = betData.getJSONArray("betNumbers");
|
|
||||||
|
|
||||||
JSONObject bet = betData.getJSONObject("bet");
|
// 2. 遍历投注数据并执行投注
|
||||||
bet.put("game", betNumbers);
|
for (int i = 0; i < betDataArray.length(); i++) {
|
||||||
bet.put("contents", betNumbers);
|
JSONObject betData = betDataArray.getJSONObject(i);
|
||||||
bet.put("amount", betNumbers);
|
String time = betData.getString("time");
|
||||||
bet.put("odds", 9.599);
|
System.out.println(" - 处理投注时间: " + time);
|
||||||
bet.put("title", betNumbers);
|
|
||||||
System.out.println(" - 投注号码: " + betNumbers.toString());
|
|
||||||
|
|
||||||
// 2. 计算投注金额
|
// 获取投注号码
|
||||||
System.out.println(" - 计算投注金额...");
|
JSONObject result = betData.getJSONObject("result");
|
||||||
double betAmount = betData.getDouble("betAmount");
|
JSONArray betNumbers = new JSONArray();
|
||||||
System.out.println(" - 投注金额: " + betAmount);
|
for (int j = 0; j < 10; j++) {
|
||||||
|
JSONObject posData = result.getJSONObject(String.valueOf(j));
|
||||||
|
for (String num : posData.keySet()) {
|
||||||
|
if (posData.get(num) != null) {
|
||||||
|
betNumbers.put(num);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println(" - 投注号码: " + betNumbers.toString());
|
||||||
|
|
||||||
// 3. 调用投注接口
|
// 计算投注金额
|
||||||
System.out.println(" - 提交投注...");
|
double betAmount = loginInfo.getAmount(); // 固定投注金额
|
||||||
String betResult = callBetApi(betNumbers, betAmount, loginInfo);
|
System.out.println(" - 投注金额: " + betAmount);
|
||||||
System.out.println(" - 投注结果: " + betResult);
|
|
||||||
|
|
||||||
// 4. 记录投注结果
|
// 调用投注接口
|
||||||
System.out.println(" - 记录投注结果...");
|
System.out.println(" - 提交投注...");
|
||||||
recordBetResult(betNumbers, betAmount, betResult);
|
String betResult = callBetApi(betNumbers, betAmount, loginInfo);
|
||||||
|
System.out.println(" - 投注结果: " + betResult);
|
||||||
|
|
||||||
|
// 记录投注结果
|
||||||
|
System.out.println(" - 记录投注结果...");
|
||||||
|
recordBetResult(betNumbers, betAmount, betResult);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println(" - 投注执行失败:");
|
System.err.println(" - 投注执行失败:");
|
||||||
@@ -156,13 +171,17 @@ public class BetSchedule {
|
|||||||
/**
|
/**
|
||||||
* 从json文件中读取投注数据
|
* 从json文件中读取投注数据
|
||||||
*/
|
*/
|
||||||
private JSONObject readBetDataFromJson() throws IOException {
|
private JSONArray readBetDataFromJson() throws IOException {
|
||||||
// 假设json文件位于项目根目录的bet-data.json
|
// 使用绝对路径读取文件
|
||||||
String filePath = "bet-data.json";
|
String projectRoot = System.getProperty("user.dir");
|
||||||
|
String filePath = projectRoot + "/PyModel/data_test_predict/betting_predictions_final_1_20.json";
|
||||||
|
System.out.println(" - 读取投注数据文件: " + filePath);
|
||||||
|
|
||||||
FileReader reader = new FileReader(filePath);
|
FileReader reader = new FileReader(filePath);
|
||||||
JSONTokener tokener = new JSONTokener(reader);
|
JSONTokener tokener = new JSONTokener(reader);
|
||||||
JSONObject betData = new JSONObject(tokener);
|
JSONArray betData = new JSONArray(tokener);
|
||||||
reader.close();
|
reader.close();
|
||||||
|
System.out.println(" - 成功读取投注数据,共" + betData.length() + "条记录");
|
||||||
return betData;
|
return betData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user