Welcome to the Cumulus Support forum.

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

Cumulus MX V4 beta test release 4.0.0 (build 4018) - 28 March 2024

Legacy Cumulus 1 release v1.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

Lowest Monthly Rainfall record desired on website

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderator: daj

User avatar
steve
Cumulus Author
Posts: 26702
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Lowest Monthly Rainfall record desired on website

Post by steve »

This may not be the best Javascript, but it appears to work.

Change your monthlyrecordT.htm as follows:

After the HTML table row for highest monthly rainfall, add:

Code: Select all

<tr class="td_rainfall_data">
    <td class="main_table_text_labels">Lowest&nbsp;Monthly&nbsp;Rainfall</td>
    <td class="right_align_indented"><span id="MonthlyRainL">---</span>&nbsp;<#rainunit></td>
    <td class="right_align_indented"><span id="MonthlyRainLT">---</span></td>
 </tr>
Before the line "function changeData(month) {" add the following

Code: Select all

var rainyears = new Array();
var raintotals = new Array(13);
var lowmonthlyrain = new Array();
var lowmonthlyrainT = new Array();

loaddata();

function loaddata() {
    var xmlhttp = new XMLHttpRequest();

    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == XMLHttpRequest.DONE ) {
           if (xmlhttp.status == 200) {
               processdata(xmlhttp.responseText);
           }
           else {
               alert('error loading rainfall.txt');
           }
        }
    };

    xmlhttp.open("GET", "rainfall.txt", true);
    xmlhttp.send();
}

function processdata(data) {
	for (var i = 1; i < 13; i++) {
		raintotals[i] = new Array();
	}
	// split each line using comma delimeter
	var arrayOfLines = data.match(/[^\r\n]+/g);
	// process each line, ignoring first line of headers
	for (var i = 1; i < arrayOfLines.length; i++) {
		var dataForYear = arrayOfLines[i].split(',');
		// add the year to the list
		rainyears.push(dataForYear[0]);
		
		// add the totals to the lists
		for (var j = 1; j < 13; j++) {
			if (dataForYear[j] == '') {
				// empty value, use a high value to exclude
				raintotals[j].push(999);
			} 
			else {
				raintotals[j].push(parseFloat(dataForYear[j]));
			}
		}
	}
	
	// find minimum for each month
	for (var month = 1; month < 13; month++) {
		var minvalue = Math.min.apply(null,raintotals[month]);
		var minyear = rainyears[raintotals[month].indexOf(minvalue)];
		
		// add value and year to corresponding arrays
		lowmonthlyrain.push(minvalue);
		lowmonthlyrainT.push(minyear);
	}
	
	var d = new Date();
	changeData(d.getMonth());

}
After the line "document.getElementById('MonthlyRainHT').innerHTML = monthlyrainT[month];", add:

Code: Select all

	document.getElementById('MonthlyRainL').innerHTML = lowmonthlyrain[month];
	document.getElementById('MonthlyRainLT').innerHTML = lowmonthlyrainT[month];
Remove the following code from near the end of the file:

Code: Select all

function init() {
    var d = new Date();
    changeData(d.getMonth());
  }
  window.onload = init;
Put your database result in a file called rainfall.txt and upload it to your site in the same place as the html pages.
Steve
User avatar
steve
Cumulus Author
Posts: 26702
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Lowest Monthly Rainfall record desired on website

Post by steve »

I've just noticed that the HTML table on your site doesn't match the code I've posted - hopefully you can work out what you need to do.
Steve
RayProudfoot
Posts: 3372
Joined: Wed 06 May 2009 6:29 pm
Weather Station: Davis VP2 with Daytime FARS
Operating System: Windows XP SP3
Location: Cheadle Hulme, Cheshire, England
Contact:

Re: Lowest Monthly Rainfall record desired on website

Post by RayProudfoot »

Steve,

Greatly appreciate you taking the time to write this for me. So far so good but I have one query.

You wrote...

After the line "document.getElementById('MonthlyRainHT').innerHTML = monthlyrainT[month];", add:

But I can't see a line with that in it. I do have one that says...

document.getElementById('MonthlyRainHY').innerHTML = monthlyrainY[month];

I'm guessing I paste your code after that line. But should lowmonthlyrainT be lowmonthlyrainY to match the high rainfall record?
Cheers,
Ray, Cheshire.

Image
RayProudfoot
Posts: 3372
Joined: Wed 06 May 2009 6:29 pm
Weather Station: Davis VP2 with Daytime FARS
Operating System: Windows XP SP3
Location: Cheadle Hulme, Cheshire, England
Contact:

Re: Lowest Monthly Rainfall record desired on website

