Example #1
0
def _get_report_data(report):
    if report.is_station():
        wifis = [
            x for x in report.get_wifi_set_all() if x.SSID == ISRAEL_RAILWAYS_SSID]
        wifi_stops_ids = set()
        for wifi in wifis:
            if bssid_tracker.tracker.has_bssid_high_confidence(wifi.key):
                stop_id, _, _ = bssid_tracker.tracker.get_stop_id(wifi.key)
                wifi_stops_ids.add(stop_id)

        wifi_stops_ids = np.array(list(wifi_stops_ids))

        # check all wifis show same station:
        if len(wifi_stops_ids) > 0 and np.all(wifi_stops_ids == wifi_stops_ids[0]):
            stop_id = wifi_stops_ids[0]
            state = DetectorState.states.STOP
        else:
            logger.warning('No stop for bssids: %s' %
                         ','.join([x.key for x in wifis]))
            stop_id = None
            state = DetectorState.states.UNKNOWN_STOP
    else:
        stop_id = stops.NOSTOP_ID
        state = DetectorState.states.NOSTOP

    timestamp = report.get_timestamp_israel_time()
    return state, stop_id, timestamp
Example #2
0
def _try_add_report(tracker_id, report):
    logger.info('tracker_id={} report={}'.format(tracker_id, report))
    is_updated_stop_time = False
    
    logger.info('fetching detector_state.')
    detector_state = DetectorState(tracker_id)
    logger.info('fetched detector_state.')
    prev_state, prev_stop_id, prev_timestamp = detector_state.get_current()
    logger.info('prev_state={} prev_stop_id={} prev_timestamp={}'.format(prev_state, prev_stop_id, prev_timestamp))
    # new report is older than last report:
    if prev_timestamp and report.timestamp < prev_timestamp:
        logger.warning('New report is older than last report. New report timestamp={}. Last report timestamp={}'.format(report.timestamp, prev_timestamp))
        return is_updated_stop_time

    state, stop_id, timestamp = _get_report_data(report)
    logger.info('state={} stop_id={} timestamp={}'.format(state, stop_id, timestamp))
    if prev_timestamp and timestamp - prev_timestamp > config.no_report_timegap:
        detector_state_transition = DetectorState.transitions.NOREPORT_TIMEGAP
    else:
        detector_state_transition = DetectorState.transitions.NORMAL

    logger.info('Setting detector state: state={} stop_id={} timestamp={}'.format(state, stop_id, timestamp))
    detector_state.set_current(state, stop_id, timestamp)
    if prev_state in [DetectorState.states.INITIAL, DetectorState.states.NOSTOP]:
        if state == DetectorState.states.NOSTOP:
            logger.info('passing big if statement')
            pass
        elif state == DetectorState.states.STOP:
            _start_stop_time(tracker_id, stop_id, timestamp)
            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.STOP:
        if state == DetectorState.states.NOSTOP:
            stop_time = get_last_detected_stop_time(tracker_id)
            _end_stop_time(
                tracker_id, prev_stop_id, stop_time.arrival, prev_timestamp, stop_time)
            is_updated_stop_time = True
        elif state == DetectorState.states.STOP:
            if detector_state_transition == DetectorState.transitions.NOREPORT_TIMEGAP:
                stop_time = get_last_detected_stop_time(tracker_id)
                print 'NOREPORT_TIMEGAP'
                _end_stop_time(tracker_id, prev_stop_id, stop_time.arrival, prev_timestamp, stop_time)
                _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