Advertisement
Garvan

NetGeoProv.js Algo

May 20th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function CachedLocation(loc, cellInfo, wifiList) {
  2.   this.location = loc;
  3.   this.cellInfo = cellInfo;
  4.   this.wifiList = wifiList;
  5. }
  6.  
  7. CachedLocation.prototype = {
  8.   constructor: CachedLocation,
  9.   isGeoip: function() {
  10.     return !this.cellInfo && !this.wifiList;
  11.   },
  12.   isCellAndWifi: function() {
  13.     return this.cellInfo && this.wifiList;
  14.   },
  15.   isCellOnly: function() {
  16.     return this.cellInfo && !this.wifiList;
  17.   },
  18.   isWifiOnly: function() {
  19.     return this.wifiList && !this.cellInfo;
  20.   },
  21.   //-> if 50% of the SSIDS match
  22.   isWifiApproxEqual: function(wifiList) {
  23.     if (!this.wifiList)
  24.       return false;
  25.   },
  26.   //if fields match and signal is within ?% (who can answer this)
  27.   isCellApproxEqual: function(cellInfo) {
  28.     if (!this.cellInfo)
  29.       return false;
  30.   }
  31. };
  32.  
  33. var gCachedLocation;
  34.  
  35. // return null if not better
  36. function getCachedLocIfBetter(newCell, newWifiList)
  37. {
  38.   if (!gCachedLocation)
  39.     return null;
  40.  
  41.   // if new request has both cell and wifi, and old is just cell
  42.   if (gCachedLocation.isCellOnly() && newCell && newWIfiList) {
  43.     return null;
  44.   }
  45.  
  46.   // if new is geoip request
  47.   if (!newCell && !newWifiList) {
  48.     return gOldLocation.location;
  49.   }
  50.  
  51.   var hasEqualCells = false;
  52.   if (newCell) {
  53.     hasEqualCells = gCachedLocation.isCellsApproxEqual(newCell);
  54.   }
  55.  
  56.   var hasEqualWifis = false;
  57.   if (newWifiList) {
  58.     hasEqualWifis = gCachedLocation.isWifiApproxEqual(newWifiList);
  59.   }
  60.  
  61.   if (gCachedLocation.isCellOnly()) {
  62.     if (hasEqualCells)
  63.       return gOldLocation.location;
  64.   }
  65.   else if (gCacheLocation.isCellAndWifi()) {
  66.     if ((hasEqualCells && hasEqualWifis) ||
  67.          (!newWifiList && hasEqualCells) ||
  68.           (!newCell && hasEqualWifis)
  69.     {
  70.       return gOldLocation.location;
  71.     }
  72.   }
  73.  
  74.   return null;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement