def tetres_user_download():
        uid = request.args.get('uid')
        if not uid:
            return 'not found : %s' % uid, 404

        output_dir_path = util.output_path()
        output_filepath = '%s.zip' % util.output_path(uid, create=False)

        # file is ready
        if not os.path.exists(output_filepath):
            return 'not found', 404

        return send_from_directory(directory=output_dir_path, filename='%s.zip' % uid)
예제 #2
0
def write(uid, eparam, operating_conditions, whole, yearly, monthly, daily):
    """
    :type uid: str
    :type eparam: pyticas_tetres.ttypes.EstimationRequestInfo
    :type operating_conditions: list[pyticas_tetres.rengine.filter.ftypes.ExtFilterGroup]
    :type whole: list[dict]
    :type yearly: list[(list[dict], list[int])]
    :type monthly: list[(list[dict], list[[int, int]])]
    :type daily: list[(list[dict], list[datetime.date])]
    """
    output_dir = util.output_path(
        '%s/%s - %s' % (uid, eparam.travel_time_route.corridor, eparam.travel_time_route.name))

    # result file
    output_file = os.path.join(output_dir, 'reliabilities-by-indices (whole-time-period).xlsx')

    wb = xlsxwriter.Workbook(output_file)

    try:
        report_helper.write_operating_condition_info_sheet(eparam, wb)
    except Exception as ex:
        getLogger(__name__).warning('Exception occured when writing data table : %s' % tb.traceback(ex, f_print=False))

    try:
        _write_whole_result_sheet(eparam, operating_conditions, wb, whole)
    except Exception as ex:
        getLogger(__name__).warning('Exception occured when writing data table : %s' % tb.traceback(ex, f_print=False))

    if yearly:
        try:
            _write_yearly_result_sheet(eparam, operating_conditions, wb, yearly)
        except Exception as ex:
            getLogger(__name__).warning(
                'Exception occured when writing data table : %s' % tb.traceback(ex, f_print=False))

    if monthly:
        try:
            _write_monthly_result_sheet(eparam, operating_conditions, wb, monthly)
        except Exception as ex:
            getLogger(__name__).warning(
                'Exception occured when writing data table : %s' % tb.traceback(ex, f_print=False))

    if daily:
        try:
            _write_daily_result_sheet(eparam, operating_conditions, wb, daily)
        except Exception as ex:
            getLogger(__name__).warning(
                'Exception occured when writing data table : %s' % tb.traceback(ex, f_print=False))

    wb.close()
예제 #3
0
def write_daily(uid, eparam, operating_conditions, daily):
    """
        :type uid: str
        :type eparam: pyticas_tetres.ttypes.EstimationRequestInfo
        :type operating_conditions: list[pyticas_tetres.rengine.filter.ftypes.ExtFilterGroup]
        :type daily: list[(list[dict], list[datetime.date])]
        """
    output_dir = util.output_path(
        '%s/%s - %s' % (uid, eparam.travel_time_route.corridor, eparam.travel_time_route.name))
    output_file_daily = os.path.join(output_dir, 'traveltime-moe-data-daily.xlsx')
    wb_daily = xlsxwriter.Workbook(output_file_daily)
    report_helper.write_operating_condition_info_sheet(eparam, wb_daily)
    report_helper.write_moe_data_sheet_daily(eparam, operating_conditions, wb_daily, daily)
    wb_daily.close()
예제 #4
0
 def _vaccum():
     allowed_days = 7 * 86400
     output_root_path = util.output_path()
     while True:
         now = time.time()
         for f in os.listdir(output_root_path):
             if f.startswith('.'):
                 continue
             filepath = os.path.join(output_root_path, f)
             if os.stat(filepath).st_mtime < now - allowed_days:
                 if os.path.isdir(filepath):
                     shutil.rmtree(filepath, ignore_errors=True)
                 else:
                     os.remove(filepath)
         time.sleep(3 * 3600)  # sleep 3hour
예제 #5
0
def write(uid, eparam, operating_conditions):
    """
    :type uid: str
    :type eparam: pyticas_tetres.ttypes.EstimationRequestInfo
    :type operating_conditions: list[pyticas_tetres.rengine.filter.ftypes.ExtFilterGroup]
    """
    output_dir = util.output_path(
        '%s/%s - %s' % (uid, eparam.travel_time_route.corridor, eparam.travel_time_route.name))

    # data file
    output_file = os.path.join(output_dir, 'traveltime-data.xlsx')
    wb = xlsxwriter.Workbook(output_file)
    report_helper.write_operating_condition_info_sheet(eparam, wb)
    report_helper.write_whole_data_sheet(eparam, operating_conditions, wb)
    wb.close()
