Пример #1
0
 def add(self, report):
     if not report.get_my_loc() or report.loc_ts_delta() > config.stop_discovery_location_timeout_seconds:
         if report.get_my_loc():
             logger.debug('Report %s skipped because of large loc_ts_delta of %d. This is ok if running from a test, as date may have ben changed.' % (str(report), report.loc_ts_delta()))
             return
         else:
             logger.debug('Report %s skipped because it has not location data' % str(report))
             return
     loc = report.get_my_loc()
     wifis = [x for x in report.get_wifi_set_all() if x.SSID == 'S-ISRAEL-RAILWAYS']
     if len(wifis) > 0:
         coords = [loc.lat, loc.lon]
         stop_id_list = stops.all_stops.query_stops(coords, meter_distance_to_coord_distance(config.station_radius_in_meters))
     
     for wifi in wifis:
         if len(stop_id_list) == 1:                
             p = get_redis_pipeline()
             stop_id = stops.all_stops[stop_id_list[0]].id
             p.zincrby("bssid:%s:counters" % (wifi.key), stop_id, 1)
             p.incr("bssid:%s:total" % (wifi.key))
             p.execute()                
         else:
             if len(stop_id_list) == 0:
                 self.wifis_near_no_station.append(wifi)
             else:
                 self.wifis_near_two_or_more_stations.append(wifi)
Пример #2
0
def load_bssids_from_json_file():
    import json
    
    with open(os.path.join(settings.BASE_DIR, 'algorithm', 'stop_data.json'), 'r') as f:
        stop_data = json.load(f)
   
    del stop_data['netid']    
    data = []
    for bssid in stop_data:
        current_stop_data = stop_data[bssid]
        coords = [current_stop_data['lat'], current_stop_data['lon']]
        stop_id_list = stops.all_stops.query_stops(coords, meter_distance_to_coord_distance(config.station_radius_in_meters))
        if stop_id_list:
            if len(stop_id_list) > 1:
                print 'problem'
            else:
                item = (stops.all_stops[stop_id_list[0]].name, stop_id_list[0], bssid.replace(':','').lower())
                data.append(item)
    #for item in sorted(data):
        #print '%s\t%d\t%s' % (item[0], item[1], item[2])
    bssids = [x[2] for x in data]
    with open(os.path.join(settings.BASE_DIR, 'algorithm', 'tracker_stop_data.json'), 'r') as f:
        tracker_stop_data = json.load(f)    
    for data_item in tracker_stop_data:
        if data_item[0] not in bssids:
            data.append((data_item[4], data_item[3], data_item[0]))
                
    return data
Пример #3
0
def print_bssids_by_stop(bssids):
    data = {}
    for x in bssids:
        print 'bassid', x
        data[x] = {}
        wifi_reports = analysis.models.SingleWifiReport.objects.filter(key = x)
        reports = list(set(x.report for x in wifi_reports))        
        for report in reports:
            if not report.get_my_loc() or report.loc_ts_delta() > config.stop_discovery_location_timeout_seconds:
                if report.get_my_loc():
                    logger.debug('Report %s skipped because of large loc_ts_delta of %d' % (str(report), report.loc_ts_delta()))
                continue
            loc = report.get_my_loc()
            coords = [loc.lat, loc.lon]
            stop_id_list = stops.all_stops.query_stops(coords, meter_distance_to_coord_distance(config.station_radius_in_meters))
            if stop_id_list:
                if len(stop_id_list) > 1:
                    print 'problem'
                else:
                    if not data[x].has_key(stop_id_list[0]):
                        data[x][stop_id_list[0]] = []
                    data[x][stop_id_list[0]].append((report.timestamp, report.device_id))
        for stop_id in data[x]:
            print stop_id
            for dict_tuple in sorted(data[x][stop_id]):
                print str(dict_tuple[0]), dict_tuple[1]
Пример #4
0
 def add(self, report):
     if report.loc_ts_delta() < config.stop_discovery_location_timeout_seconds:
         pass
     
     wifis = [x for x in report.wifi_set.all() if x.SSID == 'S-ISRAEL-RAILWAYS']
     if len(wifis) > 0:
         coords = [report.my_loc.lat, report.my_loc.lon]
         stop_id_list = stops.all_stops.query_stops(coords, meter_distance_to_coord_distance(config.station_radius_in_meters))
     
     for wifi in wifis:
         if len(stop_id_list) == 1:
             #if not self.bssid_prob_map.has_key(wifi.key):
                 #self.bssid_prob_map[wifi.key] = np.zeros(len(stops.all_stops))
                 #self.bssid_counts_map[wifi.key] = 0
             #self.bssid_prob_map[wifi.key][stop_id_list[0]] += 1
             #self.bssid_counts_map[wifi.key] += 1
             
             p = get_redis_pipeline()
             stop_id = stops.all_stops[stop_id_list[0]].id
             p.zincrby("bssid:%s:counters" % (wifi.key), stop_id, 1)
             p.incr("bssid:%s:total" % (wifi.key))
             p.execute()                
         else:
             if len(stop_id_list) == 0:
                 self.wifis_near_no_station.append(wifi)
             else:
                 self.wifis_near_two_or_more_stations.append(wifi)
Пример #5
0
 def get_sampling_of_all_routes(self):
     from common.ot_utils import meter_distance_to_coord_distance
     shape_point_tree = spatial.cKDTree(self.all_unique_coords)
     
     inds_to_go_over = np.zeros(len(self.all_unique_coords)) == 0
     inds_to_keep = np.zeros(len(self.all_unique_coords)) == -1
     dist_threshold = meter_distance_to_coord_distance(config.route_sampling__min_distance_between_points_meters)
     count = 0
     while count < len(inds_to_go_over):
         while(count < len(inds_to_go_over) and not inds_to_go_over[count]):
             count = count + 1
         if count < len(inds_to_go_over):
             inds_to_keep[count] = True
             inds_to_remove = shape_point_tree.query_ball_point(shape_point_tree.data[count], dist_threshold)
             inds_to_go_over[inds_to_remove] = False
         
         
     sampled_all_routes_tree = spatial.cKDTree(shape_point_tree.data[inds_to_keep])
     return inds_to_keep, sampled_all_routes_tree
Пример #6
0
 def add(self, report):
     if not report.get_my_loc() or report.loc_ts_delta() > config.stop_discovery_location_timeout_seconds:
         return
     loc = report.get_my_loc()
     wifis = [x for x in report.get_wifi_set_all() if x.SSID == 'S-ISRAEL-RAILWAYS']
     if len(wifis) > 0:
         coords = [loc.lat, loc.lon]
         stop_id_list = stops.all_stops.query_stops(coords, meter_distance_to_coord_distance(config.station_radius_in_meters))
     
     for wifi in wifis:
         if len(stop_id_list) == 1:                
             p = get_redis_pipeline()
             stop_id = stops.all_stops[stop_id_list[0]].id
             p.zincrby("bssid:%s:counters" % (wifi.key), stop_id, 1)
             p.incr("bssid:%s:total" % (wifi.key))
             p.execute()                
         else:
             if len(stop_id_list) == 0:
                 self.wifis_near_no_station.append(wifi)
             else:
                 self.wifis_near_two_or_more_stations.append(wifi)
Пример #7
0
 def accuracy_in_coords(self):
     from common.ot_utils import meter_distance_to_coord_distance
     return meter_distance_to_coord_distance(self.accuracy)