CVS: phpweather data_retrieval.php,1.38,1.39 phpweather.php,1.38,1.39...
Brought to you by:
iridium
From: Etienne T. <eti...@us...> - 2004-01-30 20:48:12
|
Update of /cvsroot/phpweather/phpweather In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30964 Modified Files: data_retrieval.php phpweather.php test2.php Log Message: Fixed the timestamp for METAR retreival and archiving in mysql and null backends. The timestamp is kept as a unix timestamp (UTC) in the objects. The mysql backend has been modified to keep a UTC format in the table. Index: data_retrieval.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/data_retrieval.php,v retrieving revision 1.38 retrieving revision 1.39 diff -u -3 -r1.38 -r1.39 --- data_retrieval.php 3 Jan 2004 19:05:15 -0000 1.38 +++ data_retrieval.php 30 Jan 2004 20:46:36 -0000 1.39 @@ -24,7 +24,7 @@ * @see set_metar() */ var $metar; - //var $metar_time; + var $metar_time; var $metar_arch; /** @@ -67,7 +67,7 @@ $this->set_icao($this->properties['icao']); $this->metar = false; - //$this->metar_time = false; + $this->metar_time = false; $this->metar_arch = false; $this->time_from = false; $this->time_to = false; @@ -104,7 +104,7 @@ $this->properties['icao'] = strtoupper($new_icao); $this->icao_data = false; $this->metar = false; - //$this->metar_time = false; + $this->metar_time = false; $this->decoded_metar = false; $this->metar_arch = false; $this->taf = false; @@ -284,14 +284,14 @@ $this->debug('get_metar_from_db(): Found the METAR in the database'); list($metar, $timestamp, $time) = end($data); reset($data); - + /* We set the METAR right away, and then count on * get_metar_from_web() to set it to something else, if * necessary. */ $tmp_metar = $metar; $this->metar = $metar; - //$this->metar_time = $time; + $this->metar_time = $time; if ($this->properties['always_use_db'] || $timestamp > time() - $this->properties['cache_timeout']) { @@ -368,6 +368,7 @@ if (!empty($metar_data)) { /* The first line in the file is the date */ $date = trim(array_shift($metar_data)); + /* The remaining lines are the METAR itself. This will merge the * remaining lines into one line by removing new-lines: */ @@ -385,6 +386,7 @@ } $timestamp = gmmktime($date[3], $date[4], 0, $date[1], $date[2], $date[0]); + $metar_time = $timestamp; if (!ereg('[0-9]{6}Z', $metar)) { /* Some reports don't even have a time-part, so we insert the @@ -417,22 +419,19 @@ $timestamp = time() - $this->properties['cache_timeout'] + 600; } - /* side effect */ - //$metar_time = $date[0].$date[1].$date[2].$date[3].$date[4]."00"; - /* We then cache the METAR in our database */ if ($new_station) { $this->debug('get_metar_from_web(): Inserting new METAR for <code>' . $this->get_location() . '</code>'); - $this->db->insert_metar($icao, $metar, $timestamp); + $this->db->insert_metar($icao, $metar, $timestamp, $metar_time); } else { $this->debug('get_metar_from_web(): Updating METAR for <code>' . $this->get_location() . '</code>'); - $this->db->update_metar($icao, $metar, $timestamp); + $this->db->update_metar($icao, $metar, $timestamp, $metar_time); } /* We update and return the METAR */ $this->metar = $metar; - //$this->metar_time = $metar_time; + $this->metar_time = $metar_time; return $metar; } Index: phpweather.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/phpweather.php,v retrieving revision 1.38 retrieving revision 1.39 diff -u -3 -r1.38 -r1.39 --- phpweather.php 3 Jan 2004 19:05:15 -0000 1.38 +++ phpweather.php 30 Jan 2004 20:46:36 -0000 1.39 @@ -178,7 +178,7 @@ /* Setup other variables */ if ($index===false) { /* We are getting the current METAR */ $decoded_metar['metar'] = $tmp_metar; - //$decoded_metar['time'] = $this->metar_time; + $decoded_metar['time'] = $this->metar_time; } else { if ($this->metar_arch===false) { /* error */ @@ -220,33 +220,33 @@ * Station Identifier */ $decoded_metar['icao'] = $part; - } elseif (ereg('([0-9]{2})([0-9]{2})([0-9]{2})Z', $part, $regs)) { - /* - * Date and Time of Report. - * - * We return a standard Unix UTC/GMT timestamp suitable for - * gmdate(). - * - * If you experience incorrect timestamps but cannot set the - * clock, then you can set $this->properties['offset'] to be - * the offset in hours to add. For example, if your times - * generated are 1 hour too early (so METARs appear an hour - * older than they are), set $this->properties['offset'] to be - * +1 in your defaults.php file. - */ - - if ($regs[1] > gmdate('j')) { - /* The day is greather that the current day of month => the - * report is from last month. - */ - $month = gmdate('n') - 1; - } else { - $month = gmdate('n'); - } - - $decoded_metar['time'] = - gmmktime($regs[2] + $this->properties['offset'], - $regs[3], 0, $month, $regs[1], gmdate('Y')); +// } elseif (ereg('([0-9]{2})([0-9]{2})([0-9]{2})Z', $part, $regs)) { +// /* +// * Date and Time of Report. +// * +// * We return a standard Unix UTC/GMT timestamp suitable for +// * gmdate(). +// * +// * If you experience incorrect timestamps but cannot set the +// * clock, then you can set $this->properties['offset'] to be +// * the offset in hours to add. For example, if your times +// * generated are 1 hour too early (so METARs appear an hour +// * older than they are), set $this->properties['offset'] to be +// * +1 in your defaults.php file. +// */ + +// if ($regs[1] > gmdate('j')) { +// /* The day is greather that the current day of month => the +// * report is from last month. +// */ +// $month = gmdate('n') - 1; +// } else { +// $month = gmdate('n'); +// } + +// $decoded_metar['time'] = +// gmmktime($regs[2] + $this->properties['offset'], +// $regs[3], 0, $month, $regs[1], gmdate('Y')); } elseif (ereg('(AUTO|COR|RTD|CC[A-Z]|RR[A-Z])', $part, $regs)) { @@ -708,13 +708,13 @@ number_format($decoded_metar['humidex']['humidex_c'] * 9/5 + 32, 1); } - + /* Finally we store our decoded METAR in $this->decoded_metar so * that other methods can use it. */ if ($index===false) $this->decoded_metar = $decoded_metar; else $this->decoded_metar_arch[$index] = $decoded_metar; - + return $decoded_metar; } Index: test2.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/test2.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- test2.php 20 Sep 2003 22:18:47 -0000 1.3 +++ test2.php 30 Jan 2004 20:46:36 -0000 1.4 @@ -32,7 +32,16 @@ require(PHPWEATHER_BASE_DIR . "/output/pw_images.php"); $icons = new pw_images($weather); - $weather->decode_taf(); + + echo "METAR for $icao : ".$weather->get_metar()."<br>\n"; +// echo "<br>Decoded METAR:<pre>"; +// $weather->decode_metar(); +// print_r( $weather->decoded_metar ); +// echo "</pre><br>\n"; + +// echo "time:".$weather->decoded_metar["time"]."<br>"; +// echo "time:".tms_unix2date($weather->decoded_metar["time"])."<br>"; + echo "TAF for $icao : ".$weather->get_taf()."<br>\n"; echo "<br>Print TAF:<br><br>"; @@ -41,12 +50,10 @@ else $text->print_taf($time_from,$time_to); echo "<br>\n"; - /* - echo "METAR for $icao : ".$weather->get_metar()."<br>\n"; - echo "<br>Decoded METAR:<pre>"; - print_r( $weather->decode_metar() ); - echo "</pre><br>\n"; - */ + echo "taf: <pre>";print_r($weather->taf);echo "</pre><br>"; + $weather->decode_taf(); + echo "decoded_taf: <pre>";print_r($weather->decoded_taf);echo "</pre><br>"; + } |