source: trunk/temp/meteo/load_meteo.php@ 488

Last change on this file since 488 was 488, checked in by chronos, 12 years ago
  • Upraveno: Vylepšení zobrazení stavu meteostanice.
File size: 3.9 KB
Line 
1<?php
2
3include('Image.php');
4
5class MeteoStation
6{
7 var $Id;
8 var $Name;
9 var $Period;
10 var $URL;
11
12 function LoadTestData()
13 {
14 $Data = array('MeteoStation' => $this->Id,
15 'WindSpeed' => 1.4,
16 'WindDir' => 3,
17 'WindGust' => 1.5,
18 'Pressure' => 979.8,
19 'SysTemp' => 9.9,
20 'Temperature' => 1.4,
21 'BarAltitude' => 581.0,
22 'WindChill' => 1.4,
23 'RelHumidity' => 92.6,
24 'AbsHumidity' => 4.6,
25 'DewPoint' => 0.4,
26 'Time' => time(),
27 );
28 $this->Data = $Data;
29 }
30
31 function DownloadData()
32 {
33 $XmlData = simplexml_load_file($this->URL);
34
35 $Data = array('MeteoStation' => $this->Id,
36 'WindSpeed' => trim($XmlData->windspeed),
37 'WindDir' => trim($XmlData->winddir),
38 'WindGust' => trim($XmlData->windgust),
39 'Pressure' => trim($XmlData->pressure),
40 'SysTemp' => trim($XmlData->systemp),
41 'Temperature' => trim($XmlData->temperature),
42 'BarAltitude' => trim($XmlData->baraltitude),
43 'WindChill' => trim($XmlData->windchill),
44 'RelHumidity' => trim($XmlData->relhumidity),
45 'AbsHumidity' => trim($XmlData->abshumidity),
46 'DewPoint' => trim($XmlData->dewpoint),
47 'Time' => time(),
48 );
49 $this->Data = $Data;
50 }
51
52 function SaveDataToDb()
53 {
54 $this->Database->insert('MeteoStationMeasure', array(
55 'Time' => TimeToMysqlDateTime(time()), 'MeteoStation' => $this->Data['MeteoStation'],
56 'WindSpeed' => $this->Data['WindSpeed'], 'WindDir' => $this->Data['WindDir'],
57 'WindGust' => $this->Data['WindGust'], 'Pressure' => $this->Data['Pressure'],
58 'SysTemp' => $this->Data['SysTemp'], 'Temperature' => $this->Data['Temperature'],
59 'BarAltitude' => $this->Data['BarAltitude'], 'WindChill' => $this->Data['WindChill'],
60 'RelHumidity' => $this->Data['RelHumidity'], 'AbsHumidity' => $this->Data['AbsHumidity'],
61 'DewPoint' => $this->Data['DewPoint']));
62 }
63
64 function CreateImage($FileName)
65 {
66 $Width = 150;
67 $Height = 150;
68 $Image = new Image();
69 $Image->SetSize($Width, $Height);
70 $Image->Brush->Color = COLOR_WHITE;
71 $Image->FillRect(0, 0, $Width, $Height);
72 $Image->Pen->Color = COLOR_BLUE;
73 $Image->Line(0, 0, 0, $Height - 1);
74 $Image->Line($Width - 1, 0, $Width - 1, $Height - 1);
75 $Image->Line(0, $Height - 1, $Width - 1, $Height - 1);
76 $Image->Line(0, 0, $Width - 1, 0);
77 $Image->Line(0, 16, $Width - 1, 16);
78 $Image->Font->Color = COLOR_BLACK;
79 $Image->TextOut(($Width - $Image->TextWidth($this->Name)) / 2, 13, $this->Name);
80 $Image->Font->Size = 30;
81 $Text = $this->Data['Temperature'].'°C';
82 $Image->TextOut(($Width - $Image->TextWidth($Text)) / 2, 56, $Text);
83 $Image->Font->Size = 10;
84 $Text = 'Pocitová: '.$this->Data['Temperature'].' °C';
85 $Image->TextOut(($Width - $Image->TextWidth($Text)) / 2, $Height - 70, $Text);
86 $Text = 'Rel. vlhkost: '.$this->Data['RelHumidity'].' %';
87 $Image->TextOut(($Width - $Image->TextWidth($Text)) / 2, $Height - 54, $Text);
88 $Text = 'Tlak: '.$this->Data['Pressure'].' hPa';
89 $Image->TextOut(($Width - $Image->TextWidth($Text)) / 2, $Height - 38, $Text);
90 $Text = 'Vítr: '.$this->Data['WindSpeed'].' m/s';
91 $Image->TextOut(($Width - $Image->TextWidth($Text)) / 2, $Height - 22, $Text);
92 $Text = date("d.m.Y H:i:s", $this->Data['Time']);
93 $Image->TextOut(($Width - $Image->TextWidth($Text)) / 2, $Height - 6, $Text);
94 $Image->SaveToFile($FileName);
95 }
96
97 function LoadFromDb()
98 {
99 $DbResult = $this->Database->select('Meteostation', '*', 'Id = '.$this->Id);
100 $DbRow = $DbResult->fetch_assoc();
101 $this->Name = $DbRow['Name'];
102 $this->URL = $DbRow['URL'];
103 $this->Period = $DbRow['Period'];
104 }
105}
106
107$Meteo = new MeteoStation();
108$Meteo->URL = 'http://meteo-koliba.zdechov.net/status.xml';
109$Meteo->Name = 'Koliba Zděchov';
110//$Meteo->LoadTestData();
111$Meteo->DownloadData();
112$Meteo->CreateImage('koliba.png');
113
114?>
Note: See TracBrowser for help on using the repository browser.