Read forecast data from Yr.no.

Joachim M. Giæver cb9453c0d4 Added JsonSer. to Symbol há 5 anos atrás
sami-markdown @ ea769268e2 680204ab8f Add forecast data, filtering and variation há 5 anos atrás
src cb9453c0d4 Added JsonSer. to Symbol há 5 anos atrás
.gitignore 569dbba25e Init commit há 5 anos atrás
.gitmodules 680204ab8f Add forecast data, filtering and variation há 5 anos atrás
LICENSE 6a6760b53a Updated composer.json & license há 5 anos atrás
README.md 584461eeee Updated readme há 5 anos atrás
composer.json 689099934e Fix missing slash há 5 anos atrás
index.php aeb334ff0c Add TimeInterface and make new Variation(s) in filter há 5 anos atrás
sami.conf.php 96be81232b Add CustomUnit for arithmetic methods and more stats há 5 anos atrás

README.md

Yr Forecast

Table of content

  1. App
    1. Yr
      1. Forecast
        1. Location Get information about the location,such as name, timezone and geodata
        2. Tabular
          1. Time
            1. AbstractUnit Time-object entity should inherit this
            2. ConvertableInterface Implemented on units that can be converted,such as wind speed and temperature.
            3. CustomUnit Custom unit, only used to operate on units of same kind
            4. DiffInterface Defines that an entity can be checked for differencesagains another entity.
            5. Pressure Airpressure
            6. Symbol Contains the sky data, e.g «Clody» etc
            7. Temperature Temperature
            8. WindDirection Wind direction
            9. WindSpeed Wind speed
          2. Variation
            1. Variation
          3. Statistics Make simple statistic on analysed time objects,such as highest/lowest wind speed and temperature,average wind speed and temperature etc.
          4. Time Forecast data witin a time period
          5. Variations Removes superfluous forecast data in an Time-objectonly storing changes.
        3. Tabular Holds the forecast data in Time-objects.
      2. Forecast Read forecast data from Yr.no for a specific location.

Documentation

App

App\Yr

Classes

Forecast App\Yr

  • Class is final

Read forecast data from Yr.no for a specific location.

Disclaimer: To use this package you are required to print the credits from the method getCredit()

Require the package to your project by adding (or creating) the following in the composer.json-file:

{
     "require": {
         "joachimmg/yr-forecast": "dev-master"
     },
     "repositories": [{
         "type": "vcs",
         "url": "https://git.giaever.org/joachimmg/yr-forecast.git"
     }]
}

Methods

Name Return Access Description
__construct public
getLocation Location public Returns the location data for the forecast
getCredit array final public Return the credit to Yr.no, Meterogical Institute and NRK
getSunrise ateTimeImmutable public Returns the time when the sun rise for the location
getSunset ateTimeImmutable public Returns the time when the sun sets for the location
getLinks enerator public Returns links for forecasts in other formats
getLastUpdate ateTimeImmutable public Return the time when this forecast was last update
getNextUpdate ateTimeImmutable public Return the time when this forecast will update next
getTabular Tabular public Get the forecast data

Method details

__construct App\Yr\Forecast
public function __construct(string $url);

Parameters

Type Variable Description
string $url The XML url to load data from

getLocation App\Yr\Forecast
public function getLocation();

Returns the location data for the forecast

Returns: Location


getCredit App\Yr\Forecast
final public function getCredit();

Return the credit to Yr.no, Meterogical Institute and NRK

Returns: array


getSunrise App\Yr\Forecast
public function getSunrise();

Returns the time when the sun rise for the location

Returns: ateTimeImmutable


getSunset App\Yr\Forecast
public function getSunset();

Returns the time when the sun sets for the location

Returns: ateTimeImmutable


getLinks App\Yr\Forecast
public function getLinks();

Returns links for forecasts in other formats

Returns: enerator


getLastUpdate App\Yr\Forecast
public function getLastUpdate();

Return the time when this forecast was last update

Returns: ateTimeImmutable


