Skip to content

Commit

Permalink
Formatting corrected
Browse files Browse the repository at this point in the history
  • Loading branch information
SonyShrestha committed Jun 9, 2024
1 parent afb1812 commit e52a54b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
1 change: 1 addition & 0 deletions Website/pages/cust_purchase_expected_expiry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])

Expand Down
38 changes: 13 additions & 25 deletions Website/pages/dynamic_pricing_streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand All @@ -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("<br>", 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("<br>", 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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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')

Expand All @@ -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("""
<style>
Expand All @@ -185,4 +170,7 @@ def convert_df_to_csv(df):
<div class="footer">
<p>Developed by SpicyBytes</p>
</div>
""", unsafe_allow_html=True)
""", unsafe_allow_html=True)

if __name__ == "__main__":
dynamic_pricing_streamlit()
2 changes: 1 addition & 1 deletion Website/pages/product_perishability.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def product_perishability():

# Sidebar for filtering options
with col1:
search_term_category = st.selectbox('**Category**', distinct_category, index=None)
search_term_category = st.selectbox('**Category**', distinct_category, index=len(distinct_category)-1)

# Assuming 'search_term_category' contains the category selected from the first dropdown.
distinct_subcategory = estimated_avg_expiry_df[estimated_avg_expiry_df['Category'] == search_term_category]['Sub Category'].drop_duplicates().sort_values().tolist()
Expand Down

0 comments on commit e52a54b

Please sign in to comment.