mirror of
https://github.com/fspc/water-the-theme.git
synced 2025-03-11 23:03:24 -04:00
Working nicely, would say more, but on a schedule.
This commit is contained in:
parent
e15da1c9da
commit
80c511fd55
@ -102,8 +102,207 @@ class Water_The_Theme_Public {
|
||||
|
||||
public function water_the_theme($thePage) {
|
||||
|
||||
return "boo!";
|
||||
$doc = new DOMDocument();
|
||||
$doc->loadHTML($thePage);
|
||||
$xml_tree = simplexml_import_dom($doc);
|
||||
|
||||
$short_code_name = (string)$xml_tree->body->div->attributes()->class;
|
||||
|
||||
$thePage ="<table id='$short_code_name'>";
|
||||
|
||||
// front page
|
||||
// [usgs_custom name="Timely Information" location='03071590,03071600,03071605' parameters='00010,00065,62614']
|
||||
if ($short_code_name === 'Timely Information') {
|
||||
foreach ($xml_tree->body->div->div as $div) {
|
||||
|
||||
$value = (string)$div;
|
||||
$class = (string)$div->attributes()->class;
|
||||
|
||||
$datetime = (string)$div->attributes()->datetime;
|
||||
|
||||
list($sitename, $parameter) = explode(' ', $class);
|
||||
$sitename = ucwords(preg_replace('/_/', ' ', $sitename));
|
||||
$parameter = ucwords(preg_replace('/_/', ' ', $parameter));
|
||||
|
||||
if ($parameter === 'Lake Or Reservoir Water Surface Elevation Above Ngvd 1929') {
|
||||
$parameter = '(AMSL)';
|
||||
}
|
||||
if ($sitename === 'Cheat Lake Near Stewartstown Wv') {
|
||||
if ($parameter === '(AMSL)') {
|
||||
$sitename = 'Lake Level';
|
||||
} else {
|
||||
$sitename = 'Lake';
|
||||
}
|
||||
}
|
||||
if ($sitename === 'Cheat River At Lake Lynn Pa') {
|
||||
if ($parameter === 'Gage Height') {
|
||||
$sitename = 'Below Dam';
|
||||
} else {
|
||||
$sitename = 'At Dam';
|
||||
}
|
||||
}
|
||||
if ($sitename === 'Cheat River At Davidson Pa') {
|
||||
$sitename = 'Below Dam';
|
||||
}
|
||||
|
||||
$thePage .= '<tr>';
|
||||
$thePage .= "<td>$sitename $parameter</td><td>$value</td><td datetime='$datetime'></td>";
|
||||
$thePage .= '</tr>';
|
||||
|
||||
}
|
||||
|
||||
//[nws_custom location='lldp1']
|
||||
$att = [
|
||||
'name' => 'Timely Information',
|
||||
'location' => 'lldp1',
|
||||
'parameters' => null,
|
||||
'date_range' => 'current',
|
||||
'order' => 'asc'
|
||||
];
|
||||
|
||||
$nws_custom = Water_The_Theme_Public::nws_custom($att);
|
||||
|
||||
$thePage .= $nws_custom;
|
||||
|
||||
} // end Timely Information
|
||||
|
||||
// Statics Page - last 5 lake data
|
||||
// [usgs_custom name="Statistics" location='03071590,03071600' parameters='00010,00065,62614' date_range='previous,5,16:00' order='desc']
|
||||
if ($short_code_name === 'Statistics') {
|
||||
|
||||
$statistics = [];
|
||||
|
||||
foreach ($xml_tree->body->div->div as $div) {
|
||||
|
||||
$value = (string)$div;
|
||||
$class = (string)$div->attributes()->class;
|
||||
|
||||
$datetime = (string)$div->attributes()->datetime;
|
||||
|
||||
list($sitename, $parameter) = explode(' ', $class);
|
||||
$sitename = ucwords(preg_replace('/_/', ' ', $sitename));
|
||||
$parameter = ucwords(preg_replace('/_/', ' ', $parameter));
|
||||
|
||||
if ($parameter === 'Lake Or Reservoir Water Surface Elevation Above Ngvd 1929') {
|
||||
$parameter = '(AMSL)';
|
||||
}
|
||||
if ($sitename === 'Cheat Lake Near Stewartstown Wv') {
|
||||
if ($parameter === '(AMSL)') {
|
||||
$sitename = 'Lake Level';
|
||||
} else {
|
||||
$sitename = 'Lake';
|
||||
}
|
||||
}
|
||||
if ($sitename === 'Cheat River At Lake Lynn Pa') {
|
||||
$sitename = 'Tail Race Level';
|
||||
$parameter = ' (AMSL)';
|
||||
}
|
||||
if ($sitename === 'Cheat River At Davidson Pa') {
|
||||
$sitename = 'Below Dam';
|
||||
}
|
||||
|
||||
}
|
||||
if ($sitename === 'Tail Race Level') {
|
||||
$value = (float)$value + 776.63;
|
||||
}
|
||||
$statistics[] = "<tr><td>$sitename $parameter</td><td>$value</td><td datetime='$datetime'></td></tr>";
|
||||
|
||||
//PC::debug($value . " " . $sitename . " " . $parameter);
|
||||
} // end foreach
|
||||
|
||||
list($array1, $array2, $array3) = array_chunk($statistics, ceil(count($statistics) / 3));
|
||||
foreach($array1 as $key => $value ) {
|
||||
$thePage .= $array2[$key];
|
||||
$thePage .= $array3[$key];
|
||||
$thePage .= $value;
|
||||
}
|
||||
|
||||
//PC::debug($count);
|
||||
|
||||
} // end Statistics
|
||||
|
||||
$thePage .= '</table>';
|
||||
return $thePage;
|
||||
|
||||
} // function water the theme
|
||||
|
||||
public function nws_custom( $att ) {
|
||||
|
||||
|
||||
list($name, $location, $parameters, $date_range, $order) = [
|
||||
$att['name'],
|
||||
$att['location'],
|
||||
$att['parameters'],
|
||||
$att['date_range'],
|
||||
$att['order']
|
||||
];
|
||||
$locations = explode(',', $location);
|
||||
|
||||
// Tail Race Level = Gage Datum + Gage Height
|
||||
foreach ($locations as $location) {
|
||||
|
||||
$thePage = get_transient('nws_custom-' . $name . $location . $date_range . $parameters . $order );
|
||||
|
||||
if ( !$thePage ) {
|
||||
|
||||
$url = "http://water.weather.gov/ahps2/hydrograph_to_xml.php?gage=$location&output=xml";
|
||||
|
||||
$response = wp_remote_get( $url );
|
||||
$data = wp_remote_retrieve_body( $response );
|
||||
|
||||
if ( ! $data ) {
|
||||
return 'Nation Weather Service is not Responding.';
|
||||
}
|
||||
|
||||
|
||||
$xml_tree = simplexml_load_string( $data );
|
||||
if ( False === $xml_tree ) {
|
||||
return 'Unable to parse NWS XML';
|
||||
}
|
||||
|
||||
// space to underscore; all lower case; only special character allowed is underscored
|
||||
$SiteName = (string)$xml_tree->attributes()->name;
|
||||
$SiteName = preg_replace('/[^A-Za-z0-9_]/', '', strtolower(preg_replace('/\s+/', '_', $SiteName)));
|
||||
|
||||
$waterlevel = (string)$xml_tree->zerodatum;
|
||||
|
||||
$c = 0;
|
||||
foreach ( $xml_tree->observed->datum as $datum ) {
|
||||
|
||||
// in javascript this works out of the box (* 1000)
|
||||
$datetime = strtotime($datum->valid) * 1000;
|
||||
$gageheight = $datum->primary;
|
||||
$waterflow = (string)$datum->secondary;
|
||||
|
||||
if ($waterflow === '-999' || $waterflow === 0) {
|
||||
$waterflow = '0 cfs';
|
||||
} else {
|
||||
$waterflow = $waterflow * 1000;
|
||||
$waterflow = $waterflow . " cfs";
|
||||
}
|
||||
|
||||
$tail_race_level = (float)$waterlevel + (float)$gageheight;
|
||||
|
||||
if($c === 0 && $date_range === 'current') {
|
||||
$thePage .= "<tr><td>Tail Race Level (AMSL)</td><td>$tail_race_level ft</td><td datetime='$datetime'></td></tr>";
|
||||
//$thePage .= "<tr><td>Gage Datum (AMSL)</td><td>$waterlevel ft</td><td datetime='$datetime'></td></tr>";
|
||||
$thePage .= "<tr><td>Tail Water Flow</td><td>$waterflow</td><td datetime='$datetime'></td></tr>";
|
||||
break;
|
||||
} else {
|
||||
$thePage .= "<tr><td>Tail Race Level (AMSL)</td><td>$tail_race_evel</td><td datetime='$datetime'></td></tr>";
|
||||
//$thePage .= "<tr><td>Gage Datum (AMSL)</td><td>$waterlevel ft</td><td datetime='$datetime'></td></tr>";
|
||||
$thePage .= "<tr><td>Tail Water Flow</td><td>$waterflow</td><td datetime='$datetime'></td></tr>";
|
||||
}
|
||||
$c++;
|
||||
|
||||
} // foreach xml_tree as site data
|
||||
|
||||
} // foreach NWS location
|
||||
|
||||
|
||||
set_transient( 'nws_custom-' . $name . $location . $date_range . $parameters . $order, $thePage, 60 * 15 );
|
||||
}
|
||||
|
||||
return $thePage;
|
||||
} // function nws_custom
|
||||
|
||||
}
|
||||
|
@ -29,4 +29,33 @@
|
||||
* practising this, we should strive to set a better example in our own work.
|
||||
*/
|
||||
|
||||
$( window ).load(function() {
|
||||
|
||||
// #BED8D3' '#D8E4E6'
|
||||
$('#Statistics tr:nth-child(6n), #Statistics tr:nth-child(6n-1), #Statistics tr:nth-child(6n-2)').css({backgroundColor:'#D8E4E6'});
|
||||
$('#Statistics tr:nth-child(6n-3), #Statistics tr:nth-child(6n-4), #Statistics tr:nth-child(6n-5)').css({backgroundColor:'#BED8D3'});
|
||||
|
||||
$("td[datetime]").each(function(key,value){
|
||||
var dt = $(value).attr('datetime');
|
||||
var d = new Date(Number(dt));
|
||||
d = d.toLocaleString();
|
||||
$(this).html(d);
|
||||
});
|
||||
|
||||
/*
|
||||
div:nth-child(6n), div:nth-child(6n-1), div:nth-child(6n-2) {
|
||||
background: red;
|
||||
}
|
||||
div:nth-child(6n-3), div:nth-child(6n-4), div:nth-child(6n-5) {
|
||||
background: blue;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
});
|
||||
|
||||
//$('#Statistics tr:nth-child(6n), #Statistics tr:nth-child(6n-1), #Statistics tr:nth-child(6n-2)').css({backgroundColor:'#d4cdcd'});
|
||||
//$('#Statistics tr:nth-child(6n-3), #Statistics tr:nth-child(6n-4), #Statistics tr:nth-child(6n-5)').css({backgroundColor:'#bac3c5'});
|
||||
//$('#Statistics tr:nth-child(6n-3), #Statistics tr:nth-child(6n-4), #Statistics tr:nth-child(6n-5)').css({backgroundColor:'#bac3c5'});
|
||||
|
||||
})( jQuery );
|
||||
|
Loading…
x
Reference in New Issue
Block a user