made parallel 'points' infrastructure

This commit is contained in:
Michael Q Larson
2014-12-05 20:44:42 -08:00
parent 07ba7e4fcb
commit 177dc900cf
7 changed files with 110 additions and 267 deletions

21
app.js
View File

@ -163,21 +163,18 @@ app.get('/account/unlink/:provider', userController.getOauthUnlink);
/** /**
* API examples routes. * API examples routes.
* accepts a post request. the challenge id req.body.challengeNumber
* and updates user.challengesHash & user.challengesCompleted
*
*/ */
app.post('/completed_challenge', function(req, res) { app.post('/completed_challenge', function(req, res) {
req.user.challengesHash[parseInt(req.body.cn)] = Math.round(+new Date() / 1000); req.user.challengesHash[parseInt(req.body.challengeNumber)] = Math.round(+new Date() / 1000);
req.user.challengesCompleted = function() { var ch = req.user.challengesHash;
var completed = []; var p = 0;
var h = req.user.challengesHash; for (k in ch) {
for (i = 0; i < h.length; i++) { if (ch[k] > 0) { p += 1}
console.log(h[i] > 0)
if (h[i] > 0) {
console.log(h[i]);
completed.push(i);
}
return completed;
}
} }
req.user.points = p;
req.user.save(); req.user.save();
}); });

View File

@ -19,8 +19,7 @@ exports.returnChallenge = function(req, res, next) {
video: c.video, video: c.video,
time: c.time, time: c.time,
steps: c.steps, steps: c.steps,
cc: req.user.challengesCompleted, cc: req.user.challengesHash
ch: req.user.challengesHash
}); });
}); });
}; };

View File

