Dynamic Timeframe for Template Variables

Post Reply
Posts: 56
Joined: Tue Sep 23, 2014 9:32 am

Dynamic Timeframe for Template Variables

Post by ironedge » Mon Jun 08, 2015 8:50 pm

Hi Boris,

I'd like to enhance my Meteoplug dashboard (http://wetter.isenegger.org/alle-wetterdaten/) with a new "graph" / table that e.g. shows the following information per time period (e.g. per month, year, etc.):

- The usual stuff like min/max/avg temp / wind, etc.
- number of heat days (temp >30 C)
- number of frost days (temp <0 C)
- day with largest rain amount
- number of days without any sunshine
- maximum pressure change within 3 hours
- etc.

I believe I can program it myself by using a Template ("template=http://...") that refers to a PHP file which dynamically generates the HTML code with all required variables in it ("20150301000000_month1_th*_xxx", etc.), so the Meteoplug server can insert the desired raw data into the variables (would be hundreds of variables or more per template call but I read somewhere that this shouldn't be an issue regarding load / performance). With the necessary database values at hand, I could then calculate and generate the desired Information above within the PHP file.

The only thing that prevents me in doing so is the point that I do not get the required "timeframe" information through the template mechanism. It seems that none of the two possibilities happen:
- the meteoplug Server does not translate any relative timeframe values of template variables from a given "&timeframe=YYYMMDDhhmmss-YYYMMDDhhmmss" call Parameter, i.e. [1M_month1_th*_xxx] is always the current month, not the first month of the specified "&timeframe=" period
- the "&timeframe=" value is not handed over to the Template file and cannot be retrieved by any command (like $_GET, etc.)

It would be great if you could find a way to hand-over the graph's call parameters (at least "&timeframe=xxx" or even the whole string behind the "?") to the template file in any way. By getting this information, a programmer could bascially program any desired function and calculation via PHP on his own and enhance the Meteoplug possibilities significantly. Without this Information, it's not possible to use templates in a dynamic context and I'm limited to the pre-defined graph types.

In addition to getting the "&timeframe" value, which would be the key for dynamic templates, I also thought about some additional ways to get sensor data into a template script:

- Enhance the template variable replacement in a way that you could fill an array. Means, that I could get a whole data set instead of one value only. So e.g. [20150301000000-20150331235959_hour1_th*_temp] would return all hourly temp values from 1.-31. March 2015 (from the hourly time bucket) ... could be an array or just a very long string with a delimiter. By that I could easily "dump" required parts of the database down to a certain detail level into a script for various sensors and do my calculations
- the implementation of a kind of call function that would allow the on-the-fly translation of a variable into the value. Maybe something like "meteoplug.com/translate.cgi?user=&variable=[20150601000000_hour1_th*_temp]" returning the value of that variable, or a full data set for a timeframe as in the point above ... but this call would need to be performant enough to be executed at least hundreds of times per second or more, otherwise a external programm cannot get all required data within reasonable time. I assume this is not feasible, honestly.

Or ... there is already a very simple solution that I just haven't found yet :)

Thank you very much in advance for reading and considering my proposal!

Posts: 56
Joined: Tue Sep 23, 2014 9:32 am

Re: Dynamic Timeframe for Template Variables

Post by ironedge » Fri Jun 12, 2015 2:57 pm

And, just to state the obvious, there is also another possibility to provide the "&timeframe=" parameters:

Define two new "misc" text variables, e.g. "reporttimestart" and "reporttimeend", that provide the desired Information, i.e. for:
"...&timeframe=20150301000000-20150331255959", the variable "[actual_min5_misc_reporttimestart]" would deliver the string "2015-03-01 00:00" and "[actual_min5_misc_reporttimeend]" would deliver "2015-03-31 23:59".

To have a perfect solution, there would actually be a third variable "reportresolution" containing the "&resolution=" parameter.

With this Information, templates would be a very powerful tool to enhance meteoplug in any desired way. I guess people with sufficient skills could even draw their own graphs. People like me could at least calculate any desired value not directly provided by meteoplug and output them as text / tables.

Post Reply