Skip to content

Instantly share code, notes, and snippets.

@nanthony007
Created June 29, 2021 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanthony007/feca5b1e3b300ad796a6d0b85521cdae to your computer and use it in GitHub Desktop.
Save nanthony007/feca5b1e3b300ad796a6d0b85521cdae to your computer and use it in GitHub Desktop.
# declare constants
import math
import pandas as pd
import plotly.graph_objects as go
STARBUCKS_ORDER = 2.25
STARBUCKS_REUSABLE = 2.00
REUSABLE_DISCOUNT = 0.10
KEURIG_POT = 79.99
STANDARD_POT = 19.74
KCUPS_COST = 51.27
NUMBER_OF_KCUPS = 96 # this will make 96 cups of 12oz coffee
# in order to get the same thing for the beans we need some math
# 1 table spoon is roughly 0.5 ounces
BEAN_BAG_SIZE = 28 # number in ounces
BEAN_BAG_COST = 14.85
# the number of cups we are allowing ourselves each day
# modify this to suit your needs :)
DAILY_CUPS = 2
DAYS = 365
def base_starbucks_cost(day_number: int) -> float:
# we plus one because days start at zero
return round(2.25 * (day_number + 1), 2)
def reusable_starbucks_cost(day_number: int) -> float:
base_cost = STARBUCKS_ORDER - REUSABLE_DISCOUNT
return round((base_cost * (day_number + 1)) + STARBUCKS_REUSABLE, 2)
def keurig_cost(day_number: int) -> float:
startup_cost = KEURIG_POT + KCUPS_COST
if day_number == 0:
return round(startup_cost, 2)
days_of_coffee = NUMBER_OF_KCUPS / DAILY_CUPS
# handles buying more k-cups after initial pack
refills = math.floor(day_number / days_of_coffee)
return round(startup_cost + (KCUPS_COST * refills), 2)
def coffee_pot_cost(day_number: int) -> float:
startup_cost = STANDARD_POT + BEAN_BAG_COST
if day_number == 0:
return round(startup_cost, 2)
# it is recommended 2 tablespoons per 6 ounces of water
# so our 12oz cup has 4 tablespoons or 2oz of coffee per cup
beans_per_cup = 2 # ounces of beans consumed per 12oz cup
# TODO: above gets edited when we support varying cup sizes
cups_of_beans = BEAN_BAG_SIZE / beans_per_cup
days_of_coffee = cups_of_beans / DAILY_CUPS
# handles buying more beans after initial pack
refills = math.floor(day_number / days_of_coffee)
return round(startup_cost + (BEAN_BAG_COST * refills), 2)
a = pd.Series([base_starbucks_cost(day) for day in range(DAYS)], name='starbucks')
b = pd.Series([reusable_starbucks_cost(day) for day in range(DAYS)], name='starbucks_refill')
c = pd.Series([keurig_cost(day) for day in range(DAYS)], name='keurig')
d = pd.Series([coffee_pot_cost(day) for day in range(DAYS)], name='standard')
e = pd.Series([x + 1 for x in range(DAYS)], name='days')
df = pd.DataFrame(
data=[a, b, c, d, e]
)
df = df.T
df.head()
fig = go.Figure()
fig.add_trace(go.Scatter(x=e, y=a,
mode='lines',
name='starbucks'))
fig.add_trace(go.Scatter(x=e, y=b,
mode='lines',
name='starbucks_refill'))
fig.add_trace(go.Scatter(x=e, y=c,
mode='lines', name='keurig'))
fig.add_trace(go.Scatter(x=e, y=d,
mode='lines', name='standard'))
fig.update_layout(
title=f"Coffee Expenses Over One Year Drinking {DAILY_CUPS} Cups per Day",
xaxis_title="Days Passed",
yaxis_title="USD ($) Spent",
legend_title="Legend",
)
fig.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment