Skip to content

Commit

Permalink
Support for setting tournament scores and reflecting in solutions table.
Browse files Browse the repository at this point in the history
  • Loading branch information
nwinter committed Mar 6, 2018
1 parent eb4de5b commit 147754f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion server/middleware/cron.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,15 @@ module.exports =
changed: {$gte: sessionStartDate}
'state.complete': true
isForClassroom: true
sessionSelect = 'changed creator creatorName created browser level levelID dateFirstCompleted team state.complete state.difficulty code totalScore browser isForClassroom'
tournamentScore: {$exists: false}
sessionSelect = 'changed creator creatorName created browser level levelID dateFirstCompleted team state.complete state.difficulty code totalScore browser isForClassroom tournamentScore'
recentSessions = yield LevelSession.find(sessionQuery).select(sessionSelect).limit(limit).lean().sort('changed')

# Then, add any that have a tournament score, so that we make sure we always have those up-to-date
tournamentSessionsQuery = tournamentScore: {$exists: true}
tournamentSessions = yield LevelSession.find(tournamentSessionsQuery).select(sessionSelect).limit(limit).lean().sort('changed')
recentSessions = recentSessions.concat tournamentSessions

console.log 'found', recentSessions.length, 'sessions'

lastRegistrations = yield IsraelRegistration.find({}).select('date').lean().sort('-date').limit(1)
Expand Down Expand Up @@ -210,6 +216,9 @@ module.exports =
score = 0
if session.totalScore and challengeCategory is 'tournament'
score = Math.round(Math.max 1, session.totalScore - 5) # They may cap this at 30 or 40 points. A really good score on a crowded arena might be 60-110. totalScore starts around 20, so they get positive points for improving on that. [except it apparently makes most people negative, Simple CPU sometimes, so we need to subtract less.]
if session.levelID in ['the-battle-of-sky-span'] and session.tournamentScore
challengeCategory = 'final'
score = session.tournamentScore
device = if session.browser then session.browser.name + (if not session.browser.desktop then ' mobile' else '') else null
solutions.push
# New data
Expand Down
1 change: 1 addition & 0 deletions server/middleware/levels.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ module.exports =
attrs.isForClassroom = true
else
console.log "Denying tournament finalist #{req.user.get('israelId') or req.user.id} to play #{level.get('slug')}--not in our #{_.size(israelIdsToFinalists)} finalists list"
throw new errors.PaymentRequired('You do not have access to this live tournament level.')
else if level.get('type') in ['course', 'course-ladder'] or req.query.course?

# Find the course and classroom that has assigned this level, verify access
Expand Down

0 comments on commit 147754f

Please sign in to comment.