flyzto 6 месяцев назад
Родитель
Сommit
7bcde5727b

+ 62 - 6
server/models/GamesPs.js

@@ -1,6 +1,7 @@
 const axios = require('axios');
 const Logs = require('../libs/logs');
 const Setting = require('./Setting');
+const calcTotalProfit = require('../triangle/totalProfitCalc');
 
 const childOptions = process.env.NODE_ENV == 'development' ? {
   execArgv: ['--inspect=9228']
@@ -224,16 +225,39 @@ const syncBaseEvents = ({ mk, games, outrights }) => {
           match
         };
       }).filter(item => item.match.every(entry => entry.value !== 0));
-      return { ...gameInfo, matches };
+      return { ...gameInfo, matches, uptime: Math.min(evtime, sptime) };
     });
-    // Logs.out('baseList', baseList[marketType]);
+
     submitOdds({ platform: 'ps', mk, games: gamesList });
+
+    const relatedGames = Object.values(GAMES.Relations).map(item => item.rel?.['ps'] ?? {});
+
+    if (!relatedGames.length) {
+      return 0;
+    }
+
+    let update = 0;
+    const relatedMap = new Map(relatedGames.map(item => [item.eventId, item]));
+
+    gamesList?.forEach(game => {
+      const { eventId, matches, uptime } = game;
+      const relatedGame = relatedMap.get(eventId);
+      if (relatedGame) {
+        const events = {};
+        matches.forEach(({ label, match }) => {
+          match.forEach(({ key, value }) => {
+            events[key] = value;
+          });
+        });
+        relatedGame.evtime = uptime;
+        relatedGame.events = events;
+        update ++;
+      }
+    });
+    return update;
   }
 }
 
