Changeset 531 for trunk/lib


Ignore:
Timestamp:
Dec 25, 2007, 7:51:07 PM (16 years ago)
Author:
Peter Johansson
Message:

moving more stuff to base class and add class for Blame Statistics

Location:
trunk/lib
Files:
5 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/lib/BlameStats.cc

    r529 r531  
    2323*/
    2424
    25 #include "ClassicStats.h"
     25#include "BlameStats.h"
    2626
    2727#include "Functor.h"
     
    5050
    5151
    52   ClassicStats::ClassicStats(const std::string& path)
     52  BlameStats::BlameStats(const std::string& path)
    5353    : Stats(path)
    5454  {
     
    5656
    5757
    58   ClassicStats::ClassicStats(const ClassicStats& other)
     58  BlameStats::BlameStats(const BlameStats& other)
    5959  : Stats(other)
    6060  {
     
    6262
    6363
    64   void ClassicStats::add(const std::string& user, const u_int& rev,
    65                          const Parser::line_type& lt)
    66   {
    67     assert(user.size());
    68     add_author(user);
    69 
    70     std::vector<u_int>* total = &(total_[user]);
    71     assert(total);
    72     if (total->size() < rev+1){
    73       total->reserve(revision() + 1);
    74       total->insert(total->end(), rev - total->size(), 0);
    75       total->push_back(1);
    76     }
    77     else
    78       ++(*total)[rev];
    79 
    80     std::vector<u_int>* code = &(code_[user]);
    81     assert(code);
    82     if (code->size() < rev+1){
    83       code->reserve(revision() + 1);
    84       code->insert(code->end(), rev - code->size(), 0);
    85       if (lt == Parser::code)
    86         code->push_back(1);
    87       else
    88         code->push_back(0);
    89     }
    90     else if (lt == Parser::code)
    91       ++(*code)[rev];
    92 
    93     std::vector<u_int>* comments = &(comments_[user]);
    94     assert(comments);
    95     if (comments->size() < rev+1){
    96       comments->reserve(revision() + 1);
    97       comments->insert(comments->end(), rev - comments->size(), 0);
    98       if (lt == Parser::comment)
    99         comments->push_back(1);
    100       else
    101         comments->push_back(0);
    102     }
    103     else if (lt == Parser::comment)
    104       ++(*comments)[rev];
    105 
    106     std::vector<u_int>* other = &(other_[user]);
    107     assert(other);
    108     if (other->size() < rev+1){
    109       other->reserve(revision() + 1);
    110       other->insert(other->end(), rev - other->size(), 0);
    111       if (lt == Parser::other)
    112         other->push_back(1);
    113       else
    114         other->push_back(0);
    115     }
    116     else if (lt == Parser::other)
    117       ++(*other)[rev];
    118   }
    119 
    120 
    121   void ClassicStats::do_parse(const std::string& path)
     64  void BlameStats::do_parse(const std::string& path)
    12265  {
    12366    Parser parser(path);
  • trunk/lib/BlameStats.h

    r529 r531  
    1 #ifndef _theplu_svndigest_classic_stats_
    2 #define _theplu_svndigest_classic_stats_
     1#ifndef _theplu_svndigest_blame_stats_
     2#define _theplu_svndigest_blame_stats_
    33
    44// $Id$
     
    3535  /// Class taking care of statistics from svn.
    3636  ///
    37   class ClassicStats : public Stats
     37  class BlameStats : public Stats
    3838  {
    3939  public:
     
    4141    /// @brief Default Constructor
    4242    ///
    43     explicit ClassicStats(const std::string& path);
     43    explicit BlameStats(const std::string& path);
    4444
    45     ClassicStats(const ClassicStats& other);
     45    BlameStats(const BlameStats& other);
    4646
    4747  private:
     
    5454             const Parser::line_type&);
    5555
    56     /**
    57        Load object from a stream.
    58        
    59        \return true if successful
    60      */
    61     bool do_load_cache(std::istream&);
    62 
    6356    void do_parse(const std::string&);
    64 
    65     ///
    66     /// Create statistics graph.
    67     ///
    68     std::string do_plot(const std::string&, const std::string&) const;
    69 
    70     /**
    71      */
    72     void do_print(std::ostream&) const;
    73 
    74     std::vector<u_int> vector(std::string type, std::string user) const;
    75     /**
    76        Load map from stream
    77      */
    78     void load(std::istream&, Author2Vector&);
    79 
    80     void do_print(std::ostream& os, const Author2Vector& map) const;
    8157
    8258  };
  • trunk/lib/ClassicStats.cc

    r529 r531  
    6262
    6363
    64   void ClassicStats::add(const std::string& user, const u_int& rev,
    65                          const Parser::line_type& lt)
    66   {
    67     assert(user.size());
    68     add_author(user);
    69 
    70     std::vector<u_int>* total = &(total_[user]);
    71     assert(total);
    72     if (total->size() < rev+1){
    73       total->reserve(revision() + 1);
    74       total->insert(total->end(), rev - total->size(), 0);
    75       total->push_back(1);
    76     }
    77     else
    78       ++(*total)[rev];
    79 
    80     std::vector<u_int>* code = &(code_[user]);
    81     assert(code);
    82     if (code->size() < rev+1){
    83       code->reserve(revision() + 1);
    84       code->insert(code->end(), rev - code->size(), 0);
    85       if (lt == Parser::code)
    86         code->push_back(1);
    87       else
    88         code->push_back(0);
    89     }
    90     else if (lt == Parser::code)
    91       ++(*code)[rev];
    92 
    93     std::vector<u_int>* comments = &(comments_[user]);
    94     assert(comments);
    95     if (comments->size() < rev+1){
    96       comments->reserve(revision() + 1);
    97       comments->insert(comments->end(), rev - comments->size(), 0);
    98       if (lt == Parser::comment)
    99         comments->push_back(1);
    100       else
    101         comments->push_back(0);
    102     }
    103     else if (lt == Parser::comment)
    104       ++(*comments)[rev];
    105 
    106     std::vector<u_int>* other = &(other_[user]);
    107     assert(other);
    108     if (other->size() < rev+1){
    109       other->reserve(revision() + 1);
    110       other->insert(other->end(), rev - other->size(), 0);
    111       if (lt == Parser::other)
    112         other->push_back(1);
    113       else
    114         other->push_back(0);
    115     }
    116     else if (lt == Parser::other)
    117       ++(*other)[rev];
    118   }
    119 
    120 
    12164  void ClassicStats::do_parse(const std::string& path)
    12265  {
  • trunk/lib/ClassicStats.h

    r529 r531  
    4646
    4747  private:
    48     /// using compiler generated copy
    49 
    50     ///
    51     /// @brief adding a line to user from revision to the stats
    52     ///
    53     void add(const std::string& user, const u_int& revision,
    54              const Parser::line_type&);
    55 
    56     /**
    57        Load object from a stream.
    58        
    59        \return true if successful
    60      */
    61     bool do_load_cache(std::istream&);
    62 
    6348    void do_parse(const std::string&);
    64 
    65     ///
    66     /// Create statistics graph.
    67     ///
    68     std::string do_plot(const std::string&, const std::string&) const;
    69 
    70     /**
    71      */
    72     void do_print(std::ostream&) const;
    73 
    74     std::vector<u_int> vector(std::string type, std::string user) const;
    75     /**
    76        Load map from stream
    77      */
    78     void load(std::istream&, Author2Vector&);
    79 
    80     void do_print(std::ostream& os, const Author2Vector& map) const;
    8149
    8250  };
  • trunk/lib/Makefile.am

    r519 r531  
    2626noinst_LTLIBRARIES = libsvndigest.la
    2727
    28 noinst_HEADERS = Alias.h ClassicStats.h ColumnStream.h \
     28noinst_HEADERS = Alias.h BlameStats.h ClassicStats.h ColumnStream.h \
    2929  Commitment.h Configuration.h css.h\
    3030  Date.h Directory.h File.h first_page.h Functor.h Gnuplot.h GnuplotFE.h \
     
    3333  SVNinfo.h SVNlog.h SVNproperty.h Trac.h utility.h
    3434
    35 libsvndigest_la_SOURCES = Alias.cc ClassicStats.cc ColumnStream.cc \
     35libsvndigest_la_SOURCES = Alias.cc BlameStats.cc \
     36  ClassicStats.cc ColumnStream.cc \
    3637  Commitment.cc Configuration.cc \
    3738  css.cc Date.cc Directory.cc File.cc first_page.cc\
  • trunk/lib/Stats.cc

    r530 r531  
    101101    total_["all"] = vp(vp(code_["all"], comments_["all"]), other_["all"]);
    102102  }
     103
     104
     105  void Stats::add(const std::string& user, const u_int& rev,
     106                  const Parser::line_type& lt, u_int n)
     107  {
     108    assert(user.size());
     109    add_author(user);
     110
     111    std::vector<u_int>& total = total_[user];
     112    if (total.size() < rev+1){
     113      total.reserve(revision() + 1);
     114      total.insert(total.end(), rev - total.size(), 0);
     115      total.push_back(n);
     116    }
     117    else
     118      total[rev]+=n;
     119
     120    std::vector<u_int>& code = code_[user];
     121    if (code.size() < rev+1){
     122      code.reserve(revision() + 1);
     123      code.insert(code.end(), rev - code.size(), 0);
     124      if (lt == Parser::code)
     125        code.push_back(n);
     126      else
     127        code.push_back(0);
     128    }
     129    else if (lt == Parser::code)
     130      code[rev]+=n;
     131
     132    std::vector<u_int>& comments = comments_[user];
     133    if (comments.size() < rev+1){
     134      comments.reserve(revision() + 1);
     135      comments.insert(comments.end(), rev - comments.size(), 0);
     136      if (lt == Parser::comment)
     137        code.push_back(n);
     138      else
     139        comments.push_back(0);
     140    }
     141    else if (lt == Parser::comment)
     142      comments[rev]+=n;
     143
     144    std::vector<u_int>& other = other_[user];
     145    if (other.size() < rev+1){
     146      other.reserve(revision() + 1);
     147      other.insert(other.end(), rev - other.size(), 0);
     148      if (lt == Parser::other)
     149        other.push_back(n);
     150      else
     151        other.push_back(0);
     152    }
     153    else if (lt == Parser::other)
     154      other[rev]+=n;
     155  }
    103156
    104157
  • trunk/lib/Stats.h

    r530 r531  
    5555    */
    5656    virtual ~Stats(void);
     57
     58    ///
     59    /// @brief adding \a n line(s) to \a user from \a revision to the stats
     60    ///
     61    void add(const std::string& user, const u_int& revision,
     62             const Parser::line_type&, u_int n=1);
    5763
    5864    ///
Note: See TracChangeset for help on using the changeset viewer.