temp = $this->struct(); $this->wind = $this->struct(); } private function struct(): array { return [ 'high' => null, 'low' => null, 'mean' => null ]; } /** * 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'] = $this->temp['mean'] == null ? $t->getTemperature() : $this->temp['mean']->add($t->getTemperature()); $this->wind['mean'] = $this->wind['mean'] == null ? $t->getWindSpeed() : $this->wind['mean']->add($t->getWindSpeed()); $symboldId = $t->getSymbol()->getNumber(); if (!isset($this->symbol[$symboldId])) $this->symbol[$symboldId] = [ 'symbol' => $t->getSymbol()->getName(), 'count' => 1 ]; else $this->symbol[$symboldId]['count']++; $this->count++; return $this; } public function getAverageTemperature(): AbstractUnit { return $this->temp['mean']->div( new CustomUnit($this->count, $this->temp['mean']->getUnit()) ); } public function getAverageWindSpeed(): AbstractUnit { return $this->wind['mean']->div( new CustomUnit($this->count, $this->wind['mean']->getUnit()) ); } 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; } } ?>