Things you can do with Meteoplug - HTML Templates with PHP
Posted: Fri Sep 04, 2015 9:44 am
Some time ago I showed a way how to calculate the sunshine duration with a Davis VP2 with Solar sensor and meteohub / meteoplug in the meteohub Forum (in German, sorry):
http://forum.meteohub.de/viewtopic.php? ... 947#p15952
While I really like all the graphing you can do with Meteoplug, I also wanted to show statistics about some other interesting weather parameters that are not delivered by the Meteoplug server by default. E.g. I would like to track values like "heat days" (Tmax>=30), "summer days" (Tmax>=25), etc. for a given period, or things like "the day it rained most last year / since ever", etc.
In addition, I wanted to compare values of the current year with the previous year and the all-time average/extreme values.
The only way to start programming your own statistics is via the HTML templates (http://wiki.meteoplug.com/Define_Chart# ... e_Settings). There you need to dynamically generate all the required template variables ("[actual_xxx_yyy_zzz]") of all values required to do the calculations. The Meteoplug server then replaces the variables with the corresponding values. Once you have them, you can start calculating.
The challenge is that you cannot just create a PHP script doing both the template variable definition and the calculation. This simply because obviously the PHP script runs through before the Meteoplug Server replaces the variables with the corresponding values. Means, your PHP variables at runtime still hold the variable string ("[actual...]") and not the value. My solution was to create a PHP script to generate all the required template variables and to output a Javascript which then uses the variable values to do all the calculations (at the runtime of the Javascript, the Meteoplug Server already has replaced the variables with the corresponding values).
The result is my new http://wetter.isenegger.org/langzeit-tabellen/ page, feel free to check it out.
The Meteoplug Server does not provide an API or any effective way to retrieve multiple database values at once, unfortunately. So the only way is to generate hundreds or even thousands of template variables that get replaced. It looks like the Meteoplug Server has a great and efficient process to handle the replacement because it only takes a fraction of a second to handle this large amount of template variables. Still, it may be beneficial if there would be a possibility to get arrays of data in one go (e.g. all monthly temperature average values over a definable timeframe) instead of creating a large number of single template variables for each month.
http://forum.meteohub.de/viewtopic.php? ... 947#p15952
While I really like all the graphing you can do with Meteoplug, I also wanted to show statistics about some other interesting weather parameters that are not delivered by the Meteoplug server by default. E.g. I would like to track values like "heat days" (Tmax>=30), "summer days" (Tmax>=25), etc. for a given period, or things like "the day it rained most last year / since ever", etc.
In addition, I wanted to compare values of the current year with the previous year and the all-time average/extreme values.
The only way to start programming your own statistics is via the HTML templates (http://wiki.meteoplug.com/Define_Chart# ... e_Settings). There you need to dynamically generate all the required template variables ("[actual_xxx_yyy_zzz]") of all values required to do the calculations. The Meteoplug server then replaces the variables with the corresponding values. Once you have them, you can start calculating.
The challenge is that you cannot just create a PHP script doing both the template variable definition and the calculation. This simply because obviously the PHP script runs through before the Meteoplug Server replaces the variables with the corresponding values. Means, your PHP variables at runtime still hold the variable string ("[actual...]") and not the value. My solution was to create a PHP script to generate all the required template variables and to output a Javascript which then uses the variable values to do all the calculations (at the runtime of the Javascript, the Meteoplug Server already has replaced the variables with the corresponding values).
The result is my new http://wetter.isenegger.org/langzeit-tabellen/ page, feel free to check it out.
The Meteoplug Server does not provide an API or any effective way to retrieve multiple database values at once, unfortunately. So the only way is to generate hundreds or even thousands of template variables that get replaced. It looks like the Meteoplug Server has a great and efficient process to handle the replacement because it only takes a fraction of a second to handle this large amount of template variables. Still, it may be beneficial if there would be a possibility to get arrays of data in one go (e.g. all monthly temperature average values over a definable timeframe) instead of creating a large number of single template variables for each month.