1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace App\Yr\Forecast\Tabular;
- use App\Yr\Forecast\Tabular\Time\AbstractUnit;
- use App\Yr\Forecast\Tabular\Time\Temperature;
- use App\Yr\Forecast\Tabular\Time\WindSpeed;
- /**
- * Make simple statistic on analysed time objects,
- * such as highest/lowest wind speed and temperature,
- * average wind speed and temperature etc.
- *
- * @author Joachim M. Giæver (joachim[]giaever.org)
- */
- class Statistics {
- private $temp = [];
- private $wind = [];
- private $count = 0;
- public function __construct() {
- $this->temp = $this->wind = [
- 'high' => null,
- 'low' => null,
- 'mean' => 0
- ];
- }
- /**
- * Analyse a single Time-object
- *
- * @param Time $t The time object.
- * @return Statistics
- */
- public function analyse(Time $t): self {
- $this->analyseHihgLow($t->getTemperature());
- $this->analyseHihgLow($t->getWindSpeed());
- $this->temp['mean'] += $t->getTemperature()->getValue();
- $this->wind['mean'] += $t->getWindSpeed()->getValue();
- return $this;
- }
- private function analyseHihgLow(AbstractUnit $au): self {
- $unit = null;
- if ($au instanceof Temperature)
- $unit = &$this->temp;
- elseif ($au instanceof WindSpeed)
- $unit = &$this->wind;
- else
- return $this;
- if ($unit['low'] == null || $au->getValue() < $unit['low']->getValue())
- $unit['low'] = $au;
- if ($unit['high'] == null || $au->getValue() < $unit['high']->getValue())
- $unit['high'] = $au;
- return $this;
- }
- }
- ?>
|