Browse Source

Add parameters to control the output of statistics

Remove hard-coded "100" and "10".
Xi Ruoyao 5 years ago
parent
commit
c58606d028
1 changed files with 7 additions and 6 deletions
  1. 7 6
      wifiloc.py

+ 7 - 6
wifiloc.py

@@ -102,7 +102,8 @@ def remove_bad_wifi(pts, crit = 500):
             if mac in pts[i].wifi_snr:
                 pts[i].wifi_snr.pop(mac)
 
-def toplev(infile, sim, bad_wifi_crit, sim_crit):
+def toplev(infile, sim, bad_wifi_crit, sim_crit, stat_cnt = 10,
+        stat_delta = 50):
     from itertools import groupby
     from random import shuffle
     data = read_data(infile)
@@ -112,7 +113,7 @@ def toplev(infile, sim, bad_wifi_crit, sim_crit):
     groups = groupby(data, key)
     tot = 0
     matched = 0
-    cnt = [0] * 10
+    cnt = [0] * stat_cnt
     for k, g in groups:
         points = list(g)
         if len(points) < 2:
@@ -135,15 +136,15 @@ def toplev(infile, sim, bad_wifi_crit, sim_crit):
             matched += 1
             d = dist(pt1, pt)
             # print('d =', d)
-            if int(d / 100) < 10:
-                cnt[int(d / 100)] += 1
+            if int(d / stat_delta) < stat_cnt:
+                cnt[int(d / stat_delta)] += 1
     print('测试点总数 =', tot)
     print('匹配数 =', matched)
     acc = 0
     for i in range(10):
         acc += cnt[i]
-        print(i+1, '米内匹配数 =', acc, ', 占测试点总数比例 =',
-                acc / tot, ', 占所有匹配结果比例 =',
+        print((i+1) * stat_delta, '米内匹配数 =', acc,
+                ', 占测试点总数比例 =', acc / tot, ', 占所有匹配结果比例 =',
                 acc / matched)
 
 def simple_sim(a, b):