Formatting value in HTML-Template
Moderator: Mattk
Formatting value in HTML-Template
Hi there,
I'd like to setup a HTML template within folder "/public/graphs" to be uploaded with Meteohub's FTP function.
I fill in e.g. [actual_th0_temp_c:0] to get the actual value - if it doesn't exist, I get zero.
Now I want to get the temperature value as raw format (in 1/10°C, integer value).
This means I need the value 175 for 17.5°C
I can multiply by 10 using [actual_th0_temp_c*:0], but then I get a float value with two decimals: 175.00
How can I get just the integer part of it? Can anybody help...
I'd like to setup a HTML template within folder "/public/graphs" to be uploaded with Meteohub's FTP function.
I fill in e.g. [actual_th0_temp_c:0] to get the actual value - if it doesn't exist, I get zero.
Now I want to get the temperature value as raw format (in 1/10°C, integer value).
This means I need the value 175 for 17.5°C
I can multiply by 10 using [actual_th0_temp_c*:0], but then I get a float value with two decimals: 175.00
How can I get just the integer part of it? Can anybody help...
Best Regards
Hathor27
------------------------------------------------------------

http://untersiggenthal.meteodata.ch
Hathor27
------------------------------------------------------------

http://untersiggenthal.meteodata.ch
-
- Platinum Boarder
- Posts: 873
- Joined: Fri Jan 25, 2008 6:27 pm
- Location: Isle of Skye, Scotland
Re: Formatting value in HTML-Template
How about using some javascript text manipulation?Hathor27 wrote:I can multiply by 10 using [actual_th0_temp_c*:0], but then I get a float value with two decimals: 175.00
How can I get just the integer part of it? Can anybody help...
e.g.
<script type="text/javascript">var str="[actual_th0_temp_c*:0]";document.write(Math.round(str));</script>
Re: Formatting value in HTML-Template
Thank you, skyewright, this could be a work-around. I also could use PHP... or I'm usingskyewright wrote:How about using some javascript text manipulation? e.g.
<script type="text/javascript">var str="[actual_th0_temp_c*:0]";document.write(Math.round(str));</script>
Code: Select all
sed -e 's/\.//g'
...but isn't there a chance to get it converted by meteohub directly?
Best Regards
Hathor27
------------------------------------------------------------

http://untersiggenthal.meteodata.ch
Hathor27
------------------------------------------------------------

http://untersiggenthal.meteodata.ch
-
- Platinum Boarder
- Posts: 873
- Joined: Fri Jan 25, 2008 6:27 pm
- Location: Isle of Skye, Scotland
Re: Formatting value in HTML-Template
Not that I'm aware of.Hathor27 wrote:...but isn't there a chance to get it converted by meteohub directly?

I tried an experiment using the sub-string feature but that wasn't successful, because:
a) The sub-string action seems to happen before the "multiply by 10" action.
b) Even if a) weren't a problem sub-string would only ever have been helpful if there were always the same number of digits (because unless I've missed something you can only specify left based sub-strings?).
It was after doing that experiment that I resorted to the javascript idea...
Re: Formatting value in HTML-Template
that´s why it wouldn´t be a bad thing, if Boris could add a mechanism allowing to execute a shell script right after finishing the html template and before uploading it with ftp.
Such an option would allow manipulating any template with the mighty shell scripts commands before uploading.
<Though I don´t know how easy it might be adding this>
Such an option would allow manipulating any template with the mighty shell scripts commands before uploading.
<Though I don´t know how easy it might be adding this>
Re: Formatting value in HTML-Template
I'm not quite shure...
...is this type of value formatting a kind of standard linux tool?
...or would that be a task to implement on Meteohub?
I think that would be very helpful to be able formatting numbers - or even to extracting substrings from the beginning and/or from the end of the text - how could we get that implemented?...
...is this type of value formatting a kind of standard linux tool?
...or would that be a task to implement on Meteohub?
I think that would be very helpful to be able formatting numbers - or even to extracting substrings from the beginning and/or from the end of the text - how could we get that implemented?...
Best Regards
Hathor27
------------------------------------------------------------

http://untersiggenthal.meteodata.ch
Hathor27
------------------------------------------------------------

http://untersiggenthal.meteodata.ch
Re: Formatting value in HTML-Template
Please use javascript on top to get it displayed at your preferred number format, as suggested by skyewright.
Re: Formatting value in HTML-Template
I'm sorry to be noisy here, but I have to explain a bit more precise:admin wrote:Please use javascript on top to get it displayed at your preferred number format, as suggested by skyewright.
I want to build a simple text file, without html or javascript functionality.
So I set up a file called value.html in directory graphs/ as
Code: Select all
[actual_th0_temp_c:0] [actual_th0_hum_rel:0]
[actual_thb0_temp_c:0] [actual_thb0_hum_rel:0] [actual_thb0_press_hpa:0]
[actual_sol1_radiation_wqm:0]
Code: Select all
104 89
173 61 9572
0
Best Regards
Hathor27
------------------------------------------------------------

