'trendsT.htm' using recent history to drive HighCharts
Posted: Thu 07 Aug 2014 8:42 pm
A BESPOKE VERSION OF THE 'trendsT.htm' TEMPLATE - It contains everything in the standard version 1.9.4 utf-8 template, but it adds a further plot that is drawn using the highcharts script library based on recent history tags that report readings for temperature, rainfall and pressure at hourly intervals for the last week.
This new topic carries on from https://cumulus.hosiene.co.uk/viewtopic.php?f=18&t=12284. Not all the information that was in that topic has been repeated here. All references to times below for postings in that thread quote UTC. That old thread was getting quite long!
I have started a new topic to launch version 4 of my code in the hope that the new subject title will be easier to find for everyone. Version 4 is designed to work 'out of the box', all you need to add is the various script libraries. This is explained below, but you need to decide whether to download copies onto your web site (and use the 'src' properties I quote in the zipped file) or to use one of the CDN servers (for jQuery change 'src' properties to point to Google CDN, Microsoft CDN, CDNJS CDN, or jsDelivr CDN e.g. src="//code.jquery.com/jquery-2.1.1.min.js" and for highcharts set src=code.highcharts.com/highcharts.js). Obviously, I cannot please everyone, so you may wish to change some of the text I have included, change colours, or whatever; but I hope the comments I have included will help you see where to make such changes.
PRE-REQUISITES FOR INSTALLING THIS WEB PAGE
1 - Cumulus software build 1089 (released 7 August 2014) or later is needed to provide the Cumulus web tags required by this template.
2 - The template provided in this package needs to be processed by Cumulus, it can either be treated as producing a standard Cumulus page uploaded at the standard interval onto a remote server or it could be treated as an extra template file in a different folder that is processed onto a local server together with the standard Cumulus graphs and other pages (by making changes on the 'Files' tab of the 'Internet' options assessed from the 'Configuration' menu).
3 - Although modern browsers will say the way I use 'AJAX' to obtain the update time of the large Cumulus graph is deprecated, the AJAX routine I use can cope with Microsoft's non-standard browsers back as far as IE6. I mostly use Firefox, but I did not wish to force that on those who use this web page. I used a book as a different inspiration for my code snippet, but in https://cumulus.hosiene.co.uk/viewtopic.php?f=19&t=8493 27 Oct 2012 00:53 entry, a similar approach is proposed that excludes the Microsoft specific coding I put in.
4 - Two jQuery libraries are required (see http://jquery.com/download/) :
4.1 - 'jquery-1.9.1.js' is needed to allow the page to be viewed on the obsolete versions (up to version 10) of Internet Explorer that some users of obsolete versions of Windows might choose to use. They probably have other problems, but are used to what they have and do not know what they are missing without using a modern browser.
4.2 - 'jquery-2.1.1.js' is at the time of writing the standard version of jQuery and has been used for all my testing, it ensures that my coding can work on all modern browsers (including it is claimed IE11, but I have not tested this).
5 - 'highcharts.js' (http://www.highcharts.com/download)is needed for the new script to run, I upgraded to version 4.0.3 (I previously used version 4.0.0) specially for this experiment. The reference to a source of 'highcharts-exporting.js' is not actually needed to produce the graph, it simply makes it easy to print any Highcharts graph that is produced and to convert it into an image file as requested at the start of the development, by adding a menu accessed by a 3 line symbol at the top right of the chart. The zipped folder attached includes a few screen-shots, other screen shots (of earlier versions) can be seen in https://cumulus.hosiene.co.uk/viewtopic.php?f=18&t=12284. The earlier versions were downloaded 12 times I believe.
I will point out here that one of the screen shots shows the existing Cumulus 'daily range' graphs, one shows the existing Cumulus 'observations at every minute' plot, one shows my experiment at using day names on the x-axis (with a somewhat complicated additional function) and the last shows the version I am releasing with a day count on the x-axis. Don't worry about my test data, it is of low quality.
BACKGROUND TO THIS EXPERIMENTAL PROJECT
'tempe' from Finland said he found ' detailed chart period' and 'daily chart period' as two periods for which Cumulus would automatically draw trend graphs.
He requested trends for other periods like '12 hours, one day, week, month, 3 months etc.'
Steve Loft drew his attention to the recent and historic graphs on 'http://weather.wilmslowastro.com/graphs_recent.php' and
'http://weather.wilmslowastro.com/graphs_historic.php'.
'tempe' replied that his server did not support php, but he would consider generating plots locally with a script and then uploading the resulting images to his web site. "I dont need realtime or interactive graphs, just pictures of charts would be awesome."
'sfws' proposed a script using 'highcharts' library that would take hourly samples from the Cumulus 'recent history' tags that would allow
up to 7 days (168 hours).
'water01' showed an interest in proposed scripts based on taking samples from dayfile.txt.
DEVELOPMENT NOTES
A large number of issues were raised by attempting to develop a script that could be added to the standard Cumulus trends web page and would
work for anybody:
1) The 'no_commas' version of the 'recent history' tags needed to be used because places like Finland use commas to separate integer and
decimal parts whilst script restricts commas to being used to separate elements in an array and similar syntax siturations.
2) The script that uses the Highcharts Application programming interface (api) could be in a separate file, so it has been carefully written so
all the Cumulus web tags are converted into script variables that can be referenced by the plotting script. However, to make installation on the
web easier, this script is currently included at the end of the template so it becomes part of the HTML web page.
3) The script uses auto-scaling for the y-axis, and although that normally results in the axis being divided into 5, the script allows the
3 y-axis to be divided independently.
4) The tooltip and x-axis labels are generated by functions so they can make use of information that originates from Cumulus tags, and divide the x-axis into days, but it had cope with all possible starting times within a day.
5) The script assumes that the arrays represent observations at hourly intervals, but it had to work for periods from 12 hours to 168 hours. Therefore it includes coding to check the length of one of the arrays and therefore adjusts the heading to reflect that actual array length.
(To change to a different interval between elements in the array requires someone to make manual changes to many places in the coding).
6) The script needed to allow the user to zoom into a shorter period of time, and quickly return to full period.
7) The script needed to cope with both the case when Cumulus is running continuously and when it has recently been restarted and has read some of the old data from the station logger.
8) The script was designed to plot temperature, rainfall, and pressure on a single graph to simplify coding considerably compared to the
complex Mark Crossley scripts used at 'wilmslowastro' that cope with multiple periods and all the different data. The script does however
have a number of booleans that could be fairly easily edited to remove a particular plot or tailor the plots in other ways.
9) The arrays containing the recent history tags needed to be on a Cumulus template; to make life easier it was decided that one of the
existing templates 'trendsT.htm' would be modified so none of the other templates needed any changes.
10) For ease of testing, the released version of the code assumes that the various script libraries (jQuery, Highcharts) are loaded as local
copies, this also keeps control of which versions of the libraries are used, but the relvant 'src' properties can be edited to load the libraries from other servers. An example of loading such libraries from other servers is included in the previous postings at 04 Aug 2014 13:18 in 'https://cumulus.hosiene.co.uk/viewtopic.php?f=18&t=12284'.
11) To meet the requirements expressed by 'tempe', the script libraries and the modified 'trend.htm' web pages could be loaded on a local server
and the highcharts export library could be used to generate images that could be subsequently transferred to a remote server.
12) Earlier releases of the code had a few problems with locations of brackets and commas, but it is now written so the arrays start with 'h=1' (i.e. observations just one hour ago), but the graph is plotted with the oldest (typically 7 days ago) plotted points on the left and the start of the array (1 hour ago) plotted on the right.
13) The opportunity of editing 'trendsT.htm' has been taken to make some changes to the text on the page (and consequently minor changes to
sequences) so now the sampling interval and period covered for all the plots is shown. In addition, with different parts of the page being updated at different times, the various update times are now explicitly stated.
With thanks to 'Duke' for giving me encouragement as I identified the bugs, and struggled to resolve them; to 'tempe' for making the original request, for setting me the challenge that turned out to be more difficult than I expected and for spotting all the errors that crept into my coding; also to Ron ( 'nitrx') who set me thinking more deeply about the errors I made and has provided an on-line demonstration at http://apeldoorn.tk/weer/trends.htm.
As always much gratitude to Steve Loft who has written the software that drives this page. In particular his changes in his latest build 1098
have benefitted this code considerably. See https://cumulus.hosiene.co.uk/viewtopic.php?f=4&t=12307 and build 1098 entry in https://cumulus.hosiene.co.uk/viewtopic.php?f=2&t=10777.
EDIT - Since I originally posted this contribution, I have edited the bit in blue about changing 'src' near the beginning to make it clearer.
This new topic carries on from https://cumulus.hosiene.co.uk/viewtopic.php?f=18&t=12284. Not all the information that was in that topic has been repeated here. All references to times below for postings in that thread quote UTC. That old thread was getting quite long!
I have started a new topic to launch version 4 of my code in the hope that the new subject title will be easier to find for everyone. Version 4 is designed to work 'out of the box', all you need to add is the various script libraries. This is explained below, but you need to decide whether to download copies onto your web site (and use the 'src' properties I quote in the zipped file) or to use one of the CDN servers (for jQuery change 'src' properties to point to Google CDN, Microsoft CDN, CDNJS CDN, or jsDelivr CDN e.g. src="//code.jquery.com/jquery-2.1.1.min.js" and for highcharts set src=code.highcharts.com/highcharts.js). Obviously, I cannot please everyone, so you may wish to change some of the text I have included, change colours, or whatever; but I hope the comments I have included will help you see where to make such changes.
PRE-REQUISITES FOR INSTALLING THIS WEB PAGE
1 - Cumulus software build 1089 (released 7 August 2014) or later is needed to provide the Cumulus web tags required by this template.
2 - The template provided in this package needs to be processed by Cumulus, it can either be treated as producing a standard Cumulus page uploaded at the standard interval onto a remote server or it could be treated as an extra template file in a different folder that is processed onto a local server together with the standard Cumulus graphs and other pages (by making changes on the 'Files' tab of the 'Internet' options assessed from the 'Configuration' menu).
3 - Although modern browsers will say the way I use 'AJAX' to obtain the update time of the large Cumulus graph is deprecated, the AJAX routine I use can cope with Microsoft's non-standard browsers back as far as IE6. I mostly use Firefox, but I did not wish to force that on those who use this web page. I used a book as a different inspiration for my code snippet, but in https://cumulus.hosiene.co.uk/viewtopic.php?f=19&t=8493 27 Oct 2012 00:53 entry, a similar approach is proposed that excludes the Microsoft specific coding I put in.
4 - Two jQuery libraries are required (see http://jquery.com/download/) :
4.1 - 'jquery-1.9.1.js' is needed to allow the page to be viewed on the obsolete versions (up to version 10) of Internet Explorer that some users of obsolete versions of Windows might choose to use. They probably have other problems, but are used to what they have and do not know what they are missing without using a modern browser.
4.2 - 'jquery-2.1.1.js' is at the time of writing the standard version of jQuery and has been used for all my testing, it ensures that my coding can work on all modern browsers (including it is claimed IE11, but I have not tested this).
5 - 'highcharts.js' (http://www.highcharts.com/download)is needed for the new script to run, I upgraded to version 4.0.3 (I previously used version 4.0.0) specially for this experiment. The reference to a source of 'highcharts-exporting.js' is not actually needed to produce the graph, it simply makes it easy to print any Highcharts graph that is produced and to convert it into an image file as requested at the start of the development, by adding a menu accessed by a 3 line symbol at the top right of the chart. The zipped folder attached includes a few screen-shots, other screen shots (of earlier versions) can be seen in https://cumulus.hosiene.co.uk/viewtopic.php?f=18&t=12284. The earlier versions were downloaded 12 times I believe.
I will point out here that one of the screen shots shows the existing Cumulus 'daily range' graphs, one shows the existing Cumulus 'observations at every minute' plot, one shows my experiment at using day names on the x-axis (with a somewhat complicated additional function) and the last shows the version I am releasing with a day count on the x-axis. Don't worry about my test data, it is of low quality.
BACKGROUND TO THIS EXPERIMENTAL PROJECT
'tempe' from Finland said he found ' detailed chart period' and 'daily chart period' as two periods for which Cumulus would automatically draw trend graphs.
He requested trends for other periods like '12 hours, one day, week, month, 3 months etc.'
Steve Loft drew his attention to the recent and historic graphs on 'http://weather.wilmslowastro.com/graphs_recent.php' and
'http://weather.wilmslowastro.com/graphs_historic.php'.
'tempe' replied that his server did not support php, but he would consider generating plots locally with a script and then uploading the resulting images to his web site. "I dont need realtime or interactive graphs, just pictures of charts would be awesome."
'sfws' proposed a script using 'highcharts' library that would take hourly samples from the Cumulus 'recent history' tags that would allow
up to 7 days (168 hours).
'water01' showed an interest in proposed scripts based on taking samples from dayfile.txt.
DEVELOPMENT NOTES
A large number of issues were raised by attempting to develop a script that could be added to the standard Cumulus trends web page and would
work for anybody:
1) The 'no_commas' version of the 'recent history' tags needed to be used because places like Finland use commas to separate integer and
decimal parts whilst script restricts commas to being used to separate elements in an array and similar syntax siturations.
2) The script that uses the Highcharts Application programming interface (api) could be in a separate file, so it has been carefully written so
all the Cumulus web tags are converted into script variables that can be referenced by the plotting script. However, to make installation on the
web easier, this script is currently included at the end of the template so it becomes part of the HTML web page.
3) The script uses auto-scaling for the y-axis, and although that normally results in the axis being divided into 5, the script allows the
3 y-axis to be divided independently.
4) The tooltip and x-axis labels are generated by functions so they can make use of information that originates from Cumulus tags, and divide the x-axis into days, but it had cope with all possible starting times within a day.
5) The script assumes that the arrays represent observations at hourly intervals, but it had to work for periods from 12 hours to 168 hours. Therefore it includes coding to check the length of one of the arrays and therefore adjusts the heading to reflect that actual array length.
(To change to a different interval between elements in the array requires someone to make manual changes to many places in the coding).
6) The script needed to allow the user to zoom into a shorter period of time, and quickly return to full period.
7) The script needed to cope with both the case when Cumulus is running continuously and when it has recently been restarted and has read some of the old data from the station logger.
8) The script was designed to plot temperature, rainfall, and pressure on a single graph to simplify coding considerably compared to the
complex Mark Crossley scripts used at 'wilmslowastro' that cope with multiple periods and all the different data. The script does however
have a number of booleans that could be fairly easily edited to remove a particular plot or tailor the plots in other ways.
9) The arrays containing the recent history tags needed to be on a Cumulus template; to make life easier it was decided that one of the
existing templates 'trendsT.htm' would be modified so none of the other templates needed any changes.
10) For ease of testing, the released version of the code assumes that the various script libraries (jQuery, Highcharts) are loaded as local
copies, this also keeps control of which versions of the libraries are used, but the relvant 'src' properties can be edited to load the libraries from other servers. An example of loading such libraries from other servers is included in the previous postings at 04 Aug 2014 13:18 in 'https://cumulus.hosiene.co.uk/viewtopic.php?f=18&t=12284'.
11) To meet the requirements expressed by 'tempe', the script libraries and the modified 'trend.htm' web pages could be loaded on a local server
and the highcharts export library could be used to generate images that could be subsequently transferred to a remote server.
12) Earlier releases of the code had a few problems with locations of brackets and commas, but it is now written so the arrays start with 'h=1' (i.e. observations just one hour ago), but the graph is plotted with the oldest (typically 7 days ago) plotted points on the left and the start of the array (1 hour ago) plotted on the right.
13) The opportunity of editing 'trendsT.htm' has been taken to make some changes to the text on the page (and consequently minor changes to
sequences) so now the sampling interval and period covered for all the plots is shown. In addition, with different parts of the page being updated at different times, the various update times are now explicitly stated.
With thanks to 'Duke' for giving me encouragement as I identified the bugs, and struggled to resolve them; to 'tempe' for making the original request, for setting me the challenge that turned out to be more difficult than I expected and for spotting all the errors that crept into my coding; also to Ron ( 'nitrx') who set me thinking more deeply about the errors I made and has provided an on-line demonstration at http://apeldoorn.tk/weer/trends.htm.
As always much gratitude to Steve Loft who has written the software that drives this page. In particular his changes in his latest build 1098
have benefitted this code considerably. See https://cumulus.hosiene.co.uk/viewtopic.php?f=4&t=12307 and build 1098 entry in https://cumulus.hosiene.co.uk/viewtopic.php?f=2&t=10777.
EDIT - Since I originally posted this contribution, I have edited the bit in blue about changing 'src' near the beginning to make it clearer.