Esempio n. 1
0
def _estimation_process(id, queue, counters, lock, data_path, DB_INFO, CAD_DB_INFO, IRIS_DB_INFO):
    """
    :type id: int
    :type queue: Queue
    :type counters: dict
    :type lock: Lock
    :type data_path: str
    :type DB_INFO: dict
    :type CAD_DB_INFO: dict
    :type IRIS_DB_INFO: dict
    """

    from pyticas_tetres.db.tetres import conn
    from pyticas_tetres.db.iris import conn as iris_conn
    from pyticas_tetres.db.cad import conn as cad_conn

    logger = getLogger(__name__)
    # initialize
    logger.debug('[EST WORKER %d] starting...' % (id))
    ticas.initialize(data_path)
    infra = Infra.get_infra()
    conn.connect(DB_INFO)
    cad_conn.connect(CAD_DB_INFO)
    iris_conn.connect(IRIS_DB_INFO)

    # db session is created here
    ttr_da = TTRouteDataAccess()

    logger.debug('[EST WORKER %d] is ready' % (id))
    while True:
        (a_route_id, eparam, uid) = queue.get()
        try:
            logger.debug('[EST WORKER %d] >>>>> start estimation (uid=%s, route=%d)' % (id, uid, a_route_id))
            _eparam = eparam.clone()
            try:
                _eparam.add_start_time_offset(offset=5)
            except Exception as e:
                logger.debug('Could not add five minutes offset to the starting time. Error: {}'.format(e))
            _eparam.travel_time_route = ttr_da.get_by_id(a_route_id)
            estimation.estimate(_eparam, uid)
            logger.debug('[EST WORKER %d] <<<<< end of estimation (uid=%s, route=%d)' % (id, uid, a_route_id))
        except Exception as ex:
            tb.traceback(ex)
            logger.debug('[EST WORKER %d] <<<<< end of task (exception occured) (uid=%s)' % (id, uid))

        should_pack = False

        with lock:
            counters[uid] = counters[uid] - 1
            if counters[uid] <= 0:
                del counters[uid]
                should_pack = True

        if should_pack:
            logger.debug('[EST WORKER %d] >>> make compressed file (uid=%s)' % (id, uid))
            _pack_result(uid)
            logger.debug('[EST WORKER %d] <<< end of making compressed file (uid=%s)' % (id, uid))
Esempio n. 2
0
    def init(self, app):

        conn.connect(self.DB_INFO)
        conn.check_version()

        if self.CAD_DB_INFO:
            from pyticas_tetres.db.cad import conn as cad_conn
            cad_conn.connect(self.CAD_DB_INFO)

        if self.IRIS_DB_INFO:
            from pyticas_tetres.db.iris import conn as iris_conn
            iris_conn.connect(self.IRIS_DB_INFO)

        from pyticas_tetres.util import systemconfig
        systemconfig.initialize_system_config_info()

        rservice.start()
        admin_worker.start(1, self.DB_INFO, self.CAD_DB_INFO, self.IRIS_DB_INFO)
        user_workers.start(cfg.N_WORKERS_FOR_USER_CLIENT, self.DB_INFO, self.CAD_DB_INFO, self.IRIS_DB_INFO)
Esempio n. 3
0
def _worker_process(id, queue, counters, lock, data_path, DB_INFO, CAD_DB_INFO,
                    IRIS_DB_INFO):
    """
    :type id: int
    :type queue: Queue
    :type counters: dict
    :type lock: Lock
    :type data_path: str
    :type DB_INFO: dict
    :type CAD_DB_INFO: dict
    :type IRIS_DB_INFO: dict
    """

    from pyticas_tetres.db.tetres import conn
    from pyticas_tetres.db.iris import conn as iris_conn
    from pyticas_tetres.db.cad import conn as cad_conn

    logger = getLogger(__name__)
    # initialize
    logger.debug('[ADMIN WORKER %d] starting...' % (id))
    ticas.initialize(data_path)
    infra = Infra.get_infra()
    conn.connect(DB_INFO)
    cad_conn.connect(CAD_DB_INFO)
    iris_conn.connect(IRIS_DB_INFO)

    logger.debug('[ADMIN WORKER %d] is ready' % (id))
    while True:
        (_uid, _task_added_time, _task, _args, _kwargs) = queue.get()
        try:
            logger.debug('[ADMIN WORKER %d] >>>>> start to run task (uid=%s)' %
                         (id, _uid))
            _task(*_args, **_kwargs)
            logger.debug('[ADMIN WORKER %d] <<<<< end of task (uid=%s)' %
                         (id, _uid))
        except Exception as ex:
            tb.traceback(ex)
            logger.debug(
                '[ADMIN WORKER %d] <<<<< end of task (exception occured) (uid=%s)'
                % (id, _uid))
Esempio n. 4
0
sys.path.append("Server/src")
import global_settings
import dbinfo

if __name__ == '__main__':
    from pyticas import ticas
    from pyticas.infra import Infra
    from pyticas_tetres.db.cad import conn as conn_cad
    from pyticas_tetres.db.iris import conn as conn_iris
    from pyticas_tetres.db.tetres import conn

    ticas.initialize(global_settings.DATA_PATH)
    infra = Infra.get_infra()

    conn.connect(dbinfo.tetres_db_info())
    conn_cad.connect(dbinfo.cad_db_info())
    conn_iris.connect(dbinfo.iris_incident_db_info())

    time.sleep(1)

    print('')
    print(
        '!! Do not run multiple instances of this program. (DB sync problem can be caused in bulk-insertion and deletion)')
    print('!! Stop TeTRES Server if it is running.')
    print('')
    print('# loads weather data for the given time period')
    print('')

    sdt_str = input('# Enter start date to load data (e.g. 2015-01-01) : ')
    sdate = datetime.datetime.strptime(sdt_str, '%Y-%m-%d').date()