Esempio n. 1
0
 /**
  * Update format of data for existing estimates.
  */
 protected function update_4()
 {
     $estimates = $this->app['db']->createQueryBuilder()->select('e.*')->from('estimates', 'e')->where('e.data != ""')->execute();
     while ($estimate = $estimates->fetch(\PDO::FETCH_OBJ)) {
         $dataArray = unserialize($estimate->data);
         $dataObject = \DrupalReleaseDate\EstimateDistribution::fromArray($dataArray);
         $this->app['db']->createQueryBuilder()->update('estimates', 'e')->set('e.data', ':data')->where('e.version = :version')->andWhere('e.when = :when')->setParameter('data', serialize($dataObject))->setParameter('version', $estimate->version)->setParameter('when', $estimate->when)->execute();
     }
 }
Esempio n. 2
0
 /**
  * Get the distribution of estimates from the specified number of
  * iterations, grouped into buckets of the specified size.
  *
  * @param int $iterations
  * @param int $bucketSize
  *   The period in seconds to group estimates by.
  * @param int $timeLimit
  *   The number of seconds to allow the estimation to run for.
  * @return EstimateDistribution
  */
 public function runDistribution($iterations = self::DEFAULT_ITERATIONS, $bucketSize = self::DEFAULT_BUCKET_SIZE, $timeLimit = self::DEFAULT_TIME_LIMIT)
 {
     $estimates = new EstimateDistribution();
     $abortTime = time() + $timeLimit;
     for ($run = 1; $run <= $iterations; $run++) {
         try {
             $estimate = $this->iteration($abortTime);
             $bucket = $estimate - $estimate % $bucketSize;
             $estimates->success($bucket);
         } catch (IncreasingException $e) {
             $estimates->failure();
             if ($run > $iterations * $this->increasingFailureThresholdRatio && $estimates->getFailureCount() / $run > $this->increasingFailureRatio) {
                 $runException = new IncreasingException('Run aborted after iteration ' . $run, 0, $e);
                 $runException->setDistribution($estimates);
                 throw $runException;
             }
         } catch (TimeoutException $e) {
             $estimates->failure();
             $runException = new TimeoutException('Run aborted during iteration ' . $run, 0, $e);
             $runException->setDistribution($estimates);
             throw $runException;
         }
     }
     return $estimates;
 }
 /**
  * Test a median when failures are included in the calculation
  *
  * @expectedException \RuntimeException
  *
  * @covers \DrupalReleaseDate\EstimateDistribution::getMedian
  * @uses \DrupalReleaseDate\EstimateDistribution::__construct
  * @uses \DrupalReleaseDate\EstimateDistribution::success
  */
 public function testMedianWithTooManyFailures()
 {
     $estimates = new EstimateDistribution();
     $estimates->success(1);
     $estimates->success(2);
     $estimates->success(3);
     $estimates->failure();
     $estimates->failure();
     $estimates->failure();
     $estimates->failure();
     $estimates->getMedian(true);
 }