more bug-fixing on async cron, using lodash instead of underscore

This commit is contained in:
Tyler Renelle
2012-09-24 16:45:37 -04:00
parent 13a7019413
commit 33f8c43e93
9 changed files with 42 additions and 57 deletions

View File

@@ -1,10 +1,12 @@
// Generated by CoffeeScript 1.3.3
var MODIFIER, async, content, cron, expModifier, helpers, hpModifier, model, moment, score, setModel, setupNotifications, updateStats, user;
var MODIFIER, async, content, cron, expModifier, helpers, hpModifier, model, moment, score, setModel, setupNotifications, updateStats, user, _;
async = require('async');
moment = require('moment');
_ = require('lodash');
content = require('./content');
helpers = require('./helpers');
@@ -166,7 +168,7 @@ score = function(taskId, direction, options) {
if (type === 'habit') {
if (taskObj.value !== value) {
task.push('history', {
date: moment().sod().toDate(),
date: moment().toDate(),
value: value
});
}
@@ -206,7 +208,7 @@ cron = function() {
if (daysPassed > 0) {
todoTally = 0;
tallyTask = function(taskObj, next) {
var absVal, completed, dayMapping, daysFailed, dueToday, id, repeat, task, type, value;
var absVal, completed, dayMapping, daysFailed, id, repeat, task, type, value;
id = taskObj.id, type = taskObj.type, completed = taskObj.completed, repeat = taskObj.repeat;
if (id == null) {
return;
@@ -226,9 +228,16 @@ cron = function() {
6: 's',
7: 'su'
};
dueToday = repeat && repeat[dayMapping[momentDate.day()]] === true;
daysFailed = 0;
_.times(daysPassed, function(n) {
var thatDay;
thatDay = today.subtract('days', n + 1);
if (repeat[dayMapping[thatDay.day()]] === true) {
return daysFailed++;
}
});
}
score(taskId, 'down', {
score(id, 'down', {
cron: true,
times: daysFailed
});