Post by RayProudfoot »

steve wrote:I've just noticed that the HTML table on your site doesn't match the code I've posted - hopefully you can work out what you need to do.
I think so. I added some formatting to make alternate lines a different background colour.
Cheers,
Ray, Cheshire.

Image
User avatar
steve
Cumulus Author
Posts: 26702
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Lowest Monthly Rainfall record desired on website

Post by steve »

RayProudfoot wrote:After the line "document.getElementById('MonthlyRainHT').innerHTML = monthlyrainT[month];", add:

But I can't see a line with that in it. I do have one that says...

document.getElementById('MonthlyRainHY').innerHTML = monthlyrainY[month];

I'm guessing I paste your code after that line. But should lowmonthlyrainT be lowmonthlyrainY to match the high rainfall record?
Ah, right, you've named yours with a Y as it's just the year. My extra code will work as it is, or you can use Y instead of T if you want, as long as you change all occurrences. The names don't affect the way the code works.
Steve
RayProudfoot
Posts: 3372
Joined: Wed 06 May 2009 6:29 pm
Weather Station: Davis VP2 with Daytime FARS
Operating System: Windows XP SP3
Location: Cheadle Hulme, Cheshire, England
Contact:

Re: Lowest Monthly Rainfall record desired on website

Post by RayProudfoot »

Thanks Steve. I changed all the instances and pleased to report it's pulling back the right rainfall for each month.

http://www.cheadlehulmeweather.co.uk/monthlyrecord.htm

But it's not showing which year it occurred in. Have I missed something or have you?

I can sort the formatting easy enough. I may even be able to use your code as the template for other monthly records. Much appreciated, thank you. :clap:
Cheers,
Ray, Cheshire.

Image
User avatar
steve
Cumulus Author
Posts: 26702
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Lowest Monthly Rainfall record desired on website

Post by steve »

In the HTML you have

<td class="right_align_indented"><span id="MonthlyRainLT">---</span></td>

and in the JavaScript

document.getElementById('MonthlyRainLY').innerHTML = lowmonthlyrainY[month];

The one in the HTML needs changing to match the JavaScript (MonthlyRainLY)
Steve
RayProudfoot
Posts: 3372
Joined: Wed 06 May 2009 6:29 pm
Weather Station: Davis VP2 with Daytime FARS
Operating System: Windows XP SP3
Location: Cheadle Hulme, Cheshire, England
Contact:

Re: Lowest Monthly Rainfall record desired on website

Post by RayProudfoot »

Thanks! I knew it would be something I did. :lol: Almost there. Just need to tidy up the formatting.

24 hours from tentative enquiry to supplied code. You're not losing your touch Steve! :D
Cheers,
Ray, Cheshire.

Image
RayProudfoot
Posts: 3372
Joined: Wed 06 May 2009 6:29 pm
Weather Station: Davis VP2 with Daytime FARS
Operating System: Windows XP SP3
Location: Cheadle Hulme, Cheshire, England
Contact:

Re: Lowest Monthly Rainfall record desired on website

Post by RayProudfoot »

All done. Formatting tidied up and looking good. Thanks Steve! :clap:
Cheers,
Ray, Cheshire.

Image
User avatar
steve
Cumulus Author
Posts: 26702
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Lowest Monthly Rainfall record desired on website

Post by steve »

Looks good.
Steve
RayProudfoot
Posts: 3372
Joined: Wed 06 May 2009 6:29 pm
Weather Station: Davis VP2 with Daytime FARS
Operating System: Windows XP SP3
Location: Cheadle Hulme, Cheshire, England
Contact:

Re: Lowest Monthly Rainfall record desired on website

Post by RayProudfoot »

I'm revisiting this discussion from last year as it's very likely that not only will the June low rainfall record be broken but the all-time monthly one too.

Am I right in assuming the all-time record light will not flash as there is no all-time low rainfall record flag set in the core Cumulus program? Pity I can't set the light manually. :(
Cheers,
Ray, Cheshire.

Image
User avatar
steve
Cumulus Author
Posts: 26702
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Lowest Monthly Rainfall record desired on website

Post by steve »

You're correct, lowest monthly rainfall is not a record tracked by Cumulus, sorry.
Steve
RayProudfoot
Posts: 3372
Joined: Wed 06 May 2009 6:29 pm
Weather Station: Davis VP2 with Daytime FARS
Operating System: Windows XP SP3
Location: Cheadle Hulme, Cheshire, England
Contact:

Re: Lowest Monthly Rainfall record desired on website

Post by RayProudfoot »

No worries Steve. I shall have to find a way of drawing people’s attention to it.
Cheers,
Ray, Cheshire.

Image
Post Reply