Spaces:
Sleeping
Sleeping
Fixed total value calculation and improved UI
Browse files
app.py
CHANGED
|
@@ -2,15 +2,15 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
import re
|
| 4 |
|
| 5 |
-
# π Page configuration -
|
| 6 |
-
st.set_page_config(page_title="PD2 Pricing App", layout="
|
| 7 |
st.title("π° PD2 Pricing App")
|
| 8 |
st.markdown("Upload your Excel file and calculate item prices.")
|
| 9 |
|
| 10 |
# π¨ Custom CSS for better UI
|
| 11 |
st.markdown("""
|
| 12 |
<style>
|
| 13 |
-
.stTextInput { margin-top: -8px; }
|
| 14 |
.stButton>button { width: 100%; padding: 10px; font-size: 18px; }
|
| 15 |
.summary-box {
|
| 16 |
border: 2px solid #4CAF50; padding: 15px; border-radius: 10px;
|
|
@@ -19,12 +19,12 @@ st.markdown("""
|
|
| 19 |
.summary-title { font-size: 22px; font-weight: bold; color: #4CAF50; }
|
| 20 |
.summary-value { font-size: 18px; margin-bottom: 10px; }
|
| 21 |
.item-container {
|
| 22 |
-
border: 1px solid #ddd; padding:
|
| 23 |
-
margin-bottom: 5px; background-color: #f9f9f9;
|
| 24 |
}
|
| 25 |
-
.item-name { font-size: 18px; font-weight: bold;
|
| 26 |
-
.item-price { font-size: 14px; font-style: italic; color: gray;
|
| 27 |
-
.stNumberInput>div>div>input { width:
|
| 28 |
</style>
|
| 29 |
""", unsafe_allow_html=True)
|
| 30 |
|
|
@@ -47,9 +47,9 @@ if uploaded_file:
|
|
| 47 |
|
| 48 |
# π Remove numbers from "18 Ko" to "33 Zod"
|
| 49 |
def clean_name(name):
|
| 50 |
-
name = re.sub(r'\(.*?\)', '', name)
|
| 51 |
-
name = name.replace(' nan', '').strip()
|
| 52 |
-
name = re.sub(r'^(1[8-9]|2[0-9]|3[0-3])\s', '', name)
|
| 53 |
return name
|
| 54 |
|
| 55 |
df['Name'] = df['Name'].apply(clean_name)
|
|
@@ -81,7 +81,7 @@ if uploaded_file:
|
|
| 81 |
|
| 82 |
# πΉ Format prices for display
|
| 83 |
def format_price(value_min, value_max):
|
| 84 |
-
value_min = f"{value_min:.2f}".rstrip('0').rstrip('.')
|
| 85 |
value_max = f"{value_max:.2f}".rstrip('0').rstrip('.')
|
| 86 |
return f"{value_min}-{value_max}" if value_min != value_max else value_min
|
| 87 |
|
|
@@ -90,23 +90,32 @@ if uploaded_file:
|
|
| 90 |
f"WSS: {format_price(row['WSS Min'], row['WSS Max'])}", axis=1)
|
| 91 |
|
| 92 |
# ποΈ UI with two columns
|
| 93 |
-
col1, col2 = st.columns([3, 1])
|
| 94 |
|
| 95 |
-
# π Left Column -
|
| 96 |
with col1:
|
| 97 |
st.subheader("ποΈ Select item quantities:")
|
| 98 |
user_inputs = {}
|
| 99 |
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
# π Right Column - Summary
|
| 112 |
with col2:
|
|
@@ -117,15 +126,11 @@ if uploaded_file:
|
|
| 117 |
total_hr_max = sum(user_inputs.get(name, 0) * row['HR Max'] for name, row in df.set_index('Name').iterrows())
|
| 118 |
total_gul_min = sum(user_inputs.get(name, 0) * row['GUL Min'] for name, row in df.set_index('Name').iterrows())
|
| 119 |
total_gul_max = sum(user_inputs.get(name, 0) * row['GUL Max'] for name, row in df.set_index('Name').iterrows())
|
| 120 |
-
total_wss_min = sum(user_inputs.get(name, 0) * row['WSS Min'] for name, row in df.set_index('Name').iterrows())
|
| 121 |
-
total_wss_max = sum(user_inputs.get(name, 0) * row['WSS Max'] for name, row in df.set_index('Name').iterrows())
|
| 122 |
|
| 123 |
-
# π Styled summary box
|
| 124 |
st.markdown(f"""
|
| 125 |
<div class='summary-box'>
|
| 126 |
<p class='summary-title'>π§Ύ Total Value</p>
|
| 127 |
<p class='summary-value'><strong>HR:</strong> {format_price(total_hr_min, total_hr_max)}</p>
|
| 128 |
<p class='summary-value'><strong>Gul:</strong> {format_price(total_gul_min, total_gul_max)}</p>
|
| 129 |
-
<p class='summary-value'><strong>WSS:</strong> {format_price(total_wss_min, total_wss_max)}</p>
|
| 130 |
</div>
|
| 131 |
""", unsafe_allow_html=True)
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import re
|
| 4 |
|
| 5 |
+
# π Page configuration - slightly wider layout
|
| 6 |
+
st.set_page_config(page_title="PD2 Pricing App", layout="wide")
|
| 7 |
st.title("π° PD2 Pricing App")
|
| 8 |
st.markdown("Upload your Excel file and calculate item prices.")
|
| 9 |
|
| 10 |
# π¨ Custom CSS for better UI
|
| 11 |
st.markdown("""
|
| 12 |
<style>
|
| 13 |
+
.stTextInput { margin-top: -8px; }
|
| 14 |
.stButton>button { width: 100%; padding: 10px; font-size: 18px; }
|
| 15 |
.summary-box {
|
| 16 |
border: 2px solid #4CAF50; padding: 15px; border-radius: 10px;
|
|
|
|
| 19 |
.summary-title { font-size: 22px; font-weight: bold; color: #4CAF50; }
|
| 20 |
.summary-value { font-size: 18px; margin-bottom: 10px; }
|
| 21 |
.item-container {
|
| 22 |
+
border: 1px solid #ddd; padding: 10px; border-radius: 5px;
|
| 23 |
+
margin-bottom: 5px; background-color: #f9f9f9; display: flex; align-items: center; justify-content: space-between;
|
| 24 |
}
|
| 25 |
+
.item-name { font-size: 18px; font-weight: bold; }
|
| 26 |
+
.item-price { font-size: 14px; font-style: italic; color: gray; }
|
| 27 |
+
.stNumberInput>div>div>input { width: 70px !important; height: 40px !important; }
|
| 28 |
</style>
|
| 29 |
""", unsafe_allow_html=True)
|
| 30 |
|
|
|
|
| 47 |
|
| 48 |
# π Remove numbers from "18 Ko" to "33 Zod"
|
| 49 |
def clean_name(name):
|
| 50 |
+
name = re.sub(r'\(.*?\)', '', name)
|
| 51 |
+
name = name.replace(' nan', '').strip()
|
| 52 |
+
name = re.sub(r'^(1[8-9]|2[0-9]|3[0-3])\s', '', name)
|
| 53 |
return name
|
| 54 |
|
| 55 |
df['Name'] = df['Name'].apply(clean_name)
|
|
|
|
| 81 |
|
| 82 |
# πΉ Format prices for display
|
| 83 |
def format_price(value_min, value_max):
|
| 84 |
+
value_min = f"{value_min:.2f}".rstrip('0').rstrip('.')
|
| 85 |
value_max = f"{value_max:.2f}".rstrip('0').rstrip('.')
|
| 86 |
return f"{value_min}-{value_max}" if value_min != value_max else value_min
|
| 87 |
|
|
|
|
| 90 |
f"WSS: {format_price(row['WSS Min'], row['WSS Max'])}", axis=1)
|
| 91 |
|
| 92 |
# ποΈ UI with two columns
|
| 93 |
+
col1, col2 = st.columns([3.3, 1])
|
| 94 |
|
| 95 |
+
# π Left Column - Grouped Items
|
| 96 |
with col1:
|
| 97 |
st.subheader("ποΈ Select item quantities:")
|
| 98 |
user_inputs = {}
|
| 99 |
|
| 100 |
+
categories = {
|
| 101 |
+
"Runes": ["Ko", "Fal", "Lem", "Pul", "Um", "Mal", "Ist", "Gul", "Vex", "Ohm", "Lo", "Sur", "Ber", "Jah", "Cham", "Zod"],
|
| 102 |
+
"Larzuk's Puzzles": ["Larzuk's Puzzlebox", "Larzuk's Puzzlepiece"],
|
| 103 |
+
"Stocked Mats": ["50 Perfect Gems", "50 Jewel Fragments", "50 Runes (#1-#15)", "50 Craft Infusions", "50 'Map' Orbs", "50 Infused 'Map' Orbs"],
|
| 104 |
+
"Corrupting": ["Worldstone Shard", "Tainted Worldstone Shard"],
|
| 105 |
+
"Map Enhancers": ["Catalyst Shard", "Horadrim Scarab", "Standard of Heroes"],
|
| 106 |
+
"Tokens": ["Token of Absolution", "Essence of Suffering", "Essence of Hatred", "Essence of Terror", "Essence of Destruction"],
|
| 107 |
+
"Relics": ["Relic of the Ancients", "Sigil of Madawc", "Sigil of Talic", "Sigil of Korlic"],
|
| 108 |
+
"Ubers": ["3x3 Uber Keys", "Key of Terror", "Key of Hate", "Key of Destruction"],
|
| 109 |
+
"DC Clone": ["Vision of Terror", "Pure Demonic Essence", "Black Soulstone", "Prime Evil Soul"],
|
| 110 |
+
"Rhatmas": ["Voidstone", "Splinter of the Void", "Trang-Oul's Jawbone", "Hellfire Ashes"]
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
for category, items in categories.items():
|
| 114 |
+
with st.expander(category, expanded=False):
|
| 115 |
+
for _, row in df[df["Name"].isin(items)].iterrows():
|
| 116 |
+
user_inputs[row['Name']] = st.number_input(
|
| 117 |
+
f"{row['Name']} ({row['Formatted Price']})", min_value=0, step=1, key=row['Name']
|
| 118 |
+
)
|
| 119 |
|
| 120 |
# π Right Column - Summary
|
| 121 |
with col2:
|
|
|
|
| 126 |
total_hr_max = sum(user_inputs.get(name, 0) * row['HR Max'] for name, row in df.set_index('Name').iterrows())
|
| 127 |
total_gul_min = sum(user_inputs.get(name, 0) * row['GUL Min'] for name, row in df.set_index('Name').iterrows())
|
| 128 |
total_gul_max = sum(user_inputs.get(name, 0) * row['GUL Max'] for name, row in df.set_index('Name').iterrows())
|
|
|
|
|
|
|
| 129 |
|
|
|
|
| 130 |
st.markdown(f"""
|
| 131 |
<div class='summary-box'>
|
| 132 |
<p class='summary-title'>π§Ύ Total Value</p>
|
| 133 |
<p class='summary-value'><strong>HR:</strong> {format_price(total_hr_min, total_hr_max)}</p>
|
| 134 |
<p class='summary-value'><strong>Gul:</strong> {format_price(total_gul_min, total_gul_max)}</p>
|
|
|
|
| 135 |
</div>
|
| 136 |
""", unsafe_allow_html=True)
|