Exemple #1
0
def import_data_OLD(run_id, table_name):

    # Check if the request contains json data and an id (these must be present)
    if not request.json:
        abort(400)

    # Get data dictionary from the json request
    data = request.json

    # Convert the dictionary into data frame format
    df = pandas.DataFrame(data)

    df.index = range(0, len(df))

    if df.empty:
        abort(400)

    p_layer.delete_from_table(table_name, 'RUN_ID', '=', run_id)

    df['RUN_ID'] = run_id

    # Writes data frame to sql
    eng = get_engine()
    df.to_sql(table_name, eng, if_exists='append', index=False)

    return "", 201
Exemple #2
0
def create_export_data_download():
    if not request.data:
        abort(400)

    # Get json dictionary and values
    json_data = json.loads(request.data)

    data = []

    rec = {'RUN_ID': json_data['RUN_ID'],
           'DOWNLOADABLE_DATA': json_data['DOWNLOADABLE_DATA'],
           'FILENAME': json_data['FILENAME'],
           'SOURCE_TABLE': json_data['SOURCE_TABLE'],
           'DATE_CREATED': json_data['DATE_CREATED']}

    data.append(rec)

    # Convert the dictionary into data frame format
    df = pandas.DataFrame(data)

    # Writes data frame to sql
    eng = get_engine()
    df.to_sql('EXPORT_DATA_DOWNLOAD', eng, if_exists='append', index=False)

    return "", 201
Exemple #3
0
def create_process_variables(run_id):

    # Check if the request contains json data and an id (these must be present)
    if not request.json:
        abort(400)

    # Get data dictionary from the json request
    data = request.json

    # Convert the dictionary into data frame format
    df = pandas.DataFrame(data)

    df.index = range(0, len(df))

    if df.empty:
        abort(400)

    df['RUN_ID'] = run_id

    df['PV_DEF'] = df['PV_DEF'].str.replace('&lt;', '<').str.replace('&gt;', '>')

    # Writes data frame to sql
    eng = get_engine()
    df.to_sql('PROCESS_VARIABLE_PY', eng, if_exists='append', index=False)

    return "", 201
Exemple #4
0
def edit_run_steps(run_id, value, step_number=None):

    if not run_id:
        abort(400)

    if not value:
        abort(400)

    df = p_layer.get('RUN_STEPS')

    df = df.loc[df['RUN_ID'] == run_id]

    if step_number:
        df.loc[df['STEP_NUMBER'] == float(step_number), 'STEP_STATUS'] = float(value)
    else:
        df.STEP_STATUS = value

    df.index = range(0, len(df))

    # Deletes run_steps records for the active run before inserting updated step data
    p_layer.delete_from_table('RUN_STEPS', 'RUN_ID', '=', str(df['RUN_ID'][0]))

    # Writes new data to sql
    eng = get_engine()
    df.to_sql('RUN_STEPS', eng, if_exists='append', index=False)

    return "", 200
Exemple #5
0
def create_response():
    if not request.json or 'RUN_ID' not in request.json:
        abort(400)

    # Get data dictionary from the json request
    data = request.json

    # Convert the dictionary into data frame format
    df = pandas.DataFrame(data, index=[0])

    # Writes data frame to sql
    eng = get_engine()
    df.to_sql('RESPONSE', eng, if_exists='append', index=False)

    return "", 201
Exemple #6
0
def create_run():
    # Check if the request contains json data and an id (these must be present)
    if not request.json or 'RUN_ID' not in request.json:
        abort(400)

    # Get data dictionary from the json request
    data = request.json

    # Convert the dictionary into data frame format
    df = pandas.DataFrame(data, index=[0])

    # Writes data frame to sql
    eng = get_engine()
    df.to_sql('RUN', eng, if_exists='append', index=False)

    return "", 201
Exemple #7
0
def edit_run(run_id):
    # Check if the request contains json data and an id (these must be present)
    if not request.json or not run_id:
        abort(400)

    # Get data dictionary from the json request
    data = request.json

    # Convert the dictionary into data frame format
    df = pandas.DataFrame(data, index=[0])

    # Deletes old run instance from database before inserting updated version
    p_layer.delete_from_table('RUN', 'RUN_ID', '=', str(df['RUN_ID'][0]))

    # Writes data frame to sql
    eng = get_engine()
    df.to_sql('RUN', eng, if_exists='append', index=False)

    return "", 200
Exemple #8
0
def create_run_steps(run_id):

    steps = {1: 'Calculate Shift Weight',
             2: 'Calculate Non-Response Weight',
             3: 'Calculate Minimums Weight',
             4: 'Calculate Traffic Weight',
             5: 'Calculate Unsampled Weight',
             6: 'Calculate Imbalance Weight',
             7: 'Calculate Final Weight',
             8: 'Stay Imputation',
             9: 'Fares Imputation',
             10: 'Spend Imputation',
             11: 'Rail Imputation',
             12: 'Regional Weight',
             13: 'Town Stay and Expenditure Imputation',
             14: 'Air Miles',
             }

    if not run_id:
        abort(400)

    data = []

    for key, value in steps.items():
        rec = {'RUN_ID': run_id,
               'STEP_NUMBER': key,
               'STEP_NAME': value,
               'STEP_STATUS': 0}
        data.append(rec)

    # Convert the dictionary into data frame format
    df = pandas.DataFrame(data)

    # Deletes run_steps records for the active run before inserting updated step data
    p_layer.delete_from_table('RUN_STEPS', 'RUN_ID', '=', str(df['RUN_ID'][0]))

    # Writes data frame to sql
    eng = get_engine()
    df.to_sql('RUN_STEPS', eng, if_exists='append', index=False)

    return "", 201