Skip to content

Instantly share code, notes, and snippets.

@teeler
Forked from kconragan/index.js
Created May 9, 2012 03:10

Revisions

  1. teeler revised this gist May 9, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion index.js
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,8 @@ exports.listLogs = function(req, res) {
    surfSessionsThisYear++;
    }
    // frothy
    surfSeshByLoc[i] = (surfSeshByLoc[i] || 0) + 1
    var l = log[i].location.name;
    surfSeshByLoc[l] = (surfSeshByLoc[l] || 0) + 1
    }
    res.render('list_sessions.html', {
    title: 'Latest Surf Sessions',
  2. teeler revised this gist May 9, 2012. 1 changed file with 3 additions and 8 deletions.
    11 changes: 3 additions & 8 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -25,13 +25,8 @@ exports.listLogs = function(req, res) {
    if(y === currentYear) {
    surfSessionsThisYear++;
    }
    for(var key in surfSeshByLoc) {
    if(surfSeshByLoc.hasOwnProperty(key)) {
    if(key === log[i].location.name) {
    surfSeshByLoc[key] = surfSeshByLoc[key] + 1;
    }
    }
    }
    // frothy
    surfSeshByLoc[i] = (surfSeshByLoc[i] || 0) + 1
    }
    res.render('list_sessions.html', {
    title: 'Latest Surf Sessions',
    @@ -45,4 +40,4 @@ exports.listLogs = function(req, res) {
    });
    });
    });
    };
    };
  3. @kconragan kconragan created this gist May 9, 2012.
    48 changes: 48 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    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++;
    }
    for(var key in surfSeshByLoc) {
    if(surfSeshByLoc.hasOwnProperty(key)) {
    if(key === log[i].location.name) {
    surfSeshByLoc[key] = surfSeshByLoc[key] + 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
    });
    });
    });
    };