浏览代码

计算综合利润

flyzto 6 月之前
父节点
当前提交
c86f4c679d

+ 2 - 1
server/models/Games.js

@@ -1,4 +1,5 @@
 const { fork } = require('child_process');
+const calcTotalProfit = require('../triangle/totalProfitCalc');
 
 const childOptions = process.env.NODE_ENV == 'development' ? {
   execArgv: ['--inspect=9228']
@@ -400,5 +401,5 @@ setInterval(() => {
 module.exports = {
   updateGamesList, updateGamesEvents, getGamesList,
   updateGamesRelation, getGamesRelation, removeGamesRelation,
-  getGamesEvents, getSolutions,
+  getGamesEvents, getSolutions, calcTotalProfit,
 }

+ 6 - 0
server/routes/triangle.js

@@ -87,5 +87,11 @@ router.get('/get_solutions', authMiddleware, (req, res) => {
   });
 });
 
+// 计算总利润
+router.post('/calc_total_profit', authMiddleware, (req, res) => {
+  const { sol1, sol2, gold_side_jc } = req.body;
+  const totalProfit = Games.calcTotalProfit(sol1, sol2, gold_side_jc);
+  res.sendSuccess(totalProfit);
+});
 
 module.exports = router;

+ 0 - 1
server/triangle/eventsMatch.js

@@ -11,7 +11,6 @@ const Request = {
 
 const GLOBAL_DATA = {
   relationLength: 0,
-  solutions: {},
 };
 
 const getDataFromParent = (type, callback) => {

+ 4 - 2
server/triangle/totalProfitCalc.js

@@ -164,7 +164,7 @@ const calcGoldsWithWinTarget = (data) => {
   }
 }
 
-export const calcTotalProfit = (sol1, sol2, gold_side_jc) => {
+const calcTotalProfit = (sol1, sol2, gold_side_jc) => {
 
   const winTarget1 = sol1.win_average;
   const winTarget2 = sol2.win_average;
@@ -191,4 +191,6 @@ export const calcTotalProfit = (sol1, sol2, gold_side_jc) => {
     }
   }
   return result.at(-1);
-}
+}
+
+module.exports = calcTotalProfit;

+ 4 - 1
web/apps/web-antd/src/views/match/related/index.vue

@@ -26,7 +26,10 @@ const setGameOrderWeight= (game) => {
   const { t, l, h, a } = selectedInfo.value ?? {};
   game.orderWeight = 0;
   const { leagueName, teamHomeName, teamAwayName, timestamp } = game;
-  if (timestamp == t) {
+  if (timestamp != t) {
+    game.orderWeight = -99;
+  }
+  else  {
     game.orderWeight += 1;
   }
   if (leagueName.startsWith(l)) {

+ 37 - 2
web/apps/web-antd/src/views/match/solutions/index.vue

@@ -8,6 +8,18 @@ import dayjs from 'dayjs';
 import MatchCard from '../components/match_card.vue';
 
 const solutions = ref([]);
+const selectedSolutions = reactive([]);
+
+const solutionsList = computed(() => {
+  const startTimestamp = selectedSolutions[0]?.timestamp ?? 0;
+  return solutions.value.map(item => {
+    const selected = selectedSolutions.findIndex(sol => sol.sid === item.sid) >= 0;
+    const disabled = !selected && (item.info.jc.timestamp < startTimestamp + 1000 * 60 * 60 * 2);
+    // console.log(new Date(item.info.jc.timestamp), new Date(startTimestamp), disabled);
+    return { ...item, selected, disabled };
+  })
+  .filter(item => !item.disabled);
+});
 
 const getSolutions = async () => {
   try {
@@ -177,6 +189,19 @@ const updateSolutions = async () => {
   });
 }
 
+const toggleSolution = (sid, timestamp) => {
+  const findIndex = selectedSolutions.findIndex(item => item.sid === sid);
+  if (findIndex >= 0) {
+    selectedSolutions.splice(findIndex, 1);
+  }
+  else if (selectedSolutions.length < 2) {
+    selectedSolutions.push({ sid, timestamp });
+  }
+  else {
+    selectedSolutions.splice(1, 1, { sid, timestamp });
+  }
+}
+
 let updateTimer = null;
 
 onMounted(() => {
@@ -203,7 +228,10 @@ onUnmounted(() => {
       <em>利润</em>
     </div>
     <div class="solution-list">
-      <div class="solution-item" v-for="{ sid, sol: {win_average}, info: {jc, ps, ob} } in solutions" :key="sid">
+      <div class="solution-item"
+        v-for="{ sid, sol: {win_average}, info: {jc, ps, ob}, selected, disabled } in solutionsList" :key="sid"
+        :class="{'selected': selected, 'disabled': disabled}"
+      >
         <MatchCard platform="jc"
           :eventId="jc.eventId"
           :leagueName="jc.leagueName"
@@ -232,7 +260,7 @@ onUnmounted(() => {
           :events="ob.events ?? []"
           :selected="ob.selected ?? []"/>
 
-        <div class="solution-profit">{{ win_average }}</div>
+        <div class="solution-profit" @click="!disabled && toggleSolution(sid, jc.timestamp)">{{ win_average }}</div>
       </div>
     </div>
   </div>
@@ -268,6 +296,13 @@ onUnmounted(() => {
   display: flex;
   border-radius: 10px;
   background-color: hsl(var(--card));
+  &.selected {
+    background-color: hsl(var(--primary) / 0.15);
+  }
+  &.disabled {
+    filter: blur(15px);
+    cursor: not-allowed;
+  }
   &:not(:last-child) {
     margin-bottom: 20px;
   }