Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,15 @@ a:focus {
.vote.card { cursor: default; }
.vote.card--selected { cursor: pointer; }

.voting-average, .voting-median {
display: none;
}

.flipped-stagger .voting-average, .flipped-stagger .voting-median {
display: block;
clear: both;
}

/*

Buttons
Expand Down
58 changes: 57 additions & 1 deletion app/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,55 @@ function RoomCtrl($scope, $routeParams, $timeout, socket) {
}
};

var sumOfTwo = function (a, b) {
return a + b;
};

var myParseFloat = function (a) {
var res = parseFloat(a);
if (!isNaN(res)) {
return res;
}
if (a == '\u00BD') {
return 0.5
}
return NaN
};

var floatVotes = function (votes) {
return _.map(_.pluck(votes, 'vote'), myParseFloat).filter(function(obj) {return !isNaN(obj);});
};

var calculateAverage = function (votes) {
var legalVotes = floatVotes(votes);
if (legalVotes.length == 0) {
return '\u221E';
}
var total = _.reduce(legalVotes, sumOfTwo, 0);
return Math.round(total * 2 / legalVotes.length) / 2;
};

var findMedian = function (data) {
var m = data.sort(function(a, b) {
return a - b;
});

var middle = Math.floor((m.length - 1) / 2);
if (m.length % 2) {
return m[middle];
} else {
return (m[middle] + m[middle + 1]) / 2.0;
}
}

var calculateMedian = function (votes) {
var legalVotes = floatVotes(votes);
if (legalVotes.length == 0) {
return '\u221E';
}
return findMedian(legalVotes);
};

// wipe out vote if voting state is not yet finished to prevent cheating.
// if it has already been set - use the actual vote. This works for unvoting - so that
// before the flip occurs - we don't display 'oi'
Expand All @@ -97,9 +146,11 @@ function RoomCtrl($scope, $routeParams, $timeout, socket) {
voteArr.length = $scope.voterCount - voteCount;
$scope.placeholderVotes = voteArr;


$scope.forceRevealDisable = (!$scope.forcedReveal && ($scope.votes.length < $scope.voterCount || $scope.voterCount === 0)) ? false : true;

$scope.votingAverage = calculateAverage($scope.votes.slice());
$scope.votingMedian = calculateMedian($scope.votes.slice());

if ($scope.votes.length === $scope.voterCount || $scope.forcedReveal) {
var uniqVotes = _.chain($scope.votes).pluck('vote').uniq().value().length;
if (uniqVotes === 1) {
Expand Down Expand Up @@ -169,6 +220,7 @@ function RoomCtrl($scope, $routeParams, $timeout, socket) {
var seq = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '?'];
var play = ['A\u2660', '2', '3', '5', '8', '\u2654'];
var tshirt = ['XL', 'L', 'M', 'S', 'XS', '?'];
var seq2 = ['0', '\u00BD', '1', '2', '3', '4', '5', '10', '\u221E', '?'];
switch (val) {
case ('fib'):
return fib;
Expand All @@ -180,6 +232,8 @@ function RoomCtrl($scope, $routeParams, $timeout, socket) {
return play;
case ('tshirt'):
return tshirt;
case ('seq2'):
return seq2;
default:
return [];
}
Expand Down Expand Up @@ -379,6 +433,8 @@ function RoomCtrl($scope, $routeParams, $timeout, socket) {
$scope.votingState = "";
$scope.forcedReveal = false;
$scope.forceRevealDisable = true;
$scope.votingAverage = 0;
$scope.votingMedian = 0;
$scope.scrollToSelectedCards = new ScrollIntoView($('#chosenCards'));

$scope.dropDown = new DropDown('#dd');
Expand Down
4 changes: 3 additions & 1 deletion app/partials/room.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<div id="dd" class="dropdown-wrapper btn">
<span>Mountain Goat pack</span>
<ul class="dropdown">
<li class="dropdown__item"><a href="#" ng-model="cardPack" id="deckSeq2" ng-click="setCardPack('seq2')">Sequential 2</a></li>
<li class="dropdown__item"><a href="#" ng-model="cardPack" id="deckGoat" ng-click="setCardPack('goat')">Mountain Goat</a></li>
<li class="dropdown__item"><a href="#" ng-model="cardPack" id="deckFib" ng-click="setCardPack('fib')">Fibonacci</a></li>
<li class="dropdown__item"><a href="#" ng-model="cardPack" id="deckSeq" ng-click="setCardPack('seq')">Sequential</a></li>
Expand Down Expand Up @@ -71,7 +72,8 @@
<div ng-repeat="i in placeholderVotes" class="card card--placeholder">
&nbsp;
</div>

<div class="voting-average">Average: <b>{{votingAverage}}</b></div>
<div class="voting-median">Median: <b>{{votingMedian}}</b></div>
</div>

<div ng-switch on="showAdmin" >
Expand Down