-
-
Save teeler/2641502 to your computer and use it in GitHub Desktop.
list surf sessions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.listLogs = function(req, res) { | |
SurfSession.find() | |
.populate('location') | |
.run(function(err, log) { | |
Wave.find(function(err, waves) { | |
var surfHeight = SurfSession.schema.path('surfHeight').enumValues; | |
var surfConditions = SurfSession.schema.path('surfConditions').enumValues; | |
var surfStoke = new SurfSession().generateStoke(); | |
var currentYear = moment().year(); | |
var surfSessionsThisYear = 0; | |
var surfSeshByLoc = {}; | |
waves.forEach(function(w) { | |
var wave = { | |
"name": w.name, | |
"count": 0 | |
}; | |
surfSeshByLoc[w.name] = 0; | |
}); | |
// find number of sessions for current year | |
// and build map of sessions by wave | |
for(var i = 0; i < log.length; i++) { | |
var y = moment(log[i].timestamp).year(); | |
if(y === currentYear) { | |
surfSessionsThisYear++; | |
} | |
// frothy | |
var l = log[i].location.name; | |
surfSeshByLoc[l] = (surfSeshByLoc[l] || 0) + 1 | |
} | |
res.render('list_sessions.html', { | |
title: 'Latest Surf Sessions', | |
log: log, | |
waves: waves, | |
surfSessionsThisYear: surfSessionsThisYear, | |
allSurfSessions: log.length, | |
surfHeight: surfHeight, | |
surfConditions: surfConditions, | |
surfStoke: surfStoke | |
}); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment