mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
try using "for in []" isntead of underscore for cron debugging
This commit is contained in:
@@ -504,32 +504,35 @@ ready(function(model) {
|
||||
});
|
||||
expTally = user.get('stats.exp');
|
||||
lvl = 0;
|
||||
_(user.get('stats.lvl') - 1).times(function() {
|
||||
while (lvl < (user.get('stats.lvl') - 1)) {
|
||||
lvl++;
|
||||
return expTally += 50 * Math.pow(lvl, 2) - 150 * lvl + 200;
|
||||
});
|
||||
expTally += 50 * Math.pow(lvl, 2) - 150 * lvl + 200;
|
||||
}
|
||||
return model.push('_user.history.exp', {
|
||||
date: new Date(),
|
||||
value: expTally
|
||||
});
|
||||
};
|
||||
exports.poormanscron = poormanscron = function() {
|
||||
var DAY, daysPassed, lastCron, today;
|
||||
var DAY, daysPassed, lastCron, n, today, _k, _results;
|
||||
model.setNull('_user.lastCron', new Date());
|
||||
lastCron = new Date((new Date(model.get('_user.lastCron'))).toDateString());
|
||||
today = new Date((new Date).toDateString());
|
||||
DAY = 1000 * 60 * 60 * 24;
|
||||
daysPassed = Math.floor((today.getTime() - lastCron.getTime()) / DAY);
|
||||
if (daysPassed > 0) {
|
||||
_(daysPassed).times(function() {
|
||||
return endOfDayTally();
|
||||
});
|
||||
model.set('_user.lastCron', today);
|
||||
return console.log({
|
||||
today: today,
|
||||
lastCron: lastCron,
|
||||
daysPassed: daysPassed
|
||||
}, 'cron debugging');
|
||||
_results = [];
|
||||
for (n = _k = 1; 1 <= daysPassed ? _k <= daysPassed : _k >= daysPassed; n = 1 <= daysPassed ? ++_k : --_k) {
|
||||
console.log({
|
||||
today: today,
|
||||
lastCron: lastCron,
|
||||
daysPassed: daysPassed,
|
||||
n: n
|
||||
}, "[debug] Cron (" + today + ", " + n + ")");
|
||||
_results.push(endOfDayTally());
|
||||
}
|
||||
return _results;
|
||||
}
|
||||
};
|
||||
poormanscron();
|
||||
|
||||
@@ -387,7 +387,7 @@ ready (model) ->
|
||||
# tally experience
|
||||
expTally = user.get 'stats.exp'
|
||||
lvl = 0 #iterator
|
||||
_(user.get('stats.lvl')-1).times ->
|
||||
while lvl < (user.get('stats.lvl')-1)
|
||||
lvl++
|
||||
expTally += 50 * Math.pow(lvl, 2) - 150 * lvl + 200
|
||||
model.push '_user.history.exp', { date: new Date(), value: expTally }
|
||||
@@ -401,10 +401,10 @@ ready (model) ->
|
||||
DAY = 1000 * 60 * 60 * 24
|
||||
daysPassed = Math.floor((today.getTime() - lastCron.getTime()) / DAY)
|
||||
if daysPassed > 0
|
||||
_(daysPassed).times ->
|
||||
endOfDayTally()
|
||||
model.set('_user.lastCron', today) # reset cron
|
||||
console.log {today: today, lastCron: lastCron, daysPassed: daysPassed}, 'cron debugging'
|
||||
for n in [1..daysPassed]
|
||||
console.log {today: today, lastCron: lastCron, daysPassed: daysPassed, n:n}, "[debug] Cron (#{today}, #{n})"
|
||||
endOfDayTally()
|
||||
poormanscron() # Run once on refresh
|
||||
setInterval (-> # Then run once every hour
|
||||
poormanscron()
|
||||
|
||||
Reference in New Issue
Block a user