void ShuffleCommand :: Shuffle( IOManager & io ) { ALib::RandGen rg( mSeed ); int nout = mCount; int last = mRows.size(); for ( unsigned int i = 0; i < mRows.size() && nout-- > 0; i++ ) { int pos = rg.NextInt( 0, last ); io.WriteRow( mRows[pos] ); mRows[pos].swap( mRows[--last] ); } }
void SummaryCommand :: DoFreq( IOManager & io ) { CalcFreqs(); for ( unsigned int i = 0; i < mRows.size(); i++ ) { string key = MakeKey( mRows.at(i) ); unsigned int n = mFreqMap.find( key )->second.mFreq; CSVRow r = mRows.at(i); r.insert( r.begin(), ALib::Str( n ) ); io.WriteRow( r ); } }
void ReadXMLCommand :: WriteRow( const ALib::XMLElement * r, IOManager & io ) { CSVRow row; for ( unsigned int i = 0; i < r->ChildCount(); i++ ) { const ALib::XMLElement * ce = r->ChildElement( i ); if ( ce && ce->Name() == "td" ) { row.push_back( TDToCSV( ce ) ); } } // ALib::Dump( std::cout, row ); io.WriteRow( row ); }
void SummaryCommand :: DoMode( IOManager & io ) { unsigned int mode = CalcFreqs(); for ( FreqMap::const_iterator it = mFreqMap.begin(); it != mFreqMap.end(); ++it ) { if ( it->second.mFreq == mode ) { for ( unsigned int i = 0; i < it->second.mIndex.size(); i++ ) { CSVRow r = mRows.at( it->second.mIndex.at(i) ); r.insert( r.begin(), ALib::Str( mode ) ); io.WriteRow( r ); } } } }
void SummaryCommand :: DoMinMax( IOManager & io ) { CSVRow r = mRows.at(0); for ( unsigned int i = 1; i < mRows.size(); i++ ) { if ( mType == Min && Cmp( mRows.at(i), r ) < 0 ) { r = mRows.at(i); } else if ( mType == Max && Cmp( mRows.at(i), r ) > 0 ) { r = mRows.at(i); } } for ( unsigned int i = 0; i < mRows.size(); i++ ) { if ( Cmp( r, mRows.at(i) ) == 0 ) { io.WriteRow( mRows.at(i) ); } } }