rsm-roguchi commited on
Commit
214fbd4
·
1 Parent(s): af0cb14

update price matching

Browse files
Files changed (2) hide show
  1. server/price_matching.py +10 -3
  2. ui/price_matching.py +4 -1
server/price_matching.py CHANGED
@@ -2,7 +2,7 @@ import pandas as pd
2
  from shiny import reactive, render
3
 
4
  def server(input, output, session):
5
-
6
  @reactive.calc
7
  def uploaded_data():
8
  file = input.csv_file()
@@ -11,12 +11,12 @@ def server(input, output, session):
11
  return pd.read_csv(file)
12
 
13
  @reactive.calc
 
14
  def etl_data():
15
  dat = uploaded_data()
16
  if dat is None:
17
  return None
18
 
19
- # Apply filters
20
  dat = dat[~dat["Condition"].isin(["Unopened", "Unopened - Japanese"])]
21
 
22
  exclude = ["Digimon", "Dragon", "Lorcana", "Union", "WoW"]
@@ -25,7 +25,6 @@ def server(input, output, session):
25
 
26
  dat = dat[dat["Total Quantity"] > 0]
27
 
28
- # Fix prices
29
  dat["TCG Marketplace Price"] = dat["TCG Market Price"]
30
  dat.loc[dat["TCG Marketplace Price"] < 0.25, "TCG Marketplace Price"] = 0.25
31
 
@@ -40,3 +39,11 @@ def server(input, output, session):
40
  @render.table
41
  def output_table():
42
  return etl_data()
 
 
 
 
 
 
 
 
 
2
  from shiny import reactive, render
3
 
4
  def server(input, output, session):
5
+
6
  @reactive.calc
7
  def uploaded_data():
8
  file = input.csv_file()
 
11
  return pd.read_csv(file)
12
 
13
  @reactive.calc
14
+ @reactive.event(input.transform_btn) # Run only on button press
15
  def etl_data():
16
  dat = uploaded_data()
17
  if dat is None:
18
  return None
19
 
 
20
  dat = dat[~dat["Condition"].isin(["Unopened", "Unopened - Japanese"])]
21
 
22
  exclude = ["Digimon", "Dragon", "Lorcana", "Union", "WoW"]
 
25
 
26
  dat = dat[dat["Total Quantity"] > 0]
27
 
 
28
  dat["TCG Marketplace Price"] = dat["TCG Market Price"]
29
  dat.loc[dat["TCG Marketplace Price"] < 0.25, "TCG Marketplace Price"] = 0.25
30
 
 
39
  @render.table
40
  def output_table():
41
  return etl_data()
42
+
43
+ @output
44
+ @render.download(filename="price_matched.csv")
45
+ def download_csv():
46
+ dat = etl_data()
47
+ if dat is None:
48
+ return ""
49
+ return dat.to_csv(index=False)
ui/price_matching.py CHANGED
@@ -1,7 +1,10 @@
1
  from shiny import ui
2
 
3
- app_ui = ui.page_fluid(
 
4
  ui.h2("Upload CSV and Run ETL Pipeline"),
5
  ui.input_file("csv_file", "Upload CSV File", accept=".csv"),
 
 
6
  ui.output_table("output_table")
7
  )
 
1
  from shiny import ui
2
 
3
+ ui = ui.nav_panel(
4
+ "Price Matching",
5
  ui.h2("Upload CSV and Run ETL Pipeline"),
6
  ui.input_file("csv_file", "Upload CSV File", accept=".csv"),
7
+ ui.input_action_button("transform_btn", "Transform and Display"),
8
+ ui.download_button("download_csv", "Download Cleaned CSV"),
9
  ui.output_table("output_table")
10
  )