getNextUpdate App\Yr\Forecast
public function getNextUpdate();

Return the time when this forecast will update next

Returns: ateTimeImmutable


getTabular App\Yr\Forecast
public function getTabular();

Get the forecast data

Returns: Tabular


App\Yr\Forecast

Classes

Location App\Yr\Forecast

  • Class is final

Get information about the location, such as name, timezone and geodata

Methods

Name Return Access Description
__construct public
getName string public Get the location name, e.g «Tromsø»
getType string public Get the location type, e.g «City - large town»
getCountry string public Get the location country
getTimeZone ateTimeZone public Get the location timezone
getGeoData array public Returns the geodata, in the format[ 'lat' => (float), 'lng' => (float), 'alt' => (float),]

Method details

__construct App\Yr\Forecast\Location
public function __construct(SimpleXMLElement $xml);

Parameters

Type Variable Description
SimpleXMLElement $xml The xml-part containing the location data

getName App\Yr\Forecast\Location
public function getName();

Get the location name, e.g «Tromsø»

Returns: string


getType App\Yr\Forecast\Location
public function getType();

Get the location type, e.g «City - large town»

Returns: string


getCountry App\Yr\Forecast\Location
public function getCountry();

Get the location country

Returns: string


getTimeZone App\Yr\Forecast\Location
public function getTimeZone();

Get the location timezone

Returns: ateTimeZone


getGeoData App\Yr\Forecast\Location
public function getGeoData();

Returns the geodata, in the format

[
     'lat' => (float),
     'lng' => (float),
     'alt' => (float),
]

Returns: array


Tabular App\Yr\Forecast

Holds the forecast data in Time-objects.

Use the getBetween option to limit the results.

Class also makes a simple statistic on the forecast for the periode and a variation that will exclude repetitive forecast data.

Methods

Name Return Access Description
__construct public
addTime Tabular protected Add a Time-object to the tabular
getStatistics Statistics public Get statistics for the Time-object collection
makeVariations Tabular protected
getVariations Variations public Remove superfluous weather data.
getBetween Tabular public Filter data between a certain periode, e.g$forcast->between( $forcast->getSunset(), $forecast->getSunrise()->add( new \DateInterval('P1D') ));to only show from sunset today unti sunrise tomorrow
getFrom ateTimeInterface public Return the time this tabular is from
getUntil ateTimeInterface public Return the time this tabular is until
getIterator enerator public {@inheritDoc}

Method details

__construct App\Yr\Forecast\Tabular
public function __construct(SimpleXMLElement null $xml);

Parameters

Type Variable Description
SimpleXMLElement null $xml The xml part holding the time objects, can be null

addTime App\Yr\Forecast\Tabular
protected function addTime(Time $time);

Add a Time-object to the tabular

Parameters

Type Variable Description
Time $time None

Returns: Tabular


getStatistics App\Yr\Forecast\Tabular
public function getStatistics();

Get statistics for the Time-object collection

Returns: Statistics


makeVariations App\Yr\Forecast\Tabular
protected function makeVariations();

Returns: Tabular


getVariations App\Yr\Forecast\Tabular
public function getVariations();

Remove superfluous weather data.

Checks if the data in the Time-object differs from the current Time-object and returns the unique data

Returns: Variations


getBetween App\Yr\Forecast\Tabular
public function getBetween(DateTimeInterface $from, DateTimeInterface $until);

Filter data between a certain periode, e.g

$forcast->between(
 $forcast->getSunset(),
 $forecast->getSunrise()->add(
     new \DateInterval('P1D')
 )
);

to only show from sunset today unti sunrise tomorrow

Parameters

Type Variable Description
DateTimeInterface $from None
DateTimeInterface $until None

Returns: Tabular


getFrom App\Yr\Forecast\Tabular
public function getFrom();

Return the time this tabular is from

Returns: ateTimeInterface


getUntil App\Yr\Forecast\Tabular
public function getUntil();

Return the time this tabular is until

Returns: ateTimeInterface


