Page 3 of 3

Re: RecentOutsideTemp - one year ago?

Posted: Sun 31 Jan 2016 7:44 pm
by wetterfrosch1971
Paul,

it was a small mistake in the script, look in this part from the code must be a "-" in front of "="

Code: Select all

$now -= $now % 60; //remove the seconds
it is for "round down" the second Display to Zero because in the monthly-log-Datei ist no second-display, so the second-display must be Zero.

Re: RecentOutsideTemp - one year ago?

Posted: Sun 31 Jan 2016 7:46 pm
by PaulMy
Hi Frank,
Your site looks very good and you have been doing some very nice add-ons and customizing. If there is anything I can share just let me know.

I have been able to add year-ago to my http://www.komokawerather.com home page :clap: Will see tomorrow how it goes with February last year comparison.

I had thought of doing a similar scripts for 2 years ago and 3 years ago, etc. but haven't figured how the script would detect the difference for january.txt 2015 from january.txt 2014. I assume that the "F" in

Code: Select all

$lines = file(strtolower (date('F')).'.txt'); //read the monthly.txt 
is to obtain the current month name.

I had tried to put the different years in a different /weather sub folder like /weather/2015MonthLog and /weather/2014MonthLog, but couldn't make the script work from indexT.htm unless the script and monthlog file are both in the /weather folder where index.htm is. An ongoing challenge...

Thanks so much for your help.

Paul

Re: RecentOutsideTemp - one year ago?

Posted: Sun 31 Jan 2016 9:44 pm
by wetterfrosch1971
Hi,

the "F" in "date" is only for "print the date in a complete word" and "strtolower" makes all letters small.

when you will use your other txt-datei from the other year, for example 2014, you must Change this part in the script to:

Code: Select all

$lines = file(strtolower (date('F')).'2014.txt'); //read the monthly.txt from 2014 log Datei


your monthly.txt-Datei from 2014 must be rename into:
january2014.txt
february2014.txt etc.

you can see with this small code, what doing the script

Code: Select all

<?php

$lines = strtolower(date('F').'2014.txt');
echo $lines;

?>
your monthly txt-log-Datei must look like this Result and must be on Webspace at the same place as the php-script.

or you can also use this code:

Code: Select all

$lines = file(date('m').'2014.txt');
than your monthly.txt-log-Datei must be so

012014 -> for january2014
022014 -> for february2014 etc.

you can see with this small code, what doing the script

Code: Select all

<?php

$lines = date('m').'2014.txt';
echo $lines;

?>
your monthly txt-log-Datei must look like this Result and must be on Webspace at the same place as the php-script.

Re: RecentOutsideTemp - one year ago?

Posted: Mon 01 Feb 2016 11:26 am
by wetterfrosch1971
If you want, I have a other script, which works with the same monthly.txt-log-Datei to print the AVERAGE temperature from "today one year ago".

you can see the result on my Webpage, it is the value called "Temperatur Ø"
the first value is the Temperatur Ø from today and the second value behind it, is the Temperatur Ø from one year ago.
http://www.wetterstation-badenweiler.de ... /index.php

Re: RecentOutsideTemp - one year ago?

Posted: Mon 01 Feb 2016 3:02 pm
by PaulMy
Hi Frank,
That would be good if you would do that.

Thanks,
Paul

Re: RecentOutsideTemp - one year ago?

Posted: Mon 01 Feb 2016 5:06 pm
by wetterfrosch1971
here the script to print the AVERAGE Temperature "today one year ago".
the script use the same monthly.txt-log-Datei as the other script, the monthly.txt-log-Datei must be at the same place as the script on Webspace.

the monthly.txt-log-Datei must be save with Interval from 10 minutes.

the script add all temperature values from one year ago midnight to the actual time one year ago and divide it by the numbers of readings. the solution is the average Temperatur.

Code: Select all

<?php

  date_default_timezone_set('America/Toronto'); //local date 

  $now  = ceil(time()/600)*600; // round up to 10 Minutes 
     //if you want round down use this -> //$now = floor(time()/600)*600;

  $now -= time() % 60; // round down the seconds

  $paststart = strtotime(date('d-m-Y 00:00', $now) . ' - 1 year');
  $pastnow   = strtotime(date('d-m-Y H:i', $now) . ' - 1 year');

 
  $lines = file(strtolower (date('F')).'.txt'); //read the monthly.txt Datei
                                                             //each monthly txt-datei must be on Webspace on same place as this script
                                                             //rename the monthly-txt-datei into january.txt, february.txt, etc (small letters) 
//or use this code for reading monthly.txt-Datei, but with this code, the Datei must rename into 01.txt (for january), 02.txt (for february) etc.:
//$lines = file(date('m').'.txt');

 
  $i = 0;
  

  foreach ($lines as $row){
    $row = explode(',', $row);
    
    $teileDat  = explode('/',$row[0]);
    $teileZeit = explode(':',$row[1]);

    $datstamp = mktime($teileZeit[0],$teileZeit[1],'00',$teileDat[1],$teileDat[0],$teileDat[2]);

    if($datstamp >= $paststart && $datstamp <= $pastnow){
    $i++;
	$row[2] = str_replace(",", ".", $row[2]); //replace in temperature value the comma into a Point, because php can be methematik calculate only with decimal Point

    $temps[] = $row[2];
	
    //echo $row[0].','.$row[1].' -- '.$row[2].'<br>';
      
    }

}

$wert = array_sum($temps) / count($temps); //add all values and divide by the numbers of readings

if(!$wert){
  //error
}
else{
echo '(Average Temperature one Year ago '.number_format($wert,1,",",".").' &deg;C)<br>'; //post the average temperature, round it on 1 place behind the comma, rename back the decimal-point into decimal-comma

}
?>
try it
Frank

Re: RecentOutsideTemp - one year ago?

Posted: Fri 15 Jul 2016 6:43 pm
by PaulMy
Thanks to Frank of Wetterstation-Badenweiler I have, or should say "had", this 'year ago' script working fine within my index.php until the end of June http://www.komokaweather.com. Then on July 1 it failed with a warning
Warning: file(july2015.txt) [function.file]: failed to open stream: No such file or directory in /home/content/96/5379896/html/weather/yearago/year-agoTe1.php on line 19

Warning: Invalid argument supplied for foreach() in /home/content/96/5379896/html/weather/yearago/year-agoTe1.php on line 23
Line 19 in year-agoTe1.php is $lines = file(strtolower (date('F')).'2015.txt');
Line 23 in year-agoTe1,php is foreach ($lines as $row){

The script does work if run by itself http://www.komokaweather.com/weather/ye ... agoTe1.php
but since July 1st not as an include in index.php. I have similar scripts for two years ago and 3 years ago and they all do the same.

As a temporary fix I have just included a link on index.php to those scripts so they can be clicked on, but that is not how I would like them to work. I have left in year-agoTe1.php as an "include" so you can see what it displays http://www.komokaweather.com

I know that I need the Cumulus monthly log file for the current month in the same /yearago folder but needs to be renamed from Jul15log.txt to july2015.txt (and the same for the other months and years) which I have done so july2015.txt does exist contrary what the warning says, and proof by it working as a direct call. And the previous months from February to June all worked fine.

Could that be caused by something changed on my webserver (GoDaddy) on July 1st that I am not aware of?

Any thoughts?

Thanks,
Paul