cloudy

Author Topic: Rain "Year to Date" and "Month to Date" Differential Script  (Read 12173 times)

0 Members and 1 Guest are viewing this topic.

mth

  • Guest
Rain "Year to Date" and "Month to Date" Differential Script
« on: March 20, 2010, 01:01:38 AM »
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.

Code: [Select]
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:


« Last Edit: March 20, 2010, 01:03:52 AM by mth »

Offline FrankP999

  • Posts: 1,135
  • Macon, Georgia USA
    • My Weather
Re: Rain "Year to Date" and "Month to Date" Differential Script
« Reply #1 on: March 20, 2010, 11:33:35 AM »
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

Offline BfdWx

  • Posts: 1,596
  • Branford Connecticut
    • Branford Weather
Re: Rain "Year to Date" and "Month to Date" Differential Script
« Reply #2 on: March 20, 2010, 11:42:56 AM »
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

mth

  • Guest
Re: Rain "Year to Date" and "Month to Date" Differential Script
« Reply #3 on: March 20, 2010, 03:18:33 PM »
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,

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

Offline ed2kayak

  • CoCoRaHS PA-CD-6, Weather Underground KPAMECHA7, CWOP DW5425
  • Posts: 449
  • Mechanicsburg PA
    • Cumberland Valley Weather
Re: Rain "Year to Date" and "Month to Date" Differential Script
« Reply #4 on: April 18, 2011, 08:49:44 PM »
Just tried this script. Thanks
http://cvweather.org/wxraintrending.php

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.
Ed
CoCoRaHS PA-CD-6,  Weather Underground KPAMECHA7, CWOP DW5425

mth

  • Guest
Re: Rain "Year to Date" and "Month to Date" Differential Script
« Reply #5 on: April 18, 2011, 10:36:30 PM »
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.
« Last Edit: April 18, 2011, 10:43:58 PM by mth »

Offline ed2kayak

  • CoCoRaHS PA-CD-6, Weather Underground KPAMECHA7, CWOP DW5425
  • Posts: 449
  • Mechanicsburg PA
    • Cumberland Valley Weather
Re: Rain "Year to Date" and "Month to Date" Differential Script
« Reply #6 on: April 18, 2011, 10:51:53 PM »
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
« Last Edit: April 18, 2011, 11:09:12 PM by ed2kayak »
Ed
CoCoRaHS PA-CD-6,  Weather Underground KPAMECHA7, CWOP DW5425

mth

  • Guest
Re: Rain "Year to Date" and "Month to Date" Differential Script
« Reply #7 on: April 18, 2011, 11:38:21 PM »
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


mth

  • Guest
Re: Rain "Year to Date" and "Month to Date" Differential Script
« Reply #8 on: April 19, 2011, 12:52:00 AM »
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


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.....

Offline drobbins

  • Posts: 1,694
  • Kentucky, USA
    • Cave Country Weather
Re: Rain "Year to Date" and "Month to Date" Differential Script
« Reply #9 on: April 19, 2011, 01:11:18 AM »
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 -  ?

Code: [Select]
<tr>
                <td class="data1">MTD Differential: </td>
                <td style="text-align: right;" class="data1">
 
                  <?php echo $avg_mtd_rain $uomRain?>
                </td>
« Last Edit: April 19, 2011, 11:55:47 PM by drobbins »

Offline ed2kayak

  • CoCoRaHS PA-CD-6, Weather Underground KPAMECHA7, CWOP DW5425
  • Posts: 449
  • Mechanicsburg PA
    • Cumberland Valley Weather
Re: Rain "Year to Date" and "Month to Date" Differential Script
« Reply #10 on: April 19, 2011, 01:49:21 PM »
I got my March rain total squared away, there was a bug in WD.
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
Ed
CoCoRaHS PA-CD-6,  Weather Underground KPAMECHA7, CWOP DW5425

Offline ed2kayak

  • CoCoRaHS PA-CD-6, Weather Underground KPAMECHA7, CWOP DW5425
  • Posts: 449
  • Mechanicsburg PA
    • Cumberland Valley Weather
Re: Rain "Year to Date" and "Month to Date" Differential Script
« Reply #11 on: April 19, 2011, 02:47:14 PM »
I tried converting log files to data, nothing worked.
But view>rain chart>mth to correct fixed it for me.
Thanks
Ed
CoCoRaHS PA-CD-6,  Weather Underground KPAMECHA7, CWOP DW5425

mth

  • Guest
Re: Rain "Year to Date" and "Month to Date" Differential Script
« Reply #12 on: April 19, 2011, 10:21:58 PM »
It looks like the tags are in and working:http://www.cavecountryweather.com/test.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 -  ?

Code: [Select]
<tr>
                <td class="data1">MTD Differential: </td>
                <td style="text-align: right;" class="data1">
 
                  <?php echo $avg_mtd_rain $uomRain?>
                </td>

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):
Code: [Select]
<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($monthrndifference2'.''');
?>
                         
  <?php echo "$monthrndifference$uomRain;?>
</td>

and for the Year to Date (YTD):
Code: [Select]
<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($yearrndifference2'.''');
?>

  <?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

Offline drobbins

  • Posts: 1,694
  • Kentucky, USA
    • Cave Country Weather
Re: Rain "Year to Date" and "Month to Date" Differential Script
« Reply #13 on: April 19, 2011, 11:59:07 PM »
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: