Page 1 of 2

Formatting value in HTML-Template

Posted: Fri Oct 28, 2011 10:13 pm
by Hathor27
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...

Re: Formatting value in HTML-Template

Posted: Tue Nov 01, 2011 4:46 pm
by skyewright
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...
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>

Re: Formatting value in HTML-Template

Posted: Tue Nov 01, 2011 10:00 pm
by Hathor27
skyewright 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>
Thank you, skyewright, this could be a work-around. I also could use PHP... or I'm using

Code: Select all

sed -e 's/\.//g'
instead, because I need the value in a simple textfile (not within html).

...but isn't there a chance to get it converted by meteohub directly?

Re: Formatting value in HTML-Template

Posted: Thu Nov 03, 2011 6:16 pm
by skyewright
Hathor27 wrote:...but isn't there a chance to get it converted by meteohub directly?
Not that I'm aware of. :(

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

Posted: Thu Nov 03, 2011 8:16 pm
by wfpost
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>

Re: Formatting value in HTML-Template

Posted: Thu Nov 03, 2011 8:25 pm
by Hathor27
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?...

Re: Formatting value in HTML-Template

Posted: Thu Nov 03, 2011 11:18 pm
by admin
Please use javascript on top to get it displayed at your preferred number format, as suggested by skyewright.

Re: Formatting value in HTML-Template

Posted: Thu Nov 03, 2011 11:47 pm
by Hathor27
admin wrote:Please use javascript on top to get it displayed at your preferred number format, as suggested by skyewright.
I'm sorry to be noisy here, but I have to explain a bit more precise:

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]
and after upload I'd like to see values as follows in file value.txt

Code: Select all

104 89
173 61 9572
0
I have no javascript functionality in there... how would you solve that?

Re: Formatting value in HTML-Template

Posted: Fri Nov 04, 2011 9:46 am
by admin
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?

Re: Formatting value in HTML-Template

Posted: Fri Nov 04, 2011 11:09 pm
by Hathor27
OK, I've got it - thank you anyway.
Please allow one more question on formats:

If I use

Code: Select all

[actual_sol1_radiation_wqm:0]
I get a number with one decimal place, like

Code: Select all

256.0
Different 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...

Re: Formatting value in HTML-Template

Posted: Sat Nov 05, 2011 4:49 pm
by admin
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

Posted: Mon Nov 07, 2011 12:36 am
by Hathor27
admin 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.
This is a great new formatting feature - awaiting pleasantly your new update :D

Addendum 2011 Nov 16: Works perfectly within Update 4.8g

Re: Formatting value in HTML-Template

Posted: Wed Apr 11, 2012 4:07 pm
by aco186
Hathor27 wrote:Addendum 2011 Nov 16: Works perfectly within Update 4.8g
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.

Re: Formatting value in HTML-Template

Posted: Sat Apr 14, 2012 10:51 am
by admin
it should work in general. can you please post the example that does not work for you?

Re: Formatting value in HTML-Template

Posted: Sat Apr 14, 2012 6:52 pm
by aco186
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