Beispiel #1
0
 /**
  * @covers Aclivo\Kpi\SumTotalizer::totalize
  */
 public function testTotalizer()
 {
     $margin = 0.3;
     $actual = 0;
     $target = 0;
     $lowBand = 0;
     $highBand = 0;
     $datapoints = array();
     for ($x = 1; $x <= 12; $x++) {
         $dp = new DataPoint();
         $dp->setDate(DateTime::createFromFormat('Y-n-d', "2014-{$x}-01"));
         $actual += $x * 1000;
         $dp->setActual($x * 1000);
         $target += $x * 1000 * 1 + $margin;
         $dp->setTarget($x * 1000 * 1 + $margin);
         $dp->setMargin($margin);
         $lowBand += $dp->getLowBandTarget();
         $highBand += $dp->getHighBandTarget();
         $datapoints[] = $dp;
     }
     $totalizer = new SumTotalizer();
     $total = $totalizer->totalize($datapoints);
     $this->assertEquals($actual, $total->getActual());
     $this->assertEquals($target, $total->getTarget());
     $this->assertEquals($lowBand, $total->getLowBandTarget());
     $this->assertEquals($highBand, $total->getHighBandTarget());
 }
Beispiel #2
0
 /**
  * @covers Aclivo\Kpi\DataPoint::getDirection
  */
 public function testgetDirection()
 {
     $dp = new DataPoint();
     $dp->setActual(100);
     $dp->setTarget(100);
     $dp->setMargin(0.1);
     $director = new UpDirector();
     $dp->setDirector($director);
     $this->assertEquals(Directions::GOOD, $dp->getDirection());
 }
Beispiel #3
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Aclivo\Kpi\DataPoint;
$begin = \DateTime::createFromFormat('Y-m-d', "2014-01-01");
$interval = new DateInterval('P1M');
$daterange = new DatePeriod($begin, $interval, 11, false);
$margin = 0.1;
$points = array();
foreach ($daterange as $date) {
    $m = (int) $date->format('m') . PHP_EOL;
    $dp = new DataPoint();
    $dp->setDate($date);
    $dp->setActual($m * 1000);
    $dp->setTarget($m * 1000);
    $dp->setMargin($margin);
    $points[] = $dp;
}
$header = join(';', array('Date', 'Actual', 'LowBand', 'Target', 'HighBand')) . PHP_EOL;
file_put_contents('teste.csv', $header);
for ($m = 0; $m < 12; $m++) {
    $row = array($points[$m]->getDate()->format('Ymd'), $points[$m]->getActual(), $points[$m]->getLowBandTarget(), $points[$m]->getTarget(), $points[$m]->getHighBandTarget());
    file_put_contents('teste.csv', join(';', $row) . PHP_EOL, FILE_APPEND);
}