-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Evaluate after removing member. Closes #36.
- Loading branch information
Showing
4 changed files
with
123 additions
and
98 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
/* | ||
* Shared function to evaluate sessions | ||
*/ | ||
class SessionEvaluation | ||
{ | ||
// Evaluate the polls average | ||
public static function evaluatePoll($session, $currentPoll) | ||
{ | ||
$sum = 0; | ||
$count = $currentPoll->getVotes()->count(); | ||
|
||
if($count != $session->getMembers()->count()) | ||
return false; | ||
|
||
foreach($currentPoll->getVotes() as $vote) | ||
{ | ||
$sum += $vote->getValue(); | ||
} | ||
$currentPoll->setResult($sum / $count); | ||
$currentPoll->setEndTime(new DateTime()); | ||
|
||
return true; | ||
} | ||
|
||
// Highlight highest and lowest estimate | ||
public static function highlightVotes($session, $currentPoll, $cardSet) | ||
{ | ||
include __DIR__ . "/card-frequency.php"; | ||
|
||
$votes = $currentPoll->getVotes(); | ||
// Frequency for each card | ||
$frequencies = []; | ||
foreach($cardSet as $key=>$card) | ||
{ | ||
$frequencies[$key] = new CardFrequency($key); | ||
} | ||
|
||
// Count absolute frequence | ||
foreach($votes as $vote) | ||
{ | ||
$frequencies[$vote->getValue()]->count++; | ||
} | ||
|
||
// Determine most common vote | ||
foreach($frequencies as $frequency) | ||
{ | ||
if(!isset($mostCommon) || $mostCommon->count < $frequency->count) | ||
$mostCommon = $frequency; | ||
} | ||
|
||
$min = 0; $max = 0; | ||
// Iterate over frequencies and find lowest | ||
foreach($frequencies as $frequency) | ||
{ | ||
$min = self::selectLimits($votes, $frequency, $mostCommon); | ||
if($min != 0) | ||
break; | ||
} | ||
// Iterate over frequencies and find highest | ||
foreach(array_reverse($frequencies) as $frequency) | ||
{ | ||
$max = self::selectLimits($votes, $frequency, $mostCommon); | ||
if($max != 0) | ||
break; | ||
} | ||
|
||
$currentPoll->setConsensus($min == -1 && $max == -1); | ||
} | ||
|
||
// Select highest or lowest estimates - depends on direction of loop | ||
private static function selectLimits($votes, $frequency, $mostCommon) | ||
{ | ||
// No card at all | ||
if($frequency->count == 0) | ||
return 0; | ||
// This is the most common, no lowest found | ||
if($frequency == $mostCommon) | ||
return -1; | ||
|
||
foreach($votes as $vote) | ||
{ | ||
if($vote->getValue() == $frequency->value) | ||
$vote->setHighlighted(true); | ||
} | ||
return 1; | ||
} | ||
} |