getIterator App\Yr\Forecast\Tabular
public function getIterator();

{@inheritDoc}

Returns: enerator


App\Yr\Forecast\Tabular

Classes

Statistics App\Yr\Forecast\Tabular

Make simple statistic on analysed time objects, such as highest/lowest wind speed and temperature, average wind speed and temperature etc.

Methods

Name Return Access Description
__construct public
analyse Statistics public Analyse a single Time-object
getAverageTemperature AbstractUnit public
getAverageWindSpeed AbstractUnit public
getHighestTemperature Temperature public
getLowestTemperature Temperature public
getHighestWindspeed WindSpeed public
getLowestWindSpeed WindSpeed public
getAverageSymbols array public
getMostCommonSymbol array public

Method details

__construct App\Yr\Forecast\Tabular\Statistics
public function __construct();

analyse App\Yr\Forecast\Tabular\Statistics
public function analyse(Time $t);

Analyse a single Time-object

Parameters

Type Variable Description
Time $t The time object.

Returns: Statistics


getAverageTemperature App\Yr\Forecast\Tabular\Statistics
public function getAverageTemperature();

Returns: AbstractUnit


getAverageWindSpeed App\Yr\Forecast\Tabular\Statistics
public function getAverageWindSpeed();

Returns: AbstractUnit


getHighestTemperature App\Yr\Forecast\Tabular\Statistics
public function getHighestTemperature();

Returns: Temperature


getLowestTemperature App\Yr\Forecast\Tabular\Statistics
public function getLowestTemperature();

Returns: Temperature


getHighestWindspeed App\Yr\Forecast\Tabular\Statistics
public function getHighestWindspeed();

Returns: WindSpeed


getLowestWindSpeed App\Yr\Forecast\Tabular\Statistics
public function getLowestWindSpeed();

Returns: WindSpeed


getAverageSymbols App\Yr\Forecast\Tabular\Statistics
public function getAverageSymbols();

Returns: array


getMostCommonSymbol App\Yr\Forecast\Tabular\Statistics
public function getMostCommonSymbol();

Returns: array


Time App\Yr\Forecast\Tabular

Forecast data witin a time period

Methods

Name Return Access Description
__construct public
getPeriod int public Returns the which index in the forecastits for.
getFrom ateTimeImmutable public Returns the time this forecast is from
getUntil ateTimeImmutable public Returns the time this forecast is to/until.
getSymbol Symbol public Returns the «symbol» (e.g Clody etc)
getWindDirection WindDirection public Returns the wind direction
getWindSpeed WindSpeed public Returns the wind speed
getTemperature Temperature public Returns the temperature
getPressure Pressure public Returns the pressure
getIterator enerator public {@inheritDoc}
__toString string public

Method details

__construct App\Yr\Forecast\Tabular\Time
public function __construct(SimpleXMLElement $xml);

Parameters

Type Variable Description
SimpleXMLElement $xml The xml holding the time-object

getPeriod App\Yr\Forecast\Tabular\Time
public function getPeriod();

Returns the which index in the forecast its for.

Returns: int


getFrom App\Yr\Forecast\Tabular\Time
public function getFrom();

Returns the time this forecast is from

Returns: ateTimeImmutable


getUntil App\Yr\Forecast\Tabular\Time
public function getUntil();

Returns the time this forecast is to/until.

Returns: ateTimeImmutable


getSymbol App\Yr\Forecast\Tabular\Time
public function getSymbol();

Returns the «symbol» (e.g Clody etc)

Returns: Symbol


getWindDirection App\Yr\Forecast\Tabular\Time
public function getWindDirection();

Returns the wind direction

Returns: WindDirection


getWindSpeed App\Yr\Forecast\Tabular\Time
public function getWindSpeed();

Returns the wind speed

Returns: WindSpeed


getTemperature App\Yr\Forecast\Tabular\Time
public function getTemperature();

Returns the temperature

Returns: Temperature


getPressure App\Yr\Forecast\Tabular\Time
public function getPressure();

Returns the pressure

Returns: Pressure


getIterator App\Yr\Forecast\Tabular\Time
public function getIterator();

{@inheritDoc}

Returns: enerator


__toString App\Yr\Forecast\Tabular\Time
public function __toString();

Returns: string


Variations App\Yr\Forecast\Tabular

Removes superfluous forecast data in an Time-object only storing changes.

Methods

Name Return Access Description
__construct public
getTime Time public
getData array public Returns the changes in the forecast

Method details

__construct App\Yr\Forecast\Tabular\Variations
public function __construct(array $t);

Parameters

Type Variable Description
array $t Array of Time-objects

getTime App\Yr\Forecast\Tabular\Variations
public function getTime();

Returns: Time


getData App\Yr\Forecast\Tabular\Variations
public function getData(callable $filterFn = null);

Returns the changes in the forecast

Parameters

Type Variable Description
callable $filterFn None

Returns: array


App\Yr\Forecast\Tabular\Time

Classes

AbstractUnit App\Yr\Forecast\Tabular\Time

Time-object entity should inherit this

Methods

Name Return Access Description
__construct public
transformClass AbstractUnit protected Transform custom unit to self
add AbstractUnit public Addition method
sub AbstractUnit public Subtraction method
mul AbstractUnit public Multiplication method
div AbstractUnit public Divide method
getValue float public Get the value
getUnit string public Return the unit (e.g «degree»)
diff int public Note! Working on floats, so operates on 100-times value.
__toString string public

Method details

__construct App\Yr\Forecast\Tabular\Time\AbstractUnit
public function __construct(float $value, string $unit);

Parameters

Type Variable Description
float $value The value
string $unit The unit

transformClass App\Yr\Forecast\Tabular\Time\AbstractUnit
protected function transformClass(CustomUnit $cu);

Transform custom unit to self

Parameters

Type Variable Description
CustomUnit $cu None

Returns: AbstractUnit


add App\Yr\Forecast\Tabular\Time\AbstractUnit
public function add(AbstractUnit $with);

Addition method

Parameters

Type Variable Description
AbstractUnit $with Unit to add with

Returns: AbstractUnit


sub App\Yr\Forecast\Tabular\Time\AbstractUnit
public function sub(AbstractUnit $with);

Subtraction method

Parameters

Type Variable Description
AbstractUnit $with Unit to sub with

Returns: AbstractUnit


mul App\Yr\Forecast\Tabular\Time\AbstractUnit
public function mul(AbstractUnit $with);

Multiplication method

Parameters

Type Variable Description
AbstractUnit $with Unit to multiply with

Returns: AbstractUnit


div App\Yr\Forecast\Tabular\Time\AbstractUnit
public function div(AbstractUnit $with);

Divide method

Parameters

Type Variable Description
AbstractUnit $with Unit to divide with

Returns: AbstractUnit


getValue App\Yr\Forecast\Tabular\Time\AbstractUnit
public function getValue();

Get the value

Returns: float


getUnit App\Yr\Forecast\Tabular\Time\AbstractUnit
public function getUnit();

Return the unit (e.g «degree»)

Returns: string


diff App\Yr\Forecast\Tabular\Time\AbstractUnit
public function diff(DiffInterface $d);

Note! Working on floats, so operates on 100-times value.

{@inheritDoc}

Parameters

Type Variable Description
DiffInterface $d None

Returns: int


__toString App\Yr\Forecast\Tabular\Time\AbstractUnit
public function __toString();

Returns: string


CustomUnit App\Yr\Forecast\Tabular\Time

Custom unit, only used to operate on units of same kind

Classes should transform this (see {@AbstractUnit}) to the correct class again after operation.

Pressure App\Yr\Forecast\Tabular\Time

Airpressure

Methods

Name Return Access Description
__construct public
isLowPressure bool public Check if the pressure is below normal pressure
isHighPressure bool public Check if the pressure is above normal pressure
diff int public Note! Working on floats, so operates on 100-times value.

