Commit 7dbae9db Harvey

no message

1 个父辈 1f53673b
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.calc_pre_win = exports.create_match_data = void 0;
//处理纳米数据,共用调用
const info_db = require("../info_mysql/table");
const nami_db = require("../nami_mysql/table");
const moment = require("moment");
const _ = require("lodash");
const common_1 = require("../../libs/common");
async function best_player(team_id, date = moment().format('YYYY-MM-DD')) {
var data = await nami_db.sequelize.query(`SELECT id,player_stats,home_team_id,away_team_id from db_nami.matches where
match_time<UNIX_TIMESTAMP('${moment(date).format('YYYY-MM-DD')}}') and
(home_team_id=${team_id} or away_team_id=${team_id}) and
JSON_LENGTH(player_stats)>0
ORDER BY match_time desc LIMIT 10;`)
.then(result => {
if (result && result.length > 1 && result[1]) {
return result[1];
}
return null;
})
.catch(err => {
console.log(`best_player ${team_id} >>> ${err.message}`);
return null;
});
if (!data || data.length < 1) {
return [];
}
for (let index = 0; index < data.length; index++) {
try {
const item = data[index];
var v = _(item.player_stats).filter(a => a.team_id == team_id).orderBy('rating', 'desc').take(3).map(a => ({ player_id: a.player_id, rating: a.rating })).value();
if (v[0].rating < 1) {
continue;
}
//select short_name_zh,logo from players where id in (1332014)
var res = await nami_db.players.findAll({
attributes: ['id', 'short_name_zh', 'logo'],
where: {
id: {
$in: v.map(a => a.player_id)
}
}
});
v.forEach((a) => {
var v1 = _(res).find((b) => b.id == a.player_id);
if (v1) {
a.short_name_zh = v1.short_name_zh;
a.logo = v1.logo;
}
});
return v;
}
catch (error) {
}
return [];
}
return [];
}
async function history_team(team_id, is_host = false, date = moment().format('YYYY-MM-DD')) {
var data = await info_db.sequelize.query(`select match_time,yiqiu_host_team_id,yiqiu_guest_team_id,score from ms_soccer_game where
match_time<'${moment(date).format('YYYY-MM-DD')}' and (yiqiu_host_team_id=${team_id} or yiqiu_guest_team_id =${team_id} )
ORDER BY match_time desc LIMIT 20`)
.then(result => {
if (result && result.length > 1 && result[1]) {
return result[1];
}
return null;
})
.catch(err => {
console.log(`history_team ${team_id} >>> ${err.message}`);
return null;
});
if (!data || data.length < 1) {
return { data: [], avg_jq: 0 };
}
var sum_jq_time = 0;
var time = 0;
var sum_jq = 0;
var host_jq = 0;
var spf = [0, 0, 0];
var res = data.map(function (item) {
var r = 0;
var is_host_team = item.yiqiu_host_team_id == team_id;
try {
var bf = JSON.parse(item.score);
bf = bf.map((a) => Number(a));
if (time < 4) {
if (is_host) {
if (item.yiqiu_host_team_id == team_id) {
time++;
sum_jq_time += bf[0];
}
}
else {
if (item.yiqiu_guest_team_id == team_id) {
time++;
sum_jq_time += bf[1];
}
}
}
sum_jq += (bf[0] + bf[1]);
host_jq += (item.yiqiu_host_team_id == team_id ? bf[0] : bf[1]);
if (bf[0] == bf[1]) {
r = 1;
}
else if (item.yiqiu_host_team_id == team_id) {
r = bf[0] > bf[1] ? 2 : 0;
}
else {
r = bf[0] > bf[1] ? 0 : 2;
}
if (is_host_team == is_host) {
spf[r]++;
}
return r;
}
catch (error) {
return 0;
}
}).reverse();
return { data: res, avg_jq: time > 0 ? 1.0 * sum_jq_time / time : 0, sum_jq, host_jq, spf };
}
var trait_action = {
s: (bf, is_host) => {
if (is_host) {
return bf[0] > bf[1];
}
else {
return bf[0] < bf[1];
}
},
p: (bf, is_host) => {
return bf[0] == bf[1];
},
f: (bf, is_host) => {
if (is_host) {
return bf[0] < bf[1];
}
else {
return bf[0] > bf[1];
}
},
no_f: (bf, is_host) => {
if (is_host) {
return bf[0] >= bf[1];
}
else {
return bf[0] <= bf[1];
}
},
no_p: (bf, is_host) => {
return bf[0] != bf[1];
},
jq: (bf, is_host) => {
if (is_host) {
return bf[0] > 0;
}
else {
return bf[1] > 0;
}
},
no_jq: (bf, is_host) => {
if (is_host) {
return bf[0] == 0;
}
else {
return bf[1] == 0;
}
},
};
function trait_calc(list, team_id) {
var max = { s: 0, p: 0, f: 0, no_f: 0, no_p: 0, jq: 0, no_jq: 0 };
var now = { s: 0, p: 0, f: 0, no_f: 0, no_p: 0, jq: 0, no_jq: 0 };
for (let index = list.length - 1; index >= 0; index--) {
const item = list[index];
var is_host = item.yiqiu_host_team_id == team_id;
var bf;
try {
bf = JSON.parse(item.score).map((a) => Number(a));
}
catch (error) {
continue;
}
for (const key in now) {
if (trait_action[key].call(null, bf, is_host)) {
now[key]++;
}
else {
now[key] = 0;
}
if (now[key] > max[key]) {
max[key] = now[key];
}
}
}
return { now, max };
}
async function trait_team(team_id, date = moment().format('YYYY-MM-DD')) {
var data = await info_db.sequelize.query(`select yiqiu_host_team_id,yiqiu_guest_team_id,score from ms_soccer_game where
match_time<'${moment(date).format('YYYY-MM-DD')}' and status=4 and score is not null and (yiqiu_host_team_id=${team_id} or yiqiu_guest_team_id =${team_id} )
ORDER BY match_time desc LIMIT 1000`)
.then(result => {
if (result && result.length > 1 && result[1]) {
return result[1];
}
return null;
})
.catch(err => {
console.log(`trait_team ${team_id} >>> ${err.message}`);
return null;
});
if (!data || data.length < 1) {
return null;
}
var t0 = trait_calc(data, team_id);
var t1 = trait_calc(data.filter((a) => a.yiqiu_host_team_id == team_id), team_id);
var t2 = trait_calc(data.filter((a) => a.yiqiu_guest_team_id == team_id), team_id);
return { t0, t1, t2 };
}
async function meeting(teamids, date = moment().format('YYYY-MM-DD')) {
var data = await info_db.sequelize.query(`select match_time,yiqiu_host_team_id,yiqiu_guest_team_id,score from ms_soccer_game where
match_time<'${moment(date).format('YYYY-MM-DD')}' and yiqiu_host_team_id in(${teamids.join(',')}) and yiqiu_guest_team_id in(${teamids.join(',')})
ORDER BY match_time desc LIMIT 20`)
.then(result => {
if (result && result.length > 1 && result[1]) {
return result[1];
}
return null;
})
.catch(err => {
console.log(`meeting ${teamids.join(',')} >>> ${err.message}`);
return null;
});
if (!data || data.length < 1) {
return {};
}
var sum_jq = 0;
var host_jq = 0;
var res = data.map(function (item) {
try {
var bf = typeof item.score == 'string' ? JSON.parse(item.score) : item.score;
bf = bf.map((a) => Number(a));
sum_jq += (bf[0] + bf[1]);
host_jq += (item.yiqiu_host_team_id == teamids[0] ? bf[0] : bf[1]);
if (bf[0] == bf[1]) {
return 1;
}
if (item.yiqiu_host_team_id == teamids[0]) {
return bf[0] > bf[1] ? 2 : 0;
}
return bf[0] > bf[1] ? 0 : 2;
}
catch (error) {
}
return 0;
}).reverse();
return {
sum_jq: sum_jq,
host_jq: host_jq,
z_spf: res
};
}
async function calc_odds(matchid) {
var data = await nami_db.sequelize.query(`
select
avg( CAST(JSON_UNQUOTE(JSON_EXTRACT(latest_immediate_odds, '$[0]')) AS DECIMAL(10, 2)) )s,
avg(CAST(JSON_UNQUOTE(JSON_EXTRACT(latest_immediate_odds, '$[1]')) AS DECIMAL(10, 2))) p,
avg(CAST(JSON_UNQUOTE(JSON_EXTRACT(latest_immediate_odds, '$[2]')) AS DECIMAL(10, 2)) )f
from odds_asian_immediate where id= :matchid
;
select
avg( CAST(JSON_UNQUOTE(JSON_EXTRACT(latest_immediate_odds, '$[0]')) AS DECIMAL(10, 2)) )s,
avg(CAST(JSON_UNQUOTE(JSON_EXTRACT(latest_immediate_odds, '$[1]')) AS DECIMAL(10, 2))) p,
avg(CAST(JSON_UNQUOTE(JSON_EXTRACT(latest_immediate_odds, '$[2]')) AS DECIMAL(10, 2)) )f
from odds_european_immediate where id= :matchid`, {
replacements: { matchid },
})
.then(result => {
if (result && result.length > 1 && result[1]) {
return result[1];
}
return null;
})
.catch(err => {
console.log(`calc_odds ${matchid} >>> ${err.message}`);
return null;
});
if (!data || data.length != 2 || !data[0][0].s || !data[1][0].s) {
return null;
}
// 亚洲态度:取全部公司的均值后,计算百分比,根据下面方式取概率大的一方加平。
// 如:通过多家亚指公司算出均值如下:
// 1.01 -0.78 0.85
// 第一步:先把本金加上水位都加1.则为2.01 -0.78 1.85
// 第二步:让球方为主队,则主水2.01+盘口0.78=2.79
// 第三步:用2.79 1.85计算百分比:
// 胜:4.64/(1.23+1.85)=60%
// 负:1-60%=40%
// 平:平固定算20%;
// 取概率大的一方加平,则可取:胜 平 百分比为80%。
var asia_data = data[0][0];
var asia;
if (asia_data.p > 0) {
asia = {
rate: (asia_data.f + 1) / (asia_data.s + 1 + asia_data.p) + 0.2,
pre: ['胜', '平']
};
}
else {
asia = {
rate: (asia_data.s + 1) / (asia_data.f + 1 - asia_data.p) + 0.2,
pre: ['负', '平']
};
}
var europe_data = data[1][0];
var europe;
if (europe_data.s < europe_data.f) {
europe = {
rate: (1 / europe_data.s + 1 / europe_data.p) / (1 / europe_data.s + 1 / europe_data.p + 1 / europe_data.f),
pre: ['胜', '平']
};
}
else {
europe = {
rate: (1 / europe_data.f + 1 / europe_data.p) / (1 / europe_data.s + 1 / europe_data.p + 1 / europe_data.f),
pre: ['负', '平']
};
}
return {
asia,
europe
};
}
async function lstp(sp) {
// let sql = `
// select game_id as GameId,
// competition_id,
// score as Score,
// host_id as SportsdtHostId,
// guest_id as SportsdtGuestId,
// host_name,
// guest_name,
// game_date as Date,
// game_name,
// yiqiu_game_id,
// JSON_ARRAY(first_odds_host,first_odds_guest,first_odds_handicap,sport_odds_host,sport_odds_guest,sport_odds_handicap) as Data
// from db_info.stat_soccer_ahodds
// where first_odds_host=${sp[0]}
// and first_odds_guest=${sp[1]}
// and first_odds_handicap=${sp[2]}
// and game_date<'${moment().add(-1, 'days').format("YYYY-MM-DD HH:mm:ss")}'
// order by game_date desc
// limit 300 `
// let list = await info_db.sequelize.query(sql)
// if (list[0].length > 0) {
// list = list[0]
// } else {
// list = []
// }
// if (list && list.length) {
// return;
// }
if (sp[0] < sp[2]) {
return {
rate: (1 / sp[0] + 1 / sp[1]) / (1 / sp[0] + 1 / sp[1] + 1 / sp[2]),
pre: ['胜', '平']
};
}
else {
return {
rate: (1 / sp[2] + 1 / sp[1]) / (1 / sp[0] + 1 / sp[1] + 1 / sp[2]),
pre: ['负', '平']
};
}
// list = JSON.parse(JSON.stringify(list))
// list = _.filter(list, (o) => {
// return o.host_name && o.guest_name
// })
// list = _.unionBy(list, "yiqiu_game_id");
// return base.getItemResultByList(list, true)
return null;
}
async function start1(issue_name) {
// var issue_name = moment().format('YYYY-MM-DD');
var data = await info_db.ms_soccer_game.findAll({
attributes: ['id', 'leisu_match_id', 'odds', 'yiqiu_host_team_id', 'yiqiu_guest_team_id', 'leisu_host_id', 'leisu_guest_id', 'match_time'],
where: {
sporttery_issue_name: issue_name,
odds: {
$ne: null
},
match_time: {
$gte: moment().format('YYYY-MM-DD HH:mm:ss')
}
}
});
var data1 = await info_db.ms_soccer_game.findAll({
attributes: ['id', 'leisu_match_id', 'odds', 'yiqiu_host_team_id', 'yiqiu_guest_team_id', 'leisu_host_id', 'leisu_guest_id', 'match_time'],
where: {
sporttery_issue_name: null,
$or: [
{ is_beidan: 1 },
{ is_zucai: 1 }
],
odds: {
$ne: null
},
match_time: {
$between: [moment().format('YYYY-MM-DD HH:mm:ss'), moment(issue_name).add(1, 'day').format('YYYY-MM-DD 00:00:00')]
}
}
});
data = data.concat(data1);
if (!data || data.length < 1)
return;
var sxjx_list = await info_db.tools_sxjx.findAll({
where: {
id: {
$in: data.map((a) => a.id)
}
}
});
for (let index = 0; index < data.length; index++) {
const item = data[index];
var temp = sxjx_list.find((a) => a.id == item.id);
var odds = await calc_odds(item.leisu_match_id);
if (!odds) {
continue;
}
if (temp) {
temp.xxzs[0] = odds.europe;
temp.xxzs[1] = odds.asia;
temp.xxzs[2] = {
rate: (odds.asia.rate + odds.europe.rate) / 2,
pre: [odds.asia.pre[0]]
};
temp.xxzs = temp.xxzs.map((a, index1) => {
if (index1 == 3)
return a;
var rate = _.toInteger(a.rate.toFixed(2) * 100 + 0.0001);
a.rate = rate > 90 ? 90 : rate;
return a;
});
temp.xxzs[4] = {
rate: _.toInteger((odds.asia.rate + odds.europe.rate + temp.xxzs[2].rate + temp.xxzs[3].rate) / 4),
pre: [odds.asia.pre[0]],
};
await temp.save();
continue;
}
var eu = item.odds['3000181'].eu.map((a) => Number(a));
var lstp_temp = await lstp(eu);
var model = { id: item.id };
var user_zs;
if (eu[0] < eu[2]) {
user_zs = {
rate: (1 / eu[0] + 1 / eu[1]) / (1 / eu[0] + 1 / eu[1] + 1 / eu[2]),
pre: ['胜', '平']
};
}
else {
user_zs = {
rate: (1 / eu[2] + 1 / eu[1]) / (1 / eu[0] + 1 / eu[1] + 1 / eu[2]),
pre: ['负', '平']
};
}
model.xxzs = [
odds.europe,
odds.asia,
user_zs,
lstp_temp,
{
rate: (odds.asia.rate + odds.europe.rate + user_zs.rate + lstp_temp.rate) / 4,
pre: [odds.asia.pre[0]],
}
];
model.xxzs.forEach((a) => {
var rate = _.toInteger(a.rate.toFixed(2) * 100 + 0.0001);
a.rate = rate > 90 ? 90 : rate;
});
model.xxzs[4] = {
rate: _.toInteger((odds.asia.rate + odds.europe.rate + user_zs.rate + lstp_temp.rate) / 4),
pre: [odds.asia.pre[0]],
};
model.meeting = await meeting([item.yiqiu_host_team_id, item.yiqiu_guest_team_id], item.match_time);
var history_host_team = await history_team(item.yiqiu_host_team_id, true, item.match_time);
var history_guest_team = await history_team(item.yiqiu_guest_team_id, false, item.match_time);
// { data: res, avg_jq: time > 0 ? 1.0 * sum_jq_time / time : 0, sum_jq, host_jq }
model.history = [history_host_team.data, history_guest_team.data,
{ sum_jq: history_host_team.sum_jq, host_jq: history_host_team.host_jq, spf: history_host_team.spf },
{ sum_jq: history_guest_team.sum_jq, host_jq: history_guest_team.host_jq, spf: history_guest_team.spf }
];
model.best_player = [await best_player(item.leisu_host_id, item.match_time), await best_player(item.leisu_guest_id, item.match_time)];
model.pre = [_(model.xxzs).map((a) => a.pre).flatten().countBy().toPairs().orderBy([1], ['desc']).take(2).map(a => a[0]).value(), [2, 3]];
var sum_avg_jq = history_host_team.avg_jq + history_guest_team.avg_jq;
if (sum_avg_jq > 6)
sum_avg_jq = 6.1;
model.pre[1] = [Math.floor(sum_avg_jq), Math.ceil(sum_avg_jq)];
// if (model.meeting && model.meeting.sum_jq && model.meeting.z_spf.length) {
// var avg_jq = model.meeting.sum_jq * 1.0 / model.meeting.z_spf.length;
// model.pre[1] = [Math.floor(avg_jq), Math.ceil(avg_jq)];
// } else if (history_host_team.sum_jq && history_guest_team.sum_jq) {
// var avg_jq = (1.0 * history_host_team.sum_jq / history_host_team.data.length + 1.0 * history_guest_team.sum_jq / history_guest_team.data.length) / 2.0;
// model.pre[1] = [Math.floor(avg_jq), Math.ceil(avg_jq)];
// }
model.pre[1] = _.uniq(model.pre[1]);
var h = await trait_team(item.yiqiu_host_team_id, item.match_time);
var g = await trait_team(item.yiqiu_guest_team_id, item.match_time);
model.trait = [h, g];
try {
// 胜平负 总进球 比分 半全场
//[["胜", "平"], [3, 4]]
model.pre_all = [...model.pre, ...predictScoreAndHalfFull(model.pre)];
}
catch (error) {
console.log(`predictScoreAndHalfFull error: ${JSON.stringify(model.pre)} ${error.message}`);
}
await info_db.tools_sxjx.create(model);
await (0, common_1.sleep)(2000);
}
}
function predictScoreAndHalfFull(pre) {
// 输入参数结构: pre = [["胜", "平"], [3, 4]]
const [winDrawLose, totalGoals] = pre;
// 比分预测结果
const scorePredictions = [];
// 半全场预测结果
const halfFullPredictions = [];
// 根据胜平负和总进球生成比分预测
for (const outcome of winDrawLose) {
for (const goals of totalGoals) {
// 随机生成2-4个比分预测
const count = Math.floor(Math.random() * 3) + 2;
for (let i = 0; i < count; i++) {
if (outcome === "胜") {
// 主队胜的比分: 主队进球 > 客队进球,且总和=goals
// 主队至少进1球,最多进goals-1球
// 客队最多进主队进球-1球
const minHome = Math.max(1, Math.ceil(goals / 2));
const maxHome = goals;
if (minHome > maxHome)
continue; // 无解情况跳过
const home = Math.floor(Math.random() * (maxHome - minHome + 1)) + minHome;
const away = goals - home;
scorePredictions.push(`${home}-${away}`);
}
else if (outcome === "平") {
// 平局的比分: 主队进球 = 客队进球,且总和=goals
if (goals % 2 === 0) {
const score = goals / 2;
scorePredictions.push(`${score}-${score}`);
}
}
else if (outcome === "负") {
// 客队胜的比分: 主队进球 < 客队进球,且总和=goals
// 客队至少进1球,最多进goals-1球
// 主队最多进客队进球-1球
const minAway = Math.max(1, Math.ceil(goals / 2));
const maxAway = goals;
if (minAway > maxAway)
continue; // 无解情况跳过
const away = Math.floor(Math.random() * (maxAway - minAway + 1)) + minAway;
const home = goals - away;
scorePredictions.push(`${home}-${away}`);
}
}
}
}
// 根据胜平负生成半全场预测
for (const outcome of winDrawLose) {
// 随机生成2-4个半全场预测
const count = Math.floor(Math.random() * 3) + 2;
for (let i = 0; i < count; i++) {
if (outcome === "胜") {
// 可能的情况: 胜胜, 平胜
const options = ["胜胜", "平胜"];
halfFullPredictions.push(options[Math.floor(Math.random() * options.length)]);
}
else if (outcome === "平") {
// 可能的情况: 平平, 胜平, 负平
const options = ["平平", "胜平", "负平"];
halfFullPredictions.push(options[Math.floor(Math.random() * options.length)]);
}
else if (outcome === "负") {
// 可能的情况: 负负, 平负
const options = ["负负", "平负"];
halfFullPredictions.push(options[Math.floor(Math.random() * options.length)]);
}
}
}
// 去重并限制数量
const uniqueScores = [...new Set(scorePredictions)].slice(0, 4);
const uniqueHalfFull = [...new Set(halfFullPredictions)].slice(0, 4);
return [uniqueScores, uniqueHalfFull];
}
async function calc_pre_win() {
await info_db.sequelize.query(`
UPDATE tools_sxjx a
JOIN ms_soccer_game b ON a.id = b.id
SET
a.score=b.score,
a.half=CONCAT('[', REPLACE(b.half, '-', ','), ']'),
a.pre_win = JSON_ARRAY(
CASE
WHEN JSON_EXTRACT(b.score, '$[0]') > JSON_EXTRACT(b.score, '$[1]') THEN '胜'
WHEN JSON_EXTRACT(b.score, '$[0]') < JSON_EXTRACT(b.score, '$[1]') THEN '负'
ELSE '平'
END,
LEAST(JSON_EXTRACT(b.score, '$[0]') + JSON_EXTRACT(b.score, '$[1]'), 7)
)
WHERE a.created_at>DATE_SUB(CURDATE(), INTERVAL 7 DAY)
and a.pre_win IS NULL
and b.status=4
AND b.score IS NOT NULL;
update tools_sxjx
set is_win= (
JSON_CONTAINS(JSON_EXTRACT(pre, '$[0]'), JSON_EXTRACT(pre_win, '$[0]')) OR
JSON_CONTAINS(JSON_EXTRACT(pre, '$[0]'), JSON_EXTRACT(pre_win, '$[1]')) OR
JSON_CONTAINS(JSON_EXTRACT(pre, '$[1]'), JSON_EXTRACT(pre_win, '$[0]')) OR
JSON_CONTAINS(JSON_EXTRACT(pre, '$[1]'), JSON_EXTRACT(pre_win, '$[1]'))
)
WHERE created_at>DATE_SUB(CURDATE(), INTERVAL 7 DAY) and pre IS NOT NULL AND pre_win IS NOT NULL and is_win is null;
`, {
type: info_db.sequelize.QueryTypes.UPDATE
})
.then(result => {
console.log(`calc_pre_win ok ${moment().format('YYYY-MM-DD HH:mm:ss')}`);
})
.catch(err => {
console.error(`calc_pre_win error :`, err);
});
await (0, common_1.sleep)(88);
var ret = await info_db.tools_sxjx.findAll({
attributes: ['id', 'score', 'half', 'pre_all'],
limit: 1000,
where: {
created_at: { $gt: moment().subtract(7, 'days').toDate() },
win_all: null,
open_result: null,
pre_all: { $ne: null },
pre_win: { $ne: null },
score: { $ne: null },
half: { $ne: null }
}
}).map((a) => a.dataValues);
for (let index = 0; index < ret.length; index++) {
var item = ret[index];
try {
var qc_spf = item.score[0] > item.score[1] ? '胜' : item.score[0] < item.score[1] ? '负' : '平';
var bc_spf = item.half[0] > item.half[1] ? '胜' : item.half[0] < item.half[1] ? '负' : '平';
var open_result = [
qc_spf,
item.score[0] + item.score[1],
`${item.score.join('-')}`,
`${bc_spf}${qc_spf}`
];
var win_all = item.pre_all.map((item, index) => item.find((a) => a == open_result[index]) || '');
await info_db.tools_sxjx.update({
open_result,
win_all,
}, {
where: {
id: item.id
}
});
}
catch (error) {
console.log(`calc_pre_win update win all error :${item.id} ${error.message}`);
}
await (0, common_1.sleep)(88);
}
await (0, common_1.sleep)(1000);
}
exports.calc_pre_win = calc_pre_win;
//生成比赛数据
async function create_match_data() {
for (let index = -3; index < 1; index++) {
await start1(moment().add(-index, 'days').format('YYYY-MM-DD')).catch(a => console.log(a));
}
}
exports.create_match_data = create_match_data;
//# sourceMappingURL=index.js.map
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sxjx_calc_pre_win = exports.sxjx_create_match_data = void 0;
const sxjx_1 = require("../../bl/sxjx");
async function sxjx_create_match_data() {
return (0, sxjx_1.create_match_data)();
}
exports.sxjx_create_match_data = sxjx_create_match_data;
async function sxjx_calc_pre_win() {
return (0, sxjx_1.calc_pre_win)();
}
exports.sxjx_calc_pre_win = sxjx_calc_pre_win;
//# sourceMappingURL=index.js.map
\ No newline at end of file
......@@ -2,6 +2,8 @@
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const path = require('path');
//多线程情况下 需要重新初始化config配置
require('../../config/index');
const job_handlers = new Map();
/**
* 递归加载指定目录下所有 .js 文件
......
//处理纳米数据,共用调用
import * as info_db from '../info_mysql/table';
import * as nami_db from '../nami_mysql/table';
import * as moment from 'moment';
import * as _ from 'lodash';
import { sleep } from '../../libs/common';
async function best_player(team_id: number, date = moment().format('YYYY-MM-DD')) {
var data = await nami_db.sequelize.query(
`SELECT id,player_stats,home_team_id,away_team_id from db_nami.matches where
match_time<UNIX_TIMESTAMP('${moment(date).format('YYYY-MM-DD')}}') and
(home_team_id=${team_id} or away_team_id=${team_id}) and
JSON_LENGTH(player_stats)>0
ORDER BY match_time desc LIMIT 10;`
)
.then(result => {
if (result && result.length > 1 && result[1]) {
return result[1];
}
return null;
})
.catch(err => {
console.log(`best_player ${team_id} >>> ${err.message}`);
return null;
});
if (!data || data.length < 1) {
return [];
}
for (let index = 0; index < data.length; index++) {
try {
const item = data[index];
var v = _(item.player_stats).filter(a => a.team_id == team_id).orderBy('rating', 'desc').take(3).map(a => ({ player_id: a.player_id, rating: a.rating })).value();
if (v[0].rating < 1) {
continue;
}
//select short_name_zh,logo from players where id in (1332014)
var res = await nami_db.players.findAll({
attributes: ['id', 'short_name_zh', 'logo'],
where: {
id: {
$in: v.map(a => a.player_id)
}
}
});
v.forEach((a: any) => {
var v1: any = _(res).find((b: any) => b.id == a.player_id);
if (v1) {
a.short_name_zh = v1.short_name_zh;
a.logo = v1.logo;
}
})
return v;
} catch (error) {
}
return [];
}
return [];
}
async function history_team(team_id: number, is_host = false, date = moment().format('YYYY-MM-DD')) {
var data = await info_db.sequelize.query(
`select match_time,yiqiu_host_team_id,yiqiu_guest_team_id,score from ms_soccer_game where
match_time<'${moment(date).format('YYYY-MM-DD')}' and (yiqiu_host_team_id=${team_id} or yiqiu_guest_team_id =${team_id} )
ORDER BY match_time desc LIMIT 20`
)
.then(result => {
if (result && result.length > 1 && result[1]) {
return result[1];
}
return null;
})
.catch(err => {
console.log(`history_team ${team_id} >>> ${err.message}`);
return null;
});
if (!data || data.length < 1) {
return { data: [], avg_jq: 0 };
}
var sum_jq_time = 0;
var time = 0;
var sum_jq = 0;
var host_jq = 0;
var spf: any = [0, 0, 0];
var res = data.map(function (item: any) {
var r = 0;
var is_host_team = item.yiqiu_host_team_id == team_id;
try {
var bf = JSON.parse(item.score);
bf = bf.map((a: any) => Number(a));
if (time < 4) {
if (is_host) {
if (item.yiqiu_host_team_id == team_id) {
time++;
sum_jq_time += bf[0];
}
} else {
if (item.yiqiu_guest_team_id == team_id) {
time++;
sum_jq_time += bf[1];
}
}
}
sum_jq += (bf[0] + bf[1]);
host_jq += (item.yiqiu_host_team_id == team_id ? bf[0] : bf[1]);
if (bf[0] == bf[1]) {
r = 1;
} else if (item.yiqiu_host_team_id == team_id) {
r = bf[0] > bf[1] ? 2 : 0;
} else {
r = bf[0] > bf[1] ? 0 : 2;
}
if (is_host_team == is_host) {
spf[r]++;
}
return r;
} catch (error) {
return 0;
}
}).reverse();
return { data: res, avg_jq: time > 0 ? 1.0 * sum_jq_time / time : 0, sum_jq, host_jq, spf };
}
var trait_action: any = {
s: (bf: number[], is_host: boolean) => {
if (is_host) {
return bf[0] > bf[1]
} else {
return bf[0] < bf[1]
}
},
p: (bf: number[], is_host: boolean) => {
return bf[0] == bf[1]
},
f: (bf: number[], is_host: boolean) => {
if (is_host) {
return bf[0] < bf[1]
} else {
return bf[0] > bf[1]
}
},
no_f: (bf: number[], is_host: boolean) => {
if (is_host) {
return bf[0] >= bf[1]
} else {
return bf[0] <= bf[1]
}
},
no_p: (bf: number[], is_host: boolean) => {
return bf[0] != bf[1];
},
jq: (bf: number[], is_host: boolean) => {
if (is_host) {
return bf[0] > 0
} else {
return bf[1] > 0
}
},
no_jq: (bf: number[], is_host: boolean) => {
if (is_host) {
return bf[0] == 0
} else {
return bf[1] == 0
}
},
}
function trait_calc(list: any[], team_id: number) {
var max: any = { s: 0, p: 0, f: 0, no_f: 0, no_p: 0, jq: 0, no_jq: 0 }
var now: any = { s: 0, p: 0, f: 0, no_f: 0, no_p: 0, jq: 0, no_jq: 0 }
for (let index = list.length - 1; index >= 0; index--) {
const item = list[index];
var is_host = item.yiqiu_host_team_id == team_id;
var bf;
try {
bf = JSON.parse(item.score).map((a: any) => Number(a));
} catch (error) {
continue;
}
for (const key in now) {
if (trait_action[key].call(null, bf, is_host)) {
now[key]++;
} else {
now[key] = 0;
}
if (now[key] > max[key]) {
max[key] = now[key]
}
}
}
return { now, max }
}
async function trait_team(team_id: number, date = moment().format('YYYY-MM-DD')) {
var data = await info_db.sequelize.query(
`select yiqiu_host_team_id,yiqiu_guest_team_id,score from ms_soccer_game where
match_time<'${moment(date).format('YYYY-MM-DD')}' and status=4 and score is not null and (yiqiu_host_team_id=${team_id} or yiqiu_guest_team_id =${team_id} )
ORDER BY match_time desc LIMIT 1000`
)
.then(result => {
if (result && result.length > 1 && result[1]) {
return result[1];
}
return null;
})
.catch(err => {
console.log(`trait_team ${team_id} >>> ${err.message}`);
return null;
});
if (!data || data.length < 1) {
return null;
}
var t0 = trait_calc(data, team_id);
var t1 = trait_calc(data.filter((a: any) => a.yiqiu_host_team_id == team_id), team_id);
var t2 = trait_calc(data.filter((a: any) => a.yiqiu_guest_team_id == team_id), team_id);
return { t0, t1, t2 };
}
async function meeting(teamids: any[], date = moment().format('YYYY-MM-DD')) {
var data = await info_db.sequelize.query(
`select match_time,yiqiu_host_team_id,yiqiu_guest_team_id,score from ms_soccer_game where
match_time<'${moment(date).format('YYYY-MM-DD')}' and yiqiu_host_team_id in(${teamids.join(',')}) and yiqiu_guest_team_id in(${teamids.join(',')})
ORDER BY match_time desc LIMIT 20`
)
.then(result => {
if (result && result.length > 1 && result[1]) {
return result[1];
}
return null;
})
.catch(err => {
console.log(`meeting ${teamids.join(',')} >>> ${err.message}`);
return null;
});
if (!data || data.length < 1) {
return {};
}
var sum_jq = 0;
var host_jq = 0;
var res = data.map(function (item: any) {
try {
var bf = typeof item.score == 'string' ? JSON.parse(item.score) : item.score;
bf = bf.map((a: any) => Number(a));
sum_jq += (bf[0] + bf[1]);
host_jq += (item.yiqiu_host_team_id == teamids[0] ? bf[0] : bf[1]);
if (bf[0] == bf[1]) {
return 1;
}
if (item.yiqiu_host_team_id == teamids[0]) {
return bf[0] > bf[1] ? 2 : 0;
}
return bf[0] > bf[1] ? 0 : 2;
} catch (error) {
}
return 0;
}).reverse();
return {
sum_jq: sum_jq,
host_jq: host_jq,
z_spf: res
}
}
async function calc_odds(matchid: any) {
var data = await nami_db.sequelize.query(
`
select
avg( CAST(JSON_UNQUOTE(JSON_EXTRACT(latest_immediate_odds, '$[0]')) AS DECIMAL(10, 2)) )s,
avg(CAST(JSON_UNQUOTE(JSON_EXTRACT(latest_immediate_odds, '$[1]')) AS DECIMAL(10, 2))) p,
avg(CAST(JSON_UNQUOTE(JSON_EXTRACT(latest_immediate_odds, '$[2]')) AS DECIMAL(10, 2)) )f
from odds_asian_immediate where id= :matchid
;
select
avg( CAST(JSON_UNQUOTE(JSON_EXTRACT(latest_immediate_odds, '$[0]')) AS DECIMAL(10, 2)) )s,
avg(CAST(JSON_UNQUOTE(JSON_EXTRACT(latest_immediate_odds, '$[1]')) AS DECIMAL(10, 2))) p,
avg(CAST(JSON_UNQUOTE(JSON_EXTRACT(latest_immediate_odds, '$[2]')) AS DECIMAL(10, 2)) )f
from odds_european_immediate where id= :matchid`,
{
replacements: { matchid },
}
)
.then(result => {
if (result && result.length > 1 && result[1]) {
return result[1];
}
return null;
})
.catch(err => {
console.log(`calc_odds ${matchid} >>> ${err.message}`);
return null;
});
if (!data || data.length != 2 || !data[0][0].s || !data[1][0].s) {
return null;
}
// 亚洲态度:取全部公司的均值后,计算百分比,根据下面方式取概率大的一方加平。
// 如:通过多家亚指公司算出均值如下:
// 1.01 -0.78 0.85
// 第一步:先把本金加上水位都加1.则为2.01 -0.78 1.85
// 第二步:让球方为主队,则主水2.01+盘口0.78=2.79
// 第三步:用2.79 1.85计算百分比:
// 胜:4.64/(1.23+1.85)=60%
// 负:1-60%=40%
// 平:平固定算20%;
// 取概率大的一方加平,则可取:胜 平 百分比为80%。
var asia_data = data[0][0];
var asia;
if (asia_data.p > 0) {
asia = {
rate: (asia_data.f + 1) / (asia_data.s + 1 + asia_data.p) + 0.2,
pre: ['胜', '平']
}
} else {
asia = {
rate: (asia_data.s + 1) / (asia_data.f + 1 - asia_data.p) + 0.2,
pre: ['负', '平']
}
}
var europe_data = data[1][0];
var europe;
if (europe_data.s < europe_data.f) {
europe = {
rate: (1 / europe_data.s + 1 / europe_data.p) / (1 / europe_data.s + 1 / europe_data.p + 1 / europe_data.f),
pre: ['胜', '平']
}
} else {
europe = {
rate: (1 / europe_data.f + 1 / europe_data.p) / (1 / europe_data.s + 1 / europe_data.p + 1 / europe_data.f),
pre: ['负', '平']
}
}
return {
asia,
europe
}
}
async function lstp(sp: any) {
// let sql = `
// select game_id as GameId,
// competition_id,
// score as Score,
// host_id as SportsdtHostId,
// guest_id as SportsdtGuestId,
// host_name,
// guest_name,
// game_date as Date,
// game_name,
// yiqiu_game_id,
// JSON_ARRAY(first_odds_host,first_odds_guest,first_odds_handicap,sport_odds_host,sport_odds_guest,sport_odds_handicap) as Data
// from db_info.stat_soccer_ahodds
// where first_odds_host=${sp[0]}
// and first_odds_guest=${sp[1]}
// and first_odds_handicap=${sp[2]}
// and game_date<'${moment().add(-1, 'days').format("YYYY-MM-DD HH:mm:ss")}'
// order by game_date desc
// limit 300 `
// let list = await info_db.sequelize.query(sql)
// if (list[0].length > 0) {
// list = list[0]
// } else {
// list = []
// }
// if (list && list.length) {
// return;
// }
if (sp[0] < sp[2]) {
return {
rate: (1 / sp[0] + 1 / sp[1]) / (1 / sp[0] + 1 / sp[1] + 1 / sp[2]),
pre: ['胜', '平']
}
} else {
return {
rate: (1 / sp[2] + 1 / sp[1]) / (1 / sp[0] + 1 / sp[1] + 1 / sp[2]),
pre: ['负', '平']
}
}
// list = JSON.parse(JSON.stringify(list))
// list = _.filter(list, (o) => {
// return o.host_name && o.guest_name
// })
// list = _.unionBy(list, "yiqiu_game_id");
// return base.getItemResultByList(list, true)
return null;
}
async function start1(issue_name: any) {
// var issue_name = moment().format('YYYY-MM-DD');
var data = await info_db.ms_soccer_game.findAll({
attributes: ['id', 'leisu_match_id', 'odds', 'yiqiu_host_team_id', 'yiqiu_guest_team_id', 'leisu_host_id', 'leisu_guest_id', 'match_time'],
where: {
sporttery_issue_name: issue_name,
odds: {
$ne: null
},
match_time: {
$gte: moment().format('YYYY-MM-DD HH:mm:ss')
}
}
});
var data1 = await info_db.ms_soccer_game.findAll({
attributes: ['id', 'leisu_match_id', 'odds', 'yiqiu_host_team_id', 'yiqiu_guest_team_id', 'leisu_host_id', 'leisu_guest_id', 'match_time'],
where: {
sporttery_issue_name: null,
$or: [
{ is_beidan: 1 },
{ is_zucai: 1 }
],
odds: {
$ne: null
},
match_time: {
$between: [moment().format('YYYY-MM-DD HH:mm:ss'), moment(issue_name).add(1, 'day').format('YYYY-MM-DD 00:00:00')]
}
}
});
data = data.concat(data1);
if (!data || data.length < 1) return;
var sxjx_list = await info_db.tools_sxjx.findAll({
where: {
id: {
$in: data.map((a: any) => a.id)
}
}
});
for (let index = 0; index < data.length; index++) {
const item: any = data[index];
var temp: any = sxjx_list.find((a: any) => a.id == item.id);
var odds = await calc_odds(item.leisu_match_id);
if (!odds) {
continue;
}
if (temp) {
temp.xxzs[0] = odds.europe;
temp.xxzs[1] = odds.asia;
temp.xxzs[2] = {
rate: (odds.asia.rate + odds.europe.rate) / 2,
pre: [odds.asia.pre[0]]
}
temp.xxzs = temp.xxzs.map((a: any, index1: any) => {
if (index1 == 3) return a;
var rate = _.toInteger(a.rate.toFixed(2) * 100 + 0.0001);
a.rate = rate > 90 ? 90 : rate;
return a;
})
temp.xxzs[4] = {
rate: _.toInteger((odds.asia.rate + odds.europe.rate + temp.xxzs[2].rate + temp.xxzs[3].rate) / 4),
pre: [odds.asia.pre[0]],
}
await temp.save();
continue;
}
var eu = item.odds['3000181'].eu.map((a: any) => Number(a));
var lstp_temp: any = await lstp(eu);
var model: any = { id: item.id };
var user_zs: any;
if (eu[0] < eu[2]) {
user_zs = {
rate: (1 / eu[0] + 1 / eu[1]) / (1 / eu[0] + 1 / eu[1] + 1 / eu[2]),
pre: ['胜', '平']
}
} else {
user_zs = {
rate: (1 / eu[2] + 1 / eu[1]) / (1 / eu[0] + 1 / eu[1] + 1 / eu[2]),
pre: ['负', '平']
}
}
model.xxzs = [
odds.europe,
odds.asia,
user_zs,
lstp_temp,
{
rate: (odds.asia.rate + odds.europe.rate + user_zs.rate + lstp_temp.rate) / 4,
pre: [odds.asia.pre[0]],
}
]
model.xxzs.forEach((a: any) => {
var rate = _.toInteger(a.rate.toFixed(2) * 100 + 0.0001);
a.rate = rate > 90 ? 90 : rate;
})
model.xxzs[4] = {
rate: _.toInteger((odds.asia.rate + odds.europe.rate + user_zs.rate + lstp_temp.rate) / 4),
pre: [odds.asia.pre[0]],
}
model.meeting = await meeting([item.yiqiu_host_team_id, item.yiqiu_guest_team_id], item.match_time);
var history_host_team = await history_team(item.yiqiu_host_team_id, true, item.match_time)
var history_guest_team = await history_team(item.yiqiu_guest_team_id, false, item.match_time)
// { data: res, avg_jq: time > 0 ? 1.0 * sum_jq_time / time : 0, sum_jq, host_jq }
model.history = [history_host_team.data, history_guest_team.data,
{ sum_jq: history_host_team.sum_jq, host_jq: history_host_team.host_jq, spf: history_host_team.spf },
{ sum_jq: history_guest_team.sum_jq, host_jq: history_guest_team.host_jq, spf: history_guest_team.spf }
];
model.best_player = [await best_player(item.leisu_host_id, item.match_time), await best_player(item.leisu_guest_id, item.match_time)];
model.pre = [_(model.xxzs).map((a: any) => a.pre).flatten().countBy().toPairs().orderBy([1], ['desc']).take(2).map(a => a[0]).value(), [2, 3]];
var sum_avg_jq = history_host_team.avg_jq + history_guest_team.avg_jq;
if (sum_avg_jq > 6) sum_avg_jq = 6.1;
model.pre[1] = [Math.floor(sum_avg_jq), Math.ceil(sum_avg_jq)];
// if (model.meeting && model.meeting.sum_jq && model.meeting.z_spf.length) {
// var avg_jq = model.meeting.sum_jq * 1.0 / model.meeting.z_spf.length;
// model.pre[1] = [Math.floor(avg_jq), Math.ceil(avg_jq)];
// } else if (history_host_team.sum_jq && history_guest_team.sum_jq) {
// var avg_jq = (1.0 * history_host_team.sum_jq / history_host_team.data.length + 1.0 * history_guest_team.sum_jq / history_guest_team.data.length) / 2.0;
// model.pre[1] = [Math.floor(avg_jq), Math.ceil(avg_jq)];
// }
model.pre[1] = _.uniq(model.pre[1]);
var h = await trait_team(item.yiqiu_host_team_id, item.match_time)
var g = await trait_team(item.yiqiu_guest_team_id, item.match_time)
model.trait = [h, g];
try {
// 胜平负 总进球 比分 半全场
//[["胜", "平"], [3, 4]]
model.pre_all = [...model.pre, ...predictScoreAndHalfFull(model.pre)];
} catch (error: any) {
console.log(`predictScoreAndHalfFull error: ${JSON.stringify(model.pre)} ${error.message}`)
}
await info_db.tools_sxjx.create(model);
await sleep(2000);
}
}
function predictScoreAndHalfFull(pre: any) {
// 输入参数结构: pre = [["胜", "平"], [3, 4]]
const [winDrawLose, totalGoals] = pre;
// 比分预测结果
const scorePredictions = [];
// 半全场预测结果
const halfFullPredictions = [];
// 根据胜平负和总进球生成比分预测
for (const outcome of winDrawLose) {
for (const goals of totalGoals) {
// 随机生成2-4个比分预测
const count = Math.floor(Math.random() * 3) + 2;
for (let i = 0; i < count; i++) {
if (outcome === "胜") {
// 主队胜的比分: 主队进球 > 客队进球,且总和=goals
// 主队至少进1球,最多进goals-1球
// 客队最多进主队进球-1球
const minHome = Math.max(1, Math.ceil(goals / 2));
const maxHome = goals;
if (minHome > maxHome) continue; // 无解情况跳过
const home = Math.floor(Math.random() * (maxHome - minHome + 1)) + minHome;
const away = goals - home;
scorePredictions.push(`${home}-${away}`);
} else if (outcome === "平") {
// 平局的比分: 主队进球 = 客队进球,且总和=goals
if (goals % 2 === 0) {
const score = goals / 2;
scorePredictions.push(`${score}-${score}`);
}
} else if (outcome === "负") {
// 客队胜的比分: 主队进球 < 客队进球,且总和=goals
// 客队至少进1球,最多进goals-1球
// 主队最多进客队进球-1球
const minAway = Math.max(1, Math.ceil(goals / 2));
const maxAway = goals;
if (minAway > maxAway) continue; // 无解情况跳过
const away = Math.floor(Math.random() * (maxAway - minAway + 1)) + minAway;
const home = goals - away;
scorePredictions.push(`${home}-${away}`);
}
}
}
}
// 根据胜平负生成半全场预测
for (const outcome of winDrawLose) {
// 随机生成2-4个半全场预测
const count = Math.floor(Math.random() * 3) + 2;
for (let i = 0; i < count; i++) {
if (outcome === "胜") {
// 可能的情况: 胜胜, 平胜
const options = ["胜胜", "平胜"];
halfFullPredictions.push(options[Math.floor(Math.random() * options.length)]);
} else if (outcome === "平") {
// 可能的情况: 平平, 胜平, 负平
const options = ["平平", "胜平", "负平"];
halfFullPredictions.push(options[Math.floor(Math.random() * options.length)]);
} else if (outcome === "负") {
// 可能的情况: 负负, 平负
const options = ["负负", "平负"];
halfFullPredictions.push(options[Math.floor(Math.random() * options.length)]);
}
}
}
// 去重并限制数量
const uniqueScores = [...new Set(scorePredictions)].slice(0, 4);
const uniqueHalfFull = [...new Set(halfFullPredictions)].slice(0, 4);
return [uniqueScores, uniqueHalfFull];
}
async function calc_pre_win() {
await info_db.sequelize.query(
`
UPDATE tools_sxjx a
JOIN ms_soccer_game b ON a.id = b.id
SET
a.score=b.score,
a.half=CONCAT('[', REPLACE(b.half, '-', ','), ']'),
a.pre_win = JSON_ARRAY(
CASE
WHEN JSON_EXTRACT(b.score, '$[0]') > JSON_EXTRACT(b.score, '$[1]') THEN '胜'
WHEN JSON_EXTRACT(b.score, '$[0]') < JSON_EXTRACT(b.score, '$[1]') THEN '负'
ELSE '平'
END,
LEAST(JSON_EXTRACT(b.score, '$[0]') + JSON_EXTRACT(b.score, '$[1]'), 7)
)
WHERE a.created_at>DATE_SUB(CURDATE(), INTERVAL 7 DAY)
and a.pre_win IS NULL
and b.status=4
AND b.score IS NOT NULL;
update tools_sxjx
set is_win= (
JSON_CONTAINS(JSON_EXTRACT(pre, '$[0]'), JSON_EXTRACT(pre_win, '$[0]')) OR
JSON_CONTAINS(JSON_EXTRACT(pre, '$[0]'), JSON_EXTRACT(pre_win, '$[1]')) OR
JSON_CONTAINS(JSON_EXTRACT(pre, '$[1]'), JSON_EXTRACT(pre_win, '$[0]')) OR
JSON_CONTAINS(JSON_EXTRACT(pre, '$[1]'), JSON_EXTRACT(pre_win, '$[1]'))
)
WHERE created_at>DATE_SUB(CURDATE(), INTERVAL 7 DAY) and pre IS NOT NULL AND pre_win IS NOT NULL and is_win is null;
`,
{
type: info_db.sequelize.QueryTypes.UPDATE
}
)
.then(result => {
console.log(`calc_pre_win ok ${moment().format('YYYY-MM-DD HH:mm:ss')}`);
})
.catch(err => {
console.error(`calc_pre_win error :`, err);
});
await sleep(88);
var ret = await info_db.tools_sxjx.findAll({
attributes: ['id', 'score', 'half', 'pre_all'],
limit: 1000,
where: {
created_at: { $gt: moment().subtract(7, 'days').toDate() },
win_all: null,
open_result: null,
pre_all: { $ne: null },
pre_win: { $ne: null },
score: { $ne: null },
half: { $ne: null }
}
}).map((a: any) => a.dataValues);
for (let index = 0; index < ret.length; index++) {
var item: any = ret[index];
try {
var qc_spf = item.score[0] > item.score[1] ? '胜' : item.score[0] < item.score[1] ? '负' : '平';
var bc_spf = item.half[0] > item.half[1] ? '胜' : item.half[0] < item.half[1] ? '负' : '平';
var open_result = [
qc_spf,
item.score[0] + item.score[1],
`${item.score.join('-')}`,
`${bc_spf}${qc_spf}`
]
var win_all = item.pre_all.map((item: any, index: number) => item.find((a: any) => a == open_result[index]) || '');
await info_db.tools_sxjx.update({
open_result,
win_all,
}, {
where: {
id: item.id
}
});
} catch (error: any) {
console.log(`calc_pre_win update win all error :${item.id} ${error.message}`);
}
await sleep(88);
}
await sleep(1000);
}
//生成比赛数据
async function create_match_data() {
for (let index = -3; index < 1; index++) {
await start1(moment().add(-index, 'days').format('YYYY-MM-DD')).catch(a => console.log(a))
}
}
// //2个小时执行1次
// schedule.scheduleJob('0 */2 * * *', async function () {
// for (let index = -3; index < 1; index++) {
// await start1(moment().add(-index, 'days').format('YYYY-MM-DD')).catch(a => console.log(a))
// }
// });
// //1个小时执行1次
// schedule.scheduleJob('0 * * * *', function () {
// calc_pre_win();
// })
export { create_match_data, calc_pre_win }
import { create_match_data, calc_pre_win } from '../../bl/sxjx'
export async function sxjx_create_match_data() {
return create_match_data();
}
export async function sxjx_calc_pre_win() {
return calc_pre_win();
}
......@@ -2,6 +2,9 @@
import * as fs from 'fs'
const path = require('path')
//多线程情况下 需要重新初始化config配置
require('../../config/index');
const job_handlers = new Map();
/**
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!