http://untersiggenthal.meteodata.ch
Hathor27
------------------------------------------------------------

http://untersiggenthal.meteodata.ch
Re: Formatting value in HTML-Template
As told, there is no way aparent to me to do this number format conversion inside Meteohub.
I guess the resulting text file will be processed by something. Why not
apply the conversion task there or piping the file through a preprocessor
before feeding it into the target program?
Is here a larger audience needing number format conversion inside Meteohub templates?
I guess the resulting text file will be processed by something. Why not
apply the conversion task there or piping the file through a preprocessor
before feeding it into the target program?
Is here a larger audience needing number format conversion inside Meteohub templates?
Re: Formatting value in HTML-Template
OK, I've got it - thank you anyway.
Please allow one more question on formats:
If I useI get a number with one decimal place, likeDifferent to other values I can't import this number with a plugin in an easy way.
What I mean is, that for plugin import, values like radiation and humidity are used to be integer. Other values like temperature, wind-speed, rain and so on are given in 1/10 of the value.
For export reason means that, if I just can extract the decimal point (as described below), the format gets compatible with the input format used on plugins.
Could you please find a way to output [actual_sol1_radiation_wqm] as integer value like humidity or wind-direction - without any decimal place? That would solve my problem as well...
Please allow one more question on formats:
If I use
Code: Select all
[actual_sol1_radiation_wqm:0]
Code: Select all
256.0
What I mean is, that for plugin import, values like radiation and humidity are used to be integer. Other values like temperature, wind-speed, rain and so on are given in 1/10 of the value.
For export reason means that, if I just can extract the decimal point (as described below), the format gets compatible with the input format used on plugins.
Could you please find a way to output [actual_sol1_radiation_wqm] as integer value like humidity or wind-direction - without any decimal place? That would solve my problem as well...
Best Regards
Hathor27
------------------------------------------------------------

http://untersiggenthal.meteodata.ch
Hathor27
------------------------------------------------------------

http://untersiggenthal.meteodata.ch
Re: Formatting value in HTML-Template
To please you, I am adding a precision predicate "{precision 0 [actual_sol1_radiation_wqm:0]} that will convert the number into one with the desired number of decimals, zero decimals in the given example. I would like to send you some test code. What architecture do you have? x86, Sheeva, NSLU2? Please also send your email address to info(at)meteohub.de.
Re: Formatting value in HTML-Template
This is a great new formatting feature - awaiting pleasantly your new updateadmin wrote:To please you, I am adding a precision predicate "{precision 0 [actual_sol1_radiation_wqm:0]} that will convert the number into one with the desired number of decimals, zero decimals in the given example.

Addendum 2011 Nov 16: Works perfectly within Update 4.8g
Best Regards
Hathor27
------------------------------------------------------------

http://untersiggenthal.meteodata.ch
Hathor27
------------------------------------------------------------

http://untersiggenthal.meteodata.ch
Re: Formatting value in HTML-Template
Does it work only with {precision 0 [actual_sol1_radiation_wqm:0]} or should it work also with other functions. I have Update 4.9f and it does not work.Hathor27 wrote:Addendum 2011 Nov 16: Works perfectly within Update 4.8g
Re: Formatting value in HTML-Template
it should work in general. can you please post the example that does not work for you?
Re: Formatting value in HTML-Template
This is a simle web site:
[blank_the_unknown]<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Meteohub HTML Mini-Dashboard</title>
</head>
<body bgcolor="#ffffff">
<table border="1" cellpadding="0" cellspacing="2" width="200">
<tr>
<td>{precision 0[last60m_th0_hummin_rel:0]}</td>
</tr>
<tr>
<td>{precision 0[last60m_th0_hummax_rel]}</td>
</tr>
</table>
<p></p>
</body>
</html>
and thi is a result http://acover.webhop.net:7180/meteohtml.cgi?file=test
[blank_the_unknown]<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Meteohub HTML Mini-Dashboard</title>
</head>
<body bgcolor="#ffffff">
<table border="1" cellpadding="0" cellspacing="2" width="200">
<tr>
<td>{precision 0[last60m_th0_hummin_rel:0]}</td>
</tr>
<tr>
<td>{precision 0[last60m_th0_hummax_rel]}</td>
</tr>
</table>
<p></p>
</body>
</html>
and thi is a result http://acover.webhop.net:7180/meteohtml.cgi?file=test