source: trunk/lib/Stats.h @ 439

Last change on this file since 439 was 439, checked in by Peter Johansson, 14 years ago

Merged patch release 0.6.1 to the trunk. Delta 0.6.1 - 0.6

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.2 KB
RevLine 
[165]1#ifndef _theplu_svndigest_stats_
2#define _theplu_svndigest_stats_
3
[84]4// $Id: Stats.h 439 2007-07-09 21:04:52Z peter $
[14]5
[84]6/*
7  Copyright (C) 2005 Peter Johansson
8  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
[408]9  Copyright (C) 2007 Peter Johansson
[84]10
[439]11  This file is part of svndigest, http://trac.thep.lu.se/trac/svndigest
[84]12
[149]13  svndigest is free software; you can redistribute it and/or modify it
[84]14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation; either version 2 of the License, or
16  (at your option) any later version.
17
[149]18  svndigest is distributed in the hope that it will be useful, but
[84]19  WITHOUT ANY WARRANTY; without even the implied warranty of
[149]20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
[84]21  General Public License for more details.
22
23  You should have received a copy of the GNU General Public License
24  along with this program; if not, write to the Free Software
25  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26  02111-1307, USA.
27*/
28
[118]29#include "Parser.h"
30
[164]31#include <subversion-1/svn_types.h>
[129]32
[14]33#include <map>
[118]34#include <set>
[34]35#include <string>
[14]36#include <vector>
37
38namespace theplu{
[149]39namespace svndigest{
[14]40
41  ///
42  /// Class taking care of statistics from svn.
43  ///
44  class Stats
45  {
46  public:
47    ///
48    /// @brief Default Constructor
[34]49    ///
[80]50    explicit Stats(const std::string& path);
[34]51
[60]52    ///
[118]53    /// @return set of authors
[112]54    ///
[118]55    inline const std::set<std::string>& authors(void) const { return authors_; }
56
[112]57    ///
[118]58    ///
59    ///
60    inline u_int code(void) const { return accumulated(code_).back(); }
61
62    ///
63    ///
64    ///
65    inline u_int code(const std::string& user) const 
66    { return accumulated(code_, user).back(); }
67
68    ///
69    ///
70    ///
71    inline u_int comments(void) const { return accumulated(comments_).back(); }
72
73    ///
74    ///
75    ///
76    inline u_int comments(const std::string& user) const 
77    { return accumulated(comments_, user).back(); }
78
79    ///
[202]80    ///
[118]81    ///
[202]82    inline u_int empty(void) const { return accumulated(empty_).back(); }
83
[118]84    ///
[202]85    ///
86    ///
87    inline u_int empty(const std::string& user) const 
88    { return accumulated(empty_, user).back(); }
89
90    ///
91    ///
92    ///
[112]93    inline u_int last_changed_rev(void) const { return last_changed_rev_; }
94
[345]95    ///
96    ///
97    ///
98    inline u_int lines(void) const { return accumulated(total_).back(); }
99
100    ///
101    ///
102    ///
103    inline u_int lines(const std::string& user) const 
104    { return accumulated(total_, user).back(); }
105
[185]106    void parse(const std::string&);
[14]107
[23]108    ///
[74]109    /// Create statistics graph.
[23]110    ///
[244]111    std::string plot(const std::string&, const std::string&) const;
[23]112
113    ///
[345]114    /// Create statistics graph.
115    ///
116    void plot_init(const std::string& output) const;
117
118    ///
119    /// Summary plot for the first page
120    ///
121    void plot_summary(const std::string& output) const;
122
123    ///
[23]124    /// @brief Clear all statistics
125    ///
[118]126    inline void reset(void) 
[202]127    { 
128      code_.clear(); comments_.clear(); empty_.clear(); total_.clear(); 
[345]129      authors_.clear();
130    }
[14]131
[74]132    ///
[399]133    /// \return latest revision for whole project
[74]134    ///
[112]135    inline u_int revision(void) const { return revision_; }
136
137    ///
[118]138    ///
[112]139    ///
[198]140    inline std::vector<u_int> total(const std::string& user) const 
141    { return accumulated(total_, user); }
142
[14]143    ///
144    /// @return resulting Stats
145    ///
146    Stats& operator+=(const Stats&);
147
148  private:
[118]149    // Peter, if the vector is sparse make it a map
150    typedef std::map<std::string, std::vector<u_int> > Map_;
151    typedef Map_::iterator MapIter_;
152    typedef Map_::const_iterator MapConstIter_;
153
[23]154    ///
155    /// Copy constructor (not implemented)
156    ///
[14]157    Stats(const Stats& other);
158
[23]159    ///
160    /// @return accumulated vector of total
161    ///
[118]162    std::vector<u_int> accumulated(const Map_&) const;
[23]163
164    ///
165    /// @return accumulated vector of stats_[user]
166    ///
[118]167    std::vector<u_int> accumulated(const Map_&, 
168                                   const std::string& user) const;
[23]169
[60]170    ///
171    /// @brief adding a line to user from revision to the stats
172    ///
[118]173    void add(const std::string& user, const u_int& revision,
[138]174             const Parser::line_type&); 
[60]175
[41]176
[129]177    svn_revnum_t revision_; // Should be the latest revision for whole project
178    svn_revnum_t last_changed_rev_; // Should be the latest revision for file
[80]179
[118]180    std::set<std::string> authors_;
181    Map_ code_;
182    Map_ comments_;
[202]183    Map_ empty_;
[118]184    Map_ total_;
[14]185  };
[149]186}} // end of namespace svndigest end of namespace theplu
[14]187
[71]188#endif
Note: See TracBrowser for help on using the repository browser.