示例#1
0
 public function test_FiveMinResolutionSumTwoSeries_RollupSpace_ReturnSumForBothSeries()
 {
     $value1 = 10;
     $value2 = 20;
     $nDays = 20;
     $aggregation = Aggregation::SUM;
     $start = new DateTIme('2015-10-10 00:00:00');
     $end = clone $start;
     $end->add(DateInterval::createFromDateString($nDays . ' days'));
     $dateperiod = new DatePeriod($start, DateInterval::createFromDateString('5 minutes'), $end);
     $vals1 = [];
     $vals2 = [];
     $expected = [];
     foreach ($dateperiod as $datetime) {
         $vals1[$datetime->getTimestamp()] = $value1;
         $vals2[$datetime->getTimestamp()] = $value2;
         $expected[$datetime->format('Y-m-d H:i:s')] = $value1 + $value2;
     }
     $series1 = new Series($vals1);
     $series2 = new Series($vals2);
     $convert = new ConvertToDateStringKeys();
     $action = new RollupSpace($aggregation);
     $output = $action->run([$series1, $series2]);
     $output = $convert->run($output);
     $this->assertEquals($expected, $output);
 }
示例#2
0
 public function test_FiveMinResolutionDailySum_RollupTime_ReturnSumForEachDay()
 {
     $value = 1;
     $nDays = 20;
     $resolution = Resolution::DAY;
     $aggregation = Aggregation::SUM;
     $start = new DateTIme('2015-10-10 00:00:00');
     $end = clone $start;
     $end->add(DateInterval::createFromDateString($nDays . ' days'));
     $dateperiodExpected = new DatePeriod($start, DateInterval::createFromDateString('1 day'), $end);
     $expected = [];
     foreach ($dateperiodExpected as $datetime) {
         $expected[$datetime->format('Y-m-d H:i:s')] = $value * (86400 / $resolution);
     }
     $dateperiod = new DatePeriod($start, DateInterval::createFromDateString($resolution . ' seconds'), $end);
     $valsByTimestamp = [];
     foreach ($dateperiod as $datetime) {
         $valsByTimestamp[$datetime->getTimestamp()] = $value;
     }
     $series = new Series($valsByTimestamp);
     $convert = new ConvertToDateStringKeys();
     $action = new RollupTime($resolution, $aggregation);
     $output = $action->run($series);
     $output = $convert->run($output);
     $this->assertEquals($expected, $output);
 }
示例#3
0
 public function test_FiveMinResolutionDailySum_RollupTime_ReturnSumForEachDay()
 {
     $padding = false;
     $start = new DateTime('2015-10-25 00:00:00');
     $end = new DateTime('2015-10-25 06:00:00');
     $resolution = Resolution::HOUR;
     $series = new Series([(new DateTime('2015-10-25 00:00:00'))->getTimestamp() => 1, (new DateTime('2015-10-25 02:00:00'))->getTimestamp() => 1, (new DateTime('2015-10-25 04:00:00'))->getTimestamp() => 1, (new DateTime('2015-10-25 05:00:00'))->getTimestamp() => 1]);
     $expected = ['2015-10-25 00:00:00' => 1, '2015-10-25 01:00:00' => $padding, '2015-10-25 02:00:00' => 1, '2015-10-25 03:00:00' => $padding, '2015-10-25 04:00:00' => 1, '2015-10-25 05:00:00' => 1];
     $convert = new ConvertToDateStringKeys();
     $action = new Pad($resolution, $start, $end, $padding);
     $output = $action->run($series);
     $output = $convert->run($output);
     $this->assertEquals($expected, $output);
 }
示例#4
0
 public function test_RandomInput()
 {
     $start = new DateTime('2015-10-23 23:00:00');
     $windowLength = 60 * 60 * 3;
     // 3 hours
     $windowDistance = 86400;
     $value = 1;
     $input = ['2015-10-24 00:00:00' => $value, '2015-10-24 01:47:00' => $value, '2015-10-24 02:00:00' => $value, '2015-10-25 00:32:00' => $value, '2015-10-25 01:45:00' => $value, '2015-10-25 02:07:00' => $value, '2015-10-25 03:05:00' => $value, '2015-10-26 01:15:00' => $value, '2015-10-26 02:26:00' => $value, '2015-10-26 03:10:00' => $value, '2015-10-26 08:10:00' => $value, '2015-10-26 23:00:00' => $value, '2015-10-26 23:59:59' => $value];
     $expected = ['2015-10-24 00:00:00' => $value, '2015-10-24 01:47:00' => $value, '2015-10-25 00:32:00' => $value, '2015-10-25 01:45:00' => $value, '2015-10-26 01:15:00' => $value, '2015-10-26 23:00:00' => $value, '2015-10-26 23:59:59' => $value];
     $vals = [];
     foreach ($input as $dateStr => $val) {
         $vals[(new DateTime($dateStr))->getTimestamp()] = $val;
     }
     $series = new Series($vals);
     $action = new FilterWindow($start, $windowLength, $windowDistance);
     $output = $action->run($series);
     $convert = new ConvertToDateStringKeys();
     $output = $convert->run($output);
     $this->assertEquals($expected, $output);
 }
示例#5
0
 public function test_AddTwoSeriesAndAConstant_FormulaAction_RetrieveSum()
 {
     $formula = '[sid=0] + [sid=1] + 5';
     $vals1 = [(new DateTime('2015-12-05 00:00:00'))->getTimestamp() => 100, (new DateTime('2015-12-05 01:00:00'))->getTimestamp() => 200];
     $vals2 = [(new DateTime('2015-12-05 00:00:00'))->getTimestamp() => 1000, (new DateTime('2015-12-05 01:00:00'))->getTimestamp() => 2000];
     $expected = ['2015-12-05 00:00:00' => 1105, '2015-12-05 01:00:00' => 2205];
     $seriesList = [];
     $seriesList[] = new Series($vals1);
     $seriesList[] = new Series($vals2);
     $parser = new Parser();
     $ast = $parser->parse($formula);
     $astEvaluator = new AstEvaluator();
     $astEvaluator->setPaddingValue(false);
     $astEvaluator->setVariableEvaluatorCallback(function ($options) use($seriesList) {
         $series = $seriesList[$options['sid']];
         return $series->vals;
     });
     $convert = new ConvertToDateStringKeys();
     $action = new Formula($ast, $astEvaluator);
     $output = $action->run();
     $output = $convert->run($output);
     $this->assertEquals($expected, $output);
 }