Przeglądaj źródła

动态控制开考成功率

Michael Wang 5 lat temu
rodzic
commit
693777fd14
1 zmienionych plików z 44 dodań i 40 usunięć
  1. 44 40
      src/features/OnlineExam/OnlineExamList.vue

+ 44 - 40
src/features/OnlineExam/OnlineExamList.vue

@@ -102,6 +102,7 @@ import {
 } from "vuex";
 const { mapState, mapMutations } = createNamespacedHelpers("examHomeModule");
 import CheckComputer from "./CheckComputer";
+import axios from "axios";
 
 export default {
   name: "EcsOnlineList",
@@ -161,26 +162,40 @@ export default {
         (this.isEpcc && this.countdown > 0)
       );
     },
-    raceEnter(course) {
-      const successRatePerMinute = [
-        0.1,
-        0.15,
-        0.2,
-        0.25,
-        0.3,
-        0.35,
-        0.4,
-        0.45,
-        0.5,
-        0.6,
-        0.7,
-        0.8,
-        0.9,
-        1,
-      ]; // 30秒步进
+    async raceEnter(course) {
       const minutesAfterCourseStart = Math.floor(
         moment(this.getNow()).diff(moment(course.startTime), "seconds") / 30
       );
+
+      window._hmt.push([
+        "_trackEvent",
+        "在线考试列表页面",
+        "摇号进入考试-courseId-" + course.examId,
+        minutesAfterCourseStart < 120
+          ? minutesAfterCourseStart / 2 + "分进行点击"
+          : "60分后进行点击",
+      ]);
+
+      let serverOk = false;
+      let serverPass = false;
+      try {
+        const res = await axios.get(
+          "https://rate-limit.qmth.com.cn/rateLimit",
+          { timeout: 5 * 1000 }
+        );
+        serverOk = true;
+        serverPass = res.data.pass;
+      } catch (error) {
+        console.log(error);
+        window._hmt.push([
+          "_trackEvent",
+          "在线考试列表页面",
+          "获取rateLimit失败",
+        ]);
+      }
+
+      const successRatePerMinute = [0.5, 0.5, 0.5, 0.5, 1]; // 30秒步进
+
       let idx = 0;
       if (minutesAfterCourseStart < 0) {
         idx = 0;
@@ -192,22 +207,18 @@ export default {
       } else {
         idx = successRatePerMinute.length - 1;
       }
-      if (Math.random() > 1 - successRatePerMinute[idx]) {
-        if (minutesAfterCourseStart < 120) {
-          window._hmt.push([
-            "_trackEvent",
-            "在线考试列表页面",
-            "摇号进入考试-courseId-" + course.examId,
-            minutesAfterCourseStart / 2 + "分进入",
-          ]);
-        } else {
-          window._hmt.push([
-            "_trackEvent",
-            "在线考试列表页面",
-            "摇号进入考试-courseId-" + course.examId,
-            "60分后进入",
-          ]);
-        }
+      if (
+        (serverOk && serverPass) ||
+        (!serverOk && Math.random() > 1 - successRatePerMinute[idx])
+      ) {
+        window._hmt.push([
+          "_trackEvent",
+          "在线考试列表页面",
+          "摇号进入考试-courseId-" + course.examId,
+          minutesAfterCourseStart < 120
+            ? minutesAfterCourseStart / 2 + "分进入"
+            : "60分后进入",
+        ]);
 
         this.enterExam(course);
         // return true;
@@ -224,13 +235,6 @@ export default {
             // this.enterExam(course);
           },
         });
-        // this.$Message.warning({
-        //   content: "考试人员过多,请稍等2分钟再试",
-        //   duration: 10,
-        //   closable: true,
-        // });
-
-        // return false;
       }
     },
     async enterExam(course, alreadyChecked) {