void LocationPointRead:: operator () ( argument_type &t ) { ostringstream q; boost::posix_time::ptime refTime; string validTime; bool disabled; int dataversion; WEBFW_USE_LOGGER( "wdb" ); if( to_.is_special() ) validTime = "NULL"; else validTime = wciTimeSpec( wciProtocol_, boost::posix_time::ptime( boost::posix_time::neg_infin), to_ ); for( ParamDefList::const_iterator itPar=paramDefs_.begin(); itPar != paramDefs_.end(); ++itPar ) { if( ! refTimeList_.providerReftimeDisabledAndDataversion(itPar->first, refTime, disabled, dataversion ) ) { WEBFW_LOG_WARN("No reference times found for provider '" << itPar->first << "'." << "Check that the provider is listed in provider_priority."); continue; } if( disabled ) { WEBFW_LOG_WARN("Provider '" << itPar->first << "' disabled." ); continue; } if( dataversion < -1 ) dataversion = -1; q.str(""); q << "SELECT " << wciReadReturnColoumns( wciProtocol_ ) << " FROM wci.read(" << endl << "ARRAY['" << itPar->first << "'], " << endl << "'nearest POINT(" << longitude_ << " " << latitude_ << ")', " << endl << wciTimeSpec( wciProtocol_, refTime ) << ", " << endl << validTime << ", " << endl << wciValueParameter( wciProtocol_, itPar->second ) << ", " << endl << "NULL, " << endl << "ARRAY[" << dataversion << "], NULL::wci.returnfloat ) ORDER BY referencetime"; WEBFW_LOG_DEBUG( "LocationPointRead: transactor: SQL [" << q.str() << "]" ); pqxx::result res = t.exec( q.str() ); //miutil::container::PqContainer container( res ); decodePData( paramDefs_, providers_, refTimeList_, res, false, *locationPointData_, wciProtocol_ ); } }
void LocationPointMatrixData:: operator () ( argument_type &t ) { ostringstream q; string sSurround; boost::posix_time::ptime validtimeto; boost::posix_time::ptime validtimefrom; boost::posix_time::ptime prevValidTimeTo; boost::posix_time::ptime prevValidTimeFrom; ParamDefPtr itPar; LocationPoint locationPoint; string dummyGroupProvider; int expextNValues=1; int nValues=0; int n=1; float value; int x=0; int y=0; int myDataversion( dataversion_ ); WEBFW_USE_LOGGER( logger_ ); locations_->clear(); query_->clear(); if( surroundLevel_ < 0 ) { WEBFW_LOG_WARN("The SUROUND level is less than 0, setting it to 0."); surroundLevel_ = 0; } if( wciProtocol_ < 6) { sSurround ="SURROUND "; expextNValues = 4; n=2; } else { if( surroundLevel_ > 0 ) { n = 2*surroundLevel_; expextNValues = 4*surroundLevel_*surroundLevel_; // (2*surroundLevel_)^2 q << "SURROUND(" << surroundLevel_ << ") "; sSurround = q.str(); // n=surroundLevel_; } } LocationPointMatrix pointMatrix( n, n ); LocationPointMatrix undefPointMatrix( n, n ); for( int x=0; x<n; ++x) for( int y=0; y<n; ++y ) undefPointMatrix[x][y] = LocationPoint(); if( myDataversion < -1 ) myDataversion = -1; q.str(""); q << "SELECT " << wciReadReturnColoumns( wciProtocol_ ) << " FROM wci.read(" << endl << "ARRAY['" << provider_ << "'], " << endl << "'" << sSurround << "POINT(" << longitude_ << " " << latitude_ << ")', " << endl << wciTimeSpec( wciProtocol_, reftimespec_ ) << ", " << endl << "NULL, " << endl << "ARRAY['" << paramDef_.valueparametername() << "'], " << endl << wciLevelSpec( wciProtocol_, paramDef_ ) << ", " << endl << "ARRAY[" << myDataversion << "], NULL::wci.returnfloat ) ORDER BY referencetime, validtimeto, validtimefrom"; WEBFW_LOG_DEBUG( "LocationPointMatrixData: transactor: SQL [" << q.str() << "]" ); *query_ = q.str(); pqxx::result res = t.exec( q.str() ); for( pqxx::result::const_iterator it=res.begin(); it != res.end(); ++it ) { if( it.at("value").is_null() ) continue; if( params_.findParam( it, itPar, dummyGroupProvider ) ) { if( !LocationPoint::decodeGisPoint( it.at("point").c_str(), locationPoint ) ) continue; validtimefrom = miutil::ptimeFromIsoString( it.at("validtimefrom").c_str() ); validtimeto = miutil::ptimeFromIsoString( it.at("validtimeto").c_str() ); if( prevValidTimeTo.is_special() ) { prevValidTimeTo = validtimeto; prevValidTimeFrom = validtimefrom; } else if( prevValidTimeTo != validtimeto ) { if( nValues != expextNValues ) { WEBFW_LOG_DEBUG("LocationPointMatrixData: expected: " << expextNValues << ", but got " << nValues << "."); } if( WEBFW_GET_LOGLEVEL() == log4cpp::Priority::DEBUG ) { ostringstream ost; ost << "LocationPointMatrixData: " << prevValidTimeFrom << " - " << prevValidTimeTo; for( int x=0; x<n; ++x) for( int y=0; y<n; ++y ) ost << "\n [" << x << ", " << y <<"] = " << pointMatrix[x][y].value(); WEBFW_LOG_DEBUG( ost.str() ); } locations_->insert( prevValidTimeFrom, prevValidTimeTo, pointMatrix, false ); pointMatrix = undefPointMatrix; nValues = 0; x=0; y=0; prevValidTimeTo = validtimeto; prevValidTimeFrom = validtimefrom; } if( x >= n && y < n ) { x = 0; y++; } if( x < n && y < n ) { value = it.at("value").as<float>()*itPar->scale()+itPar->offset(); locationPoint.value( value ); //WEBFW_LOG_DEBUG("LocationPointMatrixData: pointMatrix[" << y << "][" << x <<"] = " << locationPoint.value() ); pointMatrix[y][x] = locationPoint; nValues++; x++; } } } if( pointMatrix != undefPointMatrix ) { if( WEBFW_GET_LOGLEVEL() == log4cpp::Priority::DEBUG ) { ostringstream ost; ost << "LocationPointMatrixData: " << prevValidTimeFrom << " - " << prevValidTimeTo; for( int x=0; x<n; ++x) for( int y=0; y<n; ++y ) ost << "\n [" << x << ", " << y <<"] = " << pointMatrix[x][y].value(); WEBFW_LOG_DEBUG( ost.str() ); } locations_->insert( prevValidTimeFrom, prevValidTimeTo, pointMatrix, false ); } }