source: trunk/lib/Stats.h @ 454

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

adding print function in Stats class - refs #78

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.3 KB
RevLine 
[165]1#ifndef _theplu_svndigest_stats_
2#define _theplu_svndigest_stats_
3
[84]4// $Id: Stats.h 454 2007-08-18 00:01:45Z 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
[454]123    /**
124     */
125    void print(std::ostream&) const;
126
[345]127    ///
[23]128    /// @brief Clear all statistics
129    ///
[118]130    inline void reset(void) 
[202]131    { 
132      code_.clear(); comments_.clear(); empty_.clear(); total_.clear(); 
[345]133      authors_.clear();
134    }
[14]135
[74]136    ///
[399]137    /// \return latest revision for whole project
[74]138    ///
[112]139    inline u_int revision(void) const { return revision_; }
140
141    ///
[118]142    ///
[112]143    ///
[198]144    inline std::vector<u_int> total(const std::string& user) const 
145    { return accumulated(total_, user); }
146
[14]147    ///
148    /// @return resulting Stats
149    ///
150    Stats& operator+=(const Stats&);
151
152  private:
[118]153    // Peter, if the vector is sparse make it a map
154    typedef std::map<std::string, std::vector<u_int> > Map_;
155    typedef Map_::iterator MapIter_;
156    typedef Map_::const_iterator MapConstIter_;
157
[23]158    ///
159    /// Copy constructor (not implemented)
160    ///
[14]161    Stats(const Stats& other);
162
[23]163    ///
164    /// @return accumulated vector of total
165    ///
[118]166    std::vector<u_int> accumulated(const Map_&) const;
[23]167
168    ///
169    /// @return accumulated vector of stats_[user]
170    ///
[118]171    std::vector<u_int> accumulated(const Map_&, 
172                                   const std::string& user) const;
[23]173
[60]174    ///
175    /// @brief adding a line to user from revision to the stats
176    ///
[118]177    void add(const std::string& user, const u_int& revision,
[138]178             const Parser::line_type&); 
[60]179
[41]180
[454]181    void print(std::ostream& os, const Map_& map) const;
182
[129]183    svn_revnum_t revision_; // Should be the latest revision for whole project
184    svn_revnum_t last_changed_rev_; // Should be the latest revision for file
[80]185
[118]186    std::set<std::string> authors_;
187    Map_ code_;
188    Map_ comments_;
[202]189    Map_ empty_;
[118]190    Map_ total_;
[14]191  };
[149]192}} // end of namespace svndigest end of namespace theplu
[14]193
[71]194#endif
Note: See TracBrowser for help on using the repository browser.