Bug fixes on endOfDayTally, put it back into htlm for testing purposes

This commit is contained in:
Tyler Renelle 2012-06-29 09:04:35 -04:00
parent 6fe6274eb4
commit 2ca050d61e
2 changed files with 12 additions and 4 deletions

View file

@ -111,13 +111,14 @@ poormanscron = (model) ->
lastCron = new Date()
model.set('_user.lastCron', lastCron)
endOfDayTally = (model) ->
# Note: Set 12am daily cron for this
# At end of day, add value to all incomplete Daily & Todo tasks (further incentive)
# For incomplete Dailys, deduct experience
endOfDayTally = (model) ->
# users = model.at('users') #TODO this isn't working, iterate over all users
# for user in users
user = model.at '_user'
todoTally = 0
for key of model.get '_user.tasks'
task = model.at "_user.tasks.#{key}"
[type, value, completed] = [task.get('type'), task.get('value'), task.get('completed')]
@ -125,8 +126,6 @@ endOfDayTally = (model) ->
unless completed
value += if (value < 0) then (( -0.1 * value + 1 ) * -1) else (( Math.pow(0.9,value) ) * -1)
task.set('value', value)
task.setNull 'history', []
task.push "history", { date: new Date(), value: value }
# Deduct experience for missed Daily tasks,
# but not for Todos (just increase todo's value)
if (type == 'daily')
@ -135,6 +134,11 @@ endOfDayTally = (model) ->
#TODO this is implemented in exports.vote also, make it a user.on or something
user.set('hp',50);user.set('lvl',1);user.set('exp',0)
task.set('completed', false) if type == 'daily'
if type == 'daily'
task.push "history", { date: new Date(), value: task.get('value') }
else
todoTally += task.get('value')
model.push '_user.history.todos', { date: new Date(), value: todoTally }
## VIEW HELPERS ##
view.fn 'taskClasses', (type, completed, value, hideCompleted) ->
@ -335,6 +339,10 @@ ready (model) ->
user.set('lvl', lvl)
#[user.money, user.hp, user.exp, user.lvl] = [money, hp, exp, lvl]
exports.eodTally = (e, el) ->
#copy/paste endOfDayTally() here for testing purposes
return
## SHORTCUTS ##
exports.shortcuts = (e) ->

View file

@ -36,7 +36,7 @@
<br/>
<div class="container-fluid">
<!-- <a x-bind=click:endOfDayTally data-content="Implement on cron: this is meant to be run automatically once every night. <br/>See goo.gl/icdTT" data-original-title="TODO" class='task-notes btn'>Tally</a> -->
<a x-bind=click:eodTally data-content="Implement on cron: this is meant to be run automatically once every night. <br/>See goo.gl/icdTT" data-original-title="TODO" class='task-notes btn'>Tally</a>
<div class="row-fluid">
<!-- would rather have one component: <app:taskList>, which handles taskList, task, and newTask. However,