Page 3 of 3

Re: Comparing with one year ago

Posted: Sat 20 Oct 2018 10:57 pm
by dazza1223
hey mate thank you for that demo it made it more easier :D to work out i took what u said go to "https://www.w3schools.com/html/default.asp

ive leaned a lote to night bye watching video and reading so thank u for puting me on the right tracks

Re: Comparing with one year ago

Posted: Sun 21 Oct 2018 7:50 am
by sfws
It was a decade ago, after leaving paid work, while acting as a full time carer for my late mum that I first taught myself HTML to pass the time between carer duties. Looking back, it was a miserable time coping with her terminal illness, but I did feel better for learning that skill and I have found it a useful way of keeping my brain working in my retirement.

I am glad I have inspired you to follow your own learning path.

Re: Comparing with one year ago

Posted: Sun 21 Oct 2018 6:53 pm
by dazza1223
im sor sorry to here about when u hade to go through with your mum :cry: um i leaning html more better but i ive tryed to do

some mode off the code u gave me

<td class="table_two"><?=$required_fields[4];?>&nbsp;<#tempunit></td>
<td class="table_two">at&nbsp;<?=$required_fields[5];?></td>
</tr>

im trying to put all this code so it look very tidy but for the hell can i do it so do u mind place the code in the line above plz

<?php
echo "$required_fields[17]";
?> <#windunit>(
<?php
$return = calculateBeaufort($required_fields[17],'<#windunit>');
echo "$return";
?>)</td>
<td>at&nbsp;
<?php
echo (calculateTime($required_fields[18]));
?> </td>

Re: Comparing with one year ago

Posted: Sun 21 Oct 2018 8:16 pm
by sfws
The shorter format is only available if the only instruction within the PHP script section within the HTMl is an echo.
This bit of php

Code: Select all

<?php
$return = calculateBeaufort($required_fields[17],'<#windunit>');
echo "$return";
?>
has an instruction that is not an echo followed by an echo.
To express it just as an echo (and therefore use the shorter <?= format), it would need to be expressed differently as just an output

Code: Select all

<?=calculateBeaufort($required_fields[17],'<#windunit>');?>
The alternative is to separate the two PHP instructions out:
Type the call to the function (that can be placed anywhere provide the returned string is defined before it is used, therefore the php snippet

Code: Select all

<?php
$return = calculateBeaufort($required_fields[17],'<#windunit>');
?>
is placed before the HTML table (i.e. before <table>) and that leaves just the echo (that has to be placed where it is to appear) to put

Code: Select all

<td class="table_two"><?= $required_fields[17] . ' <#windunit>(' .  $return;?>)</td>
within the table cell within the table.

Re: Comparing with one year ago

Posted: Sun 21 Oct 2018 10:01 pm
by dazza1223
yep that did the trick thank you

http://www.davisworthing.co.uk/new/tod_yes_yerar.php

take a look if u see any error can u pont them out as ive been on the for 6 hr trying to sort it and i must say ur very good with php


ps i wood like to remove this lin as it taking up to much room (F3=Gentle breeze)

Re: Comparing with one year ago

