Added simple rank history graph. Improving ladder update mail.

This commit is contained in:
Nick Winter 2014-03-10 20:22:25 -07:00
parent 93028483b9
commit 6ce65488aa
5 changed files with 24 additions and 5 deletions
app
server

View file

@ -21,6 +21,10 @@ div#columns.row
span.ranked.hidden Submitted for Ranking
span.failed.hidden Failed to Rank
tr
th(colspan=4, style="color: #{team.primaryColor}")
img(src="https://chart.googleapis.com/chart?chs=450x125&cht=lxy&chco=#{team.chartColor}&chtt=Score+History&chts=#{team.chartColor},16,c&chf=a,s,000000FF&chls=2&chm=o,#{team.chartColor},0,4&chd=t:#{team.chartData}")
tr
th Result
th Opponent

View file

@ -76,6 +76,15 @@ module.exports = class MyMatchesTabView extends CocoView
team.wins = _.filter(team.matches, {state: 'win'}).length
team.ties = _.filter(team.matches, {state: 'tie'}).length
team.losses = _.filter(team.matches, {state: 'loss'}).length
team.scoreHistory = team.session.get('scoreHistory')
team.chartColor = team.primaryColor.replace '#', ''
times = (s[0] for s in team.scoreHistory)
times = (100 * (t - times[0]) / (times[times.length - 1] - times[0]) for t in times)
scores = (s[1] for s in team.scoreHistory)
lowest = _.min scores
highest = _.max scores
scores = (100 * (s - lowest) / highest for s in scores)
team.chartData = times.join(',') + '|' + scores.join(',')
ctx

View file

@ -65,7 +65,7 @@ module.exports = class LadderView extends RootView
return if @startsLoading
@insertSubView(@ladderTab = new LadderTabView({}, @level, @sessions))
@insertSubView(@myMatchesTab = new MyMatchesTabView({}, @level, @sessions))
@refreshInterval = setInterval(@fetchSessionsAndRefreshViews.bind(@), 10000)
@refreshInterval = setInterval(@fetchSessionsAndRefreshViews.bind(@), 10 * 1000)
hash = document.location.hash[1..] if document.location.hash
if hash and not (hash in ['my-matches', 'simulate', 'ladder'])
@showPlayModal(hash) if @sessions.loaded

View file

@ -123,7 +123,9 @@ module.exports = class Handler
# Keeping it simple for now and just allowing access to the first FETCH_LIMIT results.
query = {'original': mongoose.Types.ObjectId(id)}
sort = {'created': -1}
@modelClass.find(query).limit(FETCH_LIMIT).sort(sort).exec (err, results) =>
selectString = 'slug name version commitMessage created' # Is this even working?
@modelClass.find(query).select(selectString).lean().limit(FETCH_LIMIT).sort(sort).exec (err, results) =>
return @sendDatabaseError(res, err) if err
for doc in results
return @sendUnauthorizedError(res) unless @hasAccessToDocument(req, doc)
res.send(results)

View file

@ -42,8 +42,8 @@ handleLadderUpdate = (req, res) ->
for daysAgo in emailDays
# Get every session that was submitted in a 5-minute window after the time.
startTime = getTimeFromDaysAgo daysAgo
#endTime = startTime + 5 * 60 * 1000
endTime = startTime + 1 * 60 * 60 * 1000 # Debugging: make sure there's something to send
endTime = startTime + 5 * 60 * 1000
#endTime = startTime + 1.5 * 60 * 60 * 1000 # Debugging: make sure there's something to send
findParameters = {submitted: true, submitDate: {$gt: new Date(startTime), $lte: new Date(endTime)}}
# TODO: think about putting screenshots in the email
selectString = "creator team levelName levelID totalScore matches submitted submitDate numberOfWinsAndTies numberOfLosses"
@ -63,9 +63,12 @@ sendLadderUpdateEmail = (session, daysAgo) ->
if err
log.error "Couldn't find user for #{session.creator} from session #{session._id}"
return
if not user.email or not ('notification' in user.emailSubscriptions)
unless user.email and ('notification' in user.emailSubscriptions)
log.info "Not sending email to #{user.email} #{user.name} because they only want emails about #{user.emailSubscriptions}"
return
unless session.levelName
log.info "Not sending email to #{user.email} #{user.name} because the session had no levelName in it."
return
name = if user.firstName and user.lastName then "#{user.firstName} #{user.lastName}" else user.name
name = "Wizard" if not name or name is "Anoner"
@ -84,6 +87,7 @@ sendLadderUpdateEmail = (session, daysAgo) ->
losses: session.numberOfLosses
total_score: Math.round(session.totalScore * 100)
team: session.team
team_name: session.team[0].toUpperCase() + session.team.substr(1)
level_name: session.levelName
ladder_url: "http://codecombat.com/play/ladder/#{session.levelID}#my-matches"
defeat: defeatContext