joshuadunlop commited on
Commit
f42b01e
·
1 Parent(s): 8c5ebf0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -15
app.py CHANGED
@@ -4,6 +4,7 @@ from time import strftime, gmtime
4
  import streamlit as st
5
  from datetime import datetime, timedelta
6
  import pandas as pd
 
7
  from io import StringIO
8
 
9
  # Function to fetch data from ShareASale
@@ -37,12 +38,6 @@ def parse_csv_to_df(csv_data):
37
  csv_stream = StringIO(csv_data)
38
  return pd.read_csv(csv_stream, delimiter='|')
39
 
40
- # Create a DataFrame for merchantid to organisation name mapping
41
- merchant_mapping = pd.DataFrame({
42
- 'merchantid': [123, 456, 789], # Replace with your actual merchant IDs
43
- 'organisation name': ['Company A', 'Company B', 'Company C'] # Replace with your actual organisation names
44
- })
45
-
46
  # Streamlit UI
47
  st.title("Affiliate Earnings Dashboard")
48
  st.sidebar.title("Settings")
@@ -65,29 +60,26 @@ if st.sidebar.button("Fetch Data"):
65
  # Parse the CSV data into a DataFrame
66
  df = parse_csv_to_df(ledger_data)
67
 
68
- # Merge with merchant mapping
69
- df = pd.merge(df, merchant_mapping, on='merchantid', how='left')
70
-
71
  # Filter rows where action is "Transaction Created"
72
  df_filtered = df.loc[df['action'] == 'Transaction Created']
73
 
74
- # Remove 'ledgerid', 'transid', and 'merchantid' columns
75
- df_filtered = df_filtered.drop(columns=['ledgerid', 'transid', 'action', 'merchantid'])
76
 
77
  # Display the DataFrame as a table
78
  st.write("Transaction Data")
79
  st.write(df_filtered)
80
 
81
- # Create a second table summing the impact for each unique organisation name
82
- df_sumif = df_filtered.groupby('organisation name')['impact'].sum().reset_index()
83
 
84
  # Calculate the total impact
85
  total_impact = df_sumif['impact'].sum()
86
 
87
  # Add a total row to the DataFrame
88
- total_row = pd.DataFrame({'organisation name': ['Total'], 'impact': [total_impact]})
89
  df_sumif = pd.concat([df_sumif, total_row], ignore_index=True)
90
 
91
  # Display the second DataFrame as a table
92
- st.write("Impact Summary by Organisation")
93
  st.write(df_sumif)
 
4
  import streamlit as st
5
  from datetime import datetime, timedelta
6
  import pandas as pd
7
+ import csv
8
  from io import StringIO
9
 
10
  # Function to fetch data from ShareASale
 
38
  csv_stream = StringIO(csv_data)
39
  return pd.read_csv(csv_stream, delimiter='|')
40
 
 
 
 
 
 
 
41
  # Streamlit UI
42
  st.title("Affiliate Earnings Dashboard")
43
  st.sidebar.title("Settings")
 
60
  # Parse the CSV data into a DataFrame
61
  df = parse_csv_to_df(ledger_data)
62
 
 
 
 
63
  # Filter rows where action is "Transaction Created"
64
  df_filtered = df.loc[df['action'] == 'Transaction Created']
65
 
66
+ # Remove 'ledgerid' and 'transid' columns
67
+ df_filtered = df_filtered.drop(columns=['ledgerid', 'transid', 'action'])
68
 
69
  # Display the DataFrame as a table
70
  st.write("Transaction Data")
71
  st.write(df_filtered)
72
 
73
+ # Create a second table summing the impact for each unique merchantid
74
+ df_sumif = df_filtered.groupby('merchantid')['impact'].sum().reset_index()
75
 
76
  # Calculate the total impact
77
  total_impact = df_sumif['impact'].sum()
78
 
79
  # Add a total row to the DataFrame
80
+ total_row = pd.DataFrame({'merchantid': ['Total'], 'impact': [total_impact]})
81
  df_sumif = pd.concat([df_sumif, total_row], ignore_index=True)
82
 
83
  # Display the second DataFrame as a table
84
+ st.write("Impact Summary by Merchant")
85
  st.write(df_sumif)