WxSim Temperature Forecast Comparison Script

I’ve created a new script that will record and display comparisons of WxSim temperatures with those of another system. Other systems supported are the National Weather Service, Weather Underground and Environment Canada. The required plaintext-parser.php as well as all the scripts to parse the others were created by, and are available from Ken True at http://saratoga-weather.org/scripts-WXSIM.php.

You can see a Demo Page with lotsa data here, see the installation on my site and download a copy here.

Please let me know if you have any problems or questions.

  • Jim

Edited to remove the Demo link since it’s no longer maintained.

Excellent script Jim, I’ve been wanting to track this for a while but never have the time! This will make things really easy.

Thanks for sharing!

Jack

Hi Jim

Thank you very much for another great script.

It was very easy to get running:

www.silkeborg-vejret.dk/sammenlign.php

Best regards,

Henrik

This is fantastic, Jim! What a great script set to allow us to compare actuals v.s. our own and a reference forecast.

I have one suggestion to help keep the scripts safe from abuse by miscreants … use an allowed-file name for the config param so it won’t be vulnerable. Something like

<?php
$allowed = array (
  'am' => 'fc-configAM.php',
  'pm' => 'fc-configPM.php'
);

$configfile = "fc-config.php";

if (isset($_REQUEST['config']) and isset($allowed[$_REQUEST['config'])) {
  $configfile = $allowed[$_REQUEST['config']);
}
?>

That way, no bad juju can be jammed into the script :slight_smile:

Best regards,
Ken

Ken,

Thanks for that, with all the discussion on security these past couple days you’d think I’d have noticed that. Would an alternative be to check whether the file exists on the server and only include those? That would leave folks the option of creating many more, for instance in different languages etc.

  • Jim

The safest way is to use the associative lookup for allowed filenames … anything else would allow them to substitute an URL for the value (or backrefs to system files) … better to have the ‘authorized list’ be in the script, then no funny-business can be done with the parameter :slight_smile:

Thanks Ken,

I’ll do it that way, they’ll have to do some editing at the beginning of the main file, but I guess that’s ok. I think I’ll add a language file to the mix too just in case they want to serve it up in different languages.

  • Jim

The .zip file has been updated with the following changes:

Version 1.0 - 02-10-09 - Initial release
1.1 - 02-11-09 - Removed language vars from the config and created fc-language.php to make multiple languages easier to maintain.
Added a more secure file inclusion method as recommended by Ken True.

Plus, I discovered that I didn’t get the best copy of forecast-compare-include.php in there yesterday either. To upgrade, save your fc-config.php for reference then upload a whole new set of files. Edit the new config and the fc-language.php files as required.

Sorry for the inconvenience. - Jim

I’m having a little issue/trouble mainly with my mind and a little with the script. Trying to do an am/pm log and for now using the poor man’s method of using the web address to update the log. I’ve made two fc-configs, one am one pm with corresponding logs and uploaded them. This morning’s upload went smoothly but this afternoon’ wiped this mornings data and said 'this forecast has already been run". I did run a new WXSIM forecast which now shows in both charts as 2:35pm.

So am I calling the script incorrectly? Here is a snippet of the code I’m using;

		$_REQUEST['config'] = 'fc-configam.php';	      // It will default to this one if this isn't included
		$_REQUEST['lang'] = 'en';	                  // This will default to English if not included	
		include("forecast-compare-include.php");

		$_REQUEST['config'] = 'fc-configpm.php';	      // It will default to this one if this isn't included
		$_REQUEST['lang'] = 'en';	                  // This will default to English if not included	
		include("forecast-compare-include.php");

So am I improperly calling the script or improperly calling the wrong web addresses?

Thanks,

Jack

Here is where the script is running…http://stillweather.com/nuforecast_compare.php

Great script Jim!

Mike

Jack,

The code you posted looks fine, you’re calling the script twice, once with each config file. I suspect the problem is in the logging portion and I would check to make sure that you have a different log name in each of the configs. Looks like you are logging to the same one. If you want, you can turn the debug on (in both configs) and do one and then the other to make sure they are logging to the right place. The display portion is working fine and looks very nice.

  • Jim

Hmmm…getting worse now #-o

Decided to get one right first so put just one chart in. Take a look at the chart now, the data is in several times and it is wrong. If “forecast day” is today my high was 60 and wxsim was right on the mark. Where is 43 coming from and why is it populating across the fields. Sorry to be a pain but I really like this script!

Thx

Jack

Edit: OK, I think it is ok now, so did I miss today’s comparison? And if I run wxsim 3 times a day I should get data 3 times for the same day?

Jack,

You only want it to run once each day, shortly after your WxSim forecast is run. It will capture the forecast temperatures just like you see on your page. Tomorrow when you run it, it will fill in the ACT (actual) temperature that happened on that line, and build a new line for that next forecast. If you look at my page, you’ll see that the actual temperatures get filled in and stagger down and to the right because those forecasts were for xx days out.

If you want to track both am and pm forecasts, you’re just doing that same thing twice but with different config and log files.

  • Jim

OK, thanks Jim, I think (usually when I get in trouble) I found my errors so I should be able to get the two tables back up properly. Thanks for the help!

Jack

Good news Jack. You can mess around with it tonight with debug on and then upload blank logs when you’re done. That way you’ll be all set to go for tomorrows forecasts.

I know Henrik has it working ok in Denmark, I wonder if anyone has tried yet in Canada.

  • Jim

I’ve got it working too … used a crontab entry to fetch the log once daily (so there’s only one entry in mine so far).

http://saratoga-weather.org/WXSIM-stats.php

After I get a few days of data, I’ll add it to the menu … been wanting to watch these stats for quite a while.

Thanks again Jim for the great script!

Best regards,
Ken

I’m testing this with am and pm.
notice, when you are running the latest version(1.1), you have to call the script with the allowed config-files.
in forecast-compare-include is the folowing(whitch you can edit)

$allowed = array (                 // You can add additional configuration file names here
  'am' => 'fc-configAM.php',
  'pm' => 'fc-configPM.php'
);

so, I’m calling the script like this:

forecast-compare-include.php?log&config=am
forecast-config-compare.php?log&config=pm

if you don’t do it like this, you end up using fc-config.php, and not with the configurations you want.

you can call the different logs with:

		$_REQUEST['config'] = 'pm';
		$_REQUEST['lang'] = 'en';	
		include("forecast-compare-include.php");

Jozef,

I’m calling for it to log with

forecast-compare-include.php?log&config=fc-configAM.php

and I thought it was working that way, but will double check today. It could be that I misunderstood Ken’s code and need a change in the documentation. Your way is cleaner looking anyway.

Jack, if you’re still having trouble try Pinto’s forecast-compare-include.php?log&config=am

Thanks. - Jim

forecast-compare-include.php?log&config=am
forecast-config-compare.php?log&config=pm

Now I’m getting confused again…LOL. Looking at the above code there are two different ways “forecast-compare-include” and “forecast-compare-include”?

I just ran the forecast this am and for some reason it added an extra spot for today (am) which is blank. In order to get it to work this is what I had to do, and it’s probably wrong. I made two “forecast-includes” one for am one for pm, so my code looks like this now;

    <td align="center">
        <h3>WxSim &amp; NWS Forecast Comparison AM</h3>
        National Weather Service (NW), Actual Observed (Act), WxSim Generated (WS)
        

        <?php 
        $_REQUEST['config'] = 'fc-configam.php';
        include("forecast-compare-includeam.php");
        /*          
        echo "\n";
            $_REQUEST['config'] = 'fc-configWU.php';  // Example of how to force the use of an alternate configuration file
            include("forecast-compare-include.php");
        echo "\n";           
            $_REQUEST['config'] = 'fc-configEC.php';
            include("forecast-compare-include.php"); 
        */          
        ?>
 </td>
      </tr>
</table>
  <table style="border:0;margin-left:auto;margin-right:auto;">

      <tr class="table-top">


    <td align="center">
        <h3>WxSim &amp; NWS Forecast Comparison PM</h3>
        National Weather Service (NW), Actual Observed (Act), WxSim Generated (WS)
        

        <?php 
        $_REQUEST['config'] = 'fc-configpm.php';
        include("forecast-compare-includepm.php");
        /*          
        echo "\n";
            $_REQUEST['config'] = 'fc-configWU.php';  // Example of how to force the use of an alternate configuration file
            include("forecast-compare-include.php");
        echo "\n";           
            $_REQUEST['config'] = 'fc-configEC.php';
            include("forecast-compare-include.php"); 
        */          
        ?>

It would only write to “forecast.log” without this change. So now I’m not sure about the above code, thanks for the help though Pinto, I’m sure we’ll get this sorted!

Regards,

Jack

Ok, I just had my morning run and the logging part went fine the old way, but the display part did not. So, Pinto is right … as always and here’s what we have to do. These assume that properly named log files are in place.

For logging

forecast-compare-include.php?log - will log to forecast.log by default
forecast-compare-include.php?log&config=am - to log to forecastAM.log
forecast-compare-include.php?log&config=pm - to log to forecastPM.log

For display in your web page

include(“forecast-compare-include.php”); - will show forecast.log in the default English

$_REQUEST[‘config’] = ‘am’;
include(“forecast-compare-include.php”); - will show forecastAM.log

$_REQUEST[‘config’] = ‘pm’;
$_REQUEST[‘lang’] = ‘xx’; - optional language
include(“forecast-compare-include.php”); - will show forecastPM.log

Hopefully I have this right now and I’ll change the readme and test file later in the day. Thanks Pinto and sorry Jack. This is what happens when a non-programmer makes changes without fully testing, I should know better by now.

  • Jim