Read forecast data from Yr.no.
Joachim M. Giæver 6a6760b53a Updated composer.json & license | 5 years ago | |
---|---|---|
sami-markdown @ ea769268e2 | 5 years ago | |
src | 5 years ago | |
.gitignore | 5 years ago | |
.gitmodules | 5 years ago | |
LICENSE | 5 years ago | |
README.md | 5 years ago | |
composer.json | 5 years ago | |
index.php | 5 years ago | |
sami.conf.php | 5 years ago |
App\Yr
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()
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 |
App\Yr\Forecast
public function __construct(string $url);
Parameters
Type | Variable | Description |
---|---|---|
string | $url | The XML url to load data from |
App\Yr\Forecast
public function getLocation();
Returns the location data for the forecast
Returns: Location
App\Yr\Forecast
final public function getCredit();
Return the credit to Yr.no, Meterogical Institute and NRK
Returns: array
App\Yr\Forecast
public function getSunrise();
Returns the time when the sun rise for the location
Returns: ateTimeImmutable
App\Yr\Forecast
public function getSunset();
Returns the time when the sun sets for the location
Returns: ateTimeImmutable
App\Yr\Forecast
public function getLinks();
Returns links for forecasts in other formats
Returns: enerator
App\Yr\Forecast
public function getLastUpdate();
Return the time when this forecast was last update
Returns: ateTimeImmutable
App\Yr\Forecast
public function getNextUpdate();
Return the time when this forecast will update next
Returns: ateTimeImmutable
App\Yr\Forecast
public function getTabular();
Get the forecast data
Returns: Tabular
App\Yr\Forecast
Get information about the location, such as name, timezone and geodata
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),] |
App\Yr\Forecast\Location
public function __construct(SimpleXMLElement $xml);
Parameters
Type | Variable | Description |
---|---|---|
SimpleXMLElement | $xml | The xml-part containing the location data |
App\Yr\Forecast\Location
public function getName();
Get the location name, e.g «Tromsø»
Returns: string
App\Yr\Forecast\Location
public function getType();
Get the location type, e.g «City - large town»
Returns: string
App\Yr\Forecast\Location
public function getCountry();
Get the location country
Returns: string
App\Yr\Forecast\Location
public function getTimeZone();
Get the location timezone
Returns: ateTimeZone
App\Yr\Forecast\Location
public function getGeoData();
Returns the geodata, in the format
[
'lat' => (float),
'lng' => (float),
'alt' => (float),
]
Returns: array
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.
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 |
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 |
getIterator | enerator | public | {@inheritDoc} |
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 |
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
App\Yr\Forecast\Tabular
public function getStatistics();
Get statistics for the Time-object collection
Returns: Statistics
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
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
App\Yr\Forecast\Tabular
public function getIterator();
Returns: enerator
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.
Name | Return | Access | Description |
---|---|---|---|
__construct | public | ||
analyse | Statistics | public | Analyse a single Time-object |
getAverageTemperature | AbstractUnit | public | |
getAverageWindSpeed | AbstractUnit | public |
App\Yr\Forecast\Tabular\Statistics
public function __construct();
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
App\Yr\Forecast\Tabular\Statistics
public function getAverageTemperature();
Returns: AbstractUnit
App\Yr\Forecast\Tabular\Statistics
public function getAverageWindSpeed();
Returns: AbstractUnit
App\Yr\Forecast\Tabular
Forecast data witin a time period
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 |
App\Yr\Forecast\Tabular\Time
public function __construct(SimpleXMLElement $xml);
Parameters
Type | Variable | Description |
---|---|---|
SimpleXMLElement | $xml | The xml holding the time-object |
App\Yr\Forecast\Tabular\Time
public function getPeriod();
Returns the which index in the forecast its for.
Returns: int
App\Yr\Forecast\Tabular\Time
public function getFrom();
Returns the time this forecast is from
Returns: ateTimeImmutable
App\Yr\Forecast\Tabular\Time
public function getUntil();
Returns the time this forecast is to/until.
Returns: ateTimeImmutable
App\Yr\Forecast\Tabular\Time
public function getSymbol();
Returns the «symbol» (e.g Clody etc)
Returns: Symbol
App\Yr\Forecast\Tabular\Time
public function getWindDirection();
Returns the wind direction
Returns: WindDirection
App\Yr\Forecast\Tabular\Time
public function getWindSpeed();
Returns the wind speed
Returns: WindSpeed
App\Yr\Forecast\Tabular\Time
public function getTemperature();
Returns the temperature
Returns: Temperature
App\Yr\Forecast\Tabular\Time
public function getPressure();
Returns the pressure
Returns: Pressure
App\Yr\Forecast\Tabular\Time
public function getIterator();
Returns: enerator
App\Yr\Forecast\Tabular\Time
public function __toString();
Returns: string
App\Yr\Forecast\Tabular
Removes superfluous forecast data in an Time-object only storing changes.
Name | Return | Access | Description |
---|---|---|---|
__construct | public | ||
getData | array | public | Returns the changes in the forecast |
App\Yr\Forecast\Tabular\Variations
public function __construct(array $t);
Parameters
Type | Variable | Description |
---|---|---|
array | $t | Array of Time-objects |
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
Time-object entity should inherit this
Name | Return | Access | Description |
---|---|---|---|
__construct | public | ||
transformClass | AbstractUnit | protected | |
add | AbstractUnit | public | Addition 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 | Check for differences with another DiffInterface. |
__toString | string | public |
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 |
App\Yr\Forecast\Tabular\Time\AbstractUnit
protected function transformClass(CustomUnit $cu);
Parameters
Type | Variable | Description |
---|---|---|
CustomUnit | $cu | None |
Returns: AbstractUnit
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
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
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
App\Yr\Forecast\Tabular\Time\AbstractUnit
public function getValue();
Get the value
Returns: float
App\Yr\Forecast\Tabular\Time\AbstractUnit
public function getUnit();
Return the unit (e.g «degree»)
Returns: string
App\Yr\Forecast\Tabular\Time\AbstractUnit
public function diff(DiffInterface $d);
Check for differences with another DiffInterface.
The method should check that the objects is the same.
Parameters
Type | Variable | Description |
---|---|---|
DiffInterface | $d | None |
Returns: int
App\Yr\Forecast\Tabular\Time\AbstractUnit
public function __toString();
Returns: string
App\Yr\Forecast\Tabular\Time
App\Yr\Forecast\Tabular\Time
Airpressure
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 | Check for differences with another DiffInterface. |
App\Yr\Forecast\Tabular\Time\Pressure
public function __construct(SimpleXMLElement $xml);
Parameters
Type | Variable | Description |
---|---|---|
SimpleXMLElement | $xml | XML containing the pressure |
App\Yr\Forecast\Tabular\Time\Pressure
public function isLowPressure();
Check if the pressure is below normal pressure
Returns: bool
App\Yr\Forecast\Tabular\Time\Pressure
public function isHighPressure();
Check if the pressure is above normal pressure
Returns: bool
App\Yr\Forecast\Tabular\Time\Pressure
public function diff(DiffInterface $d);
Check for differences with another DiffInterface.
The method should check that the objects is the same.
Parameters
Type | Variable | Description |
---|---|---|
DiffInterface | $d | None |
Returns: int
App\Yr\Forecast\Tabular\Time
Contains the sky data, e.g «Clody» etc
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 |
App\Yr\Forecast\Tabular\Time\Symbol
public function __construct(SimpleXMLElement $xml);
Parameters
Type | Variable | Description |
---|---|---|
SimpleXMLElement | $xml | XML containing the symbol data |
App\Yr\Forecast\Tabular\Time\Symbol
public function getNumber();
Retuns the type identifier
Returns: int
App\Yr\Forecast\Tabular\Time\Symbol
public function getName();
Returns the name, e.g «clody».
Returns: string
App\Yr\Forecast\Tabular\Time\Symbol
public function getVar();
Return the var-variable
Returns: string
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
App\Yr\Forecast\Tabular\Time\Symbol
public function __toString();
Returns: string
App\Yr\Forecast\Tabular\Time
Temperature
Name | Return | Access | Description |
---|---|---|---|
__construct | public |
App\Yr\Forecast\Tabular\Time\Temperature
public function __construct(SimpleXMLElement null $xml);
Parameters
Type | Variable | Description |
---|---|---|
SimpleXMLElement null | $xml | XML containing the temperature |
App\Yr\Forecast\Tabular\Time
Wind direction
Name | Return | Access | Description |
---|---|---|---|
__construct | public | ||
getName | string | public | Returns the wind direction in full,e.g «Northeast». |
diff | int | public | Check for differences with another DiffInterface. |
App\Yr\Forecast\Tabular\Time\WindDirection
public function __construct(SimpleXMLElement $xml);
Parameters
Type | Variable | Description |
---|---|---|
SimpleXMLElement | $xml | XML element containing the wind direction |
App\Yr\Forecast\Tabular\Time\WindDirection
public function getName();
Returns the wind direction in full, e.g «Northeast».
Returns: string
App\Yr\Forecast\Tabular\Time\WindDirection
public function diff(DiffInterface $d);
Check for differences with another DiffInterface.
The method should check that the objects is the same.
Parameters
Type | Variable | Description |
---|---|---|
DiffInterface | $d | None |
Returns: int
App\Yr\Forecast\Tabular\Time
Wind speed
Name | Return | Access | Description |
---|---|---|---|
__construct | public | ||
convertTo | WindSpeed | public | Convert the wind speed to a different unit |
getName | string | public | Returns the wind name, e.g «light breeze» |
setName | WindSpeed | protected | |
diff | int | public | Check for differences with another DiffInterface. |
__toString | string | public |
App\Yr\Forecast\Tabular\Time\WindSpeed
public function __construct(SimpleXMLElement $xml);
Parameters
Type | Variable | Description |
---|---|---|
SimpleXMLElement | $xml | XML containing the wind spedd |
App\Yr\Forecast\Tabular\Time\WindSpeed
public function convertTo(string $unit);
Convert the wind speed to a different unit
Parameters
Type | Variable | Description |
---|---|---|
string | $unit | The unit to convert to, eg UNIT_FTS |
Returns: WindSpeed
App\Yr\Forecast\Tabular\Time\WindSpeed
public function getName();
Returns the wind name, e.g «light breeze»
Returns: string
App\Yr\Forecast\Tabular\Time\WindSpeed
protected function setName(string $name);
Parameters
Type | Variable | Description |
---|---|---|
string | $name | None |
Returns: WindSpeed
App\Yr\Forecast\Tabular\Time\WindSpeed
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 | None |
Returns: int
App\Yr\Forecast\Tabular\Time\WindSpeed
public function __toString();
Returns: string
App\Yr\Forecast\Tabular\Time
Defines that an entity can be checked for differences agains another entity.
Name | Return | Access | Description |
---|---|---|---|
diff | int | public | Check for differences with another DiffInterface. |
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