1 | <?php
|
---|
2 |
|
---|
3 | class PageMeteo extends Page
|
---|
4 | {
|
---|
5 | function __construct(System $System)
|
---|
6 | {
|
---|
7 | parent::__construct($System);
|
---|
8 | $this->Title = 'Meteostanice';
|
---|
9 | $this->Description = 'Stav meteostanice';
|
---|
10 | $this->ParentClass = 'PagePortal';
|
---|
11 | }
|
---|
12 |
|
---|
13 | function Show(): string
|
---|
14 | {
|
---|
15 | $Output = 'Stav meteostanice:<br/>';
|
---|
16 | $Output .= '<img src="'.$this->System->Link('/Modules/Meteostation/cache/1.png').'" alt="stav meteostanice"/>';
|
---|
17 | return $Output;
|
---|
18 | }
|
---|
19 | }
|
---|
20 |
|
---|
21 | class MeteoStation extends Model
|
---|
22 | {
|
---|
23 | public int $Id;
|
---|
24 | public string $Name;
|
---|
25 | public int $Period;
|
---|
26 | public string $URL;
|
---|
27 |
|
---|
28 | function DownloadData(): void
|
---|
29 | {
|
---|
30 | $XmlData = simplexml_load_file($this->URL);
|
---|
31 |
|
---|
32 | $Data = array('MeteoStation' => $this->Id,
|
---|
33 | 'WindSpeed' => trim($XmlData->windspeed),
|
---|
34 | 'WindDir' => trim($XmlData->winddir),
|
---|
35 | 'WindGust' => trim($XmlData->windgust),
|
---|
36 | 'Pressure' => trim($XmlData->pressure),
|
---|
37 | 'SysTemp' => trim($XmlData->systemp),
|
---|
38 | 'Temperature' => trim($XmlData->temperature),
|
---|
39 | 'BarAltitude' => trim($XmlData->baraltitude),
|
---|
40 | 'WindChill' => trim($XmlData->windchill),
|
---|
41 | 'RelHumidity' => trim($XmlData->relhumidity),
|
---|
42 | 'AbsHumidity' => trim($XmlData->abshumidity),
|
---|
43 | 'DewPoint' => trim($XmlData->dewpoint)
|
---|
44 | );
|
---|
45 | $this->Database->insert('MeteoStationMeasure', array(
|
---|
46 | 'Time' => TimeToMysqlDateTime(time()), 'MeteoStation' => $Data['MeteoStation'],
|
---|
47 | 'WindSpeed' => $Data['WindSpeed'], 'WindDir' => $Data['WindDir'],
|
---|
48 | 'WindGust' => $Data['WindGust'], 'Pressure' => $Data['Pressure'],
|
---|
49 | 'SysTemp' => $Data['SysTemp'], 'Temperature' => $Data['Temperature'],
|
---|
50 | 'BarAltitude' => $Data['BarAltitude'], 'WindChill' => $Data['WindChill'],
|
---|
51 | 'RelHumidity' => $Data['RelHumidity'], 'AbsHumidity' => $Data['AbsHumidity'],
|
---|
52 | 'DewPoint' => $Data['DewPoint']));
|
---|
53 | $this->Data = $Data;
|
---|
54 | }
|
---|
55 |
|
---|
56 | function CreateImage(string $FileName): void
|
---|
57 | {
|
---|
58 | $Image = new Image();
|
---|
59 | $Image->SetSize(150, 150);
|
---|
60 | $Image->Brush->Color = COLOR_WHITE;
|
---|
61 | $Image->FillRect(0, 0, $Image->GetWidth(), $Image->GetHeight());
|
---|
62 | //$Image->Font->Color = COLOR_RED;
|
---|
63 | //$Image->Line(10, 10, 100, 100);
|
---|
64 | $Image->TextOut(10, 10, 'Meteo '.$this->Name);
|
---|
65 | $Image->TextOut(10, 30, 'Teplote: '.$this->Data['Temperature'].' °C');
|
---|
66 | $Image->SaveToFile($FileName);
|
---|
67 | }
|
---|
68 |
|
---|
69 | function LoadFromDb(): void
|
---|
70 | {
|
---|
71 | $DbResult = $this->Database->select('Meteostation', '*', 'Id = '.$this->Id);
|
---|
72 | $DbRow = $DbResult->fetch_assoc();
|
---|
73 | $this->Name = $DbRow['Name'];
|
---|
74 | $this->URL = $DbRow['URL'];
|
---|
75 | $this->Period = $DbRow['Period'];
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | class ModuleMeteoStation extends Module
|
---|
80 | {
|
---|
81 | function __construct(System $System)
|
---|
82 | {
|
---|
83 | parent::__construct($System);
|
---|
84 | $this->Name = 'MeteoStation';
|
---|
85 | $this->Version = '1.0';
|
---|
86 | $this->Creator = 'Chronos';
|
---|
87 | $this->License = 'GNU/GPLv3';
|
---|
88 | $this->Description = 'Gathering and presentation of data from network meteostation.';
|
---|
89 | }
|
---|
90 |
|
---|
91 | function DownloadAll(): void
|
---|
92 | {
|
---|
93 | $DbResult = $this->Database->select('MeteoStation', '*');
|
---|
94 | while ($DbRow = $DbResult->fetch_assoc())
|
---|
95 | {
|
---|
96 | $MeteoStation = new MeteoStation($this->System);
|
---|
97 | $MeteoStation->Id = $DbRow['Id'];
|
---|
98 | $MeteoStation->LoadFromDb();
|
---|
99 | $MeteoStation->DownloadData();
|
---|
100 | $MeteoStation->CreateImage('cache/'.$DbRow['Id'].'.png');
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | function DoStart(): void
|
---|
105 | {
|
---|
106 | $this->System->RegisterPage(['meteo'], 'PageMeteo');
|
---|
107 | }
|
---|
108 | }
|
---|