returnValue VariablesGrid::appendTimes( const VariablesGrid& arg, MergeMethod _mergeMethod ) { // nothing to do for empty grids if ( arg.getNumPoints( ) == 0 ) return SUCCESSFUL_RETURN; if ( getNumPoints( ) == 0 ) { *this = arg; return SUCCESSFUL_RETURN; } // consistency check if ( acadoIsGreater( arg.getFirstTime( ),getLastTime( ) ) == BT_FALSE ) return ACADOERROR( RET_INVALID_ARGUMENTS ); if ( acadoIsEqual( getLastTime( ),arg.getFirstTime( ) ) == BT_FALSE ) { // simply append for( uint i=0; i<arg.getNumPoints( ); ++i ) addMatrix( *(arg.values[i]),arg.getTime( i ) ); } else { // if last and first time point coincide, merge as specified switch ( _mergeMethod ) { case MM_KEEP: break; case MM_REPLACE: setVector( getLastIndex(),arg.getFirstVector( ) ); break; case MM_DUPLICATE: addMatrix( *(arg.values[0]),arg.getTime( 0 ) ); break; } // simply append all remaining points for( uint i=1; i<arg.getNumPoints( ); ++i ) addMatrix( *(arg.values[i]),arg.getTime( i ) ); } return SUCCESSFUL_RETURN; }
std::ostream& Sequence::getCout( std::ostream& os ) const { bfs::path dir; if( showAbsolutePath() ) { dir = bfs::absolute( _directory ); dir = boost::regex_replace( dir.string(), boost::regex( "/\\./" ), "/" ); } os << std::left; if( showProperties() ) { os << std::setw( PROPERTIES_WIDTH ) << "s "; } if( showRelativePath() ) { dir = _directory; dir = boost::regex_replace( dir.string(), boost::regex( "/\\./" ), "/" ); os << std::setw( NAME_WIDTH_WITH_DIR ) << _kColorSequence + ( dir / getStandardPattern() ).string() + _kColorStd; } else { os << std::setw( NAME_WIDTH ) << _kColorSequence + ( dir / getStandardPattern() ).string() + _kColorStd; } os << " [" << getFirstTime() << ":" << getLastTime(); if( getStep() != 1 ) os << "x" << getStep(); os << "] " << getNbFiles() << " file" << ( ( getNbFiles() > 1 ) ? "s" : "" ); if( hasMissingFile() ) { os << ", " << _kColorError << getNbMissingFiles() << " missing file" << ( ( getNbMissingFiles() > 1 ) ? "s" : "" ) << _kColorStd; } return os; }
bool ReaderPlugin::getTimeDomain(OfxRangeD& range) { range.min = getFirstTime(); range.max = getLastTime(); TUTTLE_LOG_INFO("[Reader plugin] Time Domain : " << range.min << " to " << range.max); return true; }
std::vector<boost::filesystem::path> Sequence::getFiles() const { std::vector<boost::filesystem::path> allPaths; for( Time t = getFirstTime(); t <= getLastTime(); t += getStep() ) { allPaths.push_back( getAbsoluteFilenameAt( t ) ); } return allPaths; }
lString16 CRFileHistRecord::getLastTimeString( bool longFormat ) { time_t t = getLastTime(); tm * bt = localtime(&t); char str[20]; if ( !longFormat ) sprintf(str, "%02d.%02d.%04d", bt->tm_mday, 1+bt->tm_mon, 1900+bt->tm_year ); else sprintf(str, "%02d.%02d.%04d %02d:%02d", bt->tm_mday, 1+bt->tm_mon, 1900+bt->tm_year, bt->tm_hour, bt->tm_min); return Utf8ToUnicode( lString8( str ) ); }
// uses a simple O(n^2) algorithm for sorting returnValue VariablesGrid::merge( const VariablesGrid& arg, MergeMethod _mergeMethod, BooleanType keepOverlap ) { if ( ( keepOverlap == BT_FALSE ) && ( _mergeMethod == MM_DUPLICATE ) ) return ACADOERROR( RET_INVALID_ARGUMENTS ); // nothing to do if arg or object itself is empty if ( arg.getNumPoints( ) == 0 ) return SUCCESSFUL_RETURN; if ( getNumPoints( ) == 0 ) { *this = arg; return SUCCESSFUL_RETURN; } // use append if grids do not overlap if ( acadoIsSmaller( getLastTime( ),arg.getFirstTime( ) ) == BT_TRUE ) return appendTimes( arg,_mergeMethod ); // construct merged grid VariablesGrid mergedGrid; uint j = 0; BooleanType overlapping = BT_FALSE; for( uint i=0; i<getNumPoints( ); ++i ) { if ( keepOverlap == BT_FALSE ) overlapping = arg.isInInterval( getTime(i) ); // add all grid points of argument grid that are smaller // then current one of original grid while ( ( j < arg.getNumPoints( ) ) && ( acadoIsStrictlySmaller( arg.getTime( j ),getTime( i ) ) == BT_TRUE ) ) { if ( ( overlapping == BT_FALSE ) || ( ( overlapping == BT_TRUE ) && ( _mergeMethod == MM_REPLACE ) ) ) { mergedGrid.addMatrix( *(arg.values[j]),arg.getTime( j ) ); } ++j; } // merge current grid points if they are at equal times if ( acadoIsEqual( arg.getTime( j ),getTime( i ) ) == BT_TRUE ) { switch ( _mergeMethod ) { case MM_KEEP: mergedGrid.addMatrix( *(values[i]),getTime( i ) ); break; case MM_REPLACE: mergedGrid.addMatrix( *(arg.values[j]),arg.getTime( j ) ); break; case MM_DUPLICATE: mergedGrid.addMatrix( *(values[i]),getTime( i ) ); mergedGrid.addMatrix( *(arg.values[j]),arg.getTime( j ) ); break; } ++j; } else { // add current grid point of original grid if ( ( overlapping == BT_FALSE ) || ( ( overlapping == BT_TRUE ) && ( _mergeMethod == MM_KEEP ) ) ) { mergedGrid.addMatrix( *(values[i]),getTime( i ) );//arg. } } } // add all remaining grid points of argument grid while ( j < arg.getNumPoints( ) ) { if ( acadoIsStrictlyGreater( arg.getTime(j),getLastTime() ) == BT_TRUE ) mergedGrid.addMatrix( *(arg.values[j]),arg.getTime( j ) ); ++j; } // merged grid becomes current grid *this = mergedGrid; return SUCCESSFUL_RETURN; }
/** * 通过线程池进行并发查询 */ void DbProxy::queryData(map<string, string> &mSqlPart, string &sResult, bool bDbCountFlag) { typedef TC_Functor<void, TL::TLMaker<int, const TC_DBConf &, map<string,string>&, map<string,vector<double> >&, string&, QueryParam &,string&>::Result> QueryFun; typedef QueryFun::wrapper_type QueryFunWrapper; try { string sUid = mSqlPart.find("uid")->second; vector<TC_DBConf> vActive; if(bDbCountFlag) { vActive = g_app.getActiveDbInfo(); } else { //vActive = g_app.getActiveDbInfo(); } int iThreads = vActive.size(); //int iThreads = bDbCountFlag ? g_app.getDbNumber() : g_app.getDbNumber(); if(iThreads > 0) { vector<string> vPolicy(iThreads); vector<string> res(iThreads); vector<map<string, vector<double> > > vDataList(iThreads); QueryFun qeryCMD(query); _queryParam._run_times = iThreads; //TLOGDEBUG("DbProxy::queryData sUid:" << sUid << "all thread query data begin." << endl); int64_t tStart = TC_TimeProvider::getInstance()->getNowMs(); for(int i=0; i < iThreads; i++) { QueryFunWrapper fwrapper(qeryCMD, i, vActive[i], mSqlPart, vDataList[i], res[i], _queryParam,vPolicy[i]); if(bDbCountFlag) { g_app.getThreadPoolDb().exec(fwrapper); } else { //g_app.getThreadPoolDb().exec(fwrapper); } } //等待线程结束 TLOGDEBUG("DbProxy::queryData sUid:" << sUid << "wait for all thread query data done." << endl); bool rc = true; int ifail = 0; while(_queryParam._atomic.get() != _queryParam._run_times) { { TC_ThreadLock::Lock lock(_queryParam._monitor); rc = _queryParam._monitor.timedWait(6000); } ++ifail; if(!rc) { if(ifail >= 10) { break; } } } if(ifail >= 10) { TLOGDEBUG("DbProxy::queryData sUid:" << sUid << "wait for all thread query data timeout." << endl); while(_queryParam._atomic.get() != _queryParam._run_times) { { TC_ThreadLock::Lock lock(_queryParam._monitor); _queryParam._monitor.timedWait(1000); } } } if(_queryParam._atomic.get() == _queryParam._run_times) rc = true; /*bool rc = false; { TC_ThreadLock::Lock lock(_queryParam._monitor); rc = _queryParam._monitor.timedWait(60000); }*/ int64_t tEnd = TC_TimeProvider::getInstance()->getNowMs(); if(rc) { _queryParam._run_times = 0; _queryParam._run_result = 0; _queryParam._atomic = 0; TLOGDEBUG("DbProxy::queryData sUid:" << sUid << "all thread done return:" << _queryParam._run_result <<"|timecost(ms):" << (tEnd - tStart) << endl); // 返回ret code string sHead; string sLasttime = getLastTime(mSqlPart); if(createRespHead(res, sLasttime, sHead, bDbCountFlag) != 0) { _queryParam._run_times = 0; _queryParam._run_result = 0; _queryParam._atomic = 0; sResult = sHead; TLOGERROR("DbProxy::queryData query error:" << sHead << endl); return; } createRespData(sUid, mSqlPart, vDataList, sHead, sResult,vPolicy[vPolicy.size()-1]); } else { sResult ="Ret:-1\nquery timeout\n"; TLOGDEBUG("DbProxy::queryData sUid:" << sUid << "Ret:-1|query timeout." << endl); } } else { sResult ="Ret:-1\nno active db\n"; } } catch (exception &ex) { TLOGERROR("DbProxy::queryData exception:" << ex.what() << endl); sResult ="Ret:-1\n" + string(ex.what()) + "\n"; } _queryParam._run_times = 0; _queryParam._run_result = 0; _queryParam._atomic = 0; }
bool ReaderPlugin::getTimeDomain( OfxRangeD& range ) { range.min = getFirstTime(); range.max = getLastTime(); return true; }