123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- var SVR_URL = "/server/"; //http://172.30.84.3:8803
- if(location.host.indexOf("niimei") === -1){
- SVR_URL = "http://172.30.84.3:8803/server/";
- }
- function get_data(url, callback) {
- $.ajax({
- url: SVR_URL + url,
- apiName: url,
- sendTime: new Date()
- }).done(callback).fail(on_fail);
- }
- function on_fail(msg) {
- alert("很抱歉,网络错误,请查看Console");
- console.log("----- 网络请求失败 ---------")
- console.log(JSON.stringify(this));
- console.log("----------------------------")
- }
- function first_parse(ajax, obj) {
- if (typeof obj === "string") {
- obj = JSON.parse(obj);
- }
- if (typeof obj !== "object") {
- console.log(ajax);
- throw "Error ! Parsing JSON failed ." + JSON.stringify(obj);
- }
- if (obj.ret == "10000" || obj.ret == 10000 || obj.ret == 1000) {
- return obj.model;
- } else {
- console.log(ajax);
- throw "Error ! Server returned error." + JSON.stringify(obj);
- }
- }
- var faileverynum=[];
- var passeverynum=[];
- var stackeverynum=[];
- var failrate=[];
- function on_document_load() {
- get_data("fcWorkRaw/allFlows" , on_load_success_spots)
- }
- function on_load_success_spots(obj, status) {
- var spotsList = first_parse(this, obj);
- //在这里排序 spo\
- console.log("spot List : ");
- console.log(spotsList);
- var i, j, temp=[];
- for (j = 0; j < spotsList.length-1 ; j++) {
- if (spotsList[j].flowId > spotsList[j + 1].flowId) {
- temp = spotsList[j];
- spotsList[j] = spotsList[j + 1];
- spotsList[j + 1] = temp;
- }
- }
- for (i = 0; i < spotsList.length ; i++) {
- passeverynum[i] = spotsList[i].flowPass;
- faileverynum[i] = spotsList[i].flowFail;
- stackeverynum[i] = 0;
- }
- for (i = 0; i < spotsList.length ; i++) {
- if (passeverynum[i] + faileverynum[i] == 0) {
- failrate[i] = 0;
- }
- else {
- failrate[i] = faileverynum[i] / (faileverynum[i] + passeverynum[i]) * 100;
- }
- }
- showChart();
- setInterval(function(){
- get_data("fcWorkRaw/allFlows" , realtime_success);
- },1000);
- }
- function realtime_success(obj, sta) {
- var output = first_parse(this, obj);
- var i, j;
- for (i = 0; i < output.length ; i++) {
- passeverynum[i] = output[i].flowPass;
- faileverynum[i] = output[i].flowFail;
- stackeverynum[i] = 0
- }
- for (i = 0; i < output.length ; i++) {
- if (passeverynum[i] + faileverynum[i] == 0) {
- failrate[i] = 0;
- }
- else {
- failrate[i] = faileverynum[i] / (faileverynum[i] + passeverynum[i]) * 100;
- }
- }
- updateChart();
- }
|