From 1a89b2420c37e7d86d8e076f5b4179713e986c49 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Wed, 15 Feb 2012 10:41:38 -0500 Subject: [PATCH] Clean up clear_done a bit, add value to Todos as well as Dailies --- app/models/habit.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/models/habit.rb b/app/models/habit.rb index 3b0998c983..629df056d5 100644 --- a/app/models/habit.rb +++ b/app/models/habit.rb @@ -8,19 +8,20 @@ class Habit < ActiveRecord::Base default_scope :order => 'position ASC' attr_accessible :name, :habit_type, :score, :notes, :up, :down, :done, :position - # TODO set cron for this + # 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 def self.clear_done - Habit.where(:habit_type => Habit::DAILY).collect do |h| + Habit.where('habit_type in (2,3)').collect do |h| unless h.done - value = 0 - if h.score < 0 - value = ( ( -0.1 * h.score + 1 ) * -1 ) - else - value = ( ( 0.9 ** h.score ) * -1 ) + value = (h.score < 0) ? (( -0.1 * h.score + 1 ) * -1) : (( 0.9 ** h.score ) * -1) + # Deduct experience for missed Daily tasks, + # but not for Todos (just increase todo's value) + if(h.habit_type==2) + h.user.exp += value + h.user.save end h.score += value - h.user.exp += value - h.user.save end h.done = false h.save