WxSim Temperature Forecast Comparison Script

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

No need to be sorry Jim this is a great script and working bugs out is actually fun, plus slowly I learn a little bit more! So I have changed my page to your new script and wiped the log files. Ran the new ‘am’ script and it seems to have worked OK. I’ll run another forecast this afternoon for the pm and we’ll see what happens but this seems to be the answer so far!

Thanks for all your hard work!

Jack

Sorry Jack,
Was in a hurry, you are right,must be(like Jim says)

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

Edit: now i did it again:copy & paste the same(wrong) code #-o
now it’s better

I have this working… as it was/is in the original package… using the test-fc.php page…

Could somebody post, exacly, what I need to do to get a page that displays a morning and afternoon comparison on the same page? I’ve used AutoIT to create a script that is scheduled, so I can update a log once a day… won’t be hard to run the same script twice a day… but I assume I have to change it a tad to create two forecast logs?

Anyhow, if somebody could post a ‘new’ test-fc.php page that containst two forecasts, as well as post how to generate them individually, I’d love to give this a try! Adding it to the templates will be a must, once I get it working… and I believe Ken said he is working on that too! Fantastic!!!

Thanks all!

Stuntman,

Glad it’s kind of working for you and sorry that I didn’t get a chance to update the readme yet. I have to work every Thursday and that’s today. For the logging you’d use:

forecast-compare-include.php?log&config=am - in one of your autoit scripts
forecast-compare-include.php?log&config=pm - and this in the other.

forecastAM.log and forecastPM.log must be on the server write enabled.

In your web page you’d have something like this

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

$_REQUEST[‘config’] = ‘pm’;
include(“forecast-compare-include.php”);

Now since you already had it running and logging to forecast.log, you can replace one of the above with

forecast-compare-include.php?log - will default to logging to forecast.log

Then to display, replace either the am or pm above with

include(“forecast-compare-include.php”);

I’m kind of thinking I should have left the default option out of the equation, but it’s there now.

Let us know how it goes.

  • Jim

Wow… that really confused me! Not much of a web programmer I guess! Can you package one that has this all configured… an am/pm and a test-fc.php page that shows both? All I’d need to change is timezone… I’ve tried what you posted but I get either an error stating the config doesn’t exist or that it has already logged… neither of which should be the case as I do have the log files and it has never logged…

I’m sure I’m just missing something simple, but not being a coder, I don’t see it!

Thanks… and sorry to be a pain!