public function testFromDatabase()
    {
        $PDO = new PDO('sqlite::memory:');
        $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $PDO->exec('CREATE TABLE IF NOT EXISTS `' . PREFIX . 'training` (
			`accountid` int(10),
			`typeid` int(10),
			`vdot` decimal(5,2),
			`vdot_by_time` decimal(5,2)
			);
		');
        $PDO->exec('INSERT INTO `' . PREFIX . 'training` VALUES(1, 3,  0, 90)');
        // empty
        $PDO->exec('INSERT INTO `' . PREFIX . 'training` VALUES(1, 3, 50, 25)');
        // 0.5
        $PDO->exec('INSERT INTO `' . PREFIX . 'training` VALUES(1, 3, 50, 45)');
        // 0.9
        $PDO->exec('INSERT INTO `' . PREFIX . 'training` VALUES(1, 3,100, 80)');
        // 0.8, best vdot_by_time
        $PDO->exec('INSERT INTO `' . PREFIX . 'training` VALUES(2, 3, 90, 90)');
        // 1.0, other account
        $PDO->exec('INSERT INTO `' . PREFIX . 'training` VALUES(1, 5, 90, 90)');
        // 1.0, other type
        $Corrector = new VDOTCorrector();
        $Corrector->fromDatabase($PDO, 1, 3);
        $PDO->exec('DROP TABLE `' . PREFIX . 'training`');
        $this->assertEquals(0.9, $Corrector->factor());
    }
Beispiel #2
0
 /**
  * Recalculate VDOT corrector
  * @return float new factor
  */
 public function recalculateVDOTcorrector()
 {
     $Corrector = new JD\VDOTCorrector();
     $Corrector->fromDatabase(DB::getInstance(), SessionAccountHandler::getId(), Configuration::General()->competitionType());
     $this->updateVdotCorrector($Corrector->factor());
     return $Corrector->factor();
 }