-/**
- * 更新比赛盘口
- */
 const updateGamesEvents = ({ platform, mk, games, outrights }) => {
   return new Promise((resolve, reject) => {
     if (!platform || (!games && !outrights)) {
@@ -241,7 +265,8 @@ const updateGamesEvents = ({ platform, mk, games, outrights }) => {
     }
 
     if (platform == 'ps') {
-      syncBaseEvents({ mk, games, outrights });
+      const update = syncBaseEvents({ mk, games, outrights });
+      return resolve({ update });
     }
 
     const relatedGames = Object.values(GAMES.Relations).map(item => item.rel?.[platform] ?? {});
@@ -285,6 +310,9 @@ const updateGamesEvents = ({ platform, mk, games, outrights }) => {
  * 获取比赛盘口
  */
 const getGamesEvents = ({ platform, relIds = [] } = {}) => {
+  if (!relIds.length) {
+    return null;
+  }
   const idSet = new Set(relIds);
   const relations = { ...GAMES.Relations };
   Object.keys(relations).forEach(id => {
@@ -580,6 +608,33 @@ setInterval(() => {
   solutionsCleanup();
 }, 1000*30);
 
+/**
+ * 获取综合利润
+ */
+const getTotalProfit = (sid1, sid2, gold_side_inner) => {
+  const preSolution = GAMES.Solutions[sid1];
+  const subSolution = GAMES.Solutions[sid2];
+  const relId1 = preSolution?.info?.id;
+  const relId2 = subSolution?.info?.id;
+  const relIds = [relId1, relId2];
+  const gamesEvents = getGamesEvents({ relIds });
+
+  const gamesRelations = getGamesRelation();
+  const relationsMap = new Map(gamesRelations.map(item => [item.id, item.rel]));
+  const preRelation = relationsMap.get(relId1);
+  const subRelation = relationsMap.get(relId2);
+  preSolution.info = { id: relId1, ...preRelation };
+  subSolution.info = { id: relId2, ...subRelation };
+
+  const sol1 = preSolution?.sol;
+  const sol2 = subSolution?.sol;
+  if (!sol1 || !sol2 || !gold_side_inner) {
+    return {};
+  }
+  const profit = calcTotalProfit(sol1, sol2, gold_side_inner);
+  return { profit, preSolution, subSolution, gamesEvents };
+}
+
 /**
  * 获取后台设置
  */
@@ -632,4 +687,5 @@ module.exports = {
   getGamesRelation,
   updateGamesResult,
   getSolutions,
+  getTotalProfit,
 }

+ 3 - 1
server/routes/pstery.js

@@ -78,7 +78,9 @@ router.get('/get_solutions', (req, res) => {
 
 // 获取综合利润方案
 router.post('/calc_total_profit', (req, res) => {
-  res.sendSuccess({ value: 'hello world' })
+  const [sid1, sid2, gold_side_inner] = req.body;
+  const totalProfit = Games.getTotalProfit(sid1, sid2, gold_side_inner);
+  res.sendSuccess(totalProfit);
 });
 
 module.exports = router;

+ 4 - 1
server/triangle/trangleCalc.js

@@ -56,7 +56,10 @@ function getOptimalSelections(odds, rules) {
           }
           // Logs.out('candidates', candidates)
           const best = candidates.reduce((a, b) => {
-            return (item[a]-1)*rebateMap[a] > (item[b]-1)*rebateMap[b] ? a : b;
+            const aValue = (item[a]-1)*rebateMap[a];
+            const bValue = (item[b]-1)*rebateMap[b];
+            const seletcted = aValue > bValue ? a : b;
+            return seletcted;
           });
           // Logs.out('best', item, best)
           selection.push({

+ 25 - 64
web/apps/web-antd/src/views/match/solutions/index.vue

@@ -137,9 +137,9 @@ const getSolutions = async () => {
 }
 
 const calcTotalProfit = async () => {
-  const [sid1, sid2] = selectedSolutions.map(item => item.sid);
+  const sids = selectedSolutions.map(item => item.sid);
   try {
-    const totalProfit = await requestClient.post('/pstery/calc_total_profit', { sid1, sid2, gold_side_ps: 10000 });
+    const totalProfit = await requestClient.post('/pstery/calc_total_profit', [...sids, psOptions.bet]);
     return totalProfit;
   }
   catch (error) {
@@ -155,67 +155,28 @@ const parseIorKey = (iorKey) => {
   return { type, side, ratio };
 }
 
-const formatJcEvents = (events) => {
-  const eventsMap = {};
-  Object.keys(events).forEach(key => {
-    if (key == 'ior_rh_05' || key == 'ior_rc_05') {
-      return;
-    }
-    const { type, side, ratio } = parseIorKey(key);
-    let ratioKey, index;
-    if (type === 'r') {
-      if (side === 'h') {
-        ratioKey = ratio + 0.5;
-        index = 0;
-      }
-      else if (side === 'c') {
-        ratioKey = -ratio - 0.5;
-        index = 2;
-      }
-    }
-    else if (type === 'm') {
-      ratioKey = 0;
-      if (side == 'h') {
-        index = 0;
-      }
-      else if (side == 'c') {
-        index = 2;
-      }
-      else {
-        index = 1;
-      }
-    }
-    else if (type === 'wm') {
-      if (side === 'h') {
-        ratioKey = ratio;
-        index = 1;
-      }
-      else if (side === 'c') {
-        ratioKey = -ratio;
-        index = 1;
-      }
-    }
-
-    ratioKey = Math.round(ratioKey);
-
-    if (ratioKey > 0) {
-      ratioKey = `+${ratioKey}`;
-    }
-    else {
-      ratioKey = `${ratioKey}`;
-    }
-
-    if (!eventsMap[ratioKey]) {
-      eventsMap[ratioKey] = new Array(3).fill(undefined);
-    }
-
-    const value = events[key] ?? 0;
-    eventsMap[ratioKey][index] = { key, value };
-
-  });
-  return Object.keys(eventsMap).sort((a, b) => b.localeCompare(a)).map(key => {
-    return [key, ...eventsMap[key]];
-  }).filter(item => item.length == 4 && !item.some(v => !v));
+const PS_IOR_KEYS = [
+  ['0', 'ior_mh', 'ior_mn', 'ior_mc'],
+  // ['0', 'ior_rh_05', 'ior_mn', 'ior_rc_05'],
+  ['-1', 'ior_rh_15', 'ior_wmh_1', 'ior_rac_05'],
+  ['-2', 'ior_rh_25', 'ior_wmh_2', 'ior_rac_15'],
+  ['+1', 'ior_rah_05', 'ior_wmc_1', 'ior_rc_15'],
+  ['+2', 'ior_rah_15', 'ior_wmc_2', 'ior_rc_25'],
+];
+
+const formatPsEvents = (events) => {
+  return PS_IOR_KEYS.map(([label, ...keys]) => {
+    const match = keys.map(key => ({
+      key,
+      value: events[key] ?? 0
+    }));
+    return {
+      label,
+      match
+    };
+  })
+  // .filter(item => item.match.every(entry => entry.value !== 0))
+  .map(({label, match}) => [label, ...match]);
 }
 
 // const rivalIor = (ior) => {
@@ -310,7 +271,7 @@ const formatSolution = (solution, eventsList) => {
   const obEvents = eventsList.ob?.[info.ob.eventId] ?? {};
   const hgEvents = eventsList.hg?.[info.hg.eventId] ?? {};
 
-  info.ps.events = formatJcEvents(psEvents);
+  info.ps.events = formatPsEvents(psEvents);
   info.ob.events = formatEvents(obEvents, cprKeys);
   info.hg.events = formatEvents(hgEvents, cprKeys);