Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,7 @@ from langchain_core.messages import HumanMessage
|
|
| 17 |
from langchain_openai import ChatOpenAI
|
| 18 |
import base64
|
| 19 |
from utils.azure_blob import AzureBlob
|
|
|
|
| 20 |
|
| 21 |
azure_blob = AzureBlob(os.getenv("azure_blob_conn"))
|
| 22 |
ab = azure_blob
|
|
@@ -38,6 +39,7 @@ def choose_table(question):
|
|
| 38 |
try:
|
| 39 |
str_client_name = 'foodBeverageSample1'
|
| 40 |
df_data = pd.read_parquet(ab.get_latest_parquet('landing', str_client_name, 'sale', 'sol_'))
|
|
|
|
| 41 |
# connection_string = f'postgresql+psycopg2://{db_user}:{db_password}@{db_host}/{db_name}'
|
| 42 |
# engine = create_engine(connection_string)
|
| 43 |
# capsuite_ref = 'foodBeverageSample1'
|
|
@@ -85,10 +87,17 @@ def choose_table(question):
|
|
| 85 |
# print(f"Query: {query}")
|
| 86 |
|
| 87 |
# if 'cdp_sale_order_line' in query:
|
|
|
|
| 88 |
df_data['sales_amount'] = df_data['trxn_item_target_curr_unit_price'].astype(float) * df_data['trxn_item_qty'].astype(float)
|
| 89 |
df_data.rename(columns={'trxn_item_target_curr_unit_price':'unit_price'}, inplace=True)
|
| 90 |
-
df_data.rename(columns={'
|
| 91 |
-
df_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
except Exception as e:
|
| 94 |
print(f"Error while: {e}")
|
|
|
|
| 17 |
from langchain_openai import ChatOpenAI
|
| 18 |
import base64
|
| 19 |
from utils.azure_blob import AzureBlob
|
| 20 |
+
from pprint import pprint
|
| 21 |
|
| 22 |
azure_blob = AzureBlob(os.getenv("azure_blob_conn"))
|
| 23 |
ab = azure_blob
|
|
|
|
| 39 |
try:
|
| 40 |
str_client_name = 'foodBeverageSample1'
|
| 41 |
df_data = pd.read_parquet(ab.get_latest_parquet('landing', str_client_name, 'sale', 'sol_'))
|
| 42 |
+
df_data2 = pd.read_parquet(ab.get_latest_parquet('landing', str_client_name, 'membership', 'mem_'))
|
| 43 |
# connection_string = f'postgresql+psycopg2://{db_user}:{db_password}@{db_host}/{db_name}'
|
| 44 |
# engine = create_engine(connection_string)
|
| 45 |
# capsuite_ref = 'foodBeverageSample1'
|
|
|
|
| 87 |
# print(f"Query: {query}")
|
| 88 |
|
| 89 |
# if 'cdp_sale_order_line' in query:
|
| 90 |
+
df_data = pd.merge(df_data, df_data2, on='member_id', how='left',suffixes=('_sale_order_line', '_membership'))
|
| 91 |
df_data['sales_amount'] = df_data['trxn_item_target_curr_unit_price'].astype(float) * df_data['trxn_item_qty'].astype(float)
|
| 92 |
df_data.rename(columns={'trxn_item_target_curr_unit_price':'unit_price'}, inplace=True)
|
| 93 |
+
df_data.rename(columns={'display_name_sale_order_line':'customer_name'}, inplace=True)
|
| 94 |
+
df_data.rename(columns={'capsuite_ref_sale_order_line':'capsuite_ref'}, inplace=True)
|
| 95 |
+
df_data.rename(columns={'trxn_item_qty':'sales_qty'}, inplace=True)
|
| 96 |
+
df_data['trxn_date'] = pd.to_datetime(df_data['trxn_date']).dt.date
|
| 97 |
+
df_data['trxn_month'] = pd.to_datetime(df_data['trxn_date']).dt.to_period('M')
|
| 98 |
+
df_data['trxn_date'] = df_data['trxn_date'].astype(str)
|
| 99 |
+
df_data['trxn_month'] = df_data['trxn_month'].astype(str)
|
| 100 |
+
df_data = df_data[['trxn_item_id','trxn_id','sales_amount','unit_price','sales_qty','trxn_item_discount_amt','trxn_date','trxn_channel','staff_name','customer_name','prod_category','prod_type','prod_name','capsuite_ref','gender','age','trxn_month']]
|
| 101 |
|
| 102 |
except Exception as e:
|
| 103 |
print(f"Error while: {e}")
|