diff --git a/migrations/20130212_preen_cron.js b/migrations/20130212_preen_cron.js deleted file mode 100644 index 72261f246a..0000000000 --- a/migrations/20130212_preen_cron.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Set this up as a midnight cron script - * - * mongo habitrpg node_modules/moment/moment.js migrations/json.js migrations/20130212_preen_cron.js - */ - - -/* - Users are allowed to experiment with the site before registering. Every time a new browser visits habitrpg, a new - "staged" account is created - and if the user later registeres, that staged account is considered a "production" account. - This function removes all staged accounts that have been abandoned - either older than a month, or corrupted in some way (lastCron==undefined) - */ - -var un_registered = { - "auth.local": {$exists: false}, - "auth.facebook": {$exists: false} - }, - registered = { - $or: [ - { 'auth.local': { $exists: true }}, - { 'auth.facebook': { $exists: true }} - ] - }, - today = +new Date; - -// isValidDate = (d) -> -// return false if Object::toString.call(d) isnt "[object Date]" -// not isNaN(d.getTime()) - - -db.users.find(un_registered).forEach(function(user) { - if (!user) return; - if (!!user.lastCron) { - if (Math.abs(moment(today).diff(user.lastCron, 'days')) > 7) { - return db.users.remove({_id:user._id}); - } - } else { - return db.users.update({_id: user._id}, {$set: {lastCron: today}}); - } -}); - - -/** - * Don't remove missing user auths anymore. This was previously necessary due to data corruption, - * revisit if needs be - */ -/*db.sessions.find().forEach(function(sess){ - var uid = JSON.parse(sess.session).userId; - if (!uid || db.users.count({_id:uid}) === 0) { - db.sessions.remove({_id:sess._id}); - } - });*/ \ No newline at end of file diff --git a/migrations/20130508_fix_duff_party_subscriptions.js b/migrations/20130508_fix_duff_party_subscriptions.js index 8012b472b2..cd218e785b 100644 --- a/migrations/20130508_fix_duff_party_subscriptions.js +++ b/migrations/20130508_fix_duff_party_subscriptions.js @@ -8,7 +8,7 @@ // since our primary subscription will first hit parties now, we *definitely* need an index there -db.parties.ensureIndex( { 'members': 1, 'background': 1} ); +db.parties.ensureIndex( { 'members': 1}, {background: true} ); db.parties.find().forEach(function(party){ diff --git a/migrations/20130518_setup_groups.js b/migrations/20130518_setup_groups.js new file mode 100644 index 0000000000..0e04bfa1b9 --- /dev/null +++ b/migrations/20130518_setup_groups.js @@ -0,0 +1,48 @@ +/** + * In adding the Guilds feature (which supports the Challenges feature), we are consolidating parties and guilds + * into one collection: groups, with group.type either 'party' or 'guild'. We are also creating the 'habitrpg' guild, + * which everyone is auto-subscribed to, and moving tavern chat into that guild + * + * mongo habitrpg ./node_modules/lodash/lodash.js ./migrations/20130518_setup_groups.js + */ + +/** + * TODO + * 1) rename collection parties => groups + * 2) add group.type = 'party' for each current group + * 3) create habitrpg group, .type='guild' + * 4) move tavern.chat.chat into habitrpg guild + * 5) subscribe everyone to habitrpg (be sure to set that for default user too!) + */ + +db.parties.renameCollection('groups',true); +//db.parties.dropCollection(); // doesn't seem to do this step during rename... +//db.parties.ensureIndex( { 'members': 1, 'background': 1} ); + +db.groups.update({}, {$set:{type:'party'}}, {multi:true}); + +//migrate invitation mechanisms +db.users.update( + {}, + { + $remove:{party:1}, + $set:{invitations:{party:null,guilds:[]}} + }, + {multi:1} +); + +tavern = db.tavern.findOne(); +db.tavern.drop(); + +//TODO make as a callback of previous, or make sure group.type is still 'guild' for habitrpg in the end +db.groups.insert({ + _id: "habitrpg", + leader: '9', + type: 'guild', + name: "HabitRPG", + chat: tavern.messages, + info: { + blurb: '', + websites: [] + } +}); \ No newline at end of file diff --git a/migrations/20130602_survey_rewards.js b/migrations/20130602_survey_rewards.js new file mode 100644 index 0000000000..5f883f7ad1 --- /dev/null +++ b/migrations/20130602_survey_rewards.js @@ -0,0 +1,25 @@ +//mongo habitrpg ./node_modules/lodash/lodash.js migrations/20130602_survey_rewards.js + +var members = [] +members = _.uniq(members); + +var query = { + _id: {$exists:1}, + $or:[ + {_id: {$in: members}}, + //{'profile.name': {$in: members}}, + {'auth.facebook.name': {$in: members}}, + {'auth.local.username': {$in: members}}, + {'auth.local.email': {$in: members}} + ] +}; + +print(db.users.count(query)); + +db.users.update(query, + { + $set: { 'achievements.helpedHabit': true }, + $inc: { balance: 2.5 } + }, + {multi:true} +) \ No newline at end of file diff --git a/migrations/20130612_survey_rewards_individual.js b/migrations/20130612_survey_rewards_individual.js new file mode 100644 index 0000000000..1d3fbf3317 --- /dev/null +++ b/migrations/20130612_survey_rewards_individual.js @@ -0,0 +1,9 @@ +//mongo habitrpg migrations/20130612_survey_rewards_individual.js + +var query = {_id: ""}; + +db.users.update(query, + { + $set: { 'achievements.helpedHabit': true }, + $inc: { balance: 2.5 } + }) \ No newline at end of file diff --git a/migrations/20130615_add_extra_indexes.js b/migrations/20130615_add_extra_indexes.js new file mode 100644 index 0000000000..2673568184 --- /dev/null +++ b/migrations/20130615_add_extra_indexes.js @@ -0,0 +1,4 @@ +db.users.ensureIndex( { _id: 1, apiToken: 1 }, {background: true} ) +db.groups.ensureIndex( { members: 1 }, {background: true} ) +db.groups.ensureIndex( { type: 1 }, {background: true} ) +db.groups.ensureIndex( { type: 1, privacy: 1 }, {background: true} ) \ No newline at end of file diff --git a/migrations/csvexport.py b/migrations/csvexport.py index f50799e73b..4aa607cb33 100644 --- a/migrations/csvexport.py +++ b/migrations/csvexport.py @@ -1,10 +1,10 @@ import csv -data = csv.reader(open('/home/slappybag/backrs/800dollar.csv', 'rb'), delimiter=",", quotechar='|') -column = [] +with open(r"/home/slappybag/Documents/SurveyScrape.csv") as f: + reader = csv.reader(f, delimiter=',', quotechar='"') + column = [] + for row in reader: + if row: + column.append(row[4]) -for row in data: - column.append(row[9]) - -print "one:" print column \ No newline at end of file diff --git a/migrations/facebook_to_local.js b/migrations/facebook_to_local.js new file mode 100644 index 0000000000..c8238a77fc --- /dev/null +++ b/migrations/facebook_to_local.js @@ -0,0 +1,10 @@ +var oldId = "", + newId = "", + newUser = db.users.findOne({_id: newId}) + +db.users.update({_id: oldId}, {$set:{auth: newUser.auth}}); + +// remove the auth on the new user (which is a template account). The account will be preened automatically later, +// this allows us to keep the account around a few days in case there was a mistake +db.users.update({_id: newId}, {$unset:{auth:1}}); + diff --git a/migrations/metrics.js b/migrations/metrics.js new file mode 100644 index 0000000000..e424cec117 --- /dev/null +++ b/migrations/metrics.js @@ -0,0 +1,42 @@ +// mongo habitrpg ./migrations/metrics.js + +load('./node_modules/moment/moment.js'); + +var + today = +new Date, + twoWeeksAgo = +moment().subtract(14, 'days'); + + corrupt = { + $or: [ + {lastCron: {$exists:false}}, + {lastCron: 'new'} + ] + } + + un_registered = { + "auth.local": {$exists: false}, + "auth.facebook": {$exists: false} + }, + + registered = { + $or: [ + { 'auth.local': { $exists: true }}, + { 'auth.facebook': { $exists: true }} + ] + }, + + active = { + $or: [ + { 'auth.local': { $exists: true }}, + { 'auth.facebook': { $exists: true }} + ], +// $where: function(){ +// return this.history && this.history.exp && this.history.exp.length > 7; +// }, + 'lastCron': {$gt: twoWeeksAgo} + }; + +print('corrupt: ' + db.users.count(corrupt)); +print('unregistered: ' + db.users.count(un_registered)); +print('registered: ' + db.users.count(registered)); +print('active: ' + db.users.count(active)); \ No newline at end of file diff --git a/migrations/preen_cron.js b/migrations/preen_cron.js new file mode 100644 index 0000000000..51f2491db5 --- /dev/null +++ b/migrations/preen_cron.js @@ -0,0 +1,110 @@ +/** + * Set this up as a midnight cron script + * + * mongo habitrpg ./node_modules/moment/moment.js migrations/preen_cron.js + */ + +load('./node_modules/lodash/lodash.js'); +load('./node_modules/moment/moment.js'); + +var today = +new Date; + +/** + * Users are allowed to experiment with the site before registering. Every time a new browser visits habitrpg, a new + * "staged" account is created - and if the user later registers, that staged account is considered a "production" account. + * This function removes all staged accounts that have been abandoned - either older than a month, or corrupted in + * some way (lastCron==undefined) + */ +db.users.find({ + + // Un-registered users + "auth.local": {$exists: false}, + "auth.facebook": {$exists: false} + +}).forEach(function(user) { + //if (!user) return; + var lastCron = user.lastCron; + if (lastCron && moment(lastCron).isValid()) { + if (Math.abs(moment(today).diff(lastCron, 'days')) > 3) { + return db.users.remove({_id: user._id}); + } + } else { + return db.users.update({_id: user._id}, {$set: {'lastCron': today}}); + } +}); + +/** + * Remove empty parties + */ +db.groups.remove({ + 'type': 'party', + $where: "return this.members.length === 0" +}); + +/** + * Preen history for users with > 7 history entries + * This takes an infinite array of single day entries [day day day day day...], and turns it into a condensed array + * of averages, condensing more the further back in time we go. Eg, 7 entries each for last 7 days; 4 entries for last + * 4 weeks; 12 entries for last 12 months; 1 entry per year before that: [day*7 week*4 month*12 year*infinite] + */ +function preenHistory(history) { + history = _.filter(history, function(h) {return !!h}); // discard nulls (corrupted somehow) + var newHistory = []; + function preen(amount, groupBy) { + var groups, avg, start; + groups = _(history) + .groupBy(function(h) { return moment(h.date).format(groupBy) }) // get date groupings to average against + .sortBy(function(h,k) {return k;}) // sort by date + .value(); // turn into an array + amount++; // if we want the last 4 weeks, we're going 4 weeks back excluding this week. so +1 to account for exclusion + start = (groups.length - amount > 0) ? groups.length - amount : 0; + groups = groups.slice(start, groups.length - 1) + _.each(groups, function(group){ + avg = _.reduce(group, function(mem, obj){ return mem + obj.value }, 0) / group.length; + newHistory.push({date: +moment(group[0].date), value: avg}); + }) + } + + preen(50, 'YYYY'); // last 50 years + preen(12, 'YYYYMM'); // last 12 months + preen(4, 'YYYYww'); // last 4 weeks + newHistory = newHistory.concat(history.slice(-7)); // last 7 days + return newHistory; +} + +var minHistLen = 7; +db.users.find({ + + // Registered users with some history + $or: [ + { 'auth.local': { $exists: true }}, + { 'auth.facebook': { $exists: true }} + ], + 'history': {$exists: true} + +}).forEach(function(user) { + var update = {$set:{}}; + + _.each(user.tasks, function(task) { + if ( task.history && task.history.length > minHistLen ) + update['$set']['tasks.' + task.id + '.history'] = preenHistory(task.history); + }) + + if (user.history.exp && user.history.exp.length > minHistLen) + update['$set']['history.exp'] = preenHistory(user.history.exp); + if (user.history.todos && user.history.todos.length > minHistLen) + update['$set']['history.todos'] = preenHistory(user.history.todos); + + if (!_.isEmpty(update['$set'])) db.users.update({_id: user._id}, update); +}); + +/** + * Don't remove missing user auths anymore. This was previously necessary due to data corruption, + * revisit if needs be + */ +/*db.sessions.find().forEach(function(sess){ + var uid = JSON.parse(sess.session).userId; + if (!uid || db.users.count({_id:uid}) === 0) { + db.sessions.remove({_id:sess._id}); + } + });*/ \ No newline at end of file diff --git a/package.json b/package.json index 4c80dc0ef7..726c66b963 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,9 @@ "expect.js": "~0.2.0", "derby-i18n": "git://github.com/switz/derby-i18n#master", "relative-date": "~1.1.1", - "lodash": "~1.2.1" + "lodash": "~1.2.1", + "async": "~0.2.9", + "optimist": "~0.5.2" }, "private": true, "subdomain": "habitrpg", diff --git a/public/500.html b/public/500.html index 9d4d7270d1..163ae8e444 100644 --- a/public/500.html +++ b/public/500.html @@ -26,8 +26,10 @@
Try again in a few, the developer has been notified. The most likely culprit is this issue which Tyler is working to fix. (Any memory leak experts?)
+Try again in a few. We restart often due to this issue which we're is working to fix. (Any memory leak experts?)
+ +If this page persists the server may be experiencing issues; the developers have been notified. Try switching to the beta site or the main site