Browse Source

split select_bad_wifi

Xi Ruoyao 5 years ago
parent
commit
a39668fc96
2 changed files with 15 additions and 7 deletions
  1. 2 2
      percentage.py
  2. 13 5
      wifiloc.py

+ 2 - 2
percentage.py

@@ -16,10 +16,10 @@ def otsuka_sim(known_point, new_point):
     if up < match_wifi_num_crit:
         return None
     else:
-        return up / min(d1, d2)
+        return up / (d1 + d2 - up)
 
 if __name__ == '__main__':
     from wifiloc import toplev
     toplev(infile = "basicdata.csv", sim = otsuka_sim, bad_wifi_crit = 5000,
-            sim_crit = 0.5, remove_bad_wifi_policy = 2,
+            sim_crit = 0, remove_bad_wifi_policy = 2,
             skip_tests_with_bad_wifi = True)

+ 13 - 5
wifiloc.py

@@ -67,11 +67,11 @@ def best_match(known_points, new_point, similarity):
             best = pt
     return best, max_
 
-def select_bad_wifi(pts, crit):
+def get_wifi_coverage(pts):
     from collections import namedtuple
     Loc = namedtuple('Loc', ['latitude', 'longitude'])
     mac_loc = {}
-    bad_mac = set()
+    mac_cov = {}
     for i in range(len(pts)):
         for mac in pts[i].wifi_snr:
             if not mac in mac_loc:
@@ -86,10 +86,18 @@ def select_bad_wifi(pts, crit):
                 sum_lo += loc.longitude
             cent = Loc(sum_la / len(mac_loc[mac]),
                     sum_lo / len(mac_loc[mac]))
+            cov = 0
             for loc in mac_loc[mac]:
-                if dist(cent, loc) > crit:
-                    bad_mac.add(mac)
-                    break
+                cov = max(cov, dist(cent, loc))
+            mac_cov[mac] = cov
+    return mac_cov
+
+def select_bad_wifi(pts, crit):
+    bad_mac = set()
+    cov = get_wifi_coverage(pts)
+    for mac in cov:
+        if cov[mac] > crit:
+            bad_mac.add(mac)
     return bad_mac
 
 def remove_bad_wifi(pts, bad_mac):