from common import general_scheduler
from common.logging import logger_factory
from config import general_config
from fetcher.util import helper as __helper
from accessors.routes import train_route_accessor as __train_route_accessor

__logger = logger_factory.create_logger(__name__)


def __update():
    route_list = __helper.get_train_routes()
    for train_route in route_list:
        __train_route_accessor.upset_train_route(train_route)
    __logger.info('Updated')


__update_period = general_config.get_train_info_refresh_period()
__scheduler = general_scheduler.schedule(__update_period, __update)


def start():
    __update()
    __scheduler.start()
    __logger.info('Started')


def stop():
    __logger.info('Stopped')
    __scheduler.stop()
                                                   next_stop, next_bus)


def __refresh():
    bus_data = __helper.request_buses()
    mapping_threshold = __general_config.get_mapping_threshold()
    station_location = geo_data_accessor.get_station_location()
    bus_routes = bus_route_accessor.get_all_bus_routes()

    __update_bus_states_and_bus_queues(bus_data, mapping_threshold,
                                       station_location, bus_routes)
    __logger.info('Updated')


# logic part

__scheduler = general_scheduler.schedule(
    __general_config.get_eta_refresh_period(), __refresh)


def start():
    # hack: force to update immediately
    __refresh()
    __scheduler.start()
    __logger.info('Started')


def stop():
    __logger.info('Stopped')
    __scheduler.stop()
        for route in walk_route_list:
            word_pool.add(route.walk_from)
            word_pool.add(route.walk_to)
        busway_transfer_list = busway_transfer_accessor.get_all_busway_transfers()
        """:type :list[BuswayTransfer]"""
        for route in busway_transfer_list:
            word_pool.add(route.from_station)
            word_pool.add(route.to_station)
        for word in word_pool:
            add_keyword(word, word)
    except Exception, e:
        __logger.error(e)
    __logger.info('Updated')


__scheduler = general_scheduler.schedule(general_config.get_autocomplete_refresh_period(), __update)


def add_keyword(word, key):
    """
    :type word: str
    :type key: str
    :param word:
    :param key:
    :return:
    """
    __trie.add_word(word, key)


def get_words(key):
    """
def __refresh():
    all_prediction = __get_all_bus_estimates()
    for prediction in all_prediction:
        assert isinstance(prediction, BusEstimation)
        estimation_source = prediction.source
        estimation_destination = prediction.destination
        estimation_eta = prediction.eta
        __add_sample(
            estimation_source,
            estimation_destination,
            estimation_eta
        )
    __logger.info('Updated')


__scheduler = general_scheduler.schedule(general_config.get_eta_refresh_period(), __refresh)


# database part
def __get_all_bus_estimates():
    return __bus_estimate_session.query(BusEstimation).all()


def __get_bus_estimate(source, destination):
    """
    :type source: str
    :type destination: str
    :param source:
    :param destination:
    :return:
    """
Beispiel #5
0
            word_pool.add(route.walk_from)
            word_pool.add(route.walk_to)
        busway_transfer_list = busway_transfer_accessor.get_all_busway_transfers(
        )
        """:type :list[BuswayTransfer]"""
        for route in busway_transfer_list:
            word_pool.add(route.from_station)
            word_pool.add(route.to_station)
        for word in word_pool:
            add_keyword(word, word)
    except Exception, e:
        __logger.error(e)
    __logger.info('Updated')


__scheduler = general_scheduler.schedule(
    general_config.get_autocomplete_refresh_period(), __update)


def add_keyword(word, key):
    """
    :type word: str
    :type key: str
    :param word:
    :param key:
    :return:
    """
    __trie.add_word(word, key)


def get_words(key):
    """