index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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 class="btn btn-primary" @click="refreshData">
  60. 刷新数据
  61. </button>
  62. <button class="btn btn-secondary" @click="runTest(true)">
  63. 有欢乐值
  64. </button>
  65. <button class="btn btn-secondary" @click="runTest(false)">
  66. 无欢乐值
  67. </button>
  68. <button class="btn btn-secondary" @click="verifyData">
  69. 验证数据
  70. </button>
  71. <button class="btn btn-secondary" @click="filterLive">
  72. 筛选滚球
  73. </button>
  74. </div>
  75. </div>
  76. </div>
  77. <div class="data-table" v-if="prettyData">
  78. <vue-json-pretty :data="prettyData" :indent="2" :deep="prettyDeep" :showDoubleQuotes="false"></vue-json-pretty>
  79. </div>
  80. </div>
  81. </template>
  82. <script setup>
  83. import { ref, onMounted } from 'vue';
  84. import { requestClient } from '#/api/request';
  85. import dayjs from 'dayjs';
  86. import VueJsonPretty from 'vue-json-pretty';
  87. import 'vue-json-pretty/lib/styles.css';
  88. const currentTime = ref('');
  89. const gamesRelation = ref([]);
  90. const gamesSolution = ref({});
  91. const selectedTestMode = ref('');
  92. const prettyData = ref(null);
  93. const prettyDeep = ref(0);
  94. const updateTime = () => {
  95. currentTime.value = new Date().toLocaleString('zh-CN')
  96. }
  97. const refreshData = () => {
  98. updateTime();
  99. Promise.all([
  100. requestClient.get('/pstery/get_games_relation', { params: { mk: selectedTestMode.value } }),
  101. requestClient.get('/pstery/get_solutions', { params: { win_min: -99999 } })
  102. ])
  103. .then(([relations, solutions]) => {
  104. gamesRelation.value = relations;
  105. gamesSolution.value = solutions;
  106. console.log('数据已刷新');
  107. });
  108. }
  109. const showDataPretty = (data, deep) => {
  110. prettyDeep.value = 0;
  111. prettyData.value = data;
  112. prettyDeep.value = deep;
  113. }
  114. const runTest = (hasSolutions=true) => {
  115. const gamesList = gamesRelation.value.map(item => {
  116. const { eventId, leagueId, leagueName, teamHomeName, teamAwayName, timestamp } = item?.rel?.ps ?? {};
  117. const datetime = dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss');
  118. return { eventId, leagueId, leagueName, teamHomeName, teamAwayName, datetime };
  119. });
  120. gamesSolution.value.solutions.forEach((solution) => {
  121. const { sid, info: { id }} = solution;
  122. const currentGame = gamesList.find(game => game.eventId === id);
  123. if (!currentGame) {
  124. console.log('game not found', id);
  125. }
  126. else {
  127. if (!currentGame.solutions) {
  128. currentGame.solutions = [];
  129. }
  130. currentGame.solutions.push(sid);
  131. }
  132. });
  133. const dataList = gamesList.filter(item => {
  134. if (hasSolutions) {
  135. return !!item.solutions?.length;
  136. }
  137. else {
  138. return !item.solutions?.length;
  139. }
  140. }).map((item, index) => {
  141. const serial = index + 1;
  142. return { serial, ...item };
  143. });
  144. showDataPretty(dataList, 2);
  145. console.log('gamesRelation', dataList);
  146. }
  147. const verifyData = () => {
  148. const solutions = gamesSolution.value.solutions;
  149. const invalidSolutions = [];
  150. solutions.forEach((solution) => {
  151. const { sol: { win_average, win_profit_rate } } = solution;
  152. if (win_average * win_profit_rate < 0) {
  153. invalidSolutions.push(solution)
  154. }
  155. });
  156. showDataPretty(invalidSolutions, 2);
  157. console.log('invalidSolutions', invalidSolutions);
  158. }
  159. const filterLive = () => {
  160. const solutions = gamesSolution.value.solutions;
  161. const liveSolutions = solutions.filter((solution) => {
  162. const { info: { ob, hg, ps } } = solution;
  163. return ps.stage;
  164. });
  165. showDataPretty(liveSolutions, 2);
  166. console.log('liveSolutions', liveSolutions);
  167. }
  168. // const currentTime = ref('')
  169. // const updateTime = () => {
  170. // currentTime.value = new Date().toLocaleString('zh-CN')
  171. // }
  172. // const refreshData = () => {
  173. // updateTime()
  174. // console.log('数据已刷新')
  175. // }
  176. // const runTest = () => {
  177. // console.log('开始运行测试...')
  178. // // 这里可以添加具体的测试逻辑
  179. // }
  180. onMounted(() => {
  181. refreshData();
  182. })
  183. </script>
  184. <style lang="scss" scoped>
  185. .data-test-container {
  186. padding: 20px;
  187. .page-header {
  188. margin-bottom: 30px;
  189. h1 {
  190. font-size: 24px;
  191. font-weight: bold;
  192. margin-bottom: 8px;
  193. color: #333;
  194. }
  195. p {
  196. color: #666;
  197. font-size: 14px;
  198. }
  199. }
  200. .content-area {
  201. .test-panel {
  202. background: #fff;
  203. border-radius: 8px;
  204. padding: 24px;
  205. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  206. h2 {
  207. font-size: 18px;
  208. font-weight: 600;
  209. margin-bottom: 20px;
  210. color: #333;
  211. }
  212. .data-display {
  213. margin-bottom: 24px;
  214. .data-item {
  215. display: flex;
  216. align-items: center;
  217. margin-bottom: 12px;
  218. label {
  219. font-weight: 500;
  220. color: #555;
  221. min-width: 100px;
  222. }
  223. span {
  224. color: #333;
  225. &.status-success {
  226. color: #52c41a;
  227. font-weight: 500;
  228. }
  229. }
  230. }
  231. }
  232. .radio-options {
  233. margin-bottom: 20px;
  234. .radio-group {
  235. display: flex;
  236. gap: 20px;
  237. .radio-label {
  238. display: flex;
  239. align-items: center;
  240. cursor: pointer;
  241. user-select: none;
  242. .radio-input {
  243. margin-right: 8px;
  244. cursor: pointer;
  245. }
  246. .radio-text {
  247. font-size: 14px;
  248. color: #333;
  249. }
  250. }
  251. }
  252. }
  253. .action-buttons {
  254. display: flex;
  255. gap: 12px;
  256. .btn {
  257. padding: 8px 16px;
  258. border-radius: 6px;
  259. border: none;
  260. cursor: pointer;
  261. font-size: 14px;
  262. transition: all 0.2s;
  263. &.btn-primary {
  264. background: #1890ff;
  265. color: white;
  266. &:hover {
  267. background: #40a9ff;
  268. }
  269. }
  270. &.btn-secondary {
  271. background: #f5f5f5;
  272. color: #333;
  273. border: 1px solid #d9d9d9;
  274. &:hover {
  275. background: #e6f7ff;
  276. border-color: #1890ff;
  277. }
  278. }
  279. }
  280. }
  281. }
  282. }
  283. }
  284. .data-table {
  285. padding: 20px;
  286. }
  287. </style>