Method details

__construct App\Yr\Forecast\Tabular\Time\Pressure
public function __construct(SimpleXMLElement $xml);

Parameters

Type Variable Description
SimpleXMLElement $xml XML containing the pressure

isLowPressure App\Yr\Forecast\Tabular\Time\Pressure
public function isLowPressure();

Check if the pressure is below normal pressure

Returns: bool


isHighPressure App\Yr\Forecast\Tabular\Time\Pressure
public function isHighPressure();

Check if the pressure is above normal pressure

Returns: bool


diff App\Yr\Forecast\Tabular\Time\Pressure
public function diff(DiffInterface $d);

Note! Working on floats, so operates on 100-times value.

{@inheritDoc}

Parameters

Type Variable Description
DiffInterface $d None

Returns: int


Symbol App\Yr\Forecast\Tabular\Time

Contains the sky data, e.g «Clody» etc

Methods

Name Return Access Description
__construct public
getNumber int public Retuns the type identifier
getName string public Returns the name, e.g «clody».
getVar string public Return the var-variable
diff int public Check for differences with another DiffInterface.
__toString string public

Method details

__construct App\Yr\Forecast\Tabular\Time\Symbol
public function __construct(SimpleXMLElement $xml);

Parameters

Type Variable Description
SimpleXMLElement $xml XML containing the symbol data

getNumber App\Yr\Forecast\Tabular\Time\Symbol
public function getNumber();

Retuns the type identifier

Returns: int


getName App\Yr\Forecast\Tabular\Time\Symbol
public function getName();

Returns the name, e.g «clody».

Returns: string


getVar App\Yr\Forecast\Tabular\Time\Symbol
public function getVar();

Return the var-variable

Returns: string


diff App\Yr\Forecast\Tabular\Time\Symbol
public function diff(DiffInterface $s);

Check for differences with another DiffInterface.

The method should check that the objects is the same.

Parameters

Type Variable Description
DiffInterface $s None

Returns: int


__toString App\Yr\Forecast\Tabular\Time\Symbol
public function __toString();

Returns: string


Temperature App\Yr\Forecast\Tabular\Time

Temperature

Methods

Name Return Access Description
__construct public
convertTo ConvertableInterface public Convert the to a different unit
getDegree string public Return the ⁰X symbol

Method details

__construct App\Yr\Forecast\Tabular\Time\Temperature
public function __construct(SimpleXMLElement null $xml);

Parameters

Type Variable Description
SimpleXMLElement null $xml XML containing the temperature

convertTo App\Yr\Forecast\Tabular\Time\Temperature
public function convertTo(string $unit);

Convert the to a different unit

Parameters

Type Variable Description
string $unit The unit to convert to, eg UNIT_FTS

Returns: ConvertableInterface


getDegree App\Yr\Forecast\Tabular\Time\Temperature
public function getDegree();

Return the ⁰X symbol

Returns: string


WindDirection App\Yr\Forecast\Tabular\Time

Wind direction

Methods

Name Return Access Description
__construct public
getName string public Returns the wind direction in full,e.g «Northeast».
getDirection int public Returns a direction on the compass, notin degree, but in interger between 1 - 16,each explining which spectre.
diff int public Note! Working on floats, so operates on 100-times value.

Method details

__construct App\Yr\Forecast\Tabular\Time\WindDirection
public function __construct(SimpleXMLElement $xml);

Parameters

Type Variable Description
SimpleXMLElement $xml XML element containing the wind direction

getName App\Yr\Forecast\Tabular\Time\WindDirection
public function getName();

Returns the wind direction in full, e.g «Northeast».

Returns: string


getDirection App\Yr\Forecast\Tabular\Time\WindDirection
public function getDirection();

Returns a direction on the compass, not in degree, but in interger between 1 - 16, each explining which spectre.

E.g 1: North, 2: North-northeast, 3: North-east, [...] 9: South etc..

Returns: int