Posted: Mon 22 Oct 2018 7:06 am
by sfws
dazza1223 wrote:take a look, if u can see any errors can u point them out
The "Temperature Average" line has used syntax for time-stamp instead of syntax for value cell - remove "at&nbsp;" before figure, add units after figure (copy "Temperature Range" row).
Otherwise looks good.
dazza1223 wrote: (F3=Gentle breeze) is taking up to much room
In the
function calculateBeaufort(
area change the following line:

Code: Select all

$beaufort='F' . ($i2 - 1) . '=' . $speedArray[$i2-1][4];
into

Code: Select all

$beaufort='F' . ($i2 - 1);

Re: Comparing with one year ago

Posted: Mon 22 Oct 2018 8:05 am
by dazza1223
:bash: doh sorry I ment just remove Gentle breeze and leve the f3 all the same thank u for all the help u gave me


Ps have u got a website?

Re: Comparing with one year ago

Posted: Mon 22 Oct 2018 11:20 am
by sfws
dazza1223 wrote:I meant just remove Gentle breeze and leave the f3 ...


Ps have u got a website?
I understood fully what you meant, and provided code change to do exactly that in my last reply. You will see earlier in this thread some discussion about the shorter or longer format of exactly that part of the display.

I can see I did write the script with the option of either display, but I simplified the final PHP script version I posted to make it friendlier. I selected to provide the longer display as most users understand enough PHP to take something out (the bit removed in my previous reply), but those users may not know how to add extra.


My server is local, not shared online, as I am using a very tempermental windows 10 PC that constantly fails now. Plus, as I have posted many times before, I accept the dubious quality of my weather station and consequently statistics produced are often rubbish. The only use of my weather station is to produce something that varies in its content, that I can try my different scripts on.

Re: Comparing with one year ago

Posted: Mon 22 Oct 2018 11:30 am
by dazza1223
o i see ok i will have a bach at it to night thanks and u saying ( scripts) how meny have you made as i will like some more off them it u got any :D

Re: Comparing with one year ago

Posted: Fri 06 Mar 2020 4:47 pm
by sfws
I have not looked again at the code that I shared in this topic, but on my own private web server I still have a PHP script based on what was in this topic.
Without re-reading all my posts, I recall commenting that finding the right day's statistics to display (whether taken by JavaScript from dayfile.txt or by a PHP script from a daily summary database table) was made more complex by coping with both missing past data and the existance in some years of leap days.

The recent leap day proved my 2nd point:

Code: Select all

<?php
	#================================================
	# Work out date for one year ago - there is a leap year problem
	# I want last day of February compared with last day of that month in previous year
	# My test below showed that PHP subtract one year does not work like that
	$leap_day = new DateTime('2020-02-29');
	$leap_day ->	sub(new DateInterval('P1Y')); // subtract 1 year
	$test_day = $leap_day	-> format('Y-m-d'); // ISO format for output of yyyy-mm-dd
	echo "one year before leap day is $test_day";
	// returns "one year before leap day is 2019-03-01"
	# this is not what I want
	#================================================
	$working_date 	= new DateTime($previousDay);
		$working_date	->	sub(new DateInterval('P1Y')); // subtract 1 year
		$aYearAgo		= $working_date	-> format('Y-m-d'); // ISO format for output of yyyy-mm-dd
		if(substr($previousDay,5,2) == '29')
		{
			$aYearAgo	=  substr($aYearAgo, 0, 4) . substr($previousDay,0,7). '28';# compensate if this year is leap year, because was set to 1 March
		}elseif( checkdate ( substr($aYearAgo,5,2), '29', substr($aYearAgo, 0, 4)) && substr($aYearAgo,5,2) == '02' && substr($previousDay,8,2) == '28')
		{
			$aYearAgo	=  substr($aYearAgo, 0, 4) . substr($previousDay,0,7). '29';# compensate for 28 Feb this year if last year is leap year
		}
Of course having just started weather recording at a new home I only have just over 40 days of statistics (so a year ago does not exist in my database table), however I have recently resurrected the database tables for 2 previous homes and I'm exploring the idea of a "join table" approach to be able to see my old weather information as well as my current statistics.

Re: Comparing with one year ago

Posted: Fri 19 Jun 2020 5:00 pm
by meteo19
Hello
First bravo and thank you for your very good script that I have been using for several years. I have made some adaptations, I would like to calculate in addition the total rain on this date and a year before but I can't do it can you help me if possible in this script. Thank you very much and sorry for my very bad English. :oops:

Attached is the JS file
searchDayfile.js
Your script in operation
http://www.meteosegur.fr/Base-segur/wxh ... -avant.php

Re: Comparing with one year ago

Posted: Fri 19 Jun 2020 7:32 pm
by sfws
Thank you for using my script, and especially for praising it. I really appreciate that.
meteo19 wrote: Fri 19 Jun 2020 5:00 pm I would like to calculate in addition the total rain on this date and a year before but I can't do it can you help me if possible in this script.
The script uses what is stored in dayfile.txt, and in your copy of my JavaScript is what Cumulus calls the total rain (the amount falling in each day).

Code: Select all

case 14: $('#rain').prepend(parameter_array[i,1]);		break;
So you can use it to see how much rain fell on any other date such as exactly a year ago, as you already do on your site, so I don't understand why you want me to tell you how to do it:

Code: Select all

	Hier ( Jeudi 18 Jun 2020)      Un an avant ( Mardi 18 Jun 2019)
Pluie 	   2,4 mm 	  	                  0,0 mm
Perhaps by total rain you mean something different, total for month to a date in this year and total for a month to that date in previous year (or total for year or season).
If you do, then MX keeps the old month.ini and year.ini log files (renaming them with month and year added to file name), but those only give you total rain in a completed past month or completed past year. The only way in JavaScript to get the rain up to the same date as yesterday is to read that dayfile.txt and look at every day preceding the date a year ago (back to start of month or year) the daily rain totals and sum them.

The easier alternative is to get MX to upload the daily summary log file to a database table. ExportMySQL.exe dayfile does that for past days, and MX (I see you are using latest release) can automatically update the latest day at the start of the next day (see the Cumulus MX article in Wiki to learn more). Writing a SQL query to find almost any statistic you want for a year ago is I believe much easier than writing JavaScript.

Re: Comparing with one year ago

Posted: Fri 19 Jun 2020 9:03 pm
by meteo19
Good evening
You understood that it was rain until the same date as yesterday. I will try with MySQL. Thanks for your help.
Good evening from France.

Patrick