WebsitedataT.json: Difference between revisions

m
no edit summary
m (Tried to correct all typos)
mNo edit summary
# The comma at the end of the line I have used as an example is there because another parameter is defined on the next line.
# The whole object definition, of all the variables in the file, (not seen in single line extract above) is enclosed in brackets "{" to "}"
 
==Example of using arithmetic with two Cumulus web tags in value==
 
Later on this Wiki page in [[#Tailoring the file]], it is explained that you can edit a copy of this template file. I say a copy, as if you edit the original file you risk your edit being lost whenever you upgrade to a new MX release as the release distribution includes a file with this name. In [[#How the file is used]], it is explained how a JavaScript file "setpagedata.js" loads this data file, and transfers values from the data file into HTML pages.
 
If you do edit this template file, then remember it is JavaScript, there are rules for using arithmetic in this script language, but we won't go technical and list such rules here, instead we will use an example to explain. Let us suppose you wanted to include the temperature difference between now and 24 hours ago in your HTML page. How you edit HTML is covered elsewhere in this Wiki and in many tutorials available online. To get the value to our web server, we must ask MX to calculate it, therefore that value has to be calculated in this template, and you would add a new line like this:
"temperatureChange24hours":(<#temp rc=y> - <#RecentOutsideTemp d=1 rc=y>),
Here, we still define a single variable name before the colon, but after the colon we subtract one web tag value from another remembering that we need to specify that decimal points not decimal commas are needed for JavaScript to understand the values as being numerical in order for the subtraction to work. Note that brackets surround the calculation to ensure the expression within those brackets is evaluated, and the lack of quotation marks ensure the expression is treated as numerical rather than a string.
 
(By the way, if we were doing an adding operation, we have to be very cautious as "+" is normally understood in this script language as indicating concatenation of strings (see [[#Tailoring the file]] for example of plus sign being used for concatenation). Please see [[Feels_Like#Script_for_setting_values|here for an example of how addition is used]], essentially '+' can be used for adding by always using a numerical constant before the plus sign and always having any variable after the plus sign).
 
=How the file is used=
MX has to be told to convert that to a data file. There is a full explanation of what is meant by 'Cumulus processing any template' [[Customised_templates#What_is_meant_by_.27Cumulus_processes_templates.27|here]]. In this case, MX will, while processing the template, generate a data file that is stored as "CumulusMX/web/websitedata.json". This data file is still coded as JavaScript file, but now the tags have gone as they have been replaced by values.
 
The data file is used with the [[New Default Web Site Information|Web Pages]] supplied in the [[Webfiles folder|'''webfiles''']] sub-folder of the MX distribution from release 3.10.1 onwards. On your web server, each HTML page will call another JavaScript file "/CumulusMX/webfiles/js/setpagedata.js" (after uploading this file once to web site), it is that script that will both read the uploaded data file, and insert the relevant value into HTML pages in a span which has the "cmxdata" attribute, with a value for that attribute set to the appropriate variable name for the relevant JSON object. Note that "js/setpagedata.js" uses a querystring for adding the current time to make the request unique, that just ensures a fresh copy is loaded each time, preventing your browser thinking because you have loaded the file before it can reuse the copy it cached.
 
ForIn examplethe HTML, <code>&lt;span data-cmxdata="recordsbegandateISO"&gt;&lt;/span&gt;</code> would be found and then processed in the "setpagedata.js" script. andThe resultHTML inas andisplayed insert ofby the datebrowser inwill thethen JSONhave linea date within that wespan examinedelement. inAs detailexplained at the start of this Wiki page, that date originated from MX processing a web tag in the template file.
 
Similarly, <code>&lt;span data-cmxdata="temperatureChange24hours"&gt;&lt;/span&gt;</code> would make that script insert the temperature difference we defined earlier, to show how arithmetic can be used in what can be added as a modification to the JSON template.
 
In the tables below, that explain the data represented by various lines in the template file, there are multiple columns:
* Cumulus tag name (including whether any input/output modification parameters)
* JSON object variable name
* The span sequence used in HTML file to relate to thethis variable
* A description
The reason for showing all three columns is that sometimes the tag name and the variable name do not match in the JSON file, and that if you look in the HTML file you need to find what data will be inserted there, including whether any [[Webtags/Parameters|input/output modification parameter]] appears, or the default output from that tag name will appear. Please note for simplicity, not every line in the file is explained, sometimes just one example is given representing multiple lines, this is enough to show you the format (with or without parameters), and whether the tag name and JSON object variable name do match.
 
The tables show the tag name and the JSON variable name because these might not agree. The tables show the span sequence because you might be looking at the HTML file and use what you see there as a starting point for working back to either the description or the Cumulus tag name (or the [[Webtags/Parameters|input/output modification parameter]]).
 
The reason for showing all three columns is that sometimes the tag name and the variable name do not match in the JSON file, and that if you look in the HTML file you need to find what data will be inserted there, including whether any [[Webtags/Parameters|input/output modification parameter]] appears, or the default output from that tag name will appear. ''Please note for simplicity, not every line in the file is explained, sometimes just one example is given representing multiple lines, this is enough to show you the format (with or without parameters), and whether the tag name and JSON object variable name do match.''
 
=File details=
 
{{TOCright}}
* This file is designed to work with the MX default web pages (that you upload just once from the '''webfiles''' sub-folder of your MX installation) and lists all the JSON variables that those pages require to be uploaded to your web server. Note that the variables included in this file represent the degree symbol <sup>o</sup> in two different ways:
* This template file lists all the JSON variables that those pages require to be uploaded to your web server so the default HTML pages can be used as a background structure to permit displaying your weather data. As explained above, a JavaScript file on your web site loads the file with JSON data and inserts the data in appropriate places on the web page.
* The file has to cater for the majority of people using the default web site, and assumes use of a Davis weather station, therefore its content might not be optimised for your use.
* The default web pages, even if you customise them, can only display JSON variables that are defined in this file (as per tables below) and formats for content are fixed.
 
Note that the variables included in this file represent the degree symbol <sup>o</sup> in two different ways:
# As an HTML encoded entity <nowiki>&amp;deg;</nowiki> that always translates to ° if you are using in HTML web page
# As a binary character (equates to decimal 176), that only translates to ° if you are using UTF-8 encoding '''(select this on ''Internet Settings'' &rarr; ''Web/FTP Settings'' &rarr; ''General Settings'' &rarr; tick ''UTF-8 encoding'')''' to create this file with that encoding (to match the [[Reports_folder#Encoding|encoding]] used by the [[New_Default_Web_Site_Information#Installing_the_new_template_for_new_users|web pages]] included in ''webfiles'' folder)
 
The file has to cater for the majority of people using the default web site, and assumes use of a Davis weather station, therefore its content might not be optimised for your use.
The default web pages, even if you customise them, can only display JSON variables that are defined in this file (as per tables below) and formats for content are fixed.
 
==Tailoring the file==
 
If you have experience with how JSON files are coded, you can choose to use a different file to that provided with MX.
If you want to use this file as the basis of your own JSON based file uploads (either because you want to change the fixed formats in provided file, or because you are not using the default web site):
 
*To avoid Shouldloss of you wishfile when you are upgrading to tailora it,new theMX release, best practice iswould be to takecreate a copytemplate intofile with a newdifferent foldername, editand/or thatin copy,a possiblydifferent into 3 separate filesfolder, and use the '''Extra Web Files''' settings to get your tailored template [[Customised_templates#What_is_meant_by_.27Cumulus_processes_templates.27|processed]] and uploaded at your preferred interval. to become The"webbsitedata.json" suggestionon foryour multipleweb separateserver files, is purelyand becausedisable the contentsettings ofthat get the default file doesprocessed notand alluploaded. change at same interval:
*# First file, upload using the '''EOD''' selection
 
*#* Include in this file, all the '''Static information''' (marked as such in lists below), as this information rarely changes
If the remote file setting on the extra web files uses the same "webbsitedata.json" name, then "js/setpagedata.js" will load it (<code>$.getJSON('websitedata.json?_=' + Date.now(),</code>, here the plus sign is used to indicate concatenation within the query-string (bit prefixed by question mark)) and process whatever object names it finds, so all you need to do is edit the HTML file to use span definitions that match the object names.
*#* Equally include in this first file the '''Yesterday group''' as those values only change at rollover
*# Most of the rest of the information can change during a day, and is best uploaded in a second file at your real-time interval (if that is enabled)
*# You might chose to upload some information in a third file that is uploaded at the defined standard interval
 
If you have even more experience, you can also edit "js/setpagedata.js", perhaps so it can process multiple JSON files, so you can upload data that is static (see tables) or only changes when day changes at EOD in extra web files settings, and reduce the size of upload at your real-time interval. Of course you might even consider adding extra JavaScript that takes two json objects and outputs the difference between them, or you might make use of [[PHP]] that can also do a simple calculation or a much more complex one.
You will need to modify your JavaScript file "/CumulusMX/webfiles/js/setpagedata.js" (and don't forget to upload this file after editing once to web site), because it includes the loading of the data file: <code>$.getJSON('websitedata.json?_=' + Date.now(),</code>, here the plus sign is used to indicate concatenation within the query-string (bit prefixed by question mark), adding the current time to make the request unique just ensures a fresh copy is loaded each time, preventing your browser thinking because you have loaded the file before it can reuse the copy it cached. In the tailored copy of this script, it will need to load each of the tailored data files.
 
==Options==
 
There are 3 fixed pieces of information conveyed by this file refering(referring to Cumulus web tags for defining options):
# "useApparent" = whether Apparent Temperature or Feels Like temperature is required
# "showSolar" = whether a solar sensor is providing solar information or not
5,838

edits