index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <div class="data-test-container">
  3. <div class="page-header">
  4. <h1>数据测试</h1>
  5. <p>用于测试和验证比赛数据的页面</p>
  6. </div>
  7. <div class="content-area">
  8. <div class="test-panel">
  9. <h2>测试数据展示</h2>
  10. <div class="data-display">
  11. <div class="data-item">
  12. <label>当前时间:</label>
  13. <span>{{ currentTime }}</span>
  14. </div>
  15. <!-- <div class="data-item">
  16. <label>测试状态:</label>
  17. <span class="status-success">正常运行</span>
  18. </div> -->
  19. <div class="data-item">
  20. <label>数据源:</label>
  21. <span>比赛管理系统</span>
  22. </div>
  23. </div>
  24. <div class="radio-options">
  25. <div class="radio-group">
  26. <label class="radio-label">
  27. <input
  28. type="radio"
  29. name="testMode"
  30. value="1"
  31. v-model="selectedTestMode"
  32. class="radio-input"
  33. >
  34. <span class="radio-text">今日</span>
  35. </label>
  36. <label class="radio-label">
  37. <input
  38. type="radio"
  39. name="testMode"
  40. value="0"
  41. v-model="selectedTestMode"
  42. class="radio-input"
  43. >
  44. <span class="radio-text">早盘</span>
  45. </label>
  46. <label class="radio-label">
  47. <input
  48. type="radio"
  49. name="testMode"
  50. value=""
  51. v-model="selectedTestMode"
  52. class="radio-input"
  53. >
  54. <span class="radio-text">全部</span>
  55. </label>
  56. </div>
  57. </div>
  58. <div class="action-buttons">
  59. <Button @click="refreshData" :disabled="buttonDisabled">
  60. 刷新数据
  61. </Button>
  62. <Button @click="runTest(true)" :disabled="buttonDisabled">
  63. 有欢乐值
  64. </Button>
  65. <Button @click="runTest(false)" :disabled="buttonDisabled">
  66. 无欢乐值
  67. </Button>
  68. <Button @click="verifyData" :disabled="buttonDisabled">
  69. 验证数据
  70. </Button>
  71. <Button @click="filterLive" :disabled="buttonDisabled">
  72. 筛选滚球
  73. </Button>
  74. </div>
  75. </div>
  76. </div>
  77. <div class="data-table" v-if="prettyData">
  78. <div class="data-count" v-if="dataCount">
  79. <span>数据总数:{{ dataCount }}</span>
  80. </div>
  81. <vue-json-pretty :data="prettyData" :indent="2" :deep="prettyDeep" :showDoubleQuotes="false"></vue-json-pretty>
  82. </div>
  83. </div>
  84. </template>
  85. <script setup>
  86. import { ref, watch, onMounted } from 'vue';
  87. import { requestClient } from '#/api/request';
  88. import { Button, message, InputNumber } from 'ant-design-vue';
  89. import dayjs from 'dayjs';
  90. import VueJsonPretty from 'vue-json-pretty';
  91. import 'vue-json-pretty/lib/styles.css';
  92. const currentTime = ref('');
  93. const gamesRelation = ref([]);
  94. const gamesSolution = ref({});
  95. const selectedTestMode = ref('');
  96. const buttonDisabled = ref(false);
  97. const prettyData = ref(null);
  98. const prettyDeep = ref(0);
  99. const dataCount = ref('');
  100. watch(selectedTestMode, () => {
  101. refreshData();
  102. });
  103. const updateTime = () => {
  104. currentTime.value = new Date().toLocaleString('zh-CN')
  105. }
  106. const refreshData = () => {
  107. buttonDisabled.value = true;
  108. updateTime();
  109. Promise.all([
  110. requestClient.get('/pstery/get_games_relation', { params: { mk: selectedTestMode.value } }),
  111. requestClient.get('/pstery/get_solutions', { params: { win_min: -99999 } })
  112. ])
  113. .then(([relations, solutions]) => {
  114. gamesRelation.value = relations;
  115. gamesSolution.value = solutions;
  116. prettyData.value = null;
  117. prettyDeep.value = 0;
  118. message.success('数据已刷新');
  119. console.log('数据已刷新');
  120. })
  121. .catch(err => {
  122. message.error('数据刷新失败');
  123. console.error('数据刷新失败', err);
  124. })
  125. .finally(() => {
  126. buttonDisabled.value = false;
  127. });
  128. }
  129. const showDataPretty = (data, deep) => {
  130. prettyDeep.value = 0;
  131. prettyData.value = data;
  132. prettyDeep.value = deep;
  133. }
  134. const runTest = (hasSolutions=true) => {
  135. const gamesList = gamesRelation.value.map(item => {
  136. const { mk } = item ?? {};
  137. const { eventId, leagueName, teamHomeName, teamAwayName, timestamp } = item?.rel?.ps ?? {};
  138. const datetime = dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss');
  139. return { eventId, leagueName, teamHomeName, teamAwayName, datetime, mk };
  140. });
  141. gamesSolution.value.solutions.forEach((solution) => {
  142. const { sid, info: { id }} = solution;
  143. const currentGame = gamesList.find(game => game.eventId === id);
  144. if (!currentGame) {
  145. console.log('game not found', id);
  146. }
  147. else {
  148. if (!currentGame.solutions) {
  149. currentGame.solutions = [];
  150. }
  151. currentGame.solutions.push(sid);
  152. }
  153. });
  154. const dataList = gamesList.filter(item => {
  155. if (hasSolutions) {
  156. return !!item.solutions?.length;
  157. }
  158. else {
  159. return !item.solutions?.length;
  160. }
  161. }).map((item, index) => {
  162. const serial = index + 1;
  163. return { serial, ...item };
  164. });
  165. dataCount.value = `${dataList.length} / ${gamesList.length}`;
  166. showDataPretty(dataList, 2);
  167. console.log('gamesRelation', dataList);
  168. }
  169. const verifyData = () => {
  170. const solutions = gamesSolution.value.solutions;
  171. const invalidSolutions = [];
  172. solutions.forEach((solution) => {
  173. const { sol: { win_average, win_profit_rate } } = solution;
  174. if (win_average * win_profit_rate < 0) {
  175. invalidSolutions.push(solution)
  176. }
  177. });
  178. showDataPretty(invalidSolutions, 2);
  179. console.log('invalidSolutions', invalidSolutions);
  180. }
  181. const filterLive = () => {
  182. const solutions = gamesSolution.value.solutions;
  183. const liveSolutions = solutions.filter((solution) => {
  184. const { info: { ob, hg, ps } } = solution;
  185. return ps.stage;
  186. });
  187. showDataPretty(liveSolutions, 2);
  188. console.log('liveSolutions', liveSolutions);
  189. }
  190. // const currentTime = ref('')
  191. // const updateTime = () => {
  192. // currentTime.value = new Date().toLocaleString('zh-CN')
  193. // }
  194. // const refreshData = () => {
  195. // updateTime()
  196. // console.log('数据已刷新')
  197. // }
  198. // const runTest = () => {
  199. // console.log('开始运行测试...')
  200. // // 这里可以添加具体的测试逻辑
  201. // }
  202. onMounted(() => {
  203. refreshData();
  204. })
  205. </script>
  206. <style lang="scss" scoped>
  207. .data-test-container {
  208. padding: 20px;
  209. .page-header {
  210. margin-bottom: 30px;
  211. h1 {
  212. font-size: 24px;
  213. font-weight: bold;
  214. margin-bottom: 8px;
  215. color: #333;
  216. }
  217. p {
  218. color: #666;
  219. font-size: 14px;
  220. }
  221. }
  222. .content-area {
  223. .test-panel {
  224. background: #fff;
  225. border-radius: 8px;
  226. padding: 24px;
  227. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  228. h2 {
  229. font-size: 18px;
  230. font-weight: 600;
  231. margin-bottom: 20px;
  232. color: #333;
  233. }
  234. .data-display {
  235. margin-bottom: 24px;
  236. .data-item {
  237. display: flex;
  238. align-items: center;
  239. margin-bottom: 12px;
  240. label {
  241. font-weight: 500;
  242. color: #555;
  243. min-width: 100px;
  244. }
  245. span {
  246. color: #333;
  247. &.status-success {
  248. color: #52c41a;
  249. font-weight: 500;
  250. }
  251. }
  252. }
  253. }
  254. .radio-options {
  255. margin-bottom: 20px;
  256. .radio-group {
  257. display: flex;
  258. gap: 20px;
  259. .radio-label {
  260. display: flex;
  261. align-items: center;
  262. cursor: pointer;
  263. user-select: none;
  264. .radio-input {
  265. margin-right: 8px;
  266. cursor: pointer;
  267. }
  268. .radio-text {
  269. font-size: 14px;
  270. color: #333;
  271. }
  272. }
  273. }
  274. }
  275. }
  276. }
  277. }
  278. .data-table {
  279. padding: 20px;
  280. }
  281. </style>