From 3d71fcbc708bee9fd0d62530ab491f79f865307e Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Sun, 9 Mar 2014 18:46:11 -0700 Subject: [PATCH] Wins, losses, and realizing that I'm not doing server code right. --- app/templates/play/ladder/my_matches_tab.jade | 6 +----- app/views/play/ladder/my_matches_tab.coffee | 3 +++ server/routes/mail.coffee | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/templates/play/ladder/my_matches_tab.jade b/app/templates/play/ladder/my_matches_tab.jade index d2b543478..c70192221 100644 --- a/app/templates/play/ladder/my_matches_tab.jade +++ b/app/templates/play/ladder/my_matches_tab.jade @@ -11,11 +11,7 @@ div#columns.row tr th(colspan=4, style="color: #{team.primaryColor}") - span Your - span - span= team.name - span - span Matches + span Your #{team.name} Matches - #{team.wins} Wins, #{team.losses} Losses if team.session button.btn.btn-sm.btn-warning.pull-right.rank-button(data-session-id=team.session.id) diff --git a/app/views/play/ladder/my_matches_tab.coffee b/app/views/play/ladder/my_matches_tab.coffee index 998b63bfa..a5e679f1b 100644 --- a/app/views/play/ladder/my_matches_tab.coffee +++ b/app/views/play/ladder/my_matches_tab.coffee @@ -73,6 +73,9 @@ module.exports = class MyMatchesTabView extends CocoView team.matches = (convertMatch(match) for match in team.session?.get('matches') or []) team.matches.reverse() team.score = (team.session?.get('totalScore') or 10).toFixed(2) + team.wins = _.filter(team.matches, {state: 'win'}).length + team.ties = _.filter(team.matches, {state: 'tie'}).length + team.losses = _.filter(team.matches, {state: 'loss'}).length ctx diff --git a/server/routes/mail.coffee b/server/routes/mail.coffee index ed6b58795..d629883d7 100644 --- a/server/routes/mail.coffee +++ b/server/routes/mail.coffee @@ -5,6 +5,7 @@ errors = require '../commons/errors' #request = require 'request' config = require '../../server_config' LevelSession = require '../levels/sessions/LevelSession.coffee' +Level = require '../levels/Level.coffee' log = require 'winston' sendwithus = require '../sendwithus' @@ -16,9 +17,23 @@ module.exports.setup = (app) -> app.all config.mail.mailchimpWebhook, handleMailchimpWebHook app.get '/mail/cron/ladder-update', handleLadderUpdate +getAllLadderScores = (next) -> + query = Level.find({type: 'ladder'}) + .select('levelID') + .lean() + query.exec (err, levels) -> + if err + log.error "Couldn't fetch ladder levels. Error: ", err + return next [] + for level in levels + for team in ['humans', 'ogres'] + 'I ... am not doing this.' + handleLadderUpdate = (req, res) -> + log.info("Going to see about sending ladder update emails.") res.send('Great work, Captain Cron! I can take it from here.') res.end() + # TODO: somehow fetch the histograms emailDays = [1, 2, 4, 7, 30] now = new Date() getTimeFromDaysAgo = (daysAgo) -> @@ -35,7 +50,6 @@ handleLadderUpdate = (req, res) -> query = LevelSession.find(findParameters) .select(selectString) .lean() - mongoose = require 'mongoose' do (daysAgo) -> query.exec (err, results) -> if err