Fixes galore

This commit is contained in:
Philip How 2013-03-04 22:00:12 +00:00
parent 34651083ec
commit 7c10aafb1c
3 changed files with 15 additions and 17 deletions

View file

@ -56,9 +56,5 @@ module.exports.taskDeltaFormula = (currentValue, direction) ->
delta = Math.max(Math.pow(0.95,currentValue),0.25) delta = Math.max(Math.pow(0.95,currentValue),0.25)
else else
delta = -Math.min(Math.pow(0.95,currentValue),5) delta = -Math.min(Math.pow(0.95,currentValue),5)
#sign = if (direction is 'up') then 1 else -1 console.log("CV = " + currentValue + " Dir = " + direction + " delta = " + delta)
#delta = Math.pow(0.95,currentValue) * sign
#if delta < -5 then delta = -5
#console.log("CurrentValue: " + currentValue + " delta: " + delta)
#delta = if (currentValue < 0) then (( -0.1 * currentValue + 1 ) * sign) else (( Math.pow(0.9,currentValue) ) * sign)
return delta return delta

View file

@ -46,7 +46,7 @@ score = (model, taskId, direction, times, batch, cron) ->
# (aka, the total delta). This weirdness won't be necessary when calculating mathematically # (aka, the total delta). This weirdness won't be necessary when calculating mathematically
# rather than iteratively # rather than iteratively
nextDelta = algos.taskDeltaFormula(value, direction) nextDelta = algos.taskDeltaFormula(value, direction)
value += nextDelta if adjustvalue value = Math.max(value + nextDelta, -31) if adjustvalue #cap values so we don't get silly values
delta += nextDelta delta += nextDelta
addPoints = -> addPoints = ->
@ -66,10 +66,7 @@ score = (model, taskId, direction, times, batch, cron) ->
switch type switch type
when 'habit' when 'habit'
# Don't adjust values for habits that don't have both + and - calculateDelta()
#adjustvalue = if (taskObj.up==false or taskObj.down==false) then false else true
adjustvalue = true;
calculateDelta(adjustvalue)
# Add habit value to habit-history (if different) # Add habit value to habit-history (if different)
if (delta > 0) then addPoints() else subtractPoints() if (delta > 0) then addPoints() else subtractPoints()
taskObj.history ?= [] taskObj.history ?= []
@ -79,7 +76,6 @@ score = (model, taskId, direction, times, batch, cron) ->
batch.set "#{taskPath}.history", taskObj.history batch.set "#{taskPath}.history", taskObj.history
when 'daily' when 'daily'
#calculateDelta()
if cron? # cron if cron? # cron
calculateDelta() calculateDelta()
subtractPoints() subtractPoints()
@ -92,7 +88,7 @@ score = (model, taskId, direction, times, batch, cron) ->
calculateDelta() calculateDelta()
#don't touch stats on cron #don't touch stats on cron
else else
calculateDelta(false) calculateDelta()
addPoints() # obviously for delta>0, but also a trick to undo accidental checkboxes addPoints() # obviously for delta>0, but also a trick to undo accidental checkboxes
when 'reward' when 'reward'
@ -207,8 +203,11 @@ cron = (model) ->
if repeat[helpers.dayMapping[thatDay.day()]]==true if repeat[helpers.dayMapping[thatDay.day()]]==true
daysFailed++ daysFailed++
score model, id, 'down', daysFailed, batch, true score model, id, 'down', daysFailed, batch, true
if type == 'daily' if type == 'daily'
if completed #set OHV for completed dailies
newValue = taskObj.value + algos.taskDeltaFormula(taskObj.value,'up')
batch.set "tasks.#{taskObj.id}.value", newValue
taskObj.history ?= [] taskObj.history ?= []
taskObj.history.push { date: +new Date, value: value } taskObj.history.push { date: +new Date, value: value }
batch.set "tasks.#{taskObj.id}.history", taskObj.history batch.set "tasks.#{taskObj.id}.history", taskObj.history
@ -219,7 +218,10 @@ cron = (model) ->
todoTally += absVal todoTally += absVal
else if type is 'habit' #reset 'onlies' value to 0 else if type is 'habit' #reset 'onlies' value to 0
if taskObj.up==false or taskObj.down==false if taskObj.up==false or taskObj.down==false
if Math.abs(taskObj.value) < 0.02
batch.set "tasks.#{taskObj.id}.value", 0 batch.set "tasks.#{taskObj.id}.value", 0
else
batch.set "tasks.#{taskObj.id}.value", taskObj.value / 2
# Finished tallying # Finished tallying
obj.history ?= {}; obj.history.todos ?= []; obj.history.exp ?= [] obj.history ?= {}; obj.history.todos ?= []; obj.history.exp ?= []

View file

@ -15,9 +15,9 @@ module.exports.view = (view) ->
classes += " uncompleted" classes += " uncompleted"
switch switch
when value<-8 then classes += ' color-worst' when value<-20 then classes += ' color-worst'
when value>=-8 and value<-5 then classes += ' color-worse' when value>=-20 and value<-10 then classes += ' color-worse'
when value>=-5 and value<-1 then classes += ' color-bad' when value>=-10 and value<-1 then classes += ' color-bad'
when value>=-1 and value<1 then classes += ' color-neutral' when value>=-1 and value<1 then classes += ' color-neutral'
when value>=1 and value<5 then classes += ' color-good' when value>=1 and value<5 then classes += ' color-good'
when value>=5 and value<10 then classes += ' color-better' when value>=5 and value<10 then classes += ' color-better'