Ninad077 commited on
Commit
62e89ef
·
verified ·
1 Parent(s): d677dbe

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -13
app.py CHANGED
@@ -4,6 +4,10 @@ from datetime import datetime
4
  import os
5
  import configparser # For activating the config
6
 
 
 
 
 
7
  # Function to initialize session state
8
  def initialize_session_state():
9
  if 'data' not in st.session_state:
@@ -43,7 +47,7 @@ def generate_pm_id(user_data):
43
 
44
  # Function to display saved records as a table and save to CSV
45
  def display_saved_records():
46
- st.write(":violet[Saved Records]")
47
  df = pd.DataFrame.from_dict(st.session_state.data, orient='index')
48
  df.reset_index(inplace=True) # Reset index to convert index (user_name) to a regular column
49
  df.rename(columns={'index': 'User Name'}, inplace=True) # Rename the index column to 'User Name'
@@ -96,7 +100,7 @@ st.set_page_config(
96
 
97
 
98
  # Section 1: Plan Info
99
- st.sidebar.image('Fynd_logo2.png', width = 250)
100
  user_name = st.sidebar.text_input("Enter your name:")
101
  st.sidebar.title("Section 1: Plan Info")
102
  plan_name = st.sidebar.text_input("Plan Name", help="Enter the name of the plan")
@@ -215,9 +219,10 @@ if selected_fee_nature == "Slab based":
215
  with col2:
216
  threshold = st.text_input("Threshold:", key="threshold_input")
217
 
218
- # Function to add data to DataFrame
219
- def add_data(slabs_df, slab, max_value, user_input, Usage, Capping_or_Minimum_Guarantee, threshold):
220
 
 
 
 
221
  max_value = int(max_value) if max_value else None
222
  user_input = int(user_input) if user_input else None
223
  Usage = int(Usage) if Usage else None
@@ -230,18 +235,32 @@ if selected_fee_nature == "Slab based":
230
  "Usage": Usage,
231
  "Capping/Min_Guarantee_value": Capping_or_Minimum_Guarantee,
232
  "Threshold": threshold
233
- }
234
- new_row_df = pd.DataFrame([new_row])
235
- slabs_df = pd.concat([slabs_df, new_row_df], ignore_index=True)
236
- return slabs_df
237
 
238
- # Button to add data
239
  if st.button("Add Data", key="add_data_button"):
240
- slabs_df = add_data(slabs_df, slab, max_value, user_input, Usage, Capping_or_Minimum_Guarantee, threshold)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
 
242
- # Display the updated DataFrame
243
- st.write("Updated Slab Data:")
244
- st.table(slabs_df)
245
 
246
  selected_plan_validity = st.selectbox("Plan Validity", ["--please select--"] + plan_validity_options, help="Select the plan validity")
247
  selected_payment_method = st.selectbox("Payment Method", ["--please select--"] + payment_method_options, help="Select the payment method")
@@ -270,6 +289,9 @@ if selected_fee_nature == "Slab based":
270
  "Payment Method": selected_payment_method,
271
  }
272
 
 
 
 
273
  # Generate PM_id and add it to user_data
274
  pm_id = generate_pm_id(user_data)
275
  user_data['PM_id'] = pm_id
@@ -330,6 +352,11 @@ elif selected_fee_nature in ["Fixed %", "Flat currency"]:
330
  "Payment Method": selected_payment_method,
331
  }
332
 
 
 
 
 
 
333
  # Generate PM_id and add it to user_data
334
  pm_id = generate_pm_id(user_data)
335
  user_data['PM_id'] = pm_id
@@ -338,3 +365,4 @@ elif selected_fee_nature in ["Fixed %", "Flat currency"]:
338
 
339
  # Display saved records
340
  display_saved_records()
 
 
4
  import os
5
  import configparser # For activating the config
6
 
7
+
8
+ global_user_data = [] #For appending user_data
9
+
10
+
11
  # Function to initialize session state
12
  def initialize_session_state():
13
  if 'data' not in st.session_state:
 
47
 
48
  # Function to display saved records as a table and save to CSV
49
  def display_saved_records():
50
+ st.subheader(":violet[Saved Records]")
51
  df = pd.DataFrame.from_dict(st.session_state.data, orient='index')
52
  df.reset_index(inplace=True) # Reset index to convert index (user_name) to a regular column
53
  df.rename(columns={'index': 'User Name'}, inplace=True) # Rename the index column to 'User Name'
 
100
 
101
 
102
  # Section 1: Plan Info
103
+ st.sidebar.image('Fynd_logo2.png', width = 270)
104
  user_name = st.sidebar.text_input("Enter your name:")
105
  st.sidebar.title("Section 1: Plan Info")
106
  plan_name = st.sidebar.text_input("Plan Name", help="Enter the name of the plan")
 
219
  with col2:
220
  threshold = st.text_input("Threshold:", key="threshold_input")
221
 
 
 
222
 
223
+
224
+ # Function to add data to DataFrame
225
+ def add_data(slab, max_value, user_input, Usage, Capping_or_Minimum_Guarantee, threshold):
226
  max_value = int(max_value) if max_value else None
227
  user_input = int(user_input) if user_input else None
228
  Usage = int(Usage) if Usage else None
 
235
  "Usage": Usage,
236
  "Capping/Min_Guarantee_value": Capping_or_Minimum_Guarantee,
237
  "Threshold": threshold
238
+ }
239
+ slabs_df.loc[len(slabs_df)] = new_row
 
 
240
 
 
241
  if st.button("Add Data", key="add_data_button"):
242
+ add_data(slab, max_value, user_input, Usage, Capping_or_Minimum_Guarantee, threshold)
243
+ st.success(f"Data for Slab '{slab}' added successfully!")
244
+
245
+ if st.button("Add Slab", key="add_slab_button"):
246
+ # Clear previous inputs (optional)
247
+ slab = ""
248
+ max_value = ""
249
+ user_input = ""
250
+ Usage = ""
251
+ Capping_or_Minimum_Guarantee = ""
252
+ threshold = ""
253
+
254
+ # Display a message or perform other actions when starting a new slab
255
+ st.info("Enter details for a new slab below.")
256
+
257
+ # Display the slab data in reverse order (most recent on top)
258
+ if not slabs_df.empty:
259
+ st.write("Slab Data:")
260
+ st.table(slabs_df[::-1].reset_index(drop=True))
261
+ else:
262
+ st.info("No slab data available.")
263
 
 
 
 
264
 
265
  selected_plan_validity = st.selectbox("Plan Validity", ["--please select--"] + plan_validity_options, help="Select the plan validity")
266
  selected_payment_method = st.selectbox("Payment Method", ["--please select--"] + payment_method_options, help="Select the payment method")
 
289
  "Payment Method": selected_payment_method,
290
  }
291
 
292
+ global_user_data.append(user_data)
293
+
294
+
295
  # Generate PM_id and add it to user_data
296
  pm_id = generate_pm_id(user_data)
297
  user_data['PM_id'] = pm_id
 
352
  "Payment Method": selected_payment_method,
353
  }
354
 
355
+ global_user_data.append(user_data)
356
+
357
+
358
+
359
+
360
  # Generate PM_id and add it to user_data
361
  pm_id = generate_pm_id(user_data)
362
  user_data['PM_id'] = pm_id
 
365
 
366
  # Display saved records
367
  display_saved_records()
368
+