From: CMDR furrycat Date: Tue, 2 Feb 2016 12:18:28 +0000 (-0500) Subject: Generalised entry sorting. X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=e3060850158c99f121833e2caa46f4cf9bd1210d;p=furrycat%2Frace-o-matic.git Generalised entry sorting. --- diff --git a/propel/build/classes/buckyball/Entry.php b/propel/build/classes/buckyball/Entry.php index 508cb6d..d4501b8 100644 --- a/propel/build/classes/buckyball/Entry.php +++ b/propel/build/classes/buckyball/Entry.php @@ -44,28 +44,67 @@ class Entry extends BaseEntry return self::Endorsement($e)[1]; } - function ByBestSpeed($a, $b) { - $A = $a->getBestSpeed(); $B = $b->getBestSpeed(); + function Sort($a, $b, $method, $reverse = false) { + $A = $a->$method(); $B = $b->$method(); if ($A == $B) return 0; - return $A < $B ? 1 : -1; + $ret = $reverse ? 1 : -1; + return $A < $B ? $ret : -$ret; + } + + function ByDistance($a, $b) { + return self::Sort($a, $b, "getTotalDistance", true); + } + + function ByPenaltyTime($a, $b) { + return self::Sort($a, $b, "getPenaltyTime"); + } + + function ByTotalTime($a, $b) { + return self::Sort($a, $b, "getTotalTime"); + } + + function ByBonusTime($a, $b) { + return self::Sort($a, $b, "getBonusTime"); + } + + function ByCutShort($a, $b) { + return self::Sort($a, $b, "cutShort", true); + } + + function ByBestSpeed($a, $b) { + return self::Sort($a, $b, "getBestSpeed", true); } function ByAverageSpeed($a, $b) { - $A = $a->getAverageSpeed(); $B = $b->getAverageSpeed(); - if ($A == $B) return 0; - return $A < $B ? 1 : -1; + return self::Sort($a, $b, "getAverageSpeed", true); } function ByFastestLap($a, $b) { - $A = $a->getFastestLap(); $B = $b->getFastestLap(); - if ($A == $B) return 0; - return $A < $B ? -1 : 1; + return self::Sort($a, $b, "getFastestLap"); } function ByAverageLap($a, $b) { - $A = $a->getAverageLap(); $B = $b->getAverageLap(); - if ($A == $B) return 0; - return $A < $B ? -1 : 1; + return self::Sort($a, $b, "getAverageLap"); + } + + /* + Ordering by total distance then penalty time will classify racers + appropriately in endurance races, while having no effect on dashes. + Ordering by total time will classify racers in dashes while not + affecting endurance races. + Ordering by bonus time will allow a racer who didn't use the joker + to win a tiebreak with one who did. + Ordering by cut short endorsement will penalise those who didn't + compete for the full race time but only when tied for penalty. + */ + function StandardSort($a, $b) { + $methods = array("ByDistance", "ByPenaltyTime", "ByCutShort", "ByTotalTime", "ByBonusTime"); + while (count($methods)) { + $method = array_shift($methods); + $ret = self::$method($a, $b); + if ($ret) return $ret; + } + return 0; } function getName() {