Salve a tutti
Mi trovo di fronte ad un problema di cui non riesco a capire il motivo
In pratica la mia pagina web estrae delle variabili da un file xml generato da un'altra pagina, e tra di esse vi sono anche valori di temperatura, soltanto che nell'xml questa è espressa in Fahrenheit e non in Celsius, e quindi ho provveduto a generare una conversione, che tuttavia mi dà dei valori discordi di qualche decimo. Se invece faccio apparire la temperatura in Fahrenheit vedo il valore giusto.
A questo punto mi stavo chiedendo se è un problema di arrotondamento
Per maggiore chiarezza vi metto i codici:
file xml di partenza
codice:<current_observation xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:noNamespaceSchemaLocation="http://www.weather.gov/view/current_observation.xsd"> <credit>Davis Instruments Corp.</credit> <credit_URL>http://www.davisnet.com</credit_URL> <image> <url> http://www.weatherlink.com/images/Logo_Davis_reflxblu.jpg </url> <title>Davis WeatherLink</title> <link>http://www.weatherlink.com</link> </image> <suggested_pickup>15 minutes after the hour</suggested_pickup> <suggested_pickup_period>60</suggested_pickup_period> <dewpoint_c>6.1</dewpoint_c> <dewpoint_f>43</dewpoint_f> <dewpoint_string>43 F (6.1 C)</dewpoint_string> <heat_index_c>15.0</heat_index_c> <heat_index_f>59</heat_index_f> <heat_index_string>59 F (15.0 C)</heat_index_string> <latitude>41.825448062796</latitude> <location>Roma, RM, Italia</location> <longitude>12.477133083343</longitude> <observation_time>Last Updated on Oct 30 2014, 7:35 pm CET</observation_time> <observation_time_rfc822>Thu, 30 Oct 2014 19:35:05 +0100</observation_time_rfc822> <pressure_in>30.109</pressure_in> <pressure_mb>1019.6</pressure_mb> <pressure_string>1019.6 mb</pressure_string> <relative_humidity>52</relative_humidity> <station_id>romaeur</station_id> <temp_c>16.1</temp_c> <temp_f>60.9</temp_f> <temperature_string>60.9 F (16.1 C)</temperature_string> <wind_degrees>331</wind_degrees> <wind_dir>Northwest</wind_dir> <wind_kt>2</wind_kt> <wind_mph>2</wind_mph> <windchill_c>16.1</windchill_c> <windchill_f>61</windchill_f> <windchill_string>61 F (16.1 C)</windchill_string> <davis_current_observation version="1.0"> <observation_age>54</observation_age> <dewpoint_day_high_f>53</dewpoint_day_high_f> <dewpoint_day_high_time>12:00am</dewpoint_day_high_time> <dewpoint_day_low_f>40</dewpoint_day_low_f> <dewpoint_day_low_time>4:16pm</dewpoint_day_low_time> <dewpoint_month_high_f>71</dewpoint_month_high_f> <dewpoint_month_low_f>30</dewpoint_month_low_f> <dewpoint_year_high_f>71</dewpoint_year_high_f> <dewpoint_year_low_f>30</dewpoint_year_low_f> <heat_index_day_high_f>68</heat_index_day_high_f> <heat_index_day_high_time>1:12pm</heat_index_day_high_time> <heat_index_month_high_f>85</heat_index_month_high_f> <heat_index_year_high_f>85</heat_index_year_high_f> <pressure_day_high_in>30.14</pressure_day_high_in> <pressure_day_high_time>9:33am</pressure_day_high_time> <pressure_day_low_in>30.08</pressure_day_low_in> <pressure_day_low_time>3:54pm</pressure_day_low_time> <pressure_month_high_in>30.266</pressure_month_high_in> <pressure_month_low_in>29.589</pressure_month_low_in> <pressure_tendency_string>Rising Slowly</pressure_tendency_string> <pressure_year_high_in>30.339</pressure_year_high_in> <pressure_year_low_in>29.589</pressure_year_low_in> <rain_day_in>0.0000</rain_day_in> <rain_month_in>2.3780</rain_month_in> <rain_rate_day_high_in_per_hr>0.0000</rain_rate_day_high_in_per_hr> <rain_rate_hour_high_in_per_hr>0.0000</rain_rate_hour_high_in_per_hr> <rain_rate_in_per_hr>0.0000</rain_rate_in_per_hr> <rain_rate_month_high_in_per_hr>10.0787</rain_rate_month_high_in_per_hr> <rain_rate_year_high_in_per_hr>10.0787</rain_rate_year_high_in_per_hr> <rain_storm_in>0.0236</rain_storm_in> <rain_storm_start_date>10/13/2014</rain_storm_start_date> <rain_year_in>2.3937</rain_year_in> <relative_humidity_day_high>94</relative_humidity_day_high> <relative_humidity_day_high_time>12:00am</relative_humidity_day_high_time> <relative_humidity_day_low>36</relative_humidity_day_low> <relative_humidity_day_low_time>2:30pm</relative_humidity_day_low_time> <relative_humidity_in>61</relative_humidity_in> <relative_humidity_in_day_high>65</relative_humidity_in_day_high> <relative_humidity_in_day_high_time>1:50am</relative_humidity_in_day_high_time> <relative_humidity_in_day_low>60</relative_humidity_in_day_low> <relative_humidity_in_day_low_time>6:08pm</relative_humidity_in_day_low_time> <relative_humidity_in_month_high>78</relative_humidity_in_month_high> <relative_humidity_in_month_low>35</relative_humidity_in_month_low> <relative_humidity_in_year_high>78</relative_humidity_in_year_high> <relative_humidity_in_year_low>35</relative_humidity_in_year_low> <relative_humidity_month_high>97</relative_humidity_month_high> <station_name>Roma EUR meteo</station_name> <sunrise>6:41am</sunrise> <sunset>5:08pm</sunset> <temp_day_high_f>69.7</temp_day_high_f> <temp_day_high_time>2:25pm</temp_day_high_time> <temp_day_low_f>51.2</temp_day_low_f> <temp_day_low_time>5:10am</temp_day_low_time> <temp_in_day_high_f>69.6</temp_in_day_high_f> <temp_in_day_high_time>12:00am</temp_in_day_high_time> <temp_in_day_low_f>68.3</temp_in_day_low_f> <temp_in_day_low_time>1:05pm</temp_in_day_low_time> <temp_in_f>69.1</temp_in_f> <temp_in_month_high_f>80.7</temp_in_month_high_f> <temp_in_month_low_f>68.1</temp_in_month_low_f> <temp_in_year_high_f>80.7</temp_in_year_high_f> <temp_in_year_low_f>68.1</temp_in_year_low_f> <temp_month_high_f>83.6</temp_month_high_f> <temp_month_low_f>47.2</temp_month_low_f> <temp_year_high_f>83.6</temp_year_high_f> <temp_year_low_f>47.2</temp_year_low_f> <wind_day_high_mph>17</wind_day_high_mph> <wind_day_high_time>4:59pm</wind_day_high_time> <wind_month_high_mph>31</wind_month_high_mph> <wind_ten_min_avg_mph>3</wind_ten_min_avg_mph> <wind_year_high_mph>31</wind_year_high_mph> <windchill_day_low_f>51</windchill_day_low_f> <windchill_day_low_time>5:04am</windchill_day_low_time> <windchill_month_low_f>47</windchill_month_low_f> <windchill_year_low_f>47</windchill_year_low_f> </davis_current_observation> <disclaimer_url>http://www.davisnet.com/about/terms.asp</disclaimer_url> <copyright_url>http://www.davisnet.com/about/terms.asp</copyright_url> <privacy_policy_url>http://www.davisnet.com/about/privacy.asp</privacy_policy_url> <time_to_generate>0.046802997589111</time_to_generate> </current_observation>
Parte della mia pagina web relativa alla definizione delle variabili
codice:<?php $url = "http://www.weatherlink.com/xml.php?user=romaeur&pass=*****"; $ip = @file_get_contents($url); $object = simplexml_load_string($ip); $davis_current = $cur_obs->davis_current_observation; $cur_obs = simplexml_load_string($ip); $xml = simplexml_load_file('http://www.weatherlink.com/xml.php?user=romaeur&pass=********'); #Dati attuali foreach($xml->observation_time as $ultimo_aggiornamento); foreach($xml->temp_c as $temp); foreach($xml->heat_index_c as $heat); foreach($xml->relative_humidity as $hum); foreach($xml->wind_kt as $velventos); $velvento = round($velventos * 1.85,1); foreach($xml->wind_dir as $dirvento); foreach($xml->wind_degrees as $grvento); foreach($xml->pressure_mb as $press); foreach($xml->windchill_c as $chill); foreach($xml->dewpoint_c as $dew); foreach($xml->davis_current_observation->rain_day_in as $precs); foreach($xml->davis_current_observation->rain_rate_in_per_hr as $rrates); foreach($xml->davis_current_observation->rain_storm_in as $storms); foreach($xml->davis_current_observation->rain_rate_hour_high_in_per_hr as $maxrrhs); foreach($xml->davis_current_observation->rain_rate_day_high_in_per_hr as $maxrrds); $prec = round($precs / 0.039370,1); $rrate = round($rrates / 0.039370,1); $storm = round($storms / 0.039370,1); $maxrrh = round($maxrrhs / 0.039370,1); $maxrrd = round($maxrrds / 0.039370,1); #Max e Min foreach($xml->davis_current_observation->relative_humidity_day_high as $hummax); foreach($xml->davis_current_observation->relative_humidity_day_low as $hummin); foreach($xml->davis_current_observation->temp_day_low_f as $tminf); foreach($xml->davis_current_observation->temp_day_high_f as $tmaxf); $tmax = round((5/9) * ($tmaxf - 32),1); $tmin = round((5/9) * ($tminf - 32),1); foreach($xml->davis_current_observation->temp_day_high_time as $tmaxh); foreach($xml->davis_current_observation->temp_day_high_f as $max); foreach($xml->davis_current_observation->temp_day_low_time as $tminh); foreach($xml->davis_current_observation->pressure_day_high_in as $pressmaxin); foreach($xml->davis_current_observation->pressure_day_high_time as $pressmaxh); foreach($xml->davis_current_observation->pressure_day_low_time as $pressminh); foreach($xml->davis_current_observation->pressure_day_low_in as $pressminin); $pressmax = round($pressmaxin * 33.86, 1); $pressmin = round($pressminin * 33.86, 1); foreach($xml->davis_current_observation->relative_humidity_day_low_time as $humminh); foreach($xml->davis_current_observation->relative_humidity_day_high_time as $hummaxh); foreach($xml->davis_current_observation->wind_day_high_mph as $rafmaxs); $rafmax = round($rafmaxs * 1.6,1); foreach($xml->davis_current_observation->sunrise as $alba); foreach($xml->davis_current_observation->sunset as $tram); if ($grvento > 348.75 AND $grvento <=11.25) { $grvento = N; } if ($grvento > 11.25 AND $grvento <=33.75) { $grvento = NNE; } if ($grvento > 33.75 AND $grvento <=56.25) { $grvento = NE; } if ($grvento > 56.25 AND $grvento <=78.75 ) { $grvento = ENE; } if ($grvento > 78.75 AND $grvento <=101.25 ) { $grvento = E; } if ($grvento > 101.25 AND $grvento <=123.75) { $grvento = ESE; } if ($grvento > 123.75 AND $grvento <=146.25) { $grvento = SE; } if ($grvento > 146.25 AND $grvento <=168.65) { $grvento = SSE; } if ($grvento > 168.65 AND $grvento <=191.25) { $grvento = S; } if ($grvento > 191.25 AND $grvento <=213.75) { $grvento = SSO; } if ($grvento > 213.75 AND $grvento <=236.25) { $grvento = SO; } if ($grvento > 236.25 AND $grvento <=258.65) { $grvento = OSO; } if ($grvento > 258.65 AND $grvento <=281.25) { $grvento = O; } if ($grvento > 281.25 AND $grvento <=303.75) { $grvento = ONO; } if ($grvento > 303.75 AND $grvento <=326.25) { $grvento = NO; } if ($grvento > 326.25 AND $grvento <=348.75) { $grvento = NNO; } if ($grvento > 338 AND $grvento <=360) { $grvento = N; } ?>
In particolare questa è la parte con la conversione:
Vi allego anche un paio di fotocodice:foreach($xml->davis_current_observation->temp_day_low_f as $tminf); foreach($xml->davis_current_observation->temp_day_high_f as $tmaxf); $tmax = round((5/9) * ($tmaxf - 32),1); $tmin = round((5/9) * ($tminf - 32),1);
Mia pagina web
1.JPG
Pagina web di partenza che genere l'xml
2.JPG

Rispondi quotando
