From e52a54b29fa6fca390c5c181d50480d7e925d4bb Mon Sep 17 00:00:00 2001 From: sony Date: Sun, 9 Jun 2024 17:46:46 +0200 Subject: [PATCH] Formatting corrected --- .../pages/cust_purchase_expected_expiry.py | 1 + Website/pages/dynamic_pricing_streamlit.py | 38 +++++++------------ Website/pages/product_perishability.py | 2 +- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/Website/pages/cust_purchase_expected_expiry.py b/Website/pages/cust_purchase_expected_expiry.py index f96537f..39b2439 100644 --- a/Website/pages/cust_purchase_expected_expiry.py +++ b/Website/pages/cust_purchase_expected_expiry.py @@ -31,6 +31,7 @@ def cust_purchase_expected_expiry(): df = df[df['score']==100] df = df[["customer_name", "product_name", "purchase_date", "expected_expiry_date"]] + df['product_name'] = df['product_name'].str.title() df['purchase_date'] = pd.to_datetime(df['purchase_date']) df['expected_expiry_date'] = pd.to_datetime(df['expected_expiry_date']) diff --git a/Website/pages/dynamic_pricing_streamlit.py b/Website/pages/dynamic_pricing_streamlit.py index 14840ad..1cc734c 100644 --- a/Website/pages/dynamic_pricing_streamlit.py +++ b/Website/pages/dynamic_pricing_streamlit.py @@ -25,17 +25,13 @@ with open(config_file_path_json) as f: config_json = json.load(f) - -# st.set_page_config(page_title="Dynamic Pricing", layout="wide") - # Title of the Streamlit app st.title("Dynamic Pricing") # Specify the path to the GCS Parquet file platform_customer_pricing_data_path = 'gs://formatted_zone/platform_customer_pricing_data_output' - -@st.cache(allow_output_mutation=True) +@st.cache_data def load_data_from_gcs(filepath): gcs_config = config["GCS"]["credentials_path"] @@ -49,19 +45,13 @@ def load_data_from_gcs(filepath): spark.sparkContext.setLogLevel("ERROR") df = spark.read.parquet(filepath) - return df + df_pandas = df.toPandas() + return df_pandas def dynamic_pricing_streamlit(): - st.write("
", unsafe_allow_html=True) - # # Load the data from the parquet file - # @st.cache - # def load_data(parquet_path): - # return pd.read_parquet(parquet_path) - # - # parquet_path = "platform_customer_pricing_data_output" - df_pandas= load_data_from_gcs(platform_customer_pricing_data_path) + st.write("
", unsafe_allow_html=True) - df = df_pandas.toPandas() + df = load_data_from_gcs(platform_customer_pricing_data_path) # Calculate the percentage decrease from the unit price df['percentage_decrease'] = ((df['unit_price'] - df['dynamic_price']) / df['unit_price']) * 100 @@ -112,7 +102,7 @@ def dynamic_pricing_streamlit(): 'selling_date': 'Selling Date' }, inplace=True) - st.write(filtered_df.describe(),use_container_width=True) + st.write(filtered_df.describe(), use_container_width=True) # Key Metrics st.write("### Key Metrics") @@ -142,7 +132,7 @@ def dynamic_pricing_streamlit(): # Export Filtered Data st.write("### Export Filtered Data") - @st.cache + @st.cache_data def convert_df_to_csv(df): return df.to_csv(index=False).encode('utf-8') @@ -157,17 +147,12 @@ def convert_df_to_csv(df): # Interactive Widgets st.write("### Select Columns to Display") all_columns = filtered_df.columns.tolist() - filtered_df = filtered_df[filtered_df['Score']==100] - all_columns = [col for col in all_columns if col not in ['product_in_avg_expiry_file','Score','Expiry Date']] + filtered_df = filtered_df[filtered_df['Score'] == 100] + all_columns = [col for col in all_columns if col not in ['product_in_avg_expiry_file', 'Score', 'Expiry Date']] selected_columns = st.multiselect("Select Columns", all_columns, default=all_columns) - st.dataframe(filtered_df[selected_columns], use_container_width=True) - # if __name__ == "__main__": - # st.write("Streamlit app is running. Adjust the sliders or filters to explore the data.") - - # Custom CSS for footer st.markdown("""