Merge branch 'master' into production

This commit is contained in:
Nick Winter 2015-10-16 16:07:17 -07:00
commit 68c08af508
3 changed files with 79 additions and 12 deletions

View file

@ -133,6 +133,7 @@ module.exports = class CampaignEditorView extends RootView
@campaign.set('levels', campaignLevels) @campaign.set('levels', campaignLevels)
for level in _.values campaignLevels for level in _.values campaignLevels
continue if /test/.test @campaign.get('slug') # Don't overwrite level stuff for testing Campaigns
model = @levels.findWhere {original: level.original} model = @levels.findWhere {original: level.original}
model.set key, level[key] for key in Campaign.denormalizedLevelProperties model.set key, level[key] for key in Campaign.denormalizedLevelProperties
@toSave.add model if model.hasLocalChanges() @toSave.add model if model.hasLocalChanges()
@ -201,18 +202,19 @@ module.exports = class CampaignEditorView extends RootView
@insertSubView @campaignView @insertSubView @campaignView
onTreemaChanged: (e, nodes) => onTreemaChanged: (e, nodes) =>
for node in nodes unless /test/.test @campaign.get('slug') # Don't overwrite level stuff for testing Campaigns
path = node.getPath() for node in nodes
if _.string.startsWith path, '/levels/' path = node.getPath()
parts = path.split('/') if _.string.startsWith path, '/levels/'
original = parts[2] parts = path.split('/')
level = @supermodel.getModelByOriginal Level, original original = parts[2]
campaignLevel = @treema.get "/levels/#{original}" level = @supermodel.getModelByOriginal Level, original
campaignLevel = @treema.get "/levels/#{original}"
@updateRewardsForLevel level, campaignLevel.rewards @updateRewardsForLevel level, campaignLevel.rewards
level.set key, campaignLevel[key] for key in Campaign.denormalizedLevelProperties level.set key, campaignLevel[key] for key in Campaign.denormalizedLevelProperties
@toSave.add level if level.hasLocalChanges() @toSave.add level if level.hasLocalChanges()
@toSave.add @campaign @toSave.add @campaign
@campaign.set key, value for key, value of @treema.data @campaign.set key, value for key, value of @treema.data
@ -329,6 +331,7 @@ class LevelNode extends TreemaObjectNode
populateData: -> populateData: ->
return if @data.name? return if @data.name?
data = _.pick LevelsNode.levels[@keyForParent].attributes, Campaign.denormalizedLevelProperties data = _.pick LevelsNode.levels[@keyForParent].attributes, Campaign.denormalizedLevelProperties
console.log 'got the data', data
_.extend @data, data _.extend @data, data
class CampaignsNode extends TreemaObjectNode class CampaignsNode extends TreemaObjectNode

View file

@ -184,7 +184,6 @@ module.exports = class CampaignView extends RootView
context.levelDifficultyMap = @levelDifficultyMap context.levelDifficultyMap = @levelDifficultyMap
context.levelPlayCountMap = @levelPlayCountMap context.levelPlayCountMap = @levelPlayCountMap
context.isIPadApp = application.isIPadApp context.isIPadApp = application.isIPadApp
context.mapType = _.string.slugify @terrain
context.requiresSubscription = @requiresSubscription context.requiresSubscription = @requiresSubscription
context.editorMode = @editorMode context.editorMode = @editorMode
context.adjacentCampaigns = _.filter _.values(_.cloneDeep(@campaign?.get('adjacentCampaigns') or {})), (ac) => context.adjacentCampaigns = _.filter _.values(_.cloneDeep(@campaign?.get('adjacentCampaigns') or {})), (ac) =>
@ -378,7 +377,7 @@ module.exports = class CampaignView extends RootView
@particleMan.removeEmitters() @particleMan.removeEmitters()
@particleMan.attach @$el.find('.map') @particleMan.attach @$el.find('.map')
for level in @campaign.renderedLevels ? {} for level in @campaign.renderedLevels ? {}
particleKey = ['level', @terrain] particleKey = ['level', @terrain.replace('-branching-test', '')]
particleKey.push level.type if level.type and not (level.type in ['hero', 'course']) particleKey.push level.type if level.type and not (level.type in ['hero', 'course'])
particleKey.push 'replayable' if level.replayable particleKey.push 'replayable' if level.replayable
particleKey.push 'premium' if level.requiresSubscription particleKey.push 'premium' if level.requiresSubscription

View file

@ -0,0 +1,65 @@
// Grab course instance data for Courses v1 Beta
// Usage:
// mongo <address>:<port>/<database> <script file> -u <username> -p <password>
// TODO: order by average levels completed
function objectIdWithTimestamp(timestamp)
{
// Convert string date to Date object (otherwise assume timestamp is a date)
if (typeof(timestamp) == 'string') timestamp = new Date(timestamp);
// Convert date object to hex seconds since Unix epoch
var hexSeconds = Math.floor(timestamp/1000).toString(16);
// Create an ObjectId with that hex timestamp
var constructedObjectId = ObjectId(hexSeconds + "0000000000000000");
return constructedObjectId
}
var betaStartDate = new ISODate('2015-10-08');
var minMembers = 9;
var classes = [];
var ownerIDs = [];
var cursor = db['course.instances'].find({$and: [
{_id: {$gte: objectIdWithTimestamp(betaStartDate)}},
{$where: 'this.members.length > ' + minMembers}
]}).sort({_id: 1});
while (cursor.hasNext()) {
var doc = cursor.next();
var ownerID = doc.ownerID;
ownerIDs.push(ownerID);
if (!classes[ownerID.valueOf()]) classes[ownerID.valueOf()] = [];
classes.push({
courseID: doc.courseID,
courseInstanceID: doc._id,
url: 'codecombat.com/courses/' + doc.courseID.valueOf() + '/' + doc._id.valueOf(),
ownerID: doc.ownerID,
createDate: ownerID.getTimestamp(),
memberCount: doc.members.length,
name: doc.name
});
}
var userMap = {};
cursor = db.users.find({_id: {$in: ownerIDs}});
while (cursor.hasNext()) {
var doc = cursor.next();
if (!userMap[doc._id.valueOf()]) userMap[doc._id.valueOf()] = {};
userMap[doc._id.valueOf()].emailLower = doc.emailLower;
userMap[doc._id.valueOf()].name = doc.name;
}
for (var i = 0; i < classes.length; i++) {
classes[i].email = userMap[classes[i].ownerID.valueOf()].emailLower;
}
classes.sort(function(a, b) {
return b.memberCount - a.memberCount;
});
for (var i = 0; i < classes.length; i++) {
print(classes[i].url + '\t' + classes[i].memberCount + '\t' + classes[i].email + '\t' + classes[i].name);
}
print(classes.length + ' course instances with over ' + minMembers + ' members');