Parsing temperature values in hive.sh

3 posts / 0 new
Last post
Esa
Esa's picture
Parsing temperature values in hive.sh

my nearby weather station (EFTP) sends temperatures in whole digits, not with decimals and this causes the grep to fail when parsing the data.
Additionally here in north we will expect subzero temperatures as well, sometimes during the nights.

The current regexp for temps is [0-9]*\.[0-9]* which fails to notice the non-decimals like "17", and also the negative values.
I played around with http://regexr.com/ site and found that e.g this expression "-?\d\d*(\.\d+)?" would match below cases
except "+" characted but that is not expected to be found in weather data
<temp_c>19</temp_c>
<temp_c>+19</temp_c>
<temp_c>19.23</temp_c>
<temp_c>0</temp_c>
<temp_c>0.3</temp_c>
<temp_c>-0.3</temp_c>
<temp_c>-19</temp_c>
<temp_c>-19.2</temp_c>

But anyway, I can't get this expression working in the HiveTool hive.sh nor in rpi itself - any idea is there some grep version issues ?

below data from the station:
<?xml version="1.0" encoding="utf-8" ?>
<current_observation>
<credit>Weather Underground Personal Weather Station</credit>
<credit_URL>http://wunderground.com/weatherstation/</credit_URL>
<image>
<url>http://icons.wunderground.com/graphics/bh-wui_logo.gif</url>
<title>Weather Underground</title>
<link>http://wunderground.com/weatherstation/</link>
</image>
<location>
<full>, Tampere, </full>
<neighborhood></neighborhood>
<city>Tampere</city>
<state></state>
<zip></zip>
<latitude></latitude>
<longitude></longitude>
<elevation> ft</elevation>
</location>
<station_id>EFTP</station_id>
<station_type></station_type>
<observation_time>Last Updated on July 12, 12:20 PM EEST</observation_time>
<observation_time_rfc822>Tue, 12 Jul 2016 09:20:00 GMT</observation_time_rfc822>
<weather>Scattered Clouds</weather>
<icon_url_base>http://icons.wxug.com/graphics/conds/</icon_url_base>
<icon_url_name>.GIF</icon_url_name>
<icon>partlycloudy</icon>
<temperature_string>66 F (19 C)</temperature_string>
<temp_f>66</temp_f>
<temp_c>19</temp_c>
<relative_humidity>73%</relative_humidity>
<wind_string>From the at 15 MPH </wind_string>
<wind_dir></wind_dir>
<wind_degrees>240</wind_degrees>
<wind_mph>15</wind_mph>
<wind_gust_mph>-9999</wind_gust_mph>
<pressure_string>29.47" (998 mb)</pressure_string>
<pressure_mb>998</pressure_mb>
<pressure_in>29.47</pressure_in>
<dewpoint_string>57 F (14 C)</dewpoint_string>
<dewpoint_f>57</dewpoint_f>
<dewpoint_c>14</dewpoint_c>

<heat_index_string></heat_index_string>
<heat_index_f></heat_index_f>
<heat_index_c></heat_index_c>

Steven
Hi Esa,

Hi Esa,
I think i made a fix for that some time ago and sent it to Paul. I'll try to look for it next week.

Esa
Esa's picture
meanwhile waiting for that

meanwhile waiting for that fix to be published, could you share it here so I could hack the HiveTool myself ?

Log in to post comments