codecombat/scripts/recalculateStatistics.coffee

41 lines
1.2 KiB
CoffeeScript
Raw Normal View History

database = require '../server/commons/database'
mongoose = require 'mongoose'
log = require 'winston'
async = require 'async'
### SET UP ###
do (setupLodash = this) ->
GLOBAL._ = require 'lodash'
_.str = require 'underscore.string'
_.mixin _.str.exports()
database.connect()
### USER STATS ###
UserHandler = require '../server/users/user_handler'
report = (func, name, done) ->
log.info 'Started ' + name + '...'
func name, (err) ->
log.warn err if err?
log.info 'Finished ' + name
done err if done?
whenAllFinished = ->
log.info 'All recalculations finished.'
process.exit()
async.series [
2014-07-23 14:00:28 -04:00
# Misc
(c) -> report UserHandler.recalculateStats, 'gamesCompleted', c
# Edits
(c) -> report UserHandler.recalculateStats, 'articleEdits', c
(c) -> report UserHandler.recalculateStats, 'levelEdits', c
(c) -> report UserHandler.recalculateStats, 'levelComponentEdits', c
(c) -> report UserHandler.recalculateStats, 'levelSystemEdits', c
(c) -> report UserHandler.recalculateStats, 'thangTypeEdits', c
# Patches
(c) -> report UserHandler.recalculateStats, 'patchesContributed', c
(c) -> report UserHandler.recalculateStats, 'patchesSubmitted', c
], whenAllFinished