WindSpeed.php 1009 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Yr\Forecast\Tabular\Time;
  3. class WindSpeed extends AbstractUnit {
  4. const DEFAULT_VARIANCE = (4.9 / 3.5);
  5. const UNIT_MPS = 'mp/s';
  6. const UNIT_FTS = 'ft/s';
  7. const UNIT_KMH = 'km/h';
  8. const UNIT_KNOTS = 'knots';
  9. private $name;
  10. public function __construct(\SimpleXMLElement $xml){
  11. parent::__construct(
  12. (float)$xml['mps'], self::UNIT_MPS
  13. );
  14. $this->name = (string)$xml['name'];
  15. }
  16. public function convertTo(string $unit): int {
  17. switch ($unit) {
  18. case self::UNIT_KNOTS:
  19. return $this->getValue() * 1.9438445;
  20. case self::UNIT_FTS:
  21. return $this->getValue() * 3.28084;
  22. case self::UNIT_KMH:
  23. return $this->getValue() * 3.6;
  24. }
  25. }
  26. public function getName(): string {
  27. return $this->name;
  28. }
  29. public function __toString(): string {
  30. return sprintf(
  31. '%s (%s)', parent::__toString(), $this->name
  32. );
  33. }
  34. }