@ -14,208 +14,59 @@ var userSchema = new mongoose.Schema({
instagram: String, instagram: String,
linkedin: String, linkedin: String,
tokens: Array, tokens: Array,
points: { type: Number, default: 0 },
challengesCompleted: { type: Array, default: [] }, challengesCompleted: { type: Array, default: [] },
challengesHash: { challengesHash: {
0: { 0: { type: Number, default: 0 },
type: Number, 1: { type: Number, default: 0 },
default: 0, 2: { type: Number, default: 0 },
}, 3: { type: Number, default: 0 },
1: { 4: { type: Number, default: 0 },
type: Number, 5: { type: Number, default: 0 },
default: 0, 6: { type: Number, default: 0 },
}, 7: { type: Number, default: 0 },
2: { 8: { type: Number, default: 0 },
type: Number, 9: { type: Number, default: 0 },
default: 0, 10: { type: Number, default: 0 },
}, 11: { type: Number, default: 0 },
3: { 12: { type: Number, default: 0 },
type: Number, 13: { type: Number, default: 0 },
default: 0, 14: { type: Number, default: 0 },
}, 15: { type: Number, default: 0 },
4: { 16: { type: Number, default: 0 },
type: Number, 17: { type: Number, default: 0 },
default: 0, 18: { type: Number, default: 0 },
}, 19: { type: Number, default: 0 },
5: { 20: { type: Number, default: 0 },
type: Number, 21: { type: Number, default: 0 },
default: 0, 22: { type: Number, default: 0 },
}, 23: { type: Number, default: 0 },
6: { 24: { type: Number, default: 0 },
type: Number, 25: { type: Number, default: 0 },
default: 0, 26: { type: Number, default: 0 },
}, 27: { type: Number, default: 0 },
7: { 28: { type: Number, default: 0 },
type: Number, 29: { type: Number, default: 0 },
default: 0, 30: { type: Number, default: 0 },
}, 31: { type: Number, default: 0 },
8: { 32: { type: Number, default: 0 },
type: Number, 33: { type: Number, default: 0 },
default: 0, 34: { type: Number, default: 0 },
}, 35: { type: Number, default: 0 },
9: { 36: { type: Number, default: 0 },
type: Number, 37: { type: Number, default: 0 },
default: 0, 38: { type: Number, default: 0 },
}, 39: { type: Number, default: 0 },
10: { 40: { type: Number, default: 0 },
type: Number, 41: { type: Number, default: 0 },
default: 0, 42: { type: Number, default: 0 },
}, 43: { type: Number, default: 0 },
11: { 44: { type: Number, default: 0 },
type: Number, 45: { type: Number, default: 0 },
default: 0, 46: { type: Number, default: 0 },
}, 47: { type: Number, default: 0 },
12: { 48: { type: Number, default: 0 },
type: Number, 49: { type: Number, default: 0 }
default: 0,
},
13: {
type: Number,
default: 0,
},
14: {
type: Number,
default: 0,
},
15: {
type: Number,
default: 0,
},
16: {
type: Number,
default: 0,
},
17: {
type: Number,
default: 0,
},
18: {
type: Number,
default: 0,
},
19: {
type: Number,
default: 0,
},
20: {
type: Number,
default: 0,
},
21: {
type: Number,
default: 0,
},
22: {
type: Number,
default: 0,
},
23: {
type: Number,
default: 0,
},
24: {
type: Number,
default: 0,
},
25: {
type: Number,
default: 0,
},
26: {
type: Number,
default: 0,
},
27: {
type: Number,
default: 0,
},
28: {
type: Number,
default: 0,
},
29: {
type: Number,
default: 0,
},
30: {
type: Number,
default: 0,
},
31: {
type: Number,
default: 0,
},
32: {
type: Number,
default: 0,
},
33: {
type: Number,
default: 0,
},
34: {
type: Number,
default: 0,
},
35: {
type: Number,
default: 0,
},
36: {
type: Number,
default: 0,
},
37: {
type: Number,
default: 0,
},
38: {
type: Number,
default: 0,
},
39: {
type: Number,
default: 0,
},
40: {
type: Number,
default: 0,
},
41: {
type: Number,
default: 0,
},
42: {
type: Number,
default: 0,
},
43: {
type: Number,
default: 0,
},
44: {
type: Number,
default: 0,
},
45: {
type: Number,
default: 0,
},
46: {
type: Number,
default: 0,
},
47: {
type: Number,
default: 0,
},
48: {
type: Number,
default: 0,
},
49: {
type: Number,
default: 0,
}
}, },
profile: { profile: {
name: { type: String, default: '' }, name: { type: String, default: '' },

View File

@ -20,14 +20,11 @@ $(document).ready(function() {
$('#complete-dialog').modal('show'); $('#complete-dialog').modal('show');
l = location.pathname.split('/'); l = location.pathname.split('/');
cn = l[l.length - 1] cn = l[l.length - 1]
console.log(cn);
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
data: {cn: cn}, data: {challengeNumber: cn},
url: '/completed_challenge/', url: '/completed_challenge/'
success: function(data) {
console.log('success');
console.log(JSON.stringify(data));
}
}); });
}); });

View File

@ -35,8 +35,7 @@ block content
h1 Completed Challenges h1 Completed Challenges
ul ul
//each val, index in user.challengesHash
//li= index + ': ' + val
h3 Danger Zone h3 Danger Zone
button.btn.btn-danger.confirm-deletion button.btn.btn-danger.confirm-deletion
span.ion-trash-b span.ion-trash-b

View File

