-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWeatherData.php
More file actions
149 lines (115 loc) · 3.29 KB
/
WeatherData.php
File metadata and controls
149 lines (115 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
namespace ProgrammatorDev\OpenWeatherMap\Entity\Weather;
use ProgrammatorDev\OpenWeatherMap\Entity\Condition;
use ProgrammatorDev\OpenWeatherMap\Entity\Wind;
use ProgrammatorDev\OpenWeatherMap\Util\EntityTrait;
class WeatherData
{
use EntityTrait;
private \DateTimeImmutable $dateTime;
private float $temperature;
private float $temperatureFeelsLike;
private float $minTemperature;
private float $maxTemperature;
private int $humidity;
private int $cloudiness;
private int $visibility;
private int $atmosphericPressure;
/** @var Condition[] */
private array $conditions;
private Wind $wind;
private ?int $precipitationProbability;
private ?float $rainVolume;
private ?float $snowVolume;
public function __construct(array $data)
{
$this->dateTime = \DateTimeImmutable::createFromFormat('U', $data['dt']);
$this->temperature = $data['main']['temp'];
$this->temperatureFeelsLike = $data['main']['feels_like'];
$this->minTemperature = $data['main']['temp_min'];
$this->maxTemperature = $data['main']['temp_max'];
$this->humidity = $data['main']['humidity'];
$this->cloudiness = $data['clouds']['all'];
$this->visibility = $data['visibility'];
$this->atmosphericPressure = $data['main']['pressure'];
$this->conditions = $this->createEntityList(Condition::class, $data['weather']);
$this->wind = new Wind($data['wind']);
$this->precipitationProbability = isset($data['pop'])
? round($data['pop'] * 100)
: null;
$this->rainVolume = $data['rain']['1h'] ?? $data['rain']['3h'] ?? null;
$this->snowVolume = $data['snow']['1h'] ?? $data['snow']['3h'] ?? null;
}
/**
* DateTime in UTC
*/
public function getDateTime(): \DateTimeImmutable
{
return $this->dateTime;
}
public function getTemperature(): float
{
return $this->temperature;
}
public function getTemperatureFeelsLike(): float
{
return $this->temperatureFeelsLike;
}
public function getMinTemperature(): float
{
return $this->minTemperature;
}
public function getMaxTemperature(): float
{
return $this->maxTemperature;
}
public function getHumidity(): int
{
return $this->humidity;
}
public function getCloudiness(): int
{
return $this->cloudiness;
}
/**
* Visibility, meters
* Maximum value is 10000
*/
public function getVisibility(): int
{
return $this->visibility;
}
/**
* Atmospheric pressure on the sea level, hPa
*/
public function getAtmosphericPressure(): int
{
return $this->atmosphericPressure;
}
public function getConditions(): array
{
return $this->conditions;
}
public function getWind(): Wind
{
return $this->wind;
}
public function getPrecipitationProbability(): ?int
{
return $this->precipitationProbability;
}
/**
* Rain volume, mm
*/
public function getRainVolume(): ?float
{
return $this->rainVolume;
}
/**
* Snow volume, mm
*/
public function getSnowVolume(): ?float
{
return $this->snowVolume;
}
}