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)
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)
def get_stop_id(self, bssid): p = get_redis_pipeline() p.zrange("bssid:%s:counters" % (bssid), -1, -1, withscores=True) p.get("bssid:%s:total" % (bssid)) res = p.execute() stop_id, score = res[0][0] stop_id = int(stop_id) total = res[1] stop_probability = float(score)/float(total) return stop_id, stop_probability, total
def get_stop_id(self, bssid): p = get_redis_pipeline() p.zrange("bssid:%s:counters" % (bssid), -1, -1, withscores=True) p.get("bssid:%s:total" % (bssid)) res = p.execute() stop_id, score = res[0][0] total = res[1] stop_probability = float(score)/float(total) #stop_id = np.argmax(self.bssid_prob_map[bssid]) #stop_probability = self.bssid_prob_map[bssid][stop_id]/self.bssid_counts_map[bssid] return stop_id, stop_probability, total
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)
def get_stop_id(self, bssid): if USE_FILE and not bssid.startswith(FAKE_BSSID_PREFIX): if file_map.has_key(bssid): return file_map[bssid], 1, 1 else: logger.warn('Unknown bssid: %s' % bssid) return stops.NOSTOP_ID, 0, 0 else: p = get_redis_pipeline() p.zrange("bssid:%s:counters" % (bssid), -1, -1, withscores=True) p.get("bssid:%s:total" % (bssid)) res = p.execute() counts = [x[1] for x in res[0]] stop_id, score = res[0][counts.index(max(counts))] stop_id = int(stop_id) total = res[1] stop_probability = float(score)/float(total) return stop_id, stop_probability, total
_start_stop_time(tracker_id, prev_stop_id, timestamp, stop_time, True) is_updated_stop_time = True elif prev_stop_id != stop_id: stop_time = get_last_detected_stop_time(tracker_id) _end_stop_time(tracker_id, prev_stop_id, stop_time.arrival, prev_timestamp, stop_time) _start_stop_time(tracker_id, stop_id, timestamp, stop_time) is_updated_stop_time = True elif state == DetectorState.states.UNKNOWN_STOP: # TODO: Add handling of UNKNOWN_STOP stop_time logger.info('passing big if statement') pass elif prev_state == DetectorState.states.UNKNOWN_STOP: if state == DetectorState.states.NOSTOP: # TODO: Add handling of UNKNOWN_STOP stop_time logger.info('passing big if statement') pass elif state == DetectorState.states.STOP: # TODO: Add handling of UNKNOWN_STOP stop_time logger.info('passing big if statement') pass elif state == DetectorState.states.UNKNOWN_STOP: # TODO: Add handling of UNKNOWN_STOP stop_time logger.info('passing big if statement') pass return is_updated_stop_time cl = get_redis_client() p = get_redis_pipeline()
def get_bssid_stats(self, bssid): p = get_redis_pipeline() p.zrange("bssid:%s:counters" % (bssid), 0, -1, withscores=True) p.get("bssid:%s:total" % (bssid)) res = p.execute() return res[0]