Formatting value in HTML-Template

Discussion of the Meteohub software package

Moderator: Mattk

User avatar
Hathor27
Expert Boarder
Expert Boarder
Posts: 126
Joined: Thu May 05, 2011 9:33 pm
Location: Switzerland
Contact:

Formatting value in HTML-Template

Post 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...
Best Regards
Hathor27

------------------------------------------------------------
Image
http://untersiggenthal.meteodata.ch
skyewright
Platinum Boarder
Platinum Boarder
Posts: 873
Joined: Fri Jan 25, 2008 6:27 pm
Location: Isle of Skye, Scotland

Re: Formatting value in HTML-Template

Post 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>
User avatar
Hathor27
Expert Boarder
Expert Boarder
Posts: 126
Joined: Thu May 05, 2011 9:33 pm
Location: Switzerland
Contact:

Re: Formatting value in HTML-Template

Post 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?
Best Regards
Hathor27

------------------------------------------------------------
Image
http://untersiggenthal.meteodata.ch
skyewright
Platinum Boarder
Platinum Boarder
Posts: 873
Joined: Fri Jan 25, 2008 6:27 pm
Location: Isle of Skye, Scotland

Re: Formatting value in HTML-Template

Post 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...
wfpost
Platinum Boarder
Platinum Boarder
Posts: 591
Joined: Thu Jun 12, 2008 2:24 pm
Location: HONSOLGEN
Contact:

Re: Formatting value in HTML-Template

Post 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>
User avatar
Hathor27
Expert Boarder
Expert Boarder
Posts: 126
Joined: Thu May 05, 2011 9:33 pm
Location: Switzerland
Contact:

Re: Formatting value in HTML-Template

Post 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?...
Best Regards
Hathor27

------------------------------------------------------------
Image
http://untersiggenthal.meteodata.ch
User avatar
admin
Platinum Boarder
Platinum Boarder
Posts: 7879
Joined: Mon Oct 01, 2007 10:51 pm

Re: Formatting value in HTML-Template

Post by admin »

Please use javascript on top to get it displayed at your preferred number format, as suggested by skyewright.
User avatar
Hathor27
Expert Boarder
Expert Boarder
Posts: 126
Joined: Thu May 05, 2011 9:33 pm
Location: Switzerland
Contact:

Re: Formatting value in HTML-Template

Post 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?
Best Regards
Hathor27

------------------------------------------------------------
Image
http://untersiggenthal.meteodata.ch
User avatar
admin
Platinum Boarder
Platinum Boarder
Posts: 7879
Joined: Mon Oct 01, 2007 10:51 pm

Re: Formatting value in HTML-Template

Post 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?
User avatar
Hathor27
Expert Boarder
Expert Boarder
Posts: 126
Joined: Thu May 05, 2011 9:33 pm
Location: Switzerland
Contact:

Re: Formatting value in HTML-Template

Post 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...
Best Regards
Hathor27

------------------------------------------------------------
Image
http://untersiggenthal.meteodata.ch
User avatar
admin
Platinum Boarder
Platinum Boarder
Posts: 7879
Joined: Mon Oct 01, 2007 10:51 pm

Re: Formatting value in HTML-Template

Post 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.
User avatar
Hathor27
Expert Boarder
Expert Boarder
Posts: 126
Joined: Thu May 05, 2011 9:33 pm
Location: Switzerland
Contact:

Re: Formatting value in HTML-Template

Post 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
Best Regards
Hathor27

------------------------------------------------------------
Image
http://untersiggenthal.meteodata.ch
aco186
Fresh Boarder
Fresh Boarder
Posts: 12
Joined: Fri Mar 02, 2012 5:04 pm
Location: Ljubljana
Contact:

Re: Formatting value in HTML-Template

Post 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.
User avatar
admin
Platinum Boarder
Platinum Boarder
Posts: 7879
Joined: Mon Oct 01, 2007 10:51 pm

Re: Formatting value in HTML-Template

Post by admin »

it should work in general. can you please post the example that does not work for you?
aco186
Fresh Boarder
Fresh Boarder
Posts: 12
Joined: Fri Mar 02, 2012 5:04 pm
Location: Ljubljana
Contact:

Re: Formatting value in HTML-Template

Post 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
Post Reply