Becer commited on
Commit
da414e7
Β·
1 Parent(s): 9df2b7d

Fixed total value calculation and improved UI

Browse files
Files changed (1) hide show
  1. app.py +33 -28
app.py CHANGED
@@ -2,15 +2,15 @@ import streamlit as st
2
  import pandas as pd
3
  import re
4
 
5
- # πŸ“Œ Page configuration - set a narrower layout
6
- st.set_page_config(page_title="PD2 Pricing App", layout="centered")
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; } /* Reduce spacing above input */
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: 8px; border-radius: 5px;
23
- margin-bottom: 5px; background-color: #f9f9f9;
24
  }
25
- .item-name { font-size: 18px; font-weight: bold; margin-bottom: -5px; } /* Reduce spacing */
26
- .item-price { font-size: 14px; font-style: italic; color: gray; margin-bottom: -5px; } /* Reduce spacing */
27
- .stNumberInput>div>div>input { width: 60px !important; } /* Make input field shorter */
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) # Remove everything inside parentheses
51
- name = name.replace(' nan', '').strip() # Remove "nan" artifacts
52
- name = re.sub(r'^(1[8-9]|2[0-9]|3[0-3])\s', '', name) # Remove numbers
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('.') # Remove trailing zeros
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 - Items List
96
  with col1:
97
  st.subheader("πŸ›οΈ Select item quantities:")
98
  user_inputs = {}
99
 
100
- for index, row in df.iterrows():
101
- col1a, col1b = st.columns([3, 1]) # Create row layout (name | input field)
102
- with col1a:
103
- st.markdown(f"<div class='item-container'>"
104
- f"<p class='item-name'>{row['Name']}</p>"
105
- f"<p class='item-price'>{row['Formatted Price']}</p>"
106
- f"</div>", unsafe_allow_html=True)
107
- with col1b:
108
- unique_key = f"{row['Name']}_{index}"
109
- user_inputs[row['Name']] = st.number_input("", min_value=0, step=1, key=unique_key)
 
 
 
 
 
 
 
 
 
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)