Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  sql.query("SELECT * FROM Users WHERE token like ?",json.token,function (err,res) {
  2.                     if(!err){
  3.                         if(res.length>0){
  4.  
  5.                             var hospitals;
  6.                             sql.query("SELECT * FROM " +
  7.                                 " HospitalDepartaments WHERE title" +
  8.                                 " like ?",json.title,function (err,res) {
  9.                                 if(!err){
  10.  
  11.                                     var workload = [res.length];
  12.                                     for(var i=0;i<res.length;i++){
  13.                                         workload[i] = ((res[i].online/res[i].doctors)-1)*(-1);
  14.                                         workload[i]= workload[i].toFixed(2);
  15.                                     }
  16.  
  17.                                     //SERVER 3-matrix
  18.                                     sql.query("SELECT * FROM Hospitals",function (err,res) {
  19.                                         var arr=[workload.length];
  20.  
  21.                                         var mas = [0,0,0,0,0];
  22.                                         for(var z=0;z<workload.length;z++){
  23.                                             arr[z]=[workload.length];
  24.                                             for(var i=0;i<workload.length-1;i++){
  25.                                                 arr[z][i] = [3];
  26.                                                 if(z!=i){
  27.                                                     arr[z][i][0]= res[i+1].lat - res[i].lat;
  28.                                                     arr[z][i][1]= res[i+1].lnt - res[i].lnt;
  29.                                                     arr[z][i][2]= workload[i+1] - workload[i];
  30.                                                     if(i>0 && i<workload.length-1){
  31.                                                         if(arr[z][i-1][0] < arr[z][i][0]){
  32.                                                             mas[z]++;
  33.                                                         }
  34.                                                         if(arr[z][i-1][1]<arr[z][i][1]){
  35.                                                             mas[z]++;
  36.                                                         }
  37.                                                         if(arr[z][i-1][2]<arr[z][i][2]){
  38.                                                             mas[z]++;
  39.                                                         }
  40.                                                     }
  41.                                                 }
  42.                                             }
  43.                                         }
  44.                                         var index =0;
  45.                                         for(var i=0;i<mas.length;i++){
  46.                                             if(mas[index] < mas[i]){
  47.                                                 index = i;
  48.                                             }
  49.                                         }
  50.  
  51.                                         result.end(JSON.stringify({
  52.                                             lat : res[index].lat,
  53.                                             lnt : res[index].lnt,
  54.                                             title: res[index].title
  55.                                         }));
  56.                                     });
  57.                                 }
  58.                             })
  59.                         }
  60.                     }
  61.                 })
  62.  
  63.             });
  64.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement