Read forecast data from Yr.no.
|
|
6 years ago | |
|---|---|---|
| sami-markdown @ ea769268e2 | 6 years ago | |
| src | 6 years ago | |
| .gitignore | 6 years ago | |
| .gitmodules | 6 years ago | |
| LICENSE | 6 years ago | |
| README.md | 6 years ago | |
| composer.json | 6 years ago | |
| index.php | 6 years ago | |
| sami.conf.php | 6 years ago |
App\YrRead 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"
}]
}
| 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\Forecastpublic function __construct(string $url);
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $url | The XML url to load data from |
App\Yr\Forecastpublic function getLocation();
Returns the location data for the forecast
Returns: Location
App\Yr\Forecastfinal public function getCredit();
Return the credit to Yr.no, Meterogical Institute and NRK
Returns: array
App\Yr\Forecastpublic function getSunrise();
Returns the time when the sun rise for the location
Returns: ateTimeImmutable
App\Yr\Forecastpublic function getSunset();
Returns the time when the sun sets for the location
Returns: ateTimeImmutable
App\Yr\Forecastpublic function getLinks();
Returns links for forecasts in other formats
Returns: enerator
App\Yr\Forecastpublic function getLastUpdate();
Return the time when this forecast was last update
Returns: ateTimeImmutable
App\Yr\Forecastpublic function getNextUpdate();
Return the time when this forecast will update next
Returns: ateTimeImmutable
App\Yr\Forecastpublic function getTabular();
Get the forecast data
Returns: Tabular
App\Yr\ForecastGet 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\Locationpublic function __construct(SimpleXMLElement $xml);
Parameters
| Type | Variable | Description |
|---|---|---|
| SimpleXMLElement | $xml | The xml-part containing the location data |
App\Yr\Forecast\Locationpublic function getName();
Get the location name, e.g «Tromsø»
Returns: string
App\Yr\Forecast\Locationpublic function getType();
Get the location type, e.g «City - large town»
Returns: string
App\Yr\Forecast\Locationpublic function getCountry();
Get the location country
Returns: string
App\Yr\Forecast\Locationpublic function getTimeZone();
Get the location timezone
Returns: ateTimeZone
App\Yr\Forecast\Locationpublic function getGeoData();
Returns the geodata, in the format
[
'lat' => (float),
'lng' => (float),
'alt' => (float),
]
Returns: array
App\Yr\ForecastHolds 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 |
| 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} |
App\Yr\Forecast\Tabularpublic 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\Tabularprotected function addTime(Time $time);
Add a Time-object to the tabular
Parameters
| Type | Variable | Description |
|---|---|---|
| Time | $time | None |
Returns: Tabular
App\Yr\Forecast\Tabularpublic function getStatistics();
Get statistics for the Time-object collection
Returns: Statistics
App\Yr\Forecast\Tabularprotected function makeVariations();
Returns: Tabular
App\Yr\Forecast\Tabularpublic 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\Tabularpublic 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\Tabularpublic function getFrom();
Return the time this tabular is from
Returns: ateTimeInterface
App\Yr\Forecast\Tabularpublic function getUntil();
Return the time this tabular is until
Returns: ateTimeInterface
App\Yr\Forecast\Tabularpublic function getIterator();
Returns: enerator
App\Yr\Forecast\TabularMake 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 | |
| getHighestTemperature | Temperature | public | |
| getLowestTemperature | Temperature | public | |
| getHighestWindspeed | WindSpeed | public | |
| getLowestWindSpeed | WindSpeed | public | |
| getAverageSymbols | array | public | |
| getMostCommonSymbol | array | public |
App\Yr\Forecast\Tabular\Statisticspublic function __construct();
App\Yr\Forecast\Tabular\Statisticspublic function analyse(Time $t);
Analyse a single Time-object
Parameters
| Type | Variable | Description |
|---|---|---|
| Time | $t | The time object. |
Returns: Statistics
App\Yr\Forecast\Tabular\Statisticspublic function getAverageTemperature();
Returns: AbstractUnit
App\Yr\Forecast\Tabular\Statisticspublic function getAverageWindSpeed();
Returns: AbstractUnit
App\Yr\Forecast\Tabular\Statisticspublic function getHighestTemperature();
Returns: Temperature
App\Yr\Forecast\Tabular\Statisticspublic function getLowestTemperature();
Returns: Temperature
App\Yr\Forecast\Tabular\Statisticspublic function getHighestWindspeed();
Returns: WindSpeed
App\Yr\Forecast\Tabular\Statisticspublic function getLowestWindSpeed();
Returns: WindSpeed
App\Yr\Forecast\Tabular\Statisticspublic function getAverageSymbols();
Returns: array
App\Yr\Forecast\Tabular\Statisticspublic function getMostCommonSymbol();
Returns: array
App\Yr\Forecast\TabularForecast 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\Timepublic function __construct(SimpleXMLElement $xml);
Parameters
| Type | Variable | Description |
|---|---|---|
| SimpleXMLElement | $xml | The xml holding the time-object |
App\Yr\Forecast\Tabular\Timepublic function getPeriod();
Returns the which index in the forecast its for.
Returns: int
App\Yr\Forecast\Tabular\Timepublic function getFrom();
Returns the time this forecast is from
Returns: ateTimeImmutable
App\Yr\Forecast\Tabular\Timepublic function getUntil();
Returns the time this forecast is to/until.
Returns: ateTimeImmutable
App\Yr\Forecast\Tabular\Timepublic function getSymbol();
Returns the «symbol» (e.g Clody etc)
Returns: Symbol
App\Yr\Forecast\Tabular\Timepublic function getWindDirection();
Returns the wind direction
Returns: WindDirection
App\Yr\Forecast\Tabular\Timepublic function getWindSpeed();
Returns the wind speed
Returns: WindSpeed
App\Yr\Forecast\Tabular\Timepublic function getTemperature();
Returns the temperature
Returns: Temperature
App\Yr\Forecast\Tabular\Timepublic function getPressure();
Returns the pressure
Returns: Pressure
App\Yr\Forecast\Tabular\Timepublic function getIterator();
Returns: enerator
App\Yr\Forecast\Tabular\Timepublic function __toString();
Returns: string
App\Yr\Forecast\TabularRemoves superfluous forecast data in an Time-object only storing changes.
| Name | Return | Access | Description |
|---|---|---|---|
| __construct | public | ||
| getTime | Time | public | |
| getData | array | public | Returns the changes in the forecast |
App\Yr\Forecast\Tabular\Variationspublic function __construct(array $t);
Parameters
| Type | Variable | Description |
|---|---|---|
| array | $t | Array of Time-objects |
App\Yr\Forecast\Tabular\Variationspublic function getTime();
Returns: Time
App\Yr\Forecast\Tabular\Variationspublic function getData(callable $filterFn = null);
Returns the changes in the forecast
Parameters
| Type | Variable | Description |
|---|---|---|
| callable | $filterFn | None |
Returns: array
App\Yr\Forecast\Tabular\TimeTime-object entity should inherit this
| 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 |
App\Yr\Forecast\Tabular\Time\AbstractUnitpublic function __construct(float $value, string $unit);
Parameters
| Type | Variable | Description |
|---|---|---|
| float | $value | The value |
| string | $unit | The unit |
App\Yr\Forecast\Tabular\Time\AbstractUnitprotected function transformClass(CustomUnit $cu);
Transform custom unit to self
Parameters
| Type | Variable | Description |
|---|---|---|
| CustomUnit | $cu | None |
Returns: AbstractUnit
App\Yr\Forecast\Tabular\Time\AbstractUnitpublic function add(AbstractUnit $with);
Addition method
Parameters
| Type | Variable | Description |
|---|---|---|
| AbstractUnit | $with | Unit to add with |
Returns: AbstractUnit
App\Yr\Forecast\Tabular\Time\AbstractUnitpublic function sub(AbstractUnit $with);
Subtraction method
Parameters
| Type | Variable | Description |
|---|---|---|
| AbstractUnit | $with | Unit to sub with |
Returns: AbstractUnit
App\Yr\Forecast\Tabular\Time\AbstractUnitpublic function mul(AbstractUnit $with);
Multiplication method
Parameters
| Type | Variable | Description |
|---|---|---|
| AbstractUnit | $with | Unit to multiply with |
Returns: AbstractUnit
App\Yr\Forecast\Tabular\Time\AbstractUnitpublic function div(AbstractUnit $with);
Divide method
Parameters
| Type | Variable | Description |
|---|---|---|
| AbstractUnit | $with | Unit to divide with |
Returns: AbstractUnit
App\Yr\Forecast\Tabular\Time\AbstractUnitpublic function getValue();
Get the value
Returns: float
App\Yr\Forecast\Tabular\Time\AbstractUnitpublic function getUnit();
Return the unit (e.g «degree»)
Returns: string
App\Yr\Forecast\Tabular\Time\AbstractUnitpublic function diff(DiffInterface $d);
Note! Working on floats, so operates on 100-times value.
Parameters
| Type | Variable | Description |
|---|---|---|
| DiffInterface | $d | None |
Returns: int
App\Yr\Forecast\Tabular\Time\AbstractUnitpublic function __toString();
Returns: string
App\Yr\Forecast\Tabular\TimeCustom unit, only used to operate on units of same kind
Classes should transform this (see {@AbstractUnit}) to the correct class again after operation.
App\Yr\Forecast\Tabular\TimeAirpressure
| 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. |
App\Yr\Forecast\Tabular\Time\Pressurepublic function __construct(SimpleXMLElement $xml);
Parameters
| Type | Variable | Description |
|---|---|---|
| SimpleXMLElement | $xml | XML containing the pressure |
App\Yr\Forecast\Tabular\Time\Pressurepublic function isLowPressure();
Check if the pressure is below normal pressure
Returns: bool
App\Yr\Forecast\Tabular\Time\Pressurepublic function isHighPressure();
Check if the pressure is above normal pressure
Returns: bool
App\Yr\Forecast\Tabular\Time\Pressurepublic function diff(DiffInterface $d);
Note! Working on floats, so operates on 100-times value.
Parameters
| Type | Variable | Description |
|---|---|---|
| DiffInterface | $d | None |
Returns: int
App\Yr\Forecast\Tabular\TimeContains 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\Symbolpublic function __construct(SimpleXMLElement $xml);
Parameters
| Type | Variable | Description |
|---|---|---|
| SimpleXMLElement | $xml | XML containing the symbol data |
App\Yr\Forecast\Tabular\Time\Symbolpublic function getNumber();
Retuns the type identifier
Returns: int
App\Yr\Forecast\Tabular\Time\Symbolpublic function getName();
Returns the name, e.g «clody».
Returns: string
App\Yr\Forecast\Tabular\Time\Symbolpublic function getVar();
Return the var-variable
Returns: string
App\Yr\Forecast\Tabular\Time\Symbolpublic 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\Symbolpublic function __toString();
Returns: string
App\Yr\Forecast\Tabular\TimeTemperature
| Name | Return | Access | Description |
|---|---|---|---|
| __construct | public | ||
| convertTo | ConvertableInterface | public | Convert the to a different unit |
| getDegree | string | public | Return the ⁰X symbol |
App\Yr\Forecast\Tabular\Time\Temperaturepublic function __construct(SimpleXMLElement null $xml);
Parameters
| Type | Variable | Description |
|---|---|---|
| SimpleXMLElement null | $xml | XML containing the temperature |
App\Yr\Forecast\Tabular\Time\Temperaturepublic 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
App\Yr\Forecast\Tabular\Time\Temperaturepublic function getDegree();
Return the ⁰X symbol
Returns: string
App\Yr\Forecast\Tabular\TimeWind direction
| 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. |
App\Yr\Forecast\Tabular\Time\WindDirectionpublic function __construct(SimpleXMLElement $xml);
Parameters
| Type | Variable | Description |
|---|---|---|
| SimpleXMLElement | $xml | XML element containing the wind direction |
App\Yr\Forecast\Tabular\Time\WindDirectionpublic function getName();
Returns the wind direction in full, e.g «Northeast».
Returns: string
App\Yr\Forecast\Tabular\Time\WindDirectionpublic 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
App\Yr\Forecast\Tabular\Time\WindDirectionpublic function diff(DiffInterface $d);
Note! Working on floats, so operates on 100-times value.
Parameters
| Type | Variable | Description |
|---|---|---|
| DiffInterface | $d | None |
Returns: int
App\Yr\Forecast\Tabular\TimeWind speed
| 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 |
App\Yr\Forecast\Tabular\Time\WindSpeedpublic function __construct(SimpleXMLElement $xml);
Parameters
| Type | Variable | Description |
|---|---|---|
| SimpleXMLElement | $xml | XML containing the wind spedd |
App\Yr\Forecast\Tabular\Time\WindSpeedpublic 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
App\Yr\Forecast\Tabular\Time\WindSpeedpublic function getName();
Returns the wind name, e.g «light breeze»
Returns: string
App\Yr\Forecast\Tabular\Time\WindSpeedprotected function setName(string $name);
Used on conversion
Parameters
| Type | Variable | Description |
|---|---|---|
| string | $name | None |
Returns: WindSpeed
App\Yr\Forecast\Tabular\Time\WindSpeedpublic function diff(DiffInterface $e);
Note! Working on floats, so operates on 100-times value.
Parameters
| Type | Variable | Description |
|---|---|---|
| DiffInterface | $e | None |
Returns: int
App\Yr\Forecast\Tabular\Time\WindSpeedpublic function __toString();
Returns: string
App\Yr\Forecast\Tabular\TimeImplemented on units that can be converted, such as wind speed and temperature.
| Name | Return | Access | Description |
|---|---|---|---|
| convertTo | ConvertableInterface | public | Convert the to a different unit |
App\Yr\Forecast\Tabular\Time\ConvertableInterfacepublic 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
App\Yr\Forecast\Tabular\TimeDefines 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\DiffInterfacepublic 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| Name | Return | Access | Description |
|---|---|---|---|
| __construct | public | ||
| addEntity | Variation | public | |
| getTime | Time | public | |
| getIntersection | DiffInterface v null | public | |
| isEmpty | bool | public | |
| getIterator | enerator | public |
App\Yr\Forecast\Tabular\Variation\Variationpublic function __construct(Time $t);
Parameters
| Type | Variable | Description |
|---|---|---|
| Time | $t | None |
App\Yr\Forecast\Tabular\Variation\Variationpublic function addEntity(DiffInterface $entity, DiffInterface null $intersects);
Parameters
| Type | Variable | Description |
|---|---|---|
| DiffInterface | $entity | None |
| DiffInterface null | $intersects | None |
Returns: Variation
App\Yr\Forecast\Tabular\Variation\Variationpublic function getTime();
Returns: Time
App\Yr\Forecast\Tabular\Variation\Variationpublic function getIntersection(DiffInterface $entity);
Parameters
| Type | Variable | Description |
|---|---|---|
| DiffInterface | $entity | None |
Returns: DiffInterface v null
App\Yr\Forecast\Tabular\Variation\Variationpublic function isEmpty();
Returns: bool
App\Yr\Forecast\Tabular\Variation\Variationpublic function getIterator();
Returns: enerator