123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace App\Yr\Forecast\Tabular\Time;
- /**
- * Wind speed
- *
- * @author Joachim M. Giæver (joachim[]giaever.org)
- */
- class WindSpeed extends AbstractUnit {
- const DEFAULT_VARIANCE = (4.9 / 3.5);
- const UNIT_MPS = 'mp/s';
- const UNIT_FTS = 'ft/s';
- const UNIT_KMH = 'km/h';
- const UNIT_KNOTS = 'knots';
- private $name;
- /**
- * @param \SimpleXMLElement $xml XML containing the wind spedd
- */
- public function __construct(\SimpleXMLElement $xml){
- parent::__construct(
- (float)$xml['mps'], self::UNIT_MPS
- );
- $this->name = (string)$xml['name'];
- }
- /**
- * Convert the wind speed to a different unit
- *
- * @param string $unit The unit to convert to, eg UNIT_FTS
- */
- public function convertTo(string $unit): int {
- switch ($unit) {
- case self::UNIT_KNOTS:
- return $this->getValue() * 1.9438445;
- case self::UNIT_FTS:
- return $this->getValue() * 3.28084;
- case self::UNIT_KMH:
- return $this->getValue() * 3.6;
- }
- }
- /**
- * Returns the wind name, e.g «light breeze»
- */
- public function getName(): string {
- return $this->name;
- }
- /**
- * {@inheritDoc}
- */
- public function diff(DiffInterface $e): int {
- if (parent::diff($e))
- return ($this->getName() != $e->getName()) ? 1 : 0;
- return 0;
- }
- public function __toString(): string {
- return sprintf(
- '%s (%s)', parent::__toString(), $this->name
- );
- }
- }
|