packages = ['pandas', 'numpy']

Duplicate Customer Report

Let's clean some data...

Input

Output

Non-Native Gift Card Report

You're not from here?

Input

Output

Float Attendant Reservation Report

Comparative AND Correct

Input

Output

Float Attendant Upgrade Leaderboard

You can never be too competitive...

Input

Output

First Timer Report

Who did they have on their first time?

Input

Output

Gift Card Raffle Report

Christmas comes on 03/01/23

Input

Output

Patch Notes

Patch 1.4 18/09/2022:

Patch 1.3 17/09/2022

Patch 1.2 15/09/2022

import asyncio from js import document, FileReader from pyodide.ffi import create_proxy import pandas as pd import numpy as np import io async def generate_duplicate_customers(event): #READ AND PROCESS PROXY FILE file = event.target.files.to_py() data="" for f in file: data = await f.text() csv_buffer = io.StringIO(data) #FILTER FOR BAD CUSTOMERS df = pd.read_csv(csv_buffer) df['FullName'] = df['Customer First Name'] + " " + df['Customer Last Name'] dup_num = df.groupby('Phone').filter(lambda x: len(x) >= 2) ready = dup_num.loc[:,['Phone', 'FullName', 'Email']] out = ready.groupby('Phone').value_counts().to_csv() #APPEND DOWNLOADABLE CSV element = document.createElement('a') element.setAttribute('href', 'data:text/csv;charset=utf-8,' + out) element.innerHTML = "Duplicate Customers Report" document.getElementById("dup-cust-output").appendChild(element) async def generate_external_giftcards(event): #READ AND PROCESS PROXY FILE file = event.target.files.to_py() data="" for f in file: data = await f.text() csv_buffer = io.StringIO(data) #FILTER FOR EXTERNAL BOUGHT GIFTCARDS df = pd.read_csv(csv_buffer) test = df[['id', 'State', 'Customer Name', 'Items', 'Total']] drop = test.dropna() gc_sales = drop[drop['Items'].str.contains('for Gift Card')] remove_MN = gc_sales[gc_sales['Items'].str.contains('nmin') == False] remove_BV = remove_MN[remove_MN['Items'].str.contains('nbel') == False] remove_RH = remove_BV[remove_BV['Items'].str.contains('nrou') == False] final = remove_RH.to_csv() #APPEND DOWNLOADABLE CSV element = document.createElement('a') element.setAttribute('href', 'data:text/csv;charset=utf-8,' + final) element.innerHTML = "Non-Native GiftCard Report" document.getElementById("external-giftcard-output").appendChild(element) async def generate_upgrade_tally(event): #READ AND PROCESS PROXY FILE file = event.target.files.to_py() data="" for f in file: data = await f.text() csv_buffer = io.StringIO(data) #FILTER FOR PACKAGE SALES & ATTENDANTS df = pd.read_csv(csv_buffer) findUpgrades(df) df = excludeNormals(df) imp = df[['Items', 'Closed By']] count = imp.groupby('Closed By').value_counts() tally = pd.DataFrame(data=count) output_tally = tally.to_csv() #APPEND DOWNLOADABLE CSV element = document.createElement('a') element.setAttribute('href', 'data:text/csv;charset=utf-8,' + output_tally) element.innerHTML = "FA Upgrade Tally" document.getElementById("Upgrade-Tally-Output").appendChild(element) async def generate_booking_revenue(event): #READ AND PROCESS PROXY FILE file = event.target.files.to_py() data="" for f in file: data = await f.text() csv_buffer = io.StringIO(data) #FILTER FOR NON-PREPAID BOOKINGS PER FA df = pd.read_csv(csv_buffer) excludeCustomers(df) imp = df[['Service', 'Booked By', 'Service Credit Source', 'Customer First Name', 'Customer Last Name', 'Total Paid']] remove_prepay = imp.loc[imp['Service Credit Source'] == 'individual'] count = remove_prepay.groupby('Booked By').value_counts() out = count.to_csv() #APPEND DOWNLOADABLE CSV element = document.createElement('a') element.setAttribute('href', 'data:text/csv;charset=utf-8,' + out) element.innerHTML = "FA Reservation Report" document.getElementById("booking-revenue-output").appendChild(element) async def first_timer(event): #READ AND PROCESS PROXY FILE file = event.target.files.to_py() data="" for f in file: data = await f.text() csv_buffer = io.StringIO(data) #FIND APPTS. THAT WERE UPGRADEABLE df = pd.read_csv(csv_buffer) df = df[['Service','Customer First Name', 'Customer Last Name', 'Customer Appointment Number','Total Paid', 'Checkout By']] df = findUpgradable(df) df = df.loc[df['Customer Appointment Number'] == 1] df = df[['Checkout By', 'Service']] df = df.groupby('Checkout By').value_counts() new = pd.DataFrame(data=df) outputVal = new.to_csv() #APPEND DOWNLOADABLE CSV element = document.createElement('a') element.setAttribute('href', 'data:text/csv;charset=utf-8,' + outputVal) element.innerHTML = "First Timer Report" document.getElementById("First-Timer-Output").appendChild(element) async def gc_raffle(event): #READ AND PROCESS PROXY FILE file = event.target.files.to_py() data="" for f in file: data = await f.text() csv_buffer = io.StringIO(data) sales = pd.read_csv(csv_buffer) sales = sales[["Date", "Items", "Total"]] sales = sales.dropna() sales = sales[sales['Items'].str.contains('Gift Card')] sales['Total'] = sales['Total'].str.replace('$','', regex=False) sales["Total"] = pd.to_numeric(sales["Total"]) sales = sales[sales["Total"] > 0] sales["Tickets"] = np.floor(sales["Total"].astype(float) / 50) sales = sales.reset_index(drop=True) sales["TicketNumbers"] = 0 running = 0 for i in range(len(sales)): if(i == 0): sales.at[i, "TicketNumbers"] = sales.at[i, "Tickets"] running += sales.at[i, "Tickets"] else: running += sales.at[i-1, "Tickets"] sales.at[i, "TicketNumbers"] = " " + str(running.astype(int)) + " - " + str((running.astype(int)) + int(sales.at[i, "Tickets"] - 1)) sales = sales[["Date", "Items", "Total", "Tickets", "TicketNumbers"]] outputVal = sales.to_csv() #APPEND DOWNLOADABLE CSV element = document.createElement('a') element.setAttribute('href', 'data:text/csv;charset=utf-8,' + outputVal) element.innerHTML = "Raffle Report" document.getElementById("gc-raffle-Output").appendChild(element) def findUpgradable(df): values = df['Total Paid'] for i in range(len(values)): if(values[i] == '$79.00'): continue if(values[i] == '$94.00'): continue if(values[i] == '$44.00'): continue if(values[i] == '$59.00'): continue if(values[i] == '$90.00'): continue if(values[i] == '$110.00'): continue if(values[i] == '$150.00'): continue df = df.drop(i) return df def findUpgrades(df): items = df['Items'] for i in range(len(items)): #Sauna if('Upgrade to Couples Infrared Sauna Intro Pack' in items[i]): df.loc[i,['Items']] = 'Couples Sauna Intro Pack' continue if('Couples Sauna Intro pack' in items[i]): df.loc[i,['Items']] = 'Couples Sauna Intro Pack' continue if('Infrared Sauna Intro pack upgrade' in items[i]): df.loc[i,['Items']] = 'Sauna Intro Pack' continue if('Sauna Intro Pack' in items[i]): df.loc[i,['Items']] = 'Sauna Intro Pack' continue if('1 x SAUNA (CAVE CLUB) membership' in items[i]): df.loc[i,['Items']] = 'Sauna Membership' continue if('Sauna 20 Pack' in items[i]): df.loc[i,['Items']] = 'Sauna 20 Pack' continue #Float if('Couples Intro Float Pack' in items[i]): df.loc[i,['Items']] = 'Couples Float Intro Pack' continue if('Upgrade to Couples Float Intro Pack' in items[i]): df.loc[i,['Items']] = 'Couples Float Intro Pack' continue if('Float Starter Intro Pack' in items[i]): df.loc[i,['Items']] = 'Float Intro Pack' continue if('Float Therapy intro pack upgrade' in items[i]): df.loc[i,['Items']] = 'Float Intro Pack' continue if('1 x FLOAT (CAVE CLUB) membership' in items[i]): df.loc[i,['Items']] = 'Float Membership' continue if('Float Therapy 24 Pack' in items[i]): df.loc[i,['Items']] = 'Float 24 Pack' continue #Massage if('Massage Intro Pack' in items[i]): df.loc[i,['Items']] = 'Massage Intro Pack' continue if('Massage-Intro pack upgrade' in items[i]): df.loc[i,['Items']] = 'Massage Intro Pack' continue if('1 x MASSAGE CAVE CLUB' in items[i]): df.loc[i,['Items']] = 'Massage Membership' def excludeNormals(df): items = df['Items'] for i in range(len(items)): if(items[i] == 'Float Intro Pack'): continue if(items[i] == 'Couples Float Intro Pack'): continue if(items[i] == 'Float Membership'): continue if(items[i] == 'Float 24 Pack'): continue if(items[i] == 'Sauna Intro Pack'): continue if(items[i] == 'Couples Sauna Intro Pack'): continue if(items[i] == 'Sauna Membership'): continue if(items[i] == 'Sauna 20 Pack'): continue if(items[i] == 'Massage Intro Pack'): continue if(items[i] == 'Massage Membership'): continue df = df.drop(i) return df def excludeCustomers(df): atts = df['Booked By'] for i in range(len(atts)): if('Cassie Berry 🍓' in atts[i]): df.loc[i,['Booked By']] = 'AAA Cassie Berry 🍓' continue if('Charlize Schoeman🧜' in atts[i]): df.loc[i,['Booked By']] = 'AAA Charlize Schoeman🧜' continue if('Elaria Tadros' in atts[i]): df.loc[i,['Booked By']] = 'AAA Elaria Tadros' continue if('Jacinta Galea 👸' in atts[i]): df.loc[i,['Booked By']] = 'AAA Jacinta Galea 👸' continue if('Jeremy Woodward🏃‍♂️' in atts[i]): df.loc[i,['Booked By']] = 'AAA Jeremy Woodward🏃‍♂️' continue if('Lucas Rose🥏' in atts[i]): df.loc[i,['Booked By']] = 'AAA Lucas Rose🥏' continue if('Nat Dolly🥳' in atts[i]): df.loc[i,['Booked By']] = 'AAA Nat Dolly🥳' continue if('Stella Halatanu' in atts[i]): df.loc[i,['Booked By']] = 'AAA Stella Halatanu' continue if('Tanya Motiani 🌟' in atts[i]): df.loc[i,['Booked By']] = 'AAA Tanya Motiani 🌟' continue if('Thomas Hogan 🎧' in atts[i]): df.loc[i,['Booked By']] = 'AAA Thomas Hogan 🎧' continue if('Wisdom Agbeze🧙' in atts[i]): df.loc[i,['Booked By']] = 'AAA Wisdom Agbeze🧙' continue if('Jaime Strong' in atts[i]): df.loc[i,['Booked By']] = 'AAA Jaime Strong' continue if('Kira Schembri 🍋' in atts[i]): df.loc[i,['Booked By']] = 'AAA Kira Schembri 🍋' continue if('Katelyn Woods 🍑' in atts[i]): df.loc[i,['Booked By']] = 'Katelyn Woods 🍑' continue if('Judah Raposo Alves🦄' in atts[i]): df.loc[i,['Booked By']] = 'AAA Judah Raposo Alves🦄' continue if('Andrew Vecchio🤸🏻‍♂️' in atts[i]): df.loc[i,['Booked By']] = 'AAA Andrew Vecchio🤸🏻‍♂️' continue def dupCustProxy(): # Create a Python proxy for the callback function # generate_duplicate_customers() is your function to process events from FileReader file_event = create_proxy(generate_duplicate_customers) # Set the listener to the callback e = document.getElementById("dupCust") e.addEventListener("change", file_event, False) def extGCProxy(): # generate_external_giftcards() is your function to process events from FileReader file_event = create_proxy(generate_external_giftcards) e = document.getElementById("badGC") e.addEventListener("change", file_event, False) def upgradeLBProxy(): file_event = create_proxy(generate_upgrade_tally) e = document.getElementById("upgradeTally") e.addEventListener("change", file_event, False) def bookingRevenueProxy(): file_event = create_proxy(generate_booking_revenue) e = document.getElementById("bookingRevenue") e.addEventListener("change", file_event, False) def firstTimerProxy(): file_event = create_proxy(first_timer) e = document.getElementById("firstTimer") e.addEventListener("change", file_event, False) def raffleProxy(): file_event = create_proxy(gc_raffle) e = document.getElementById("gc-raffle") e.addEventListener("change", file_event, False) dupCustProxy() extGCProxy() upgradeLBProxy() bookingRevenueProxy() firstTimerProxy() raffleProxy()