PLearn 0.1
Public Member Functions | Static Protected Attributes | Private Types
PLearn::StatsCommand Class Reference

The first sentence should be a BRIEF DESCRIPTION of what the class does. More...

#include <StatsCommand.h>

Inheritance diagram for PLearn::StatsCommand:
Inheritance graph
[legend]
Collaboration diagram for PLearn::StatsCommand:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 StatsCommand ()
virtual void run (const std::vector< std::string > &args)
 The actual implementation of the 'StatsCommand' command.

Static Protected Attributes

static PLearnCommandRegistry reg_
 This allows to register the 'StatsCommand' command in the command registry.

Private Types

typedef PLearnCommand inherited

Detailed Description

The first sentence should be a BRIEF DESCRIPTION of what the class does.

Place the rest of the class programmer documentation here. Doxygen supports Javadoc-style comments. See http://www.doxygen.org/manual.html

Todo:
Write class to-do's here if there are any.
Deprecated:
Write deprecated stuff here if there is any. Indicate what else should be used instead.

Definition at line 58 of file StatsCommand.h.


Member Typedef Documentation

Definition at line 60 of file StatsCommand.h.


Constructor & Destructor Documentation

PLearn::StatsCommand::StatsCommand ( )

Definition at line 54 of file StatsCommand.cc.

    : PLearnCommand(
        "stats",
        "allow to extract some stats from stats file",
        "plearn stats sum_sort <statsfile> --filter=boost_regex --replace=boost_regex=new_value\n"
        "FULL DETAILED HELP HERE \n"
        )
{}

Member Function Documentation

void PLearn::StatsCommand::run ( const std::vector< std::string > &  args) [virtual]

The actual implementation of the 'StatsCommand' command.

Implements PLearn::PLearnCommand.

Definition at line 64 of file StatsCommand.cc.

References PLearn::endl(), PLearn::filter(), PLearn::VecStatsCollector::getFieldNames(), PLearn::VecStatsCollector::getStats(), i, PLearn::load(), m, PLERROR, PLearn::pout, PLearn::VecStatsCollector::size(), PLearn::sortRows(), PLearn::split_on_first(), and PLearn::StatsCollector::sum().

{
    if(args[0]=="sum_sort"){
        //plearn Stats sum_sort <statsfile> --filter=boost_regex --replace=boost_regex=new_value
        if(args.size()<2)
            PLERROR("plearn stats sum_sort <statsfile> --filter=boost_regex --replace=boost_regex=new_value");

        //default regex that match all non new line caracter
        boost::regex filter(".*");
        boost::regex replace_re;
        string replace_new = "";

            
        string statsfile = args[1];
        string test_re;
        try{
            for(uint i=2;i<args.size();i++){
                if(args[i].substr(0,9)=="--filter="){
                    test_re=args[i].substr(9);
                    filter.assign(test_re);
                }else if(args[i].substr(0,10)=="--replace="){
                    split_on_first(args[i].substr(10), "=",
                                   test_re, replace_new);
                    replace_re.assign(test_re);
                }else
                    PLERROR("In StatsCommand::run() - unknow parameter '%s'", 
                            args[i].c_str());
            }
        }catch (boost::regex_error& e){
            PLERROR("invalid regular expression: \"%s\"\n %s",
                    test_re.c_str(),
                    e.what());
        }
        TVec<StatsCollector> stats1;
        VecStatsCollector stats;

        PLearn::load(statsfile, stats);
        Mat m(stats.size(),2);
        for(int i = 0;i<stats.size();i++){
            m(i,0)=i;
            m(i,1)=stats.getStats(i).sum();
        }

        pout<<"NAME "<<"SUM"<<endl;
        sortRows(m,1,false);
        for(int i=0;i<m.length();i++){
            string f = stats.getFieldNames()[int(m(i,0))];
            if(boost::regex_match(f, filter)){
                if(replace_re.size()>0)
                    f = boost::regex_replace(f,replace_re,"");
                pout<<f<<" "<<m(i,1)<<endl;
            }
        }
    }else
        PLERROR("Currently only the sub commands sum_sort is supported!");
}

Here is the call graph for this function:


Member Data Documentation

This allows to register the 'StatsCommand' command in the command registry.

Definition at line 67 of file StatsCommand.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines