mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-14 16:02:14 +00:00
Clean up clear_done a bit, add value to Todos as well as Dailies
This commit is contained in:
parent
02d15cccf4
commit
1a89b2420c
1 changed files with 10 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue