[Phphtmllib-devel] SF.net SVN: phphtmllib:[3410] trunk/open2300/lib/modules
Status: Beta
Brought to you by:
hemna
From: <he...@us...> - 2010-03-03 18:06:39
|
Revision: 3410 http://phphtmllib.svn.sourceforge.net/phphtmllib/?rev=3410&view=rev Author: hemna Date: 2010-03-03 18:06:33 +0000 (Wed, 03 Mar 2010) Log Message: ----------- updates to pull out debug code Modified Paths: -------------- trunk/open2300/lib/modules/api/RemoteUpdate.inc trunk/open2300/lib/modules/home/widgets/CurrentConditions.inc trunk/open2300/lib/modules/home/widgets/RemoteMetarConditions.inc Modified: trunk/open2300/lib/modules/api/RemoteUpdate.inc =================================================================== --- trunk/open2300/lib/modules/api/RemoteUpdate.inc 2010-03-03 17:13:33 UTC (rev 3409) +++ trunk/open2300/lib/modules/api/RemoteUpdate.inc 2010-03-03 18:06:33 UTC (rev 3410) @@ -12,7 +12,7 @@ } function render($indent_level=0, $output_debug=0) { - $GLOBALS['log']->debug('RemoteUpdate called'); + //$GLOBALS['log']->debug('RemoteUpdate called'); $r = Request::singleton(); //first lets make sure we don't already have this entry @@ -46,8 +46,7 @@ //now save it to the db $wx->save(); - $GLOBALS['log']->debug('RemoteUpdate -- saved new entry.'); - + //$GLOBALS['log']->debug('RemoteUpdate -- saved new entry.'); } } ?> \ No newline at end of file Modified: trunk/open2300/lib/modules/home/widgets/CurrentConditions.inc =================================================================== --- trunk/open2300/lib/modules/home/widgets/CurrentConditions.inc 2010-03-03 17:13:33 UTC (rev 3409) +++ trunk/open2300/lib/modules/home/widgets/CurrentConditions.inc 2010-03-03 18:06:33 UTC (rev 3410) @@ -1,142 +1,141 @@ <?php /** - * This file contains the CurrentConditions + * This file contains the CurrentConditions * widget class. */ - + class CurrentConditions extends AjaxableHTMLWidget { - - /** - * This contains the current - * weatherDataObject for - * the conditions that you want to display - * - * @var weatherDataObject - */ - protected $wx; - - protected $rain_total; - - protected $temp_low_high = array("low" => 0, + + /** + * This contains the current + * weatherDataObject for + * the conditions that you want to display + * + * @var weatherDataObject + */ + protected $wx; + + protected $rain_total; + + protected $temp_low_high = array("low" => 0, "high" => 0); - /** - * Class Constructor - * - */ - public function __construct(weatherDataObject $wx=null) { - $log = Log::singleton(); - parent::__construct(); - if ($wx == null) { - //we don't have the current conditions. - //we need to get them - $this->wx = weatherDataObject::find("1=1 order by datetime desc limit 0,1"); - } else { - $this->wx = $wx; - } - - //load min max temps - $db = open2300DB::singleton(); - $today = date("Y-m-d"); - $stmt = $db->queryBindOneRowCache("Select min(temp_out) as low, max(temp_out) as high from weather where datetime like :date", - array(":date" => $today.'%')); - $this->temp_low_high["low"] = $stmt->low; - $this->temp_low_high["high"] = $stmt->high; - - $year = date("Y"); - $stmt = $db->queryBindOneRowCache("Select rain_total from weather where datetime like :date order by datetime asc limit 0,1", - array(":date" => $year.'%')); - $year_rain_start = $stmt->rain_total; - - $this->rain_total = sprintf("%0.2f", $this->wx->get_rain_total() - $year_rain_start); + /** + * Class Constructor + * + */ + public function __construct(weatherDataObject $wx=null) { + $log = Log::singleton(); + parent::__construct(); + if ($wx == null) { + //we don't have the current conditions. + //we need to get them + $this->wx = weatherDataObject::find("1=1 order by datetime desc limit 0,1"); + } else { + $this->wx = $wx; + } - //get the peak winds - //$db->set_debug_flag(true); - $sql = "select datetime,wind_speed, wind_angle, wind_direction from weather where ". + //load min max temps + $db = open2300DB::singleton(); + $today = date("Y-m-d"); + $stmt = $db->queryBindOneRowCache("Select min(temp_out) as low, max(temp_out) as high from weather where datetime like :date", + array(":date" => $today.'%')); + $this->temp_low_high["low"] = $stmt->low; + $this->temp_low_high["high"] = $stmt->high; + + $year = date("Y"); + $stmt = $db->queryBindOneRowCache("Select rain_total from weather where datetime like :date order by datetime asc limit 0,1", + array(":date" => $year.'%')); + $year_rain_start = $stmt->rain_total; + + $this->rain_total = sprintf("%0.2f", $this->wx->get_rain_total() - $year_rain_start); + + //get the peak winds + //$db->set_debug_flag(true); + $sql = "select datetime,wind_speed, wind_angle, wind_direction from weather where ". "wind_speed = (select max(wind_speed) from weather where datetime like :date) ". "and datetime like :date2"; - $stmt = $db->queryBindOneRow($sql, - array(":date" => $today.'%', - ":date2" => $today.'%')); - $log->debug(var_export($stmt,true)); - $this->peak_wind['speed'] = $stmt->wind_speed; - $this->peak_wind['angle'] = $stmt->wind_angle; - $this->peak_wind['direction'] = $stmt->wind_direction; - $this->peak_wind['time'] = substr($stmt->datetime,10); - $log->debug("peak wind was ".$stmt->wind_speed); - } - - public function get_content() { - - $div = new DIVtag(array('id'=>$this->get_ajax_replacement_divid().'contents')); + $stmt = $db->queryBindOneRow($sql, + array(":date" => $today.'%', ":date2" => $today.'%')); + //$log->debug(var_export($stmt,true)); + $this->peak_wind['speed'] = $stmt->wind_speed; + $this->peak_wind['angle'] = $stmt->wind_angle; + $this->peak_wind['direction'] = $stmt->wind_direction; + $this->peak_wind['time'] = substr($stmt->datetime,10); + //$log->debug("peak wind was ".$stmt->wind_speed); + } - //build the title - //$title = DIVtag::factory('cctitle', Atag::factory(AjaxRequestBuilder::build_replace_url('CurrentConditions', array(), $this->get_ajax_replacement_divid()), 'Current Conditions', 'linkrefresh')); - $title = DIVtag::factory('cctitle', "Current Conditions -- Updated : ", new SPANtag(array('id' => 'idUpdateSeconds'),'')); - $div->add($title); - - //now add the update block - $update_div = new DIVtag(array('id' => 'idcclastupdate'), $this->wx->get_datetime()); - $div->add($update_div); - - - $table = TABLEtag::factory("100%",0,2); - $outside_temp = $this->wx->get_temp_out(); - $table->add_row(new TDtag(array("width" => "120"),"Outside :"), - new DIVtag(array('style' => 'text-align:center; padding-top:2px;height:75px; background-color:#ffffcc;'), - new SPANtag(array('id' => 'idTempF', 'style' => 'font-weight:bold;'),$outside_temp)," F / ", - new SPANtag(array('id' => 'idTempC','style' => 'font-weight:bold;'),WXConversion::fahrenheit_to_celsius($outside_temp)),' C / ', - new SPANtag(array('id' => 'idTempK','style' => 'font-weight:bold;'),WXConversion::fahrenheit_to_kelvin($outside_temp)), " K", - BRtag::factory(), $this->wx->get_forecast(), - new DIVtag(array('style' => 'padding-top:5px;'), 'Feels like '.$this->wx->get_wind_chill()." F"), - new DIVtag(array('style' => 'padding-top:5px;'), $this->temp_low_high["low"].' F / '.$this->temp_low_high["high"].' F Low/High'))); - - $table->add_row("Relative Humidity : ", $this->wx->get_rel_hum_out().' %'); - - //wind - $table->add_row("Wind : ",new TDtag(array(), SPANtag::factory('',"From the ".$this->wx->get_wind_direction()." ".$this->wx->get_wind_speed().'mph@'.$this->wx->get_wind_angle()), - $this->get_wind_angle_image($this->wx->get_wind_angle()), - SPANtag::factory('',"Peak winds ".$this->peak_wind['direction']." ".$this->peak_wind['speed'].'mph@'.$this->peak_wind['angle']." ".$this->peak_wind['time']))); - - $table->add_row(" ", " "); - $pressure = $this->wx->get_rel_pressure(); - $table->add_row("Pressure : ", $pressure. ' inHG / '.WXConversion::inchmercury_to_millibars($pressure). ' mbar'); - - - $table->add_row('Rainfall : ',$this->wx->get_rain_1h().'"/ '.$this->wx->get_rain_24h().'" / '.$this->rain_total.'"<br>'. + public function get_content() { + + $div = new DIVtag(array('id'=>$this->get_ajax_replacement_divid().'contents')); + + //build the title + //$title = DIVtag::factory('cctitle', Atag::factory(AjaxRequestBuilder::build_replace_url('CurrentConditions', array(), $this->get_ajax_replacement_divid()), 'Current Conditions', 'linkrefresh')); + $title = DIVtag::factory('cctitle', "Current Conditions -- Updated : ", new SPANtag(array('id' => 'idUpdateSeconds'),'')); + $div->add($title); + + //now add the update block + $update_div = new DIVtag(array('id' => 'idcclastupdate'), $this->wx->get_datetime()); + $div->add($update_div); + + + $table = TABLEtag::factory("100%",0,2); + $outside_temp = $this->wx->get_temp_out(); + $table->add_row(new TDtag(array("width" => "120"),"Outside :"), + new DIVtag(array('style' => 'text-align:center; padding-top:2px;height:75px; background-color:#ffffcc;'), + new SPANtag(array('id' => 'idTempF', 'style' => 'font-weight:bold;'),$outside_temp)," F / ", + new SPANtag(array('id' => 'idTempC','style' => 'font-weight:bold;'),WXConversion::fahrenheit_to_celsius($outside_temp)),' C / ', + new SPANtag(array('id' => 'idTempK','style' => 'font-weight:bold;'),WXConversion::fahrenheit_to_kelvin($outside_temp)), " K", + BRtag::factory(), $this->wx->get_forecast(), + new DIVtag(array('style' => 'padding-top:5px;'), 'Feels like '.$this->wx->get_wind_chill()." F"), + new DIVtag(array('style' => 'padding-top:5px;'), $this->temp_low_high["low"].' F / '.$this->temp_low_high["high"].' F Low/High'))); + + $table->add_row("Relative Humidity : ", $this->wx->get_rel_hum_out().' %'); + + //wind + $table->add_row("Wind : ",new TDtag(array(), SPANtag::factory('',"From the ".$this->wx->get_wind_direction()." ".$this->wx->get_wind_speed().'mph@'.$this->wx->get_wind_angle()), + $this->get_wind_angle_image($this->wx->get_wind_angle()), + SPANtag::factory('',"Peak winds ".$this->peak_wind['direction']." ".$this->peak_wind['speed'].'mph@'.$this->peak_wind['angle']." ".$this->peak_wind['time']))); + + $table->add_row(" ", " "); + $pressure = $this->wx->get_rel_pressure(); + $table->add_row("Pressure : ", $pressure. ' inHG / '.WXConversion::inchmercury_to_millibars($pressure). ' mbar'); + + + $table->add_row('Rainfall : ',$this->wx->get_rain_1h().'"/ '.$this->wx->get_rain_24h().'" / '.$this->rain_total.'"<br>'. ' 1hr / 24hrs / total.'); - - $table->add_row(" ", " "); - $inside_temp = $this->wx->get_temp_in(); - $table->add_row('Inside : ', $inside_temp." F / ". WXConversion::fahrenheit_to_celsius($inside_temp).'C / '.WXConversion::fahrenheit_to_kelvin($inside_temp). " K");; - - - $div->add($table); - - //$div->add(new DIVtag(array('style' => 'padding-top:10px;background-color: #aaaaaa;'),$this->wx)); - - $script = SCRIPTtag::factory(); - $ts = time(); - $script->add("set_orig_time_ts(".$ts.");"); - - //$div->add($script); - return $div; - } - - - protected function get_wind_angle_image($angle) { - - //calculate the offset to the image from the angle. - if ($angle == 360) { - $angle = 0; - } - - $offset = -1*round($angle) * 14; - $img = new IMGtag(array('id' => 'idWindArrow', 'style' => 'overflow: hidden; left: '.$offset.'px; position: relative;', + + $table->add_row(" ", " "); + $inside_temp = $this->wx->get_temp_in(); + $table->add_row('Inside : ', $inside_temp." F / ". WXConversion::fahrenheit_to_celsius($inside_temp).'C / '.WXConversion::fahrenheit_to_kelvin($inside_temp). " K");; + + + $div->add($table); + + //$div->add(new DIVtag(array('style' => 'padding-top:10px;background-color: #aaaaaa;'),$this->wx)); + + $script = SCRIPTtag::factory(); + $ts = time(); + $script->add("set_orig_time_ts(".$ts.");"); + + //$div->add($script); + return $div; + } + + + protected function get_wind_angle_image($angle) { + + //calculate the offset to the image from the angle. + if ($angle == 360) { + $angle = 0; + } + + $offset = -1*round($angle) * 14; + $img = new IMGtag(array('id' => 'idWindArrow', 'style' => 'overflow: hidden; left: '.$offset.'px; position: relative;', 'src' =>'/images/360arrows_blue.gif')); - return new DIVtag(array('id' => 'idWindArrowDiv', 'style' => 'position:relative;overflow:hidden;top:1px;left:1px;width:14px;height:14px;'), $img); - } + return new DIVtag(array('id' => 'idWindArrowDiv', 'style' => 'position:relative;overflow:hidden;top:1px;left:1px;width:14px;height:14px;'), $img); + } } ?> Modified: trunk/open2300/lib/modules/home/widgets/RemoteMetarConditions.inc =================================================================== --- trunk/open2300/lib/modules/home/widgets/RemoteMetarConditions.inc 2010-03-03 17:13:33 UTC (rev 3409) +++ trunk/open2300/lib/modules/home/widgets/RemoteMetarConditions.inc 2010-03-03 18:06:33 UTC (rev 3410) @@ -52,17 +52,17 @@ $proxy = $GLOBALS["config"]->get("proxy"); if (!empty($proxy)) { - $context = stream_context_create(array("http" => array("proxy" => "tcp://web-proxy.rose.hp.com:8088"))); + $context = stream_context_create(array("http" => array("proxy" => "tcp://".$proxy))); } else { $context = null; } $json = file_get_contents($this->url,0, $context); - Log::singleton()->debug("json returned is ".$json); + //Log::singleton()->debug("json returned is ".$json); $metar = json_decode($json); //echo var_export($metar, true)."\n"; $metar->season = "Spring"; - Log::singleton()->debug(var_export($metar, true)); + //Log::singleton()->debug(var_export($metar, true)); $conditions = array(); $conditions["season"] = $GLOBALS["config"]->get("season"); @@ -70,7 +70,7 @@ $conditions["clouds"] = $clouds; $rained = $this->has_rained(); $conditions["rained"] = $rained; - $conditions["banner"] = $this->get_banner_filename($conditions["season"], $clouds, $rained); + $conditions = $this->get_banner_filename(&$conditions, $rained); return $conditions; //return $metar; @@ -137,7 +137,9 @@ } - private function get_banner_filename($season, $clouds, $rain, $offset=null) { + private function get_banner_filename($conditions, $rain, $offset=null) { + $season = $conditions["season"]; + $clouds = $conditions["clouds"]; $tod = $this->get_time_of_day($offset); //echo (var_export($tod, true)."\n"); $filename = "/images/banners/".$season."/".$tod."_"; @@ -148,11 +150,12 @@ $filename .= $clouds.".jpg"; } - //echo var_export($filename, true)."\n"; + $conditions["filename"] = $filename; if (file_exists($GLOBALS['path_base']."/htdocs".$filename)) { - return $filename; + $conditions["banner"] = "yes"; } else { - return null; + $conditions["banner"] = "no"; + Log::singleton()->debug("Need banner image ".$filename); // if (!is_null($offset)) { // $offset += 1; // } else { @@ -160,6 +163,7 @@ // } // return $this->get_banner_filename($season, $clouds, $rain, $offset); } + return $conditions; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |