basic1.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. var faileverynum=[];
  13. var passeverynum=[];
  14. var stackeverynum=[];
  15. var failrate=[];
  16. var flowID=1;
  17. var num=0;
  18. var hispass=[];
  19. var hisfail=[];
  20. var hisstack=[];
  21. var hisrate=[];
  22. var goodpass=[];
  23. var goodid=[];
  24. var goodfailrate=[];
  25. var badpass=[];
  26. var badid=[];
  27. var badfailrate=[];
  28. var t=0;
  29. var n=0;
  30. function on_fail(msg) {
  31. alert("很抱歉,网络错误,请查看Console");
  32. console.log("----- 网络请求失败 ---------")
  33. console.log(JSON.stringify(this));
  34. console.log("----------------------------")
  35. }
  36. function secondtime_load_spots_data() {
  37. get_data("fcBiFactoryDaily/list?type=" + num +"&flowId="+flowID, second_success);
  38. num++;
  39. }
  40. function chart_load_spots_data() {
  41. get_data("fcBiWorkerDaily/get?type=0&limit=3", chart_success);
  42. }
  43. function chart1_load_spots_data() {
  44. get_data("fcBiWorkerDaily/get?type=4&limit=3", chart1_success);
  45. }
  46. function first_parse(ajax, obj) {
  47. if (typeof obj === "string") {
  48. obj = JSON.parse(obj);
  49. }
  50. if (typeof obj !== "object") {
  51. console.log(ajax);
  52. throw "Error ! Parsing JSON failed ." + JSON.stringify(obj);
  53. }
  54. if (obj.ret == "10000" || obj.ret == 10000 || obj.ret == 1000) {
  55. return obj.model;
  56. } else {
  57. console.log(ajax);
  58. throw "Error ! Server returned error." + JSON.stringify(obj);
  59. }
  60. }
  61. function on_document_load() {
  62. get_data("fcWorkRaw/allFlows" , on_load_success_spots)
  63. }
  64. function on_load_success_spots(obj, status) {
  65. var spotsList = first_parse(this, obj);
  66. //在这里排序 spo\
  67. console.log("spot List : ");
  68. console.log(spotsList);
  69. var i, j, temp=[];
  70. for (j = 0; j < spotsList.length-1 ; j++) {
  71. if (spotsList[j].flowId > spotsList[j + 1].flowId) {
  72. temp = spotsList[j];
  73. spotsList[j] = spotsList[j + 1];
  74. spotsList[j + 1] = temp;
  75. }
  76. }
  77. for (i = 0; i < spotsList.length ; i++) {
  78. passeverynum[i] = spotsList[i].flowPass;
  79. faileverynum[i] = spotsList[i].flowFail;
  80. stackeverynum[i] = 0;
  81. }
  82. for (i = 0; i < spotsList.length ; i++) {
  83. if (passeverynum[i] + faileverynum[i] == 0) {
  84. failrate[i] = 0;
  85. }
  86. else {
  87. failrate[i] = faileverynum[i] / (faileverynum[i] + passeverynum[i]) * 100;
  88. }
  89. }
  90. for(i=1;i<5;i++) {
  91. secondtime_load_spots_data();
  92. }
  93. chart_load_spots_data();
  94. chart1_load_spots_data();
  95. showChart();
  96. setInterval(function(){
  97. get_data("fcWorkRaw/allFlows" , realtime_success);
  98. },1000);
  99. }
  100. function second_success(obj, sta) {
  101. var history = first_parse(this, obj);
  102. var i, j;
  103. console.log(" history : ");
  104. console.log(history);
  105. hispass[t] = 0;
  106. hisfail[t] = 0;
  107. hisstack[t] = 0;
  108. hisrate[t]=0;
  109. for(i=0;i<history.length;i++){
  110. hispass[t] = history[i].passNum+hispass[t];
  111. hisfail[t] = history[i].failNum+hisfail[t];
  112. hisstack[t] = history[i].avgDue+hisstack[t];
  113. hisrate[t] = history[i].failRate;
  114. hisrate[t]=hisrate[t]/100;
  115. }
  116. if(history.length!=1){
  117. hisrate[t]=hisfail[t]/(hispass[t]+hisfail[t]);
  118. }
  119. if(hispass[t]+hisfail[t]==0){
  120. hisrate[t]=0;
  121. }
  122. t++;
  123. }
  124. function chart_success(obj, sta) {
  125. var redchart = first_parse(this, obj);
  126. var i, j;
  127. i=j=0;
  128. console.log(" redchart : ");
  129. console.log(redchart);
  130. for(i=0;i<3;i++){
  131. goodid[i]=redchart.list[i].workerId;
  132. goodpass[i]=redchart.list[i].passNum;
  133. goodfailrate[i]=redchart.list[i].failRate/100;
  134. }
  135. }
  136. function chart1_success(obj, sta) {
  137. var blackchart = first_parse(this, obj);
  138. var i, j;
  139. i=j=0;
  140. console.log(" black chart : ");
  141. console.log(blackchart);
  142. for(i=0;i<3;i++){
  143. badid[i]=blackchart.list[i].workerId;
  144. badpass[i]=blackchart.list[i].passNum;
  145. badfailrate[i]=blackchart.list[i].failRate/100;
  146. }
  147. }
  148. function realtime_success(obj, sta) {
  149. var output = first_parse(this, obj);
  150. var i, j;
  151. for (i = 0; i < output.length ; i++) {
  152. passeverynum[i] = output[i].flowPass;
  153. faileverynum[i] = output[i].flowFail;
  154. stackeverynum[i] = 0
  155. }
  156. for (i = 0; i < output.length ; i++) {
  157. if (passeverynum[i] + faileverynum[i] == 0) {
  158. failrate[i] = 0;
  159. }
  160. else {
  161. failrate[i] = faileverynum[i] / (faileverynum[i] + passeverynum[i]) * 100;
  162. }
  163. }
  164. updateChart();
  165. }