Author Topic: getting a bit complex  (Read 244 times)

0 Members and 1 Guest are viewing this topic.

Offline txweather.org

  • Forecaster
  • *****
  • Posts: 1526
    • Texas Weather
getting a bit complex
« on: April 09, 2019, 10:41:20 PM »
So I am trying to use something like:

if(file_exists($tDir.'uptimepurpleair.png')) {
           do_check(langtransstr("PurpleAIR Status"),$tDir.'uptimepurpleair.png',2*31,'file');

To display in the puirpleair and blitz page when the devices are online base on the image timestamp change...

The problem is that as soon as I insert that in to my purpleair page it brakes....

How can I insert this or something similar to display that the device is "ONLINE" just like what the wxstatus.pgp page does but instead of current to display online :)

Thanks for your help!

----
Davis Vantage Pro2 Plus +FARS|Meteobridge Nano SD|Meteohub|Meteobridge MR-3020|WU KTXSPRIN75/PWS JRARGWX75/CWOP EW2972/WBB TXWDVUE75/Blitzortung ID: 1142|AWEKAS: 12095
Donations are welcome: https://paypal.me/ffuentesb

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 7418
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: getting a bit complex
« Reply #1 on: April 10, 2019, 11:02:26 AM »
You'll need the extra functions from include-wxstatus.php to make the do_check() functions work

Code: [Select]
<?php
// Functions used on this page

function do_check($title$fileOrAppTime,$maxFileSecs,$type='file') {
if(preg_match('/file/i',$type)) {
   $cur_status do_check_file($fileOrAppTime,$maxFileSecs);
} else {
   $cur_status do_check_applic($fileOrAppTime,$maxFileSecs);
}
 list($stat,$age,$data) = explode("\t",$cur_status);
echo 
"    <tr>
      <td>
$title</td>
      <td align=\"center\">
$stat</td>
      <td align=\"right\">
$age</td>
      <td align=\"right\">
$data</td>
    </tr>\n"
;

}
// check time on a file for last update
function do_check_file($chkfile,$maxFileSecs) {
  global 
$SITE;
  
$timeFormat $SITE['timeFormat']; 
  
$now time();
  if (
file_exists($chkfile)) {
    
$age $now filemtime($chkfile);
$updateTime date($timeFormat,filemtime($chkfile));
  } else {
    
$age 'unknown';
$updateTime 'file not found';
  }
  
$status '';
  
$hms sec2hms($age);
  print 
"<!-- $chkfile age = $age secs. $hms -->\n";
  
$age $hms;
  if (
file_exists($chkfile) and (filemtime($chkfile) + $maxFileSecs $now) ) {     // stale file
    
$status "<span style=\"color: green\"><b>".langtransstr('Current')."</b></span>\t$age\t$updateTime ";

  } else {
    
$status "<span style=\"color: red\"><b>".langtransstr('NOT Current')."</b></span>\t$age\t > " sec2hms($maxFileSecs) ."<br/><b>$updateTime</b>";
  }
  
  return(
$status);


}
// check time on an application returned update time
function do_check_applic($applTime,$maxFileSecs) {
  global 
$SITE;
  
$timeFormat $SITE['timeFormat']; 
  
$now time();
    
$age $now $applTime;
$updateTime date($timeFormat,$applTime);
  
$status '';
  
$hms sec2hms($age);
  
  print 
"<!-- age = $age secs. $hms -->\n";
  
$age=$hms;
  if (
$applTime $maxFileSecs $now ) {     // stale file
    
$status "<span style=\"color: green\"><b>".langtransstr('Current')."</b></span>\t$age\t$updateTime ";

  } else {
    
$status "<span style=\"color: red\"><b>".langtransstr('NOT Current')."</b></span>\t$age\t > " sec2hms($maxFileSecs) . " <br/><b>$updateTime</b>";
  }
  
  return(
$status);


}

//
  
function sec2hms ($sec$padHours false
  {

    
// holds formatted string
    
$hms "";
    if (! 
is_numeric($sec)) { return($sec); }
    
// there are 3600 seconds in an hour, so if we
    // divide total seconds by 3600 and throw away
    // the remainder, we've got the number of hours
    
$hours intval(intval($sec) / 3600); 

    
// add to $hms, with a leading 0 if asked for
    
$hms .= ($padHours
          ? 
str_pad($hours2"0"STR_PAD_LEFT). ':'
          
$hours':';
     
    
// dividing the total seconds by 60 will give us
    // the number of minutes, but we're interested in 
    // minutes past the hour: to get that, we need to 
    // divide by 60 again and keep the remainder
    
$minutes intval(($sec 60) % 60); 

    
// then add to $hms (with a leading 0 if needed)
    
$hms .= str_pad($minutes2"0"STR_PAD_LEFT). ':';

    
// seconds are simple - just divide the total
    // seconds by 60 and keep the remainder
    
$seconds intval($sec 60); 

    
// add to $hms, again with a leading 0 if needed
    
$hms .= str_pad($seconds2"0"STR_PAD_LEFT);

    
// done!
    
return $hms;
    
  }
//=========================================================================
// change the hh:mm AM/PM to h:mmam/pm format
function fixup_time $WDtime ) {
  global 
$timeOnlyFormat,$DebugMode;
  if (
$WDtime == "00:00: AM") { return ''; }
  
$t explode(':',$WDtime);
  if (
preg_match('/p/i',$WDtime)) { $t[0] = $t[0] + 12; }
  if (
$t[0] > 23) {$t[0] = 12; }
  if (
preg_match('/^12.*a/i',$WDtime)) { $t[0] = 0; }
  
$t2 join(':',$t); // put time back to gether;
  
$t2 preg_replace('/[^\d\:]/is','',$t2); // strip out the am/pm if any
  
return ($t2);
}

//=========================================================================
// adjust date to standard format
//
function fixup_date ($WDdate) {
  global 
$SITE;
  
$d explode('/',$WDdate);
  if(!isset(
$d[2])) {$d=explode("-",$WDdate); }
  if(!isset(
$d[2])) {$d=explode(".",$WDdate); }
  if (
$d[2] > 70 and $d[2] <= 99) {$d[2] += 1900;} // 2 digit dates 70-99 are 1970-1999
  
if ($d[2] < 99) {$d[2] += 2000; } // 2 digit dates (left) are assumed 20xx dates.
  
if ($SITE['WDdateMDY']) {
    
$new sprintf('%04d-%02d-%02d',$d[2],$d[0],$d[1]); //  M/D/YYYY -> YYYY-MM-DD
  
} else {
    
$new sprintf('%04d-%02d-%02d',$d[2],$d[1],$d[0]); // D/M/YYYY -> YYYY-MM-DD
  
}
  
  return(
$new);
}

// end of functions
?>
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline txweather.org

  • Forecaster
  • *****
  • Posts: 1526
    • Texas Weather
Re: getting a bit complex
« Reply #2 on: April 10, 2019, 03:31:15 PM »
Thanks Ken!

----
Davis Vantage Pro2 Plus +FARS|Meteobridge Nano SD|Meteohub|Meteobridge MR-3020|WU KTXSPRIN75/PWS JRARGWX75/CWOP EW2972/WBB TXWDVUE75/Blitzortung ID: 1142|AWEKAS: 12095
Donations are welcome: https://paypal.me/ffuentesb

 

anything