Welcome to the new home of the Cumulus Support forum.

Latest Cumulus release v1.9.4 (build 1099) - Nov 28 2014
Latest Cumulus MX release - v3.0.0 build 3044 7 December 2018. See the Wiki for download

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: 26714
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 » Wed 10 May 2017 5:40 pm

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: 26714
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 » Wed 10 May 2017 6:25 pm

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: 2633
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 » Wed 10 May 2017 6:44 pm

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: 2633
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 » Wed 10 May 2017 6:45 pm

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: 26714
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 » Wed 10 May 2017 6:51 pm

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: 2633
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 » Wed 10 May 2017 6:58 pm

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: 26714
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 » Wed 10 May 2017 7:04 pm

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: 2633
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 » Wed 10 May 2017 7:19 pm

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: 2633
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 » Wed 10 May 2017 7:37 pm

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

Image

User avatar
steve
Cumulus Author
Posts: 26714
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 » Thu 11 May 2017 9:17 am

Looks good.
Steve

RayProudfoot
Posts: 2633
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 » Tue 26 Jun 2018 1:02 pm

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: 26714
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 » Tue 26 Jun 2018 1:23 pm

You're correct, lowest monthly rainfall is not a record tracked by Cumulus, sorry.
Steve

RayProudfoot
Posts: 2633
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 » Tue 26 Jun 2018 2:33 pm

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

Image

Post Reply