Преглед на файлове

Added SectorName Query Functionality

Fruit of Eden преди 6 години
родител
ревизия
007350543b
променени са 3 файла, в които са добавени 32 реда и са изтрити 35 реда
  1. 13 0
      js/basic.js
  2. 11 15
      js/common.js
  3. 8 20
      js/lazhang-data.js

+ 13 - 0
js/basic.js

@@ -284,5 +284,18 @@ function on_secname_retn(obj, sta) {
     }
 }
 
+/**
+ *  Calc b/a+b * 100(precision = 2), when b is zero, return zero
+ * @param a
+ * @param b
+ */
+function get_factor(a,b){
+    if(a+b === 0){
+        return 0;
+    }else{
+        return Math.floor(10000* b / (a+b) ) / 100;
+    }
+}
+
 $(document).ready(on_document_load);
 get_server_url();

+ 11 - 15
js/common.js

@@ -22,43 +22,39 @@ function history_success(obj, sta) {
         t = 3;
     } else {
         t = 0;
+        return;
     }
-
     if (t === 2 || t === 3) {
         hispass[t] = 0;
         hisfail[t] = 0;
         hisstack[t] = 0;
         hisrate[t] = 0;
-        for (i = 0; i < history.length - 1; i++) {
+        for (i = 0; i < history.length - 1; i++) { //除了今日
             hispass[t] = history[i].passNum + hispass[t];
             hisfail[t] = history[i].failNum + hisfail[t];
             hisstack[t] = history[i].avgDue + hisstack[t];
         }
-
         hispass[t] += hispass[0];
         hisfail[t] += hisfail[0];
         hisstack[t] += hisstack[0];
-
-        if (hispass[t] + hisfail[t] === 0) {
-            hisrate[t] = 0;
-        } else {
-            hisrate[t] = Math.floor(hisfail[t] * 10000 / (hispass[t] + hisfail[t])) / 100;
-        }
-
+        hisrate[t] = get_factor(hispass[t], hisfail[t]);
     } else if (t === 1) {
         hispass[1] = history[0].passNum;
         hisfail[1] = history[0].failNum;
         hisstack[1] = history[0].avgDue;
-        if (hispass[1] + hisfail[1] === 0) {
-            hisrate[1] = 0;
-        } else {
-            hisrate[1] = Math.floor(hisfail[1]  * 10000 / (hispass[1] + hisfail[1])) / 100;
-        }
+        hisrate[t] = get_factor(hispass[1], hisfail[1]);
     }
+
     todayotherpass = history[history.length - 1].passNum;
     todayotherfail = history[history.length - 1].failNum;
     todayotherstack = history[history.length - 1].avgDue;
+
+    hispass[0] = todayotherpass + schedulepass;
+    hisfail[0] = todayotherfail + schedulefail;
+    hisstack[0] = todayotherstack + schedulestack;
+    hisrate[0] = get_factor(hispass[0], hisfail[0]);
 }
+
 var todayotherpass , todayotherfail, todayotherstack;
 
 function isUserOfThisFlow(uid) {

+ 8 - 20
js/lazhang-data.js

@@ -208,13 +208,7 @@ function realtime_success(obj, sta) {
                     z++;
                 }
             }
-            if (failNumber[k] + passNumber[k] == 0) {
-                failrate[k] = 0;
-            } else {
-                failrate[k] = failNumber[k] / (failNumber[k] + passNumber[k]) * 100;
-            }
-            /*stackeverynum[k]=stackeverynum[k]/z;*/
-            ///
+            failrate[k] = get_factor(passNumber[k], failNumber[k]);
 
         }
         output.list.forEach(function (val, fid, arr) {
@@ -224,22 +218,16 @@ function realtime_success(obj, sta) {
         })
     }
 
-    hispass[0] = hhp;
-    hisfail[0] = hhf;
-
+    schedulepass = hhp;
+    schedulefail = hhf;
     if (output.list.length > 0) {
-        hisstack[0] = hhs / output.list.length;
+        schedulestack = hhs / output.list.length;
     } else {
-        hisstack[0] = 0;
-    }
-
-    if (hispass[0] + hisfail[0] <= 0) {
-        hisrate[0] = 0;
-    } else {
-        hisrate[0] = Math.floor(hisfail[0] / (hispass[0] + hisfail[0]) * 10000) / 100;
+        schedulestack = 0;
     }
+    updateChart();
 
+}
 
-    updateChart();
+var schedulepass = 0, schedulefail = 0, schedulestack = 0;
 
-}