basic.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. var SVR_URL = "/server/"; //http://172.30.84.3:8803
  2. if(location.host.indexOf("niimei") === -1){
  3. SVR_URL = "http://172.30.84.3:8803/server/";
  4. }
  5. function get_data(url, callback) {
  6. $.ajax({
  7. url: SVR_URL + url,
  8. apiName: url,
  9. sendTime: new Date()
  10. }).done(callback).fail(on_fail);
  11. }
  12. function on_fail(msg) {
  13. alert("很抱歉,网络错误,请查看Console");
  14. console.log("----- 网络请求失败 ---------")
  15. console.log(JSON.stringify(this));
  16. console.log("----------------------------")
  17. }
  18. function on_data_success(obj, status) {
  19. }
  20. function first_parse(ajax, obj) {
  21. if (typeof obj === "string") {
  22. obj = JSON.parse(obj);
  23. }
  24. if (typeof obj !== "object") {
  25. console.log(ajax);
  26. throw "Error ! Parsing JSON failed ." + JSON.stringify(obj);
  27. }
  28. if (obj.ret == "10000" || obj.ret == 10000 || obj.ret == 1000) {
  29. return obj.model;
  30. } else {
  31. console.log(ajax);
  32. throw "Error ! Server returned error." + JSON.stringify(obj);
  33. }
  34. }
  35. var flowData;
  36. var sID = [];
  37. var passNumber = [];
  38. var failNumber = [];
  39. var failrate = [];
  40. var stacknum = 0;
  41. var stackeverynum = [];
  42. var failnum=0;
  43. var passnum=0
  44. var passdata=[];
  45. var faildata=[];
  46. var num=1;
  47. var hispass=[];
  48. var hisfail=[];
  49. var hisstack=[];
  50. var hisrate=[];
  51. var t=0;
  52. function firsttime_load_spots_data() {
  53. get_data("fcWorkRaw/allSpots?flowId=" + thisPageFlow, first_success)
  54. }
  55. function secondtime_load_spots_data() {
  56. get_data("fcWorkRaw/allFlows?type=" + num, second_success);
  57. num++;
  58. }
  59. function first_success(obj, sta) {
  60. var output = first_parse(this, obj);
  61. //在这里排序 spo\
  62. console.log(" output : ");
  63. console.log(output);
  64. var i, j;
  65. failnum=0;
  66. for (i = 0; i < output.length ; i++) {
  67. passNumber[i] = output[i].passNum;
  68. passnum=passNumber[i]
  69. }
  70. for (i = 0; i < output.length ; i++) {
  71. failNumber[i] = output[i].failNum;
  72. failnum=failNumber[i]+failnum;
  73. }
  74. for (i = 0; i < output.length ; i++) {
  75. if (failNumber[i] + passNumber[i] == 0) {
  76. failrate[i] = 0;
  77. }
  78. else {
  79. failrate[i] = failNumber[i] / (failNumber[i] + passNumber[i]) * 100;
  80. }
  81. }
  82. stackeverynum[0] = 0;
  83. for (i = 1; i < output.length ; i++) {
  84. stackeverynum[i] = passNumber[i - 1] - passNumber[i] - failNumber[i];
  85. stacknum = stackeverynum[i] + stacknum;
  86. }
  87. for(i=1;i<5;i++) {
  88. secondtime_load_spots_data();
  89. }
  90. showChart();
  91. setInterval(function(){
  92. get_data("fcWorkRaw/allSpots?flowId=" + thisPageFlow, realtime_success);
  93. },1000);
  94. document.getElementById("test1").innerHTML = passnum;
  95. document.getElementById("test2").innerHTML = failnum;
  96. document.getElementById("test3").innerHTML = Math.floor(passnum/(passnum+failnum)*100)/100+'%';
  97. document.getElementById("test4").innerHTML = stacknum;
  98. }
  99. function second_success(obj, sta) {
  100. var history = first_parse(this, obj);
  101. var i, j;
  102. for (i = 0; i < history.length; i++) {
  103. if (history[i].flowId == thisPageFlow) {
  104. hispass[t] = history[t].flowPass;
  105. hisfail[t] = history[t].flowFail;
  106. hisstack[t] = 0;
  107. if (hispass[t] + hisfail[t] == 0) {
  108. hisrate[t] = 0;
  109. }
  110. else {
  111. hisrate[t] = hisfail[i] / (hispass[i] + hisfail[i]) * 100;
  112. }
  113. t++;
  114. }
  115. }
  116. }
  117. function realtime_success(obj, sta) {
  118. var output = first_parse(this, obj);
  119. var i, j;
  120. for (i = 0; i < output.length ; i++) {
  121. passNumber[i] = output[i].passNum;
  122. }
  123. for (i = 0; i < output.length ; i++) {
  124. failNumber[i] = output[i].failNum;
  125. }
  126. for (i = 0; i < output.length ; i++) {
  127. if (failNumber[i] + passNumber[i] == 0) {
  128. failrate[i] = 0;
  129. }
  130. else {
  131. failrate[i] = failNumber[i] / (failNumber[i] + passNumber[i]) * 100;
  132. }
  133. }
  134. stackeverynum[0] = 0;
  135. for (i = 1; i < output.length ; i++) {
  136. stackeverynum[i] = passNumber[i - 1] - passNumber[i] - failNumber[i];
  137. stacknum = stackeverynum[i] + stacknum;
  138. }
  139. updateChart();
  140. document.getElementById("test1").innerHTML = passnum;
  141. document.getElementById("test2").innerHTML = failnum;
  142. document.getElementById("test3").innerHTML = Math.floor(passnum/(passnum+failnum)*100)/100+'%';
  143. document.getElementById("test4").innerHTML = stacknum;
  144. }
  145. function on_load_success_spots(obj, status) {
  146. var spotsList = first_parse(this, obj);
  147. //在这里排序 spo\
  148. console.log("spot List : ");
  149. console.log(spotsList);
  150. var i, j, temp;
  151. for (i = 0; i < spotsList.list.length - 1; i++) {
  152. for (j = 0; j < spotsList.list.length - i - 1; j++) {
  153. if (spotsList.list[j].orderNum > spotsList.list[j + 1].orderNum) {
  154. temp = spotsList.list[j];
  155. spotsList.list[j] = spotsList.list[j + 1];
  156. spotsList.list[j + 1] = temp;
  157. }
  158. }
  159. }
  160. flowData = spotsList.list;
  161. for (i = 0; i < spotsList.list.length ; i++) {
  162. sID[i] = spotsList.list[i].spotId;
  163. namedata[i] = spotsList.list[i].spotName;
  164. }
  165. firsttime_load_spots_data();
  166. }
  167. function on_document_load() {
  168. // First Step
  169. get_data("fcSpot/list?flowId=" + thisPageFlow, on_load_success_spots)
  170. }
  171. var namedata = [];