Welcome to the Cumulus Support forum.

Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080

Annual Data Summary - sunshine hours

Discussion and support for 3rd-party (non-Sandaysoft) tools for Cumulus
Post Reply
Graham64
Posts: 74
Joined: Mon 23 Aug 2010 5:04 pm
Weather Station: Davis Vantage Pro 2
Operating System: Windows XP
Location: Cornwall, England
Contact:

Annual Data Summary - sunshine hours

Post by Graham64 »

I've been using David's excellent Annual data summary pages as a means to improve my almost non-existent PHP and Javascript skills. I wanted to add Sunshine hrs to the pages.

But there is a problem because my version of dayfile.txt before 01/01/2011 does not have the sunshine hours field.

My modified Javascript version deals with the fact that the early dayfile.txt is shorter than the 2011 file and just leaves blank fields for sunshine in 2010 (see http://poundstockpacket.org.uk/datasummary_gj.html)

However my modified PHP version produces an error of Notice: Undefined offset: 24 when it tries to display 2010 sunshine hrs. I assume that this is because my dayfile.txt in 2010 didn't have field 24, sunshine hours (see http://poundstockpacket.org.uk/datasummary_gj_01.php)

I have got around the problem by hardcoding a trap for the error (see http://poundstockpacket.org.uk/datasummary_gj_02.php) This looks for 2010 and sunshine hours

Code: Select all

// need to trap old 'layouts' that did not contain sunshine data
	if( $tableYear == '2010' && $whatdata == 'sunhours')
			{$data[$id] = '';}
	else
			{ $data[$id] = $buf_arr[$dayfilecol]; } 
I have two questions:
  • Why does the Javascript version not produce an error?
    Is there a better way of dealing with the problem in PHP without hardcoding?
Thanks
Graham
User avatar
mcrossley
Posts: 14384
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Annual Data Summary - sunshine hours

Post by mcrossley »

Without looking at the full code, just working with your snippet...

Code: Select all

if ($dayfilecol >= count($buf_arr)) {
  $data[$id] = '';
} else {
  $data[$id] = $buf_arr[$dayfilecol];
}
Last edited by mcrossley on Tue 17 May 2011 8:18 am, edited 1 time in total.
User avatar
mcrossley
Posts: 14384
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Annual Data Summary - sunshine hours

Post by mcrossley »

Oh, and your Javascript does produce an error "Uncaught TypeError: Cannot call method 'split' of undefined" at line 86 of jquery.js, but your browser may be set to ignore script errors - most are by default 'cause there are so many of them out there!
User avatar
steve
Cumulus Author
Posts: 26672
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Annual Data Summary - sunshine hours

Post by steve »

mcrossley wrote:if ($dayfilecol >= count($buf_arr)
This is what I do in Cumulus; just check that there are sufficient fields in the entry.
Steve
Graham64
Posts: 74
Joined: Mon 23 Aug 2010 5:04 pm
Weather Station: Davis Vantage Pro 2
Operating System: Windows XP
Location: Cornwall, England
Contact:

Re: Annual Data Summary - sunshine hours

Post by Graham64 »

Mark/Steve
Thanks very much for the suggestion for the PHP fix - I have added the more general check for $dayfilecol as you both suggested. There is now no error.

Mark
Thanks for the pointing out the Javascript error, my browser didn't show it. I used Firebug to look at the problem - I think it was the same error as with the PHP version.
I have solved the problem by trapping the error using

Code: Select all

if(wd_data.length>=dayfilecol)
See http://poundstockpacket.org.uk/datasummary_gj.html

Thanks again to you both - this Forum is so useful. I'm learning a great deal, all I need now is more free time to program!

Graham
Post Reply