Rain "Year to Date" and "Month to Date" Differential Script

Murry Conarroe of Wildwood Weather (http://weather.wildwoodnaturist.com/) has graciously developed a nice script to calculate the “Year to Date” and “Month to Date” rainfall differential (departure from average) totals that utilizes the dailynoaareport files created by Weather Display. The script will update these differential totals on a daily basis and utilize your entire historical data archive.

See my dashboard under the Rain section (note the MTD Differential and the YTD Differential) http://www.relayweather.com/
Additionally, I’ve added the differentials in my “Rain Trending” page at the bottom of the main table: http://www.relayweather.com/wxraintrending.php

To use the script, download the raintodate.php file (there are a couple of adjustable settings at the top) and add the following line to your dashboard file.

include_once('raintodate.php');   // for ytd/mtd rain calculations 

It needs to be somewhere after the
“include_once($WXtags); // for the bulk of our data”
line to ensure that the variables in the testtags.php file are available.

The two variables created by the raintodate.php file that you can use anywhere in the dashboard are $avg_ytd_rain and $avg_mtd_rain.

I know that this has been a desirable variable that many of us want! Many thanks to Murry! :occasion5:


raintodate.zip (1.39 KB)

mth
Can you please explain how to implement this? I am unclear what you mean by “add the following line to your dashboard file.” What is the dashboard file?

Thanks

Frank

Frank,

In your 'new weather pages" page (http://www.frankpinkston.com/weather/wxindex.php) that is your “dashboard”. It would be the file named ajax-dashboard.php

Hope this helps!

Jack

Frank,

As Jack stated, you place this line of code into the file. (preferrably at the top of the file but below the call for the WXtags or testtags)
include_once(‘raintodate.php’);

This then allows you to have use of the two tags that the raintodate.php script creates.

Year to Date Rain Difference from Average: $avg_ytd_rain

Month to Date Rain Difference from Average: $avg_mtd_rain

Michael

Michael

Just tried this script. Thanks

Not sure It working correctly for me
I believe that I have all the testtags added correctly.
For march I only have 0.01 in. We had 5.57 inches of rain March.


Something is not right there…do you have the path set correctly for the dailynoaareport files?
I believe yours should be set like this:

$loc = “./”; // set to path of dailynoaareport files

For the averages column, the following tags are required:
$avrainjan
$avrainfeb
$avrainmar
$avrainapr
$avrainmay
$avrainjun
$avrainjul
$avrainaug
$avrainsep
$avrainoct
$avrainnov
$avraindec

These variables are taken directly for WD.

Checking now, your climate report for March 2011 shows 4.20 in of rain, but your wxraintrending.php shows 0.00 for March 2011.?
Maybe I’m confused about how it works.

Yes my dailynoaareport is at $loc = “./”; // set to path of dailynoaareport files

You’re correct, something is wrong with my March tag ($avrainmarnow) in WD. I just got the old script out (been a while) and these are the tags that are required. Notice my March total is 0.00. I need to look into that.

//Start Rain Trending
$avrainjan = ‘2.43’;
$avrainfeb = ‘2.23’;
$avrainmar = ‘2.75’;
$avrainapr = ‘3.96’;
$avrainmay = ‘3.28’;
$avrainjun = ‘3.66’;
$avrainjul = ‘4.12’;
$avrainaug = ‘3.72’;
$avrainsep = ‘4.73’;
$avrainoct = ‘3.54’;
$avrainnov = ‘2.45’;
$avraindec = ‘3.64’;

$avrainjannow = ‘1.95’;
$avrainfebnow = ‘2.72’;
$avrainmarnow = ‘0.00’;
$avrainaprnow = ‘2.27’;
$avrainmaynow = ‘3.06’;
$avrainjunnow = ‘0.94’;
$avrainjulnow = ‘5.53’;
$avrainaugnow = ‘2.75’;
$avrainsepnow = ‘7.24’;
$avrainoctnow = ‘3.02’;
$avrainnovnow = ‘2.00’;
$avraindecnow = ‘1.77’;
//End Rain Trending

Ed,

I got my March rain total squared away, there was a bug in WD.

I see in your testtags file that you don’t have the following set up:

$avrainjannow
$avrainfebnow
$avrainmarnow
etc…

It looks like the tags are in and working:http://www.cavecountryweather.com/index.php
Couple of questions:

  1. How to add the + and - symbols?
  2. I am not quite sure where the value "YTD Differential: 16.66 in " came from and is it + or - ?
 <tr>
                <td class="data1">MTD Differential: </td>
                <td style="text-align: right;" class="data1">
				  
                  <?php echo $avg_mtd_rain . $uomRain; ?>
                </td>

How did you correct March?. Testtags, not sure what happened. This time I deleted them in my webfiles folder, then they were overwritten w/the new ones.
ED

I tried converting log files to data, nothing worked.
But view>rain chart>mth to correct fixed it for me.
Thanks

Drobbins,

Its been a very long time since I added this…this is what I have in my ajax-dashboard for the MTD and YTD rain totals:

For the Month to Date (MTD):

<td class="data1">MTD Differential:</td>
                <td style="text-align: right;" class="data1">
				  <?php $monthrndifference=$monthrn-$avg_mtd_rain;
				  if ($monthrndifference >= 0)
				     echo "+";
				   else
				     echo ""; 
                                   ?>
          <?php $monthrndifference =  round($monthrndifference,3);
						$monthrndifference =  number_format($monthrndifference, 2, '.', '');
						?>                         
				  <?php echo "$monthrndifference" . $uomRain;?>
				</td>

and for the Year to Date (YTD):

<td class="data1" nowrap="nowrap">YTD Differential:</td>
                <td style="text-align: right;" class="data1">
				  <?php $yearrndifference=$yearrn-$avg_ytd_rain;
				  if ($yearrndifference >= 0)
				     echo "+";
				   else
				     echo ""; 
                                   ?>
          <?php $yearrndifference =  round($yearrndifference,3);
						$yearrndifference =  number_format($yearrndifference, 2, '.', '');
						?>
				  <?php echo "$yearrndifference" . $uomRain; ?>
				</td>

Currently, you’re only displaying the average month to date rainfall. You need to change your code. Basically, based on all of your data since station inception, you’ve averaged 3.08" of rain from April 1 to April 19. Then you compare this value to the current month rain to come up with a “+” or “-” value from normal. Same applies for the year to date rain but starts from Jan 1. I hope this makes sense.

Regards,
Michael

Yes it makes sense. Unfortunately I don’t know how to write the code. I copied and pasted yours and it is working perfectly.
Much appreciated! :hello1: