[Phphtmllib-devel] SF.net SVN: phphtmllib:[3491] trunk/open2300/lib/modules/api/ AviationWeather.in
Status: Beta
Brought to you by:
hemna
|
From: <he...@us...> - 2010-06-17 17:07:19
|
Revision: 3491
http://phphtmllib.svn.sourceforge.net/phphtmllib/?rev=3491&view=rev
Author: hemna
Date: 2010-06-17 17:07:12 +0000 (Thu, 17 Jun 2010)
Log Message:
-----------
updates
Modified Paths:
--------------
trunk/open2300/lib/modules/api/AviationWeather.inc
Modified: trunk/open2300/lib/modules/api/AviationWeather.inc
===================================================================
--- trunk/open2300/lib/modules/api/AviationWeather.inc 2010-06-17 16:47:32 UTC (rev 3490)
+++ trunk/open2300/lib/modules/api/AviationWeather.inc 2010-06-17 17:07:12 UTC (rev 3491)
@@ -15,13 +15,14 @@
class AviationWeather extends JSONWidget {
const ID = "avwx";
+ const METAR_CACHE_TIMEOUT = 300;
- //protected $url = "http://api.itimeteo.com/getMetar.ims?icao=XX_ICAO_XX&decoded=true&displayAirport=true&format=json";
-
//list of airports to fetch.
protected $airports;
protected $metars = array();
+
+ protected $timer = NULL;
private $cache;
@@ -32,6 +33,7 @@
}
$this->cache = AirportCache::singleton();
+ //$this->timer = new Timer();
}
public function build_object() {
@@ -39,7 +41,9 @@
$size = count($this->airports);
if ($size > 0) {
foreach($this->airports as $icao) {
+ //$this->timer->start();
$airport = $this->process_airport($icao);
+ //echo "Time took ".$this->timer->get_elapsed()."<br>";
$this->metars[] = $airport;
}
}
@@ -63,19 +67,14 @@
$wxInfo["altitude"] = $airport["elevation"];
- if (!isset($airport["details"])) {
+ if (!isset($airport["details"]) || true) {
$info = $this->get_airport_info($icao);
- var_dump($info);
if (!is_null($info)) {
$airport["details"] = 1;
$wxInfo = array_merge($wxInfo, $info);
$this->cache->set($icao,$airport);
}
}
-
- if (isset($airport["details"])) {
- var_dump($airport["details"]);
- }
}
//$this->metars[] = $wxInfo;
//need to combine this info w/ the airport data cache.
@@ -139,24 +138,18 @@
$runway["crosswind"] = $q."kt ".$runway["xw_direction"];
$runway["headwind"] = $m."kt ".$runway["xw_head"];
-//
-// l = Rway.runwayd.value;
-// n = Rway.wdirection.value;
-// k = Rway.wspeed.value;
-// o = Math.abs(n - l);
-// oo = (n - l); //determine left or right relative wind
-// p = .0174*o;
-// q = Math.abs(k*(Math.sin(p)));
-// m = Math.abs(k*(Math.cos(p)));
-// Rway.cwresult.value=eval(Math.round(q));
-//
-// Rway.cwresultloss.value=eval(Math.round(m));
-
return $xw;
}
public function get_metar($station, &$wxInfo) {
+
+ $cache_key = "METAR_".$station;
+
+ $metar = $this->cache->get($cache_key);
+ if ($metar) {
+ return $metar;
+ }
// This function retrieves METAR information for a given station from the
// National Weather Service. It assumes that the station exists.
// A slower URL is "ftp://weather.noaa.gov/data/observations/metar/stations/$station.TXT"
@@ -181,6 +174,8 @@
}
$metar = trim(str_replace(' ', ' ', $metar));
}
+
+ $this->cache->set($cache_key, $metar, AviationWeather::METAR_CACHE_TIMEOUT);
return $metar;
}
@@ -568,7 +563,7 @@
$info = null;
//they will fail always unless the icao is 4 chars...lame.
if (strlen($icao) == 4) {
- echo "\nfetch $icao";
+ //echo "\nfetch $icao";
$url = "http://api.itimeteo.com/getAirport.ims?format=json&icao=".strtoupper($icao);
@@ -581,13 +576,13 @@
$raw = file_get_contents($url,0, $context);
$json = json_decode($raw);
- echo "\rfetch $icao ".$json->status;
- var_dump($json);
+ //echo "\rfetch $icao ".$json->status;
+ //var_dump($json);
if ($json->Status == 200) {
$info = array("Name" => $json->Airport->Name,
"GeonameID" => $json->Airport->GeonameID,
"Timezone" => $json->Airport->Timezone,
- "TimezoneOffset" => $this->get_timezone_offset($info->Timezone, "GMT"),
+ "TimezoneOffset" => $this->get_timezone_offset("GMT",$json->Airport->Timezone),
"Latitude" => $json->Airport->Latitude,
"Longitude" => $json->Airport->Longitude);
return $info;
@@ -611,7 +606,7 @@
$origin_dt = new DateTime("now", $origin_dtz);
$remote_dt = new DateTime("now", $remote_dtz);
$offset = $origin_dtz->getOffset($origin_dt) - $remote_dtz->getOffset($remote_dt);
- return $offset;
+ return $offset/3600;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|