At a Loss
This morning I, realized I had been spending way too much money. I began to relate my spending habits with the days of the week and realized that tracking the amount of money I had spent would be a perfect way for me to tell how far along into the week we are. Originally I aimed to make this in java processing, but python was much more receptive to the list structure I wanted to use, so I switched to python mode.
Here is a snapshot of September 24th at 4:44
And here is a snapshot of today, October 1st at 4:45
sun = []
mon = [10.56, 9.10, 19.68, 5.62, 7.39]
tue = [7.27, 6.75, 8.85, 7.39]
wed = [7.39, 7.39, 2.85]
thu = [2.00, 6.75, 13.75]
fri = [6.75, 9.08, 9.08]
sat = [7.27, 6.75, 8.85, 7.39]
sunTot = 0
monTot = 0
tueTot = 0
wedTot = 0
thuTot = 0
friTot = 0
satTot = 0
sunAvg = 0
monAvg = 0
tueAvg = 0
wedAvg = 0
thuAvg = 0
friAvg = 0
satAvg = 0
weekTot = 0
weekAvg = 0
sunLoss = 0
monLoss = 0
tueLoss = 0
wedLoss = 0
thuLoss = 0
friLoss = 0
satLoss = 0
lossList = []
todayTotal = 0
lossPerSecond = 0
dayLoss = 0
previousDayLoss = 0
startingCash = 0
totalLoss = 0
currentCash = 0
def setup():
size(800,300)
startingCash = 240 #Dollars
initialize()
previousDayLoss = cashUsed()
def initialize():
sunTot = total(sun)
monTot = total(mon)
tueTot = total(tue)
wedTot = total(wed)
thuTot = total(thu)
friTot = total(fri)
satTot = total(sat)
weekList = [sunTot, monTot, tueTot, wedTot, thuTot, friTot, satTot]
weekTot = total(weekList)
sunAvg = sunTot / weekTot
monAvg = monTot / weekTot
tueAvg = tueTot / weekTot
wedAvg = wedTot / weekTot
thuAvg = thuTot / weekTot
friAvg = friTot / weekTot
satAvg = satTot / weekTot
weekAvg = weekTot / 7.0
sunLoss = sunAvg * startingCash
monLoss = monAvg * startingCash
tueLoss = tueAvg * startingCash
wedLoss = wedAvg * startingCash
thuLoss = thuAvg * startingCash
friLoss = friAvg * startingCash
satLoss = satAvg * startingCash
lossList = [sunLoss, monLoss, tueLoss, wedLoss, thuLoss, friLoss, satLoss]
todayTotal = lossList[dayOfWeek()]
lossPerSecond = todayTotal / 86400
def draw():
background(findBg())
dayLoss = ((((hour() * 60) + minute()) * 60) + second()) * lossPerSecond
totalLoss = previousDayLoss + dayLoss
currentCash = startingCash - totalLoss
printCash()
def total(alist):
total = 0
for i in alist:
total += i
return total
def dayOfWeek():
# 5 is number of days into 2014 for sunday
daystotal = (365*(year() - 1)) + (int(floor((year()-1)/4))) -(int(floor((year() - 1)/100))) + (int(floor((year() - 1)/400))) + day()
return daystotal % 7
def week():
return month() * 4 + day() % 7
def cashUsed():
w = week()
d = dayOfWeek()
daysElapsed = (w % 2) * 7 + d - 1
loss = 0
for i in range(daysElapsed):
loss += lossList[i%7] / 2
return loss
def findBg():
return map(255.0 * ((((week() % 2) * 7) + dayOfWeek()) / 14.0),255,0,0,255) \
+ map(hour()+8,24,0,0,18)
def printCash():
textAlign(CENTER)
cashLeft = "%f" % currentCash
fill(100)
textSize(width * .20)
lost = nfs(totalLoss,3,2)
text("$"+lost,width*.505, height*.71)
fill(255,0,0)
stroke(0)
textSize(width * .20)
lost = nfs(totalLoss,3,2)
text("$"+lost,width*.5, height*.7)