basic1.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 first_parse(ajax, obj) {
  19. if (typeof obj === "string") {
  20. obj = JSON.parse(obj);
  21. }
  22. if (typeof obj !== "object") {
  23. console.log(ajax);
  24. throw "Error ! Parsing JSON failed ." + JSON.stringify(obj);
  25. }
  26. if (obj.ret == "10000" || obj.ret == 10000 || obj.ret == 1000) {
  27. return obj.model;
  28. } else {
  29. console.log(ajax);
  30. throw "Error ! Server returned error." + JSON.stringify(obj);
  31. }
  32. }
  33. var faileverynum=[];
  34. var passeverynum=[];
  35. var stackeverynum=[];
  36. var failrate=[];
  37. function on_document_load() {
  38. get_data("fcWorkRaw/allFlows" , on_load_success_spots)
  39. }
  40. function on_load_success_spots(obj, status) {
  41. var spotsList = first_parse(this, obj);
  42. //在这里排序 spo\
  43. console.log("spot List : ");
  44. console.log(spotsList);
  45. var i, j, temp=[];
  46. for (j = 0; j < spotsList.length-1 ; j++) {
  47. if (spotsList[j].flowId > spotsList[j + 1].flowId) {
  48. temp = spotsList[j];
  49. spotsList[j] = spotsList[j + 1];
  50. spotsList[j + 1] = temp;
  51. }
  52. }
  53. for (i = 0; i < spotsList.length ; i++) {
  54. passeverynum[i] = spotsList[i].flowPass;
  55. faileverynum[i] = spotsList[i].flowFail;
  56. stackeverynum[i] = 0;
  57. }
  58. for (i = 0; i < spotsList.length ; i++) {
  59. if (passeverynum[i] + faileverynum[i] == 0) {
  60. failrate[i] = 0;
  61. }
  62. else {
  63. failrate[i] = faileverynum[i] / (faileverynum[i] + passeverynum[i]) * 100;
  64. }
  65. }
  66. showChart();
  67. setInterval(function(){
  68. get_data("fcWorkRaw/allFlows" , realtime_success);
  69. },1000);
  70. }
  71. function realtime_success(obj, sta) {
  72. var output = first_parse(this, obj);
  73. var i, j;
  74. for (i = 0; i < output.length ; i++) {
  75. passeverynum[i] = output[i].flowPass;
  76. faileverynum[i] = output[i].flowFail;
  77. stackeverynum[i] = 0
  78. }
  79. for (i = 0; i < output.length ; i++) {
  80. if (passeverynum[i] + faileverynum[i] == 0) {
  81. failrate[i] = 0;
  82. }
  83. else {
  84. failrate[i] = faileverynum[i] / (faileverynum[i] + passeverynum[i]) * 100;
  85. }
  86. }
  87. updateChart();
  88. }