def write(uid, eparam, ext_filter_groups, whole, yearly, monthly):
    """
    :type uid: str
    :type eparam: pyticas_tetres.ttypes.EstimationRequestInfo
    :type ext_filter_groups: list[pyticas_tetres.rengine.filter.ftypes.ExtFilterGroup]
    :type whole: list[list[dict]]
    :type yearly: list[list[list[dict]]]
    :type monthly: list[list[list[dict]]]
    """
    output_dir = util.output_path('%s/%s - %s' %
                                  (uid, eparam.travel_time_route.corridor,
                                   eparam.travel_time_route.name))

    # result file
    output_file = os.path.join(output_dir, 'time-of-day-reliabilities.xlsx')
    wb = xlsxwriter.Workbook(output_file)
    report_helper.write_operating_condition_info_sheet(eparam, wb)

    try:
        _write_tod_result_sheet(eparam, ext_filter_groups, wb, whole)
    except Exception as ex:
        getLogger(__name__).warning(
            'Exception occured when writing data table : %s' %
            tb.traceback(ex, f_print=False))

    if yearly:
        try:
            _write_tod_yearly_result_sheet(eparam, ext_filter_groups, wb,
                                           yearly)
        except Exception as ex:
            getLogger(__name__).warning(
                'Exception occured when writing data table : %s' %
                tb.traceback(ex, f_print=False))

    if monthly:
        try:
            _write_tod_monthly_result_sheet(eparam, ext_filter_groups, wb,
                                            monthly)
        except Exception as ex:
            getLogger(__name__).warning(
                'Exception occured when writing data table : %s' %
                tb.traceback(ex, f_print=False))

    wb.close()
예제 #7
0
def write(uid, eparam, operating_conditions):
    """
    :type uid: str
    :type eparam: pyticas_tetres.ttypes.EstimationRequestInfo
    :type operating_conditions: list[pyticas_tetres.rengine.filter.ftypes.ExtFilterGroup]
    """

    # faverolles 10/12/2019: Created function to write moe spreadsheets

    output_dir = util.output_path(
        '%s/%s - %s' % (uid, eparam.travel_time_route.corridor, eparam.travel_time_route.name))

    # data file
    output_file = os.path.join(output_dir, 'traveltime-moe-data.xlsx')
    # per_route_moe_file = os.path.join(output_dir, "per-route-moe-data.xlsx")
    wb = xlsxwriter.Workbook(output_file)
    report_helper.write_operating_condition_info_sheet(eparam, wb)
    report_helper.write_moe_data_sheet(eparam, operating_conditions, wb)
    wb.close()
    def tetres_user_get_result():
        uid = request.form.get('uid')
        if not uid:
            return prot.response_error('invalid request')

        output_path = util.output_path(uid, create=False)
        output_filepath = '%s.zip' % output_path

        # file is ready
        if os.path.exists(output_filepath):
            return prot.response_success('file is ready')

        # process is runninng
        elif os.path.exists(output_path):
            return prot.response_fail('process is running')

        # invalid uid
        else:
            return prot.response_error('invalid uid')
예제 #9
0
def write(uid, eparam, operating_conditions, whole, yearly, monthly, daily):
    """
    :type uid: str
    :type eparam: pyticas_tetres.ttypes.EstimationRequestInfo
    :type operating_conditions: list[pyticas_tetres.rengine.filter.ftypes.ExtFilterGroup]
    :type whole: list[dict]
    :type yearly: list[(list[dict], list[int])]
    :type monthly: list[(list[dict], list[str])]
    :type daily: list[(list[dict], list[datetime.date])]
    :type output_dir: str
    """
    output_dir = util.output_path('%s/%s - %s' %
                                  (uid, eparam.travel_time_route.corridor,
                                   eparam.travel_time_route.name))

    try:
        _write_cumulative_travel_rates(eparam, operating_conditions,
                                       output_dir)
    except Exception as ex:
        getLogger(__name__).warning(
            'Exception occured when writing data table : %s' %
            tb.traceback(ex, f_print=False))

    try:
        _write_whole_indices(eparam,
                             operating_conditions,
                             whole,
                             output_dir,
                             chart_type='bar')
    except Exception as ex:
        getLogger(__name__).warning(
            'Exception occured when writing data table : %s' %
            tb.traceback(ex, f_print=False))

    if yearly:
        try:
            _write_yearly_index_variations(eparam, operating_conditions,
                                           yearly, output_dir)
        except Exception as ex:
            getLogger(__name__).warning(
                'Exception occured when writing data table : %s' %
                tb.traceback(ex, f_print=False))

        try:
            _write_yearly_index_variations_oc(eparam,
                                              operating_conditions,
                                              yearly,
                                              output_dir,
                                              chart_type='bar')
        except Exception as ex:
            getLogger(__name__).warning(
                'Exception occured when writing data table : %s' %
                tb.traceback(ex, f_print=False))

    if monthly:
        try:
            _write_monthly_index_variations(eparam, operating_conditions,
                                            monthly, output_dir)
        except Exception as ex:
            getLogger(__name__).warning(
                'Exception occured when writing data table : %s' %
                tb.traceback(ex, f_print=False))

        try:
            _write_monthly_index_variations_by_oc(eparam,
                                                  operating_conditions,
                                                  monthly,
                                                  output_dir,
                                                  chart_type='line')
        except Exception as ex:
            getLogger(__name__).warning(
                'Exception occured when writing data table : %s' %
                tb.traceback(ex, f_print=False))

    try:
        _write_daily_index_variations(eparam,
                                      operating_conditions,
                                      daily,
                                      output_dir,
                                      chart_type='line')
    except Exception as ex:
        getLogger(__name__).warning(
            'Exception occured when writing data table : %s' %
            tb.traceback(ex, f_print=False))

    try:
        _write_daily_travel_rate_and_buffer_index(eparam, operating_conditions,
                                                  daily, output_dir)
    except Exception as ex:
        getLogger(__name__).warning(
            'Exception occured when writing data table : %s' %
            tb.traceback(ex, f_print=False))
예제 #10
0
def _output_path(uid):
    """
    :type uid: str
    :rtype: str
    """
    return util.output_path(uid, create=False)