|
@@ -3,6 +3,7 @@
|
|
namespace App\Yr\Forecast\Tabular;
|
|
namespace App\Yr\Forecast\Tabular;
|
|
|
|
|
|
use App\Yr\Forecast\Tabular\Time\AbstractUnit;
|
|
use App\Yr\Forecast\Tabular\Time\AbstractUnit;
|
|
|
|
+use App\Yr\Forecast\Tabular\Time\CustomUnit;
|
|
use App\Yr\Forecast\Tabular\Time\Temperature;
|
|
use App\Yr\Forecast\Tabular\Time\Temperature;
|
|
use App\Yr\Forecast\Tabular\Time\WindSpeed;
|
|
use App\Yr\Forecast\Tabular\Time\WindSpeed;
|
|
|
|
|
|
@@ -17,12 +18,18 @@ class Statistics {
|
|
private $temp = [];
|
|
private $temp = [];
|
|
private $wind = [];
|
|
private $wind = [];
|
|
private $count = 0;
|
|
private $count = 0;
|
|
|
|
+ private $symbol = [];
|
|
|
|
|
|
public function __construct() {
|
|
public function __construct() {
|
|
- $this->temp = $this->wind = [
|
|
|
|
|
|
+ $this->temp = $this->struct();
|
|
|
|
+ $this->wind = $this->struct();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function struct(): array {
|
|
|
|
+ return [
|
|
'high' => null,
|
|
'high' => null,
|
|
'low' => null,
|
|
'low' => null,
|
|
- 'mean' => 0
|
|
|
|
|
|
+ 'mean' => null
|
|
];
|
|
];
|
|
}
|
|
}
|
|
|
|
|
|
@@ -35,11 +42,36 @@ class Statistics {
|
|
public function analyse(Time $t): self {
|
|
public function analyse(Time $t): self {
|
|
$this->analyseHihgLow($t->getTemperature());
|
|
$this->analyseHihgLow($t->getTemperature());
|
|
$this->analyseHihgLow($t->getWindSpeed());
|
|
$this->analyseHihgLow($t->getWindSpeed());
|
|
- $this->temp['mean'] += $t->getTemperature()->getValue();
|
|
|
|
- $this->wind['mean'] += $t->getWindSpeed()->getValue();
|
|
|
|
|
|
+
|
|
|
|
+ $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;
|
|
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 {
|
|
private function analyseHihgLow(AbstractUnit $au): self {
|
|
$unit = null;
|
|
$unit = null;
|
|
|
|
|