1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace App\Yr\Forecast\Tabular\Time;
- abstract class AbstractUnit implements DiffInterface {
- const DEFAULT_VARIANCE = 2;
- private $value;
- private $unit;
- public function __construct(float $value, string $unit) {
- $this->value = $value;
- $this->unit = $unit;
- }
- public function getValue(): float {
- return $this->value;
- }
- public function getUnit(): string {
- return $this->unit;
- }
- public function setThresholdValue(int $t): self {
- $this->threshold = $t;
- }
- public function diff(DiffInterface $d): bool {
- if ($d instanceof $this)
- return abs($this->value - $d->getValue()) > static::DEFAULT_VARIANCE;
- return false;
- }
- public function __toString(): string {
- return sprintf(
- "%s: %f %s", basename(str_replace(
- '\\', DIRECTORY_SEPARATOR, get_class($this)
- )), $this->value, $this->unit);
- }
- }
|