@ -4,133 +4,133 @@
ol(start='0') ol(start='0')
h4 Web Design h4 Web Design
li li
a(href="/challenges/0", class="#{ cc.indexOf(0) > -1 ? 'strikethrough' : '' }") A One-minute Introduction to Free Code Camp a(href="/challenges/0", class="#{ cc[0] > 0 ? 'strikethrough' : '' }") A One-minute Introduction to Free Code Camp
| &nbsp; (1 min) | &nbsp; (1 min)
li li
a(href="/challenges/1", class="#{ cc.indexOf(1) > -1 ? 'strikethrough' : '' }") Enter the Free Code Camp Chat Room a(href="/challenges/1", class="#{ cc[1] > 0 ? 'strikethrough' : '' }") Enter the Free Code Camp Chat Room
| &nbsp; (10 mins) | &nbsp; (10 mins)
li li
a(href="/challenges/2", class="#{ cc.indexOf(2) > -1 ? 'strikethrough' : '' }") Create a Website and Deploy it to the Internet a(href="/challenges/2", class="#{ cc[2] > 0 ? 'strikethrough' : '' }") Create a Website and Deploy it to the Internet
| &nbsp; (5 mins) | &nbsp; (5 mins)
li li
a(href="/challenges/3", class="#{ cc.indexOf(3) > -1 ? 'strikethrough' : '' }") Install Github's Atom Text Editor a(href="/challenges/3", class="#{ cc[3] > 0 ? 'strikethrough' : '' }") Install Github's Atom Text Editor
| &nbsp; (5 mins) | &nbsp; (5 mins)
li li
a(href="/challenges/4", class="#{ cc.indexOf(4) > -1 ? 'strikethrough' : '' }") Modify and Redeploy Your Website a(href="/challenges/4", class="#{ cc[4] > 0 ? 'strikethrough' : '' }") Modify and Redeploy Your Website
| &nbsp; (5 mins) | &nbsp; (5 mins)
li li
a(href="/challenges/5", class="#{ cc.indexOf(5) > -1 ? 'strikethrough' : '' }") Add Dynamic Content to your Website a(href="/challenges/5", class="#{ cc[5] > 0 ? 'strikethrough' : '' }") Add Dynamic Content to your Website
| &nbsp; (10 mins) | &nbsp; (10 mins)
li li
a(href="/challenges/6", class="#{ cc.indexOf(6) > -1 ? 'strikethrough' : '' }") Codecademy's HTML & CSS track a(href="/challenges/6", class="#{ cc[6] > 0 ? 'strikethrough' : '' }") Codecademy's HTML & CSS track
| &nbsp; (7 hrs) | &nbsp; (7 hrs)
li li
a(href="/challenges/7", class="#{ cc.indexOf(7) > -1 ? 'strikethrough' : '' }") Experiment with HTML and CSS in CodePen a(href="/challenges/7", class="#{ cc[7] > 0 ? 'strikethrough' : '' }") Experiment with HTML and CSS in CodePen
| &nbsp; (10 mins) | &nbsp; (10 mins)
li li
a(href="/challenges/8", class="#{ cc.indexOf(8) > -1 ? 'strikethrough' : '' }") Codecademy's jQuery track a(href="/challenges/8", class="#{ cc[8] > 0 ? 'strikethrough' : '' }") Codecademy's jQuery track
| &nbsp; (3 hrs) | &nbsp; (3 hrs)
li li
a(href="/challenges/9", class="#{ cc.indexOf(9) > -1 ? 'strikethrough' : '' }") Code School's Try jQuery a(href="/challenges/9", class="#{ cc[9] > 0 ? 'strikethrough' : '' }") Code School's Try jQuery
| &nbsp; (4 hrs) | &nbsp; (4 hrs)
li li
a(href="/challenges/10", class="#{ cc.indexOf(10) > -1 ? 'strikethrough' : '' }") Code School's Discover DevTools a(href="/challenges/10", class="#{ cc[10] > 0 ? 'strikethrough' : '' }") Code School's Discover DevTools
| &nbsp; (2 hrs) | &nbsp; (2 hrs)
li li
a(href="/challenges/11", class="#{ cc.indexOf(11) > -1 ? 'strikethrough' : '' }") jQuery Exercises a(href="/challenges/11", class="#{ cc[11] > 0 ? 'strikethrough' : '' }") jQuery Exercises
| &nbsp; (1 hr) | &nbsp; (1 hr)
li li
a(href="/challenges/12", class="#{ cc.indexOf(12) > -1 ? 'strikethrough' : '' }") Customize Bootstrap with Bootswatch a(href="/challenges/12", class="#{ cc[12] > 0 ? 'strikethrough' : '' }") Customize Bootstrap with Bootswatch
| &nbsp; (10 mins) | &nbsp; (10 mins)
li li
a(href="/challenges/13", class="#{ cc.indexOf(13) > -1 ? 'strikethrough' : '' }") Inject Life with CSS Transformations a(href="/challenges/13", class="#{ cc[13] > 0 ? 'strikethrough' : '' }") Inject Life with CSS Transformations
| &nbsp; (15 mins) | &nbsp; (15 mins)
h4 Computer Science and JavaScript h4 Computer Science and JavaScript
li li
a(href="/challenges/14", class="#{ cc.indexOf(14) > -1 ? 'strikethrough' : '' }") Codecademy's JavaScript track a(href="/challenges/14", class="#{ cc[14] > 0 ? 'strikethrough' : '' }") Codecademy's JavaScript track
| &nbsp; (10 hrs) | &nbsp; (10 hrs)
li li
a(href="/challenges/15", class="#{ cc.indexOf(15) > -1 ? 'strikethrough' : '' }") Stanford's Introduction to Computer Science a(href="/challenges/15", class="#{ cc[15] > 0 ? 'strikethrough' : '' }") Stanford's Introduction to Computer Science
| &nbsp; (24 hrs) | &nbsp; (24 hrs)
li li
a(href="/challenges/16", class="#{ cc.indexOf(16) > -1 ? 'strikethrough' : '' }") Get Help The Hacker Way with RSAP a(href="/challenges/16", class="#{ cc[16] > 0 ? 'strikethrough' : '' }") Get Help The Hacker Way with RSAP
| &nbsp; (30 mins) | &nbsp; (30 mins)
li li
a(href="/challenges/17", class="#{ cc.indexOf(17) > -1 ? 'strikethrough' : '' }") Learn Regular Expressions a(href="/challenges/17", class="#{ cc[17] > 0 ? 'strikethrough' : '' }") Learn Regular Expressions
| &nbsp; (1 hr) | &nbsp; (1 hr)
li li
a(href="/challenges/18", class="#{ cc.indexOf(18) > -1 ? 'strikethrough' : '' }") Start Your First Pair Programming Session a(href="/challenges/18", class="#{ cc[18] > 0 ? 'strikethrough' : '' }") Start Your First Pair Programming Session
| &nbsp; (30 mins | Pair) | &nbsp; (30 mins | Pair)
li li
a(href="/challenges/19", class="#{ cc.indexOf(19) > -1 ? 'strikethrough' : '' }") Easy Algorithm Scripting Challenges on Coderbyte a(href="/challenges/19", class="#{ cc[19] > 0 ? 'strikethrough' : '' }") Easy Algorithm Scripting Challenges on Coderbyte
| &nbsp; (15 hrs | Pair) | &nbsp; (15 hrs | Pair)
li li
a(href="/challenges/20", class="#{ cc.indexOf(20) > -1 ? 'strikethrough' : '' }") Stanford's Relational Databases Mini-course a(href="/challenges/20", class="#{ cc[20] > 0 ? 'strikethrough' : '' }") Stanford's Relational Databases Mini-course
| &nbsp; (1 hr) | &nbsp; (1 hr)
li li
a(href="/challenges/21", class="#{ cc.indexOf(21) > -1 ? 'strikethrough' : '' }") Stanford's SQL Mini-course a(href="/challenges/21", class="#{ cc[21] > 0 ? 'strikethrough' : '' }") Stanford's SQL Mini-course
| &nbsp; (4 hrs | Pair) | &nbsp; (4 hrs | Pair)
li li
a(href="/challenges/22", class="#{ cc.indexOf(22) > -1 ? 'strikethrough' : '' }") Stanford's JSON Mini-course a(href="/challenges/22", class="#{ cc[22] > 0 ? 'strikethrough' : '' }") Stanford's JSON Mini-course
| &nbsp; (1 hrs | Pair) | &nbsp; (1 hrs | Pair)
li li
a(href="/challenges/23", class="#{ cc.indexOf(23) > -1 ? 'strikethrough' : '' }") Medium Algorithm Scripting Challenges on Coderbyte a(href="/challenges/23", class="#{ cc[23] > 0 ? 'strikethrough' : '' }") Medium Algorithm Scripting Challenges on Coderbyte
| &nbsp; (15 hrs | Pair) | &nbsp; (15 hrs | Pair)
li li
a.disabled(href="/challenges/24", class="#{ cc.indexOf(24) > -1 ? 'strikethrough' : '' }") Build an Interview Question Machine a.disabled(href="/challenges/24", class="#{ cc[24] > 0 ? 'strikethrough' : '' }") Build an Interview Question Machine
| &nbsp; (5 hrs | Pair) | &nbsp; (5 hrs | Pair)
li li
a.disabled(href="/challenges/25", class="#{ cc.indexOf(25) > -1 ? 'strikethrough' : '' }") Build a Text-based Adventure a.disabled(href="/challenges/25", class="#{ cc[25] > 0 ? 'strikethrough' : '' }") Build a Text-based Adventure
| &nbsp; (5 hrs | Pair) | &nbsp; (5 hrs | Pair)
li li
a.disabled(href="/challenges/26", class="#{ cc.indexOf(26) > -1 ? 'strikethrough' : '' }") Hard Algorithm Scripting Challenges on Coderbyte a.disabled(href="/challenges/26", class="#{ cc[26] > 0 ? 'strikethrough' : '' }") Hard Algorithm Scripting Challenges on Coderbyte
| &nbsp; (15 hrs | Pair) | &nbsp; (15 hrs | Pair)
h4 Full Stack JavaScript Development h4 Full Stack JavaScript Development
li li
a.disabled(href="/challenges/27", class="#{ cc.indexOf(27) > -1 ? 'strikethrough' : '' }") Code School's Try Git a.disabled(href="/challenges/27", class="#{ cc[27] > 0 ? 'strikethrough' : '' }") Code School's Try Git
| &nbsp; (30 mins) | &nbsp; (30 mins)
li li
a.disabled(href="/challenges/28", class="#{ cc.indexOf(28) > -1 ? 'strikethrough' : '' }") Install Node.js a.disabled(href="/challenges/28", class="#{ cc[28] > 0 ? 'strikethrough' : '' }") Install Node.js
| &nbsp; (1 hr) | &nbsp; (1 hr)
li li
a.disabled(href="/challenges/29", class="#{ cc.indexOf(29) > -1 ? 'strikethrough' : '' }") Clone a Github Repo a.disabled(href="/challenges/29", class="#{ cc[29] > 0 ? 'strikethrough' : '' }") Clone a Github Repo
| &nbsp; (15 mins) | &nbsp; (15 mins)
li li
a.disabled(href="/challenges/30", class="#{ cc.indexOf(30) > -1 ? 'strikethrough' : '' }") Deploy an app to Heroku a.disabled(href="/challenges/30", class="#{ cc[30] > 0 ? 'strikethrough' : '' }") Deploy an app to Heroku
| &nbsp; (15 mins) | &nbsp; (15 mins)
li li
a.disabled(href="/challenges/31", class="#{ cc.indexOf(31) > -1 ? 'strikethrough' : '' }") Code School's Real-time web with Node.JS a.disabled(href="/challenges/31", class="#{ cc[31] > 0 ? 'strikethrough' : '' }") Code School's Real-time web with Node.JS
| &nbsp; (5 hrs) | &nbsp; (5 hrs)
li li
a.disabled(href="/challenges/32", class="#{ cc.indexOf(32) > -1 ? 'strikethrough' : '' }") Try MongoDB a.disabled(href="/challenges/32", class="#{ cc[32] > 0 ? 'strikethrough' : '' }") Try MongoDB
| &nbsp; (30 mins) | &nbsp; (30 mins)
li li
a.disabled(href="/challenges/33", class="#{ cc.indexOf(33) > -1 ? 'strikethrough' : '' }") Explore your Network with the LinkedIn API a.disabled(href="/challenges/33", class="#{ cc[33] > 0 ? 'strikethrough' : '' }") Explore your Network with the LinkedIn API
| &nbsp; (1 hr) | &nbsp; (1 hr)
li li
a.disabled(href="/challenges/34", class="#{ cc.indexOf(34) > -1 ? 'strikethrough' : '' }") Build your first API a.disabled(href="/challenges/34", class="#{ cc[34] > 0 ? 'strikethrough' : '' }") Build your first API
| &nbsp; (10 hrs | Pair) | &nbsp; (10 hrs | Pair)
li li
a.disabled(href="/challenges/35", class="#{ cc.indexOf(35) > -1 ? 'strikethrough' : '' }") Aggregate Data with Chron Jobs and Screen Scraping a.disabled(href="/challenges/35", class="#{ cc[35] > 0 ? 'strikethrough' : '' }") Aggregate Data with Chron Jobs and Screen Scraping
| &nbsp; (10 hrs | Pair) | &nbsp; (10 hrs | Pair)
li li
a.disabled(href="/challenges/36", class="#{ cc.indexOf(36) > -1 ? 'strikethrough' : '' }") Code School's Shaping up with Angular.JS a.disabled(href="/challenges/36", class="#{ cc[36] > 0 ? 'strikethrough' : '' }") Code School's Shaping up with Angular.JS
| &nbsp; (5 hrs) | &nbsp; (5 hrs)
li li
a.disabled(href="/challenges/37", class="#{ cc.indexOf(37) > -1 ? 'strikethrough' : '' }") Reverse Engineer SnapChat a.disabled(href="/challenges/37", class="#{ cc[37] > 0 ? 'strikethrough' : '' }") Reverse Engineer SnapChat
| &nbsp; (50 hrs | Pair) | &nbsp; (50 hrs | Pair)
li li
a.disabled(href="/challenges/38", class="#{ cc.indexOf(38) > -1 ? 'strikethrough' : '' }") Reverse Engineer Reddit a.disabled(href="/challenges/38", class="#{ cc[38] > 0 ? 'strikethrough' : '' }") Reverse Engineer Reddit
| &nbsp; (50 hrs | Pair) | &nbsp; (50 hrs | Pair)
li li
a.disabled(href="/challenges/39", class="#{ cc.indexOf(39) > -1 ? 'strikethrough' : '' }") Reverse Engineer Pintrest a.disabled(href="/challenges/39", class="#{ cc[39] > 0 ? 'strikethrough' : '' }") Reverse Engineer Pintrest
| &nbsp; (50 hrs | Pair) | &nbsp; (50 hrs | Pair)
li li
a.disabled(href="/challenges/40", class="#{ cc.indexOf(40) > -1 ? 'strikethrough' : '' }") Help a Nonprofit: Team Project a.disabled(href="/challenges/40", class="#{ cc[40] > 0 ? 'strikethrough' : '' }") Help a Nonprofit: Team Project
| &nbsp; (150 hrs | Pair) | &nbsp; (150 hrs | Pair)
li li
a.disabled(href="/challenges/41", class="#{ cc.indexOf(41) > -1 ? 'strikethrough' : '' }") Help a Nonprofit: Solo Project a.disabled(href="/challenges/41", class="#{ cc[41] > 0 ? 'strikethrough' : '' }") Help a Nonprofit: Solo Project
| &nbsp; (150 hrs | Pair) | &nbsp; (150 hrs | Pair)
li li
a.disabled(href="/challenges/42", class="#{ cc.indexOf(42) > -1 ? 'strikethrough' : '' }") Crack the Coding Interview a.disabled(href="/challenges/42", class="#{ cc[42] > 0 ? 'strikethrough' : '' }") Crack the Coding Interview
| &nbsp; (5 hrs) | &nbsp; (5 hrs)

View File

@ -20,7 +20,7 @@
img(src='#{user.profile.picture}') img(src='#{user.profile.picture}')
else else
img(src='#{user.gravatar(60)}') img(src='#{user.gravatar(60)}')
| #{user.profile.name || user.email || user.id}&nbsp;[&nbsp;#{user.challengesCompleted.length}&nbsp;]&nbsp; | #{user.profile.name || user.email || user.id}&nbsp;[&nbsp;#{user.points}&nbsp;]
i.caret i.caret
ul.dropdown-menu ul.dropdown-menu
li li