@app.route('/wholesale/labeled/')
def get_table_psws_labeled():
    labs_conn = psycopg2.connect(user=os.environ.get('aws_db_user'), password=os.environ.get('aws_db_password'), host=os.environ.get('aws_db_host'), port=os.environ.get('aws_db_port'), database=os.environ.get('aws_db_name'))
    labs_curs = labs_conn.cursor()
    Q_select_all = 'SELECT product_name, market_name, country_code,\n                        source_name, currency_code, date_price,\n                        observed_price, observed_alps_class, alps_type_method,\n                        alps_stressness, observed_arima_alps_class, arima_alps_stressness\n                        FROM wholesale_prices\n                        WHERE observed_alps_class IS NOT NULL\n                        OR observed_arima_alps_class IS NOT NULL;\n                        '
    labs_curs.execute(Q_select_all)
    rows = labs_curs.fetchall()
    df = pd.DataFrame(rows, columns=['product_name', 'market_name', 'country_code', 'source_name', 'currency_code', 'date_price', 'observed_price', 'observed_alps_class', 'alps_type_method', 'alps_stressness', 'observed_arima_alps_class', 'arima_alps_stressness'])
    labs_curs.close()
    labs_conn.close()
    df['date_price'] = df['date_price'].apply((lambda x: datetime.date.strftime(x, '%Y-%m-%d')))
    df['alps_stressness'] = df['alps_stressness'].apply((lambda x: (round((x * 100), 2) if (type(x) == float) else None)))
    df['alps_stressness'] = df['alps_stressness'].astype(str)
    df['observed_alps_class'] = df['observed_alps_class'].astype(str)
    df['observed_alps_class'] = (((df['observed_alps_class'] + ' (') + df['alps_stressness']) + ' %)')
    df['alps_type_method'] = df['alps_type_method'].astype(str)
    df['arima_alps_stressness'] = df['arima_alps_stressness'].apply((lambda x: (round((x * 100), 2) if (type(x) == float) else None)))
    df['arima_alps_stressness'] = df['arima_alps_stressness'].astype(str)
    df['observed_arima_alps_class'] = (((df['observed_arima_alps_class'].astype(str) + ' (') + df['arima_alps_stressness']) + ' %)')
    df['observed_alps_class'] = df['observed_alps_class'].replace('None (nan %)', 'Not available')
    df['alps_stressness'] = df['alps_stressness'].replace('nan', 'Not available')
    df['alps_type_method'] = df['alps_type_method'].replace('None', 'Not available')
    df['observed_arima_alps_class'] = df['observed_arima_alps_class'].replace('None (nan %)', 'Not available')
    df['arima_alps_stressness'] = df['arima_alps_stressness'].replace('nan', 'Not available')
    df['price_category'] = 'wholesale'
    result = []
    for (_, row) in df.iterrows():
        result.append(dict(row))
    return jsonify(result)
@app.route('/wholesale/labeled/')
def get_table_psws_labeled():
    labs_conn = psycopg2.connect(user=os.environ.get('aws_db_user'), password=os.environ.get('aws_db_password'), host=os.environ.get('aws_db_host'), port=os.environ.get('aws_db_port'), database=os.environ.get('aws_db_name'))
    labs_curs = labs_conn.cursor()
    Q_select_all = 'SELECT product_name, market_name, country_code,\n                        source_name, currency_code, date_price,\n                        observed_price, observed_alps_class, alps_type_method,\n                        alps_stressness, observed_arima_alps_class, arima_alps_stressness\n                        FROM wholesale_prices\n                        WHERE observed_alps_class IS NOT NULL\n                        OR observed_arima_alps_class IS NOT NULL;\n                        '
    labs_curs.execute(Q_select_all)
    rows = labs_curs.fetchall()
    df = pd.DataFrame(rows, columns=['product_name', 'market_name', 'country_code', 'source_name', 'currency_code', 'date_price', 'observed_price', 'observed_alps_class', 'alps_type_method', 'alps_stressness', 'observed_arima_alps_class', 'arima_alps_stressness'])
    labs_curs.close()
    labs_conn.close()
    df['date_price'] = df['date_price'].apply((lambda x: datetime.date.strftime(x, '%Y-%m-%d')))
    df['alps_stressness'] = df['alps_stressness'].apply((lambda x: (round((x * 100), 2) if (type(x) == float) else None)))
    df['alps_stressness'] = df['alps_stressness'].astype(str)
    df['observed_alps_class'] = df['observed_alps_class'].astype(str)
    df['observed_alps_class'] = (((df['observed_alps_class'] + ' (') + df['alps_stressness']) + ' %)')
    df['alps_type_method'] = df['alps_type_method'].astype(str)
    df['arima_alps_stressness'] = df['arima_alps_stressness'].apply((lambda x: (round((x * 100), 2) if (type(x) == float) else None)))
    df['arima_alps_stressness'] = df['arima_alps_stressness'].astype(str)
    df['observed_arima_alps_class'] = (((df['observed_arima_alps_class'].astype(str) + ' (') + df['arima_alps_stressness']) + ' %)')
    df['observed_alps_class'] = df['observed_alps_class'].replace('None (nan %)', 'Not available')
    df['alps_stressness'] = df['alps_stressness'].replace('nan', 'Not available')
    df['alps_type_method'] = df['alps_type_method'].replace('None', 'Not available')
    df['observed_arima_alps_class'] = df['observed_arima_alps_class'].replace('None (nan %)', 'Not available')
    df['arima_alps_stressness'] = df['arima_alps_stressness'].replace('nan', 'Not available')
    df['price_category'] = 'wholesale'
    result = []
    for (_, row) in df.iterrows():
        result.append(dict(row))
    return jsonify(result)