Page 1 of 3
Script to display snow data on website for CMX 4.3+
Posted: Mon 06 Jan 2025 8:59 pm
by surban21
This script replaces a previous version that stopped working in CMX ver. 4.3 and above due to restructuring of the tables in diary.db.
Released: version 2.0 Feb. 20, 2025 (use only with CMX 4.3 and above)
snowDisplay version 2.0
- ver 2.0 - Feb. 20, 2025 - Initial release of Seasonal Snowfall Data for CMX using an .exe/dll to pull data from diary.db
- Created an exe/dll file to pull data from diary.db instead of using a php script, thus elliminating the need to install php on your local machine solely for that purpose.
- Removed the PHP version of intlDateFormatter for localized month names. Now uses javascript's version which is independant of any PHP versions.
- Calculations for the snowfall statistics section now uses the date when snowfall (snow24hr) was first recorded.
** PHP no longer needs to be installed locally on same machine running CMX in order to pull data from diary.db, as was previously required. **
The ZIP file includes the necessary snowDisplay files and a read_me.txt file with installation instructions.
snowDisplay_v_2_0.zip
Please see image below which was using sample data at the time for testing.
Runs successfully in CUtils, Cumulus MXUI web template, the standard CMX website template, and as a standalone webpage. Hasn't been tested on other templates but shouldn't be any reason it wouldn't work. For templates just add <?php include_once "./snowDisplay.php";?> where you want it to be displayed. Then for templates using htm or html extensions change the webpage extension to .php and update your menu to point to the .php page.
Thanks to PaulMy as portions of this script is inspired from komokaweather.com snowfall-log.pdf.
Some key features in this program include;
- Setting user defined variables such as; timezone, whether northern or southern hemisphere, unit of measure (inches or centimeter), the use of using a comma or dot (period) for decimal places
- Setting a preferred language (default language is english).
- Daily, Monthly and yearly cumulative snowfall and event totals
- Cumulative days with snowfall
- Cumulative snowfall depth
- Average annual snowfall depth
- Probability of snowfall %
pic of it used as an include in a template
snowDisplay_v_2_0.png
Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+
Posted: Fri 10 Jan 2025 10:55 pm
by PaulMy
MUST have php installed on the same computer running CumulusMX to use this script.
From where and how would I install PHP?
Enjoy,
Paul
Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+
Posted: Fri 10 Jan 2025 11:57 pm
by water01
Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+
Posted: Sat 11 Jan 2025 7:45 am
by sutne
Does it have to be run on the local CMX computer?
If the diary.db is uploaded to the web-server, I suppose this script can be included in the web-pages?
Re: SnowDisplay.php js functions for monthly totals and cumulative totals seem only to work for latest year
Posted: Sat 11 Jan 2025 1:14 pm
by lse-cumulus
Hi Steve,
I like your new scripts (espcially the streamlined snowQuery.php and wanted to integrate them into my site.
I adapted your scripts for php 5.3.x, but I had to remove the month name formatter for international calendar from snowDisplay.php as function IntlDateFormatter is not available before PHP 5.5.
Basically working fine, as seen here on my webpage
https://leonas.ddns.net/Wetterstation.S ... isplay.php
But the Monthly totals and cumulative Totals are only shown during startup or when I select the latest year 2024/2025 (or when I refresh the browser)
See screenshot:
Leo.SnowDisplay.monthly.cumulative.Totals.ok.jpg
When I switch the years e.g. to 2023/2024 the daily data is switching to the correct yearly data, but the monthly totals and cumulative totals are not displayed.
See 2nd screenshot:
Leo.SnowDisplay.monthly.cumulative.Totals.NOK.jpg
.
When I go back to 2024/2025 the totals also remain empty, but with a browser refresh the totals are shown again.
Seems to be an issue in the javascript code. In that JS part of your snowDisplay.php script a did not make changes (only added a Number().toFixed(1) to solve an error reported in the F12 browser Console). Now I do not see any errors in F12 Console.
So I am wondering if this JS aggregation is working for you on your site (could not find a link to check it out) and the problem is only in my (modified) scripts, or if this is a general issue in the JS part of the code.
Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+
Posted: Sat 11 Jan 2025 1:47 pm
by surban21
sutne wrote: ↑Sat 11 Jan 2025 7:45 am
Does it have to be run on the local CMX computer?
If the diary.db is uploaded to the web-server, I suppose this script can be included in the web-pages?
I don't have the ability to try that so I can't say for sure. snowQuery.php does need access to the diary.db and I'm sure the paths in both files will need to be adjusted but with some tweaking I feel it could work. Unless I'm missing something.
Re: SnowDisplay.php js functions for monthly totals and cumulative totals seem only to work for latest year
Posted: Sat 11 Jan 2025 2:21 pm
by surban21
lse-cumulus wrote: ↑Sat 11 Jan 2025 1:14 pm
Seems to be an issue in the javascript code. In that JS part of your snowDisplay.php script a did not make changes (only added a Number().toFixed(1) to solve an error reported in the F12 browser Console). Now I do not see any errors in F12 Console.
So I am wondering if this JS aggregation is working for you on your site (could not find a link to check it out) and the problem is only in my (modified) scripts, or if this is a general issue in the JS part of the code.
I don't have a public site but it is working for me on my local machine as well as other sites that I know have been using this publicly. I do have some time available if you want to attach a zip of the modified snowDisplay.php. I'll take a look at it and see what I can find. As a side note, I thought intlDateFormatter was available starting in php version 5.3. But I suppose i could easily have been mistaken.
Steve
Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+
Posted: Sat 11 Jan 2025 2:26 pm
by PaulMy
Thanks David,
https://windows.php.net/download/
I don 't think I have it on my Windows 10 PC yet, and so many options from that link. Which one(s) would be good to download, and any specific instructions?
Enjoy,
Paul
Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+
Posted: Sat 11 Jan 2025 2:51 pm
by water01
PaulMy wrote: ↑Sat 11 Jan 2025 2:26 pm
Thanks David,
https://windows.php.net/download/
I don 't think I have it on my Windows 10 PC yet, and so many options from that link. Which one(s) would be good to download, and any specific instructions?
Enjoy,
Paul
I use it to integrate with my web designer software so I can test it on the windows machine before I use it where it naturally resides on your website server.
To that end I always use the Non Thread safe version which is the one they advise to use with an ISS (Internet Information Services i.e. a web server).
The program I use uses the base php.exe which it calls from within it, so not having looked at this code (chances of me getting snow are fairly small, even in our current cold spell!!) so I do not know how it is used, but that is usual way i.e. calling the .exe.
Re: SnowDisplay.php js functions for monthly totals and cumulative totals seem only to work for latest year
Posted: Sat 11 Jan 2025 5:04 pm
by lse-cumulus
surban21 wrote: ↑Sat 11 Jan 2025 2:21 pm
lse-cumulus wrote: ↑Sat 11 Jan 2025 1:14 pm
Seems to be an issue in the javascript code. In that JS part of your snowDisplay.php script a did not make changes (only added a Number().toFixed(1) to solve an error reported in the F12 browser Console). Now I do not see any errors in F12 Console.
So I am wondering if this JS aggregation is working for you on your site (could not find a link to check it out) and the problem is only in my (modified) scripts, or if this is a general issue in the JS part of the code.
I don't have a public site but it is working for me on my local machine as well as other sites that I know have been using this publicly. I do have some time available if you want to attach a zip of the modified snowDisplay.php. I'll take a look at it and see what I can find. As a side note, I thought intlDateFormatter was available starting in php version 5.3. But I suppose i could easily have been mistaken.
Steve
Hi steve,
please find attached my modified version 1.1 ofr snowDisplay.php
Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+ (php 5.3 version 1.2 now accumuluates also)
Posted: Sat 11 Jan 2025 8:19 pm
by lse-cumulus
Steve,
I think I solved my problem.
After debugging in Chrome F12 Console, I saw that the data in the snowDepthArray and snow24hrArray is not stored as Number but as String.
Therefore I added some Number() conversions in js function updateMonthlyAndCumulativeTables() before the typeof check was made to avoid that nothing was accumulated.
Code: Select all
// Accumulate data for the month
for (let day = 1; day <= 31; day++) {
const snowDepth = snowDepthArray[selectedYear]?. [monthStr]?. [
day
]; // Get snow depth for the day
const snow24hr = snow24hrArray[selectedYear]?. [monthStr]?. [day]; // Get 24hr snow for the day
// If there is snow on this day, accumulate the snow depth
// leo: use Number() as data in snowDepthArray is stored as string and not as number; so that typeof works
if (typeof Number(snowDepth) === 'number' && Number(snowDepth) > 0) {
totalSnowDepth = (totalSnowDepth || 0) + Number(snowDepth);
monthlyEventCount++; // Increase event count if snowDepth > 0
}
// If there is snow in the last 24 hours, accumulate the snow24hr
// leo: use Number() as data in snow24hrArray is stored as string and not as number; so that typeof works
if (typeof Number(snow24hr) === 'number' && Number(snow24hr) >= 0) {
totalSnow24hr = (totalSnow24hr || 0) + Number(snow24hr);
monthly24hrEventCount++; // Increase event count for 24hr snow if snow24hr > 0
}
}
The script now works on my CU website as intended
https://leonas.ddns.net/Wetterstation.S ... isplay.php
Attached my version 1.2 of snowDisplay.php.
Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+ (php 5.3 version 1.2 now accumuluates also)
Posted: Sat 11 Jan 2025 10:34 pm
by surban21
lse-cumulus wrote: ↑Sat 11 Jan 2025 8:19 pm
I think I solved my problem.
After debugging in Chrome F12 Console, I saw that the data in the snowDepthArray and snow24hrArray is not stored as Number but as String.
Therefore I added some Number() conversions in js function updateMonthlyAndCumulativeTables() before the typeof check was made to avoid that nothing was accumulated.
It's like trying to find a needle in a haystack. Glad it worked - but - I'm afraid this will count null as a number since it will treat null as 0. This will give you a false "Event" count. Look in the monthly totals for Jan in the NS column. you'll notice the count shows 4 when actually it should be 2. This will happen when either NS or TD contains a value but the other doesn't. When this happens, null has to be treated an object so it is not given a value of 0 and then counted in the "Events" row. This gave me all sorts of fits when I was writing the code and settled with what I had written. There may be other ways around this but I'm not sure, and I don't want to break what I have as it is working.
As a side note, may I ask why not upgrade php?
Steve
Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+
Posted: Sat 11 Jan 2025 11:54 pm
by lse-cumulus
Steve,
thx for the hint that JS Number(null) gives 0. Now I understand your JS code better. I found a way to fix now also my event counters.
You are right that is a tricky coding, and the root cause is that the json_encode() from script snowQueury.php works differently in your and my PHP environment. So you need your JS code and I need my adaptations (and I introduced this transient problem by changing the snowQueury.php script in the first place ...).
I am happy that it works now also for me in my PWS environment:
https://leonas.ddns.net/Wetterstation.S ... isplay.php
I appreciate your support.
The PHP Upgrade is on my backlog to do list but has to take into account some special dependencies in my web server environment.
Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+
Posted: Sat 18 Jan 2025 9:33 pm
by surban21
There's an updated version released: Jan. 18, 2025. It can be downloaded on the first page of this thread if interested.
snowDisplay_v_1_1
** Fixed some issues with its appearance when run within CUtils and the CMX web template.
** Should now be more cross-platform capable.
** Fixed the yearDropdown list as it was not populating properly on some templates.
** Overall has a cleaner appearance.
Re: PHP Script for Website Seasonal Snowfall Data for CMX 4.3+
Posted: Sun 19 Jan 2025 12:06 pm
by Dador
Steve,
I use the script and I admit that the translation option is great. I just have a small comment on the Polish translation. If You could include my corrections in the next version.
Code: Select all
'Events' => 'Zdarzenia',
'Most - year' => 'Najwięcej - rok',
The original translation of 'Events' -> 'Imprezy' is incorrect. In Polish 'imprezy' is in English 'party'
I will be grateful because I won't have to manually correct this with each update.