Changeset 16955
- Timestamp:
- 07/18/13 13:02:39 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/tngweather.cc
r16727 r16955 21 21 #include "HeadersTNGWeather.h" 22 22 23 #include < Soprano/Soprano>23 #include <QtXml/QDomDocument> 24 24 25 25 namespace ba = boost::asio; … … 127 127 } 128 128 129 const Soprano::Parser* p = Soprano::PluginManager::instance()->discoverParserForSerialization( Soprano::SerializationRdfXml ); 130 Soprano::StatementIterator it = p->parseString(QString(data.c_str()), QUrl(""), Soprano::SerializationRdfXml ); 131 129 QDomDocument doc; 130 if (!doc.setContent(QString(data.data()), false)) 131 { 132 Warn("Parsing of xml failed [0]."); 133 PostClose(false); 134 return; 135 } 136 137 if (fIsVerbose) 138 Out() << "Parsed:\n-------\n" << doc.toString().toStdString() << endl; 139 140 const QDomElement root = doc.documentElement(); 141 const QDomElement item = root.firstChildElement("item"); 142 143 const QDomElement med = item.firstChildElement("tngw:dimmSeeing.median"); 144 const QDomElement sdev = item.firstChildElement("tngw:dimmSeeing.stdev"); 145 const QDomElement dust = item.firstChildElement("tngw:dustTotal"); 146 const QDomElement delta = item.firstChildElement("tngw:deltaM1"); 147 const QDomElement pres = item.firstChildElement("tngw:airPressure"); 148 const QDomElement dew = item.firstChildElement("tngw:dewPoint"); 149 const QDomElement wdir = item.firstChildElement("tngw:windDirection"); 150 const QDomElement speed = item.firstChildElement("tngw:windSpeed"); 151 const QDomElement hum = item.firstChildElement("tngw:hum"); 152 const QDomElement tmp0 = item.firstChildElement("tngw:tempGround"); 153 const QDomElement tmp2 = item.firstChildElement("tngw:temp2M"); 154 const QDomElement tmp5 = item.firstChildElement("tngw:temp5M"); 155 const QDomElement tmp10 = item.firstChildElement("tngw:temp10M"); 156 const QDomElement solar = item.firstChildElement("tngw:solarimeter"); 157 const QDomElement date = item.firstChildElement("tngw:date"); 158 159 if (med.isNull() || sdev.isNull() || dust.isNull() || delta.isNull() || 160 pres.isNull() || dew.isNull() || wdir.isNull() || speed.isNull() || 161 hum.isNull() || hum.isNull() || tmp0.isNull() || tmp2.isNull() || 162 tmp5.isNull() || tmp10.isNull() || solar.isNull() || date.isNull()) 163 { 164 Warn("Parsing of xml failed [1]."); 165 PostClose(false); 166 return; 167 } 132 168 133 169 DimWeather w; 134 Time time(Time::none); 135 try 136 { 137 while (it.next()) 138 { 139 const string pre = (*it).predicate().toString().toStdString(); 140 const string obj = (*it).object().toString().toStdString(); 141 142 const size_t slash = pre.find_last_of('/'); 143 if (slash==string::npos) 144 continue; 145 146 const string id = pre.substr(slash+1); 147 148 if (obj=="N/A") 149 continue; 150 151 if (id=="dimmSeeing") 152 w.fSeeing = stof(obj); 153 if (id=="dustTotal") 154 w.fDustTotal = stof(obj); 155 if (id=="deltaM1") 156 w.fDeltaM1 = stof(obj); 157 if (id=="airPressure") 158 w.fAirPressure = stof(obj); 159 if (id=="dewPoint") 160 w.fDewPoint = stof(obj); 161 if (id=="windDirection") 162 w.fWindDirection = stof(obj); 163 if (id=="windSpeed") 164 w.fWindSpeed = stof(obj)*3.6; 165 if (id=="hum") 166 w.fHumidity = stof(obj); 167 if (id=="tempGround") 168 w.fTempGround = stof(obj); 169 if (id=="temp2M") 170 w.fTemp2M = stof(obj); 171 if (id=="temp5M") 172 w.fTemp5M = stof(obj); 173 if (id=="temp10M") 174 w.fTemp10M = stof(obj); 175 if (id=="date") 176 { 177 time.SetFromStr(obj, "%Y-%m-%dT%H:%M:%S"); 178 179 if (!time.IsValid()) 180 { 181 struct tm tm; 182 183 vector<char> buf(255); 184 if (strptime(obj.c_str(), "%c", &tm)) 185 time = Time(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, 186 tm.tm_hour, tm.tm_min, tm.tm_sec); 187 } 188 } 189 190 /* 191 Out() << "S: " << (*it).subject().toString().toStdString() << endl; 192 Out() << "P: " << (*it).predicate().toString().toStdString() << endl; 193 Out() << "O: " << (*it).object().toString().toStdString() << endl; 194 Out() << "C: " << (*it).context().toString().toStdString() << endl; 195 */ 196 } 197 198 if (!time.IsValid()) 199 throw runtime_error("time invalid"); 200 201 if (time!=fLastReport && fIsVerbose) 202 { 203 Out() << endl; 204 Out() << "Date: " << time << endl; 205 Out() << "Seeing: " << w.fSeeing << endl; 206 Out() << "DustTotal: " << w.fDustTotal << endl; 207 Out() << "DeltaM1: " << w.fDeltaM1 << endl; 208 Out() << "AirPressure: " << w.fAirPressure << endl; 209 Out() << "DewPoint: " << w.fDewPoint << endl; 210 Out() << "WindDirection: " << w.fWindDirection << endl; 211 Out() << "WindSpeed: " << w.fWindSpeed << endl; 212 Out() << "Humidity: " << w.fHumidity << endl; 213 Out() << "TempGround: " << w.fTempGround << endl; 214 Out() << "Temp2M: " << w.fTemp2M << endl; 215 Out() << "Temp5M: " << w.fTemp5M << endl; 216 Out() << "Temp10M: " << w.fTemp10M << endl; 217 Out() << endl; 218 } 219 220 fLastReport = time; 221 222 UpdateWeather(time, w); 223 224 if (fDust==w.fDustTotal) 225 return; 226 227 UpdateDust(time, w.fDustTotal); 228 fDust = w.fDustTotal; 229 230 ostringstream out; 231 out << setprecision(3) << "Dust: " << fDust << "ug/m^3 [" << time << "]"; 232 Message(out); 233 } 234 235 catch (const exception &e) 236 { 237 Out() << "Corrupted data received: " << e.what() << endl; 238 fLastReport = Time(Time::none); 239 return; 240 } 170 w.fSeeingMed = med .text().toFloat(); 171 w.fSeeingStdev = sdev .text().toFloat(); 172 w.fDustTotal = dust .text().toFloat(); 173 w.fDeltaM1 = delta.text().toFloat(); 174 w.fAirPressure = pres .text().toFloat(); 175 w.fDewPoint = dew .text().toFloat(); 176 w.fWindDirection = wdir .text().toFloat(); 177 w.fWindSpeed = speed.text().toFloat()*3.6; 178 w.fHumidity = hum .text().toFloat(); 179 w.fTempGround = tmp0 .text().toFloat(); 180 w.fTemp2M = tmp2 .text().toFloat(); 181 w.fTemp5M = tmp5 .text().toFloat(); 182 w.fTemp10M = tmp10.text().toFloat(); 183 w.fSolarimeter = solar.text().toFloat(); 184 185 const string obj = date.text().toStdString(); 186 187 Time time(obj); 188 if (!time.IsValid()) 189 { 190 struct tm tm; 191 192 vector<char> buf(255); 193 if (strptime(obj.c_str(), "%c", &tm)) 194 time = Time(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, 195 tm.tm_hour, tm.tm_min, tm.tm_sec); 196 } 197 198 if (!time.IsValid()) 199 throw runtime_error("time invalid"); 200 201 if (time!=fLastReport && fIsVerbose) 202 { 203 Out() << endl; 204 Out() << "Date: " << time << endl; 205 Out() << "Seeing: " << w.fSeeingMed << " +- " << w.fSeeingStdev << endl; 206 Out() << "DustTotal: " << w.fDustTotal << endl; 207 Out() << "DeltaM1: " << w.fDeltaM1 << endl; 208 Out() << "AirPressure: " << w.fAirPressure << endl; 209 Out() << "DewPoint: " << w.fDewPoint << endl; 210 Out() << "WindDirection: " << w.fWindDirection << endl; 211 Out() << "WindSpeed: " << w.fWindSpeed << endl; 212 Out() << "Humidity: " << w.fHumidity << endl; 213 Out() << "TempGround: " << w.fTempGround << endl; 214 Out() << "Temp2M: " << w.fTemp2M << endl; 215 Out() << "Temp5M: " << w.fTemp5M << endl; 216 Out() << "Temp10M: " << w.fTemp10M << endl; 217 Out() << "Solarimeter: " << w.fSolarimeter << endl; 218 Out() << endl; 219 } 220 221 fLastReport = time; 222 223 UpdateWeather(time, w); 224 225 if (fDust==w.fDustTotal) 226 return; 227 228 UpdateDust(time, w.fDustTotal); 229 fDust = w.fDustTotal; 230 231 ostringstream out; 232 out << setprecision(3) << "Dust: " << fDust << "ug/m^3 [" << time << "]"; 233 Message(out); 241 234 } 242 235 … … 385 378 ConnectionDimWeather(ba::io_service& ioservice, MessageImp &imp) : 386 379 ConnectionWeather(ioservice, imp), 387 fDimWeather("TNG_WEATHER/DATA", "F:1;F:1;F:1;F:1;F:1;F:1;F:1;F:1;F:1;F:1;F:1;F:1 ",380 fDimWeather("TNG_WEATHER/DATA", "F:1;F:1;F:1;F:1;F:1;F:1;F:1;F:1;F:1;F:1;F:1;F:1;F:1;F:1", 388 381 "|T_10M[deg C]:Temperature 10m above ground" 389 382 "|T_5M[deg C]:Temperature 5m above ground" … … 397 390 "|DeltaM1" 398 391 "|Dust[ug/m^3]:Dust (total)" 399 "|Seeing[W/m^2]:Seeing"), 392 "|Seeing[arcsec]:Seeing Median" 393 "|SeeingStdev[arcsec]:Seeing Stdev" 394 "|Solarimeter[W/m^2]:Solarimeter"), 400 395 fDimAtmosphere("TNG_WEATHER/DUST", "F:1", 401 396 "|Dust[ug/m^3]:Dust (total)")
Note:
See TracChangeset
for help on using the changeset viewer.