diff App\Yr\Forecast\Tabular\Time\WindDirection
public function diff(DiffInterface $d);

Note! Working on floats, so operates on 100-times value.

{@inheritDoc}

Parameters

Type Variable Description
DiffInterface $d None

Returns: int


WindSpeed App\Yr\Forecast\Tabular\Time

Wind speed

Methods

Name Return Access Description
__construct public
convertTo ConvertableInterface public Convert the to a different unit
getName string public Returns the wind name, e.g «light breeze»
setName WindSpeed protected Used on conversion
diff int public Note! Working on floats, so operates on 100-times value.
__toString string public

Method details

__construct App\Yr\Forecast\Tabular\Time\WindSpeed
public function __construct(SimpleXMLElement $xml);

Parameters

Type Variable Description
SimpleXMLElement $xml XML containing the wind spedd

convertTo App\Yr\Forecast\Tabular\Time\WindSpeed
public function convertTo(string $unit);

Convert the to a different unit

Parameters

Type Variable Description
string $unit The unit to convert to, eg UNIT_FTS

Returns: ConvertableInterface


getName App\Yr\Forecast\Tabular\Time\WindSpeed
public function getName();

Returns the wind name, e.g «light breeze»

Returns: string


setName App\Yr\Forecast\Tabular\Time\WindSpeed
protected function setName(string $name);

Used on conversion

Parameters

Type Variable Description
string $name None

Returns: WindSpeed


diff App\Yr\Forecast\Tabular\Time\WindSpeed
public function diff(DiffInterface $e);

Note! Working on floats, so operates on 100-times value.

{@inheritDoc}

Parameters

Type Variable Description
DiffInterface $e None

Returns: int


__toString App\Yr\Forecast\Tabular\Time\WindSpeed
public function __toString();

Returns: string


Interfaces

ConvertableInterface App\Yr\Forecast\Tabular\Time

Implemented on units that can be converted, such as wind speed and temperature.

Methods

Name Return Access Description
convertTo ConvertableInterface public Convert the to a different unit

Method details

convertTo App\Yr\Forecast\Tabular\Time\ConvertableInterface
public function convertTo(string $unit);

Convert the to a different unit

Parameters

Type Variable Description
string $unit The unit to convert to, eg UNIT_FTS

Returns: ConvertableInterface


DiffInterface App\Yr\Forecast\Tabular\Time

Defines that an entity can be checked for differences agains another entity.

Methods

Name Return Access Description
diff int public Check for differences with another DiffInterface.

Method details

diff App\Yr\Forecast\Tabular\Time\DiffInterface
public function diff(DiffInterface $e);

Check for differences with another DiffInterface.

The method should check that the objects is the same.

Parameters

Type Variable Description
DiffInterface $e The object to check agains

Returns: int


App\Yr\Forecast\Tabular\Variation

Classes

Variation App\Yr\Forecast\Tabular\Variation

Methods

Name Return Access Description
__construct public
addEntity Variation public
getTime Time public
getIntersection DiffInterface v null public
isEmpty bool public
getIterator enerator public

Method details

__construct App\Yr\Forecast\Tabular\Variation\Variation
public function __construct(Time $t);

Parameters

Type Variable Description
Time $t None

addEntity App\Yr\Forecast\Tabular\Variation\Variation
public function addEntity(DiffInterface $entity, DiffInterface null $intersects);

Parameters

Type Variable Description
DiffInterface $entity None
DiffInterface null $intersects None

Returns: Variation


getTime App\Yr\Forecast\Tabular\Variation\Variation
public function getTime();

Returns: Time


getIntersection App\Yr\Forecast\Tabular\Variation\Variation
public function getIntersection(DiffInterface $entity);

Parameters

Type Variable Description
DiffInterface $entity None

Returns: DiffInterface v null


isEmpty App\Yr\Forecast\Tabular\Variation\Variation
public function isEmpty();

Returns: bool


getIterator App\Yr\Forecast\Tabular\Variation\Variation
public function getIterator();

Returns: enerator