Skip to content

Commit

Permalink
#34 point calculation is now less complex
Browse files Browse the repository at this point in the history
  • Loading branch information
lazygalaxy committed Apr 30, 2016
1 parent a259eb8 commit 6badb91
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 333 deletions.
2 changes: 1 addition & 1 deletion .meteor/release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[email protected].1
[email protected].2.4
162 changes: 81 additions & 81 deletions .meteor/versions
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
[email protected].5
[email protected].7
[email protected].3
[email protected].7
[email protected].1
[email protected].7
[email protected].7
[email protected].7
[email protected].6
[email protected].3
[email protected].7
[email protected].7
[email protected].3
[email protected].5
[email protected].7
check@1.1.3
[email protected].7
[email protected].8
[email protected].4
[email protected].9
[email protected].4
[email protected].8
[email protected].8
[email protected].8
[email protected].7
[email protected].4
[email protected].8
[email protected].8
[email protected].4
[email protected].6
[email protected].8
check@1.2.1
chrismbeckett:[email protected]_1
[email protected].16
[email protected].4
[email protected].4
[email protected].4
[email protected].3
[email protected].5
[email protected].11
[email protected].4
[email protected].2
[email protected].9
[email protected].10
[email protected].11
[email protected].17
[email protected].5
[email protected].7
[email protected].5
[email protected].4
[email protected].6
[email protected].12
[email protected].5
[email protected].3
[email protected].10
[email protected].11
[email protected].12
ephemer:[email protected]
[email protected].9
[email protected].10
[email protected].10
[email protected].11
fortawesome:[email protected]
[email protected].7
[email protected].3
[email protected].8
[email protected].8
[email protected].4
[email protected].6
[email protected].8
[email protected].4
[email protected].9
[email protected].9
[email protected].5
[email protected].7
idorecall:[email protected]
iron:[email protected]
iron:[email protected]
Expand All @@ -49,53 +49,53 @@ iron:[email protected]
jparker:[email protected]
jparker:[email protected]
jparker:[email protected]
[email protected].7
[email protected].10
[email protected].17
[email protected].8
[email protected].11
[email protected].13
[email protected].3
[email protected].10
[email protected].10
[email protected].13
[email protected].3
[email protected].11
modules@0.5.2
[email protected].2
momentjs:moment@2.12.0
[email protected].6
[email protected].3
[email protected].8
[email protected].11
[email protected].18
[email protected].9
[email protected].12
[email protected].14
[email protected].4
[email protected].11
[email protected].11
[email protected].16
[email protected].4
[email protected].12
modules@0.6.1
[email protected].3
momentjs:moment@2.13.1
[email protected].7
[email protected].4
nimble:[email protected]
npm-bcrypt@0.7.8_2
[email protected].42
[email protected].10
[email protected].6
[email protected].6
npm-bcrypt@0.8.5
[email protected].43
[email protected].11
[email protected].7
[email protected].7
rajit:[email protected]
[email protected].8
[email protected].3
[email protected].6
[email protected].8
[email protected].7
[email protected].6
[email protected].9
[email protected].8
[email protected].4
[email protected].6
[email protected].9
[email protected].4
[email protected].7
[email protected].9
[email protected].8
[email protected].7
[email protected].10
[email protected].9
[email protected].5
[email protected].7
simple:[email protected]
[email protected].10
[email protected].10
[email protected].7
[email protected].5
[email protected].5
[email protected].8
[email protected].3
[email protected].12
[email protected].11
[email protected].11
[email protected].8
[email protected].6
[email protected].6
[email protected].9
[email protected].4
[email protected].13
twbs:[email protected]
[email protected].10
[email protected].7
[email protected].8
[email protected].7
[email protected].8
[email protected].11
[email protected].8
[email protected].9
[email protected].8
[email protected].9
zenorocha:[email protected]
16 changes: 8 additions & 8 deletions client/layout/message.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template name="message">
{{#if gtLength0 getUnverifiedEmails}}
<div class="container text-center">
<div class="alert alert-warning" role="alert">
<p><strong>Warning!</strong> Please do not forget to verify {{getUnverifiedEmails}} by clicking on the verification link we emailed to you.</p> Click on this button if you would like another verification link:
<button class="btn btn-success email-verify-button"><i class="fa fa-check"></i>&nbsp;Send Verification Link</button>
</div>
</div>
{{/if}}
{{#if gtLength0 getUnverifiedEmails}}
<div class="container text-center">
<div class="alert alert-warning" role="alert">
<p><strong>Warning!</strong> Please do not forget to verify {{getUnverifiedEmails}} by clicking on the verification link we emailed you.</p> Click on this button if you would like another verification link:
<button class="btn btn-success email-verify-button"><i class="fa fa-check"></i>&nbsp;Send Verification Link</button>
</div>
</div>
{{/if}}
</template>
2 changes: 1 addition & 1 deletion client/pages/points.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</table>
{{> matchRules}} {{else}} {{#with getSelectedCompetition}}
<h2>{{label}} starts on the {{prettyDate startDate}}.</h2>
<p>Please come back when the competition starts to view user predictions and points.</p>
<p>This user has not made any predictions yet.</p>
{{/with}} {{/if}}
</div>
</template>
Expand Down
4 changes: 2 additions & 2 deletions client/pages/rankings.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ <h4 class="modal-title">Ranking Rules</h4>
<tr>
<td>{{rank}}</td>
<td><img alt="image" class="img-circle" src="{{avatar}}" style="height:40px;" />&nbsp;{{username}}</td>
<td>{{prettyDate date}}</td>
<td>{{prettyDate lastPredictionDate}}</td>
{{#if isSelectedPaid}}
<td>Yes ({{paidDate}})</td>
{{/if}}
<td class="user-selection"><a id="{{_id}}" href="{{pathFor route='points'}}">{{points}}</a></td>
<td class="user-selection"><a id="{{id}}" href="{{pathFor route='points'}}">{{points}}</a></td>
</tr>
</template>

Expand Down
105 changes: 0 additions & 105 deletions client/pages/rankings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,111 +5,6 @@ Template.rankings.helpers({
var isPaid = isSelectedPaid();

return calculateRankings(group._id, competition._id, isPaid);


// var competition = Session.get('selectedCompetition');
// var group = Session.get('selectedGroup');
// var isPaid = isSelectedPaid();
// var nowDate = new Date();
//
// var predictionMap = Predictions.find({
// competitionId: competition._id
// }).fetch().reduce(function (map, obj) {
// if (!map[obj.userId]) {
// map[obj.userId] = {}
// }
// map[obj.userId][obj._id] = obj;
// return map;
// }, {});
//
// var resultMap = Results.find({
// competitionId: competition._id
// }).fetch().reduce(function (map, obj) {
// //TODO: consider the highest weighted here if multiple exists
// map[obj.itemId] = obj;
// return map;
// }, {});
//
// var users = [];
// Object.keys(predictionMap).forEach(function (userId) {
// var user = CustomUsers.findOne({
// _id: userId
// });
// var hasUserPaid = user[getPaidAttribute()];
// if (!isPaid || (user.emails[0].verified && hasUserPaid)) {
// //if the user belongs to the selected group
// if (user.groups.indexOf(group._id) >= 0) {
// user.points = 0;
// Object.keys(predictionMap[userId]).forEach(function (predictionId) {
// var prediction = predictionMap[userId][predictionId];
// if (!user.date || user.date < prediction.date) {
// user.date = prediction.date;
// }
//
// //if there is an actual result then calculate the points accordingly
// if (resultMap[prediction.itemId]) {
// var result = resultMap[prediction.itemId];
// if (result.answer) {
// var question = Questions.findOne({
// _id: prediction.itemId
// });
// if (question.date < nowDate) {
// if (question.optionType == 'INTEGER') {
// if (Math.abs(result.answer - prediction.answer) <= question.threshold) {
// user.points += parseInt(question.points);
// }
// } else if (result.answer == prediction.answer) {
// user.points += parseInt(question.points);
// }
// }
// } else {
// var match = Matches.findOne({
// _id: prediction.itemId
// });
// if (match.date < nowDate) {
// //calculate the actual points
// if (result.homeScore == prediction.homeScore && result.awayScore == prediction.awayScore) {
// user.points += 3;
// } else if ((result.homeScore - result.awayScore) == (prediction.homeScore - prediction.awayScore)) {
// user.points += 2;
// } else if ((result.homeScore > result.awayScore && prediction.awayScore > prediction.awayScore) || (result.homeScore < result.awayScore && prediction.awayScore < prediction.awayScore)) {
// user.points += 1;
// }
// }
// }
// }
// });
// users.push(user);
// }
// }
// });
//
//
// users.sort(function (a, b) {
// if (a.points < b.points)
// return 1;
// else if (a.points > b.points)
// return -1;
// else if (a.date < b.date)
// return -1;
// else if (a.date > b.date)
// return 1;
// else
// return 0;
// });
//
// var rank = 1;
// var points = Number.POSITIVE_INFINITY;
// users.forEach(function (user) {
// if (user.points == points) {
// user.rank = '-';
// } else {
// user.rank = rank++;
// points = user.points;
// }
// });
//
// return users;
}
});

Expand Down
1 change: 1 addition & 0 deletions common/points.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ calculateRankings = function (groupId, competitionId, isPaid = false) {
if (!isPaid || (user.emails[0].verified && user[getPaidAttribute()])) {
if (!data[userPointInfo.userId]) {
data[userPointInfo.userId] = {}
data[userPointInfo.userId].id = user._id;
data[userPointInfo.userId].username = user.username;
data[userPointInfo.userId].avatar = user.profile.avatar;
data[userPointInfo.userId].points = 0;
Expand Down
21 changes: 9 additions & 12 deletions server/observers.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,22 @@ Meteor.startup(function () {
});

//TODO resolve issue where this is called multiple time on startup
Results.find({}).observeChanges({
Predictions.find({}).observeChanges({
added: function (id, doc) {
upsertCalculatePoints(doc.competitionId);
upsertPointInfoByPrediction(id);
},
changed: function (id, doc) {
var result = Results.findOne({
_id: id
});
upsertCalculatePoints(result.competitionId);
upsertPointInfoByPrediction(id);
}
});

Predictions.find({}).observeChanges({

Results.find({}).observeChanges({
added: function (id, doc) {
if (!Points.findOne({
_id: id
})) {
upsertCalculatePoints(doc.competitionId);
}
upsertPointInfoByResult(id);
},
changed: function (id, doc) {
upsertPointInfoByResult(id);
}
});
});
Loading

0 comments on commit 6badb91

Please sign in to comment.