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
Line 
1#ifndef _theplu_svndigest_stats_
2#define _theplu_svndigest_stats_
3
4// $Id: Stats.h 439 2007-07-09 21:04:52Z peter $
5
6/*
7  Copyright (C) 2005 Peter Johansson
8  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
9  Copyright (C) 2007 Peter Johansson
10
11  This file is part of svndigest, http://trac.thep.lu.se/trac/svndigest
12
13  svndigest is free software; you can redistribute it and/or modify it
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
18  svndigest is distributed in the hope that it will be useful, but
19  WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
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
29#include "Parser.h"
30
31#include <subversion-1/svn_types.h>
32
33#include <map>
34#include <set>
35#include <string>
36#include <vector>
37
38namespace theplu{
39namespace svndigest{
40
41  ///
42  /// Class taking care of statistics from svn.
43  ///
44  class Stats
45  {
46  public:
47    ///
48    /// @brief Default Constructor
49    ///
50    explicit Stats(const std::string& path);
51
52    ///
53    /// @return set of authors
54    ///
55    inline const std::set<std::string>& authors(void) const { return authors_; }
56
57    ///
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    ///
80    ///
81    ///
82    inline u_int empty(void) const { return accumulated(empty_).back(); }
83
84    ///
85    ///
86    ///
87    inline u_int empty(const std::string& user) const 
88    { return accumulated(empty_, user).back(); }
89
90    ///
91    ///
92    ///
93    inline u_int last_changed_rev(void) const { return last_changed_rev_; }
94
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
106    void parse(const std::string&);
107
108    ///
109    /// Create statistics graph.
110    ///
111    std::string plot(const std::string&, const std::string&) const;
112
113    ///
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    ///
124    /// @brief Clear all statistics
125    ///
126    inline void reset(void) 
127    { 
128      code_.clear(); comments_.clear(); empty_.clear(); total_.clear(); 
129      authors_.clear();
130    }
131
132    ///
133    /// \return latest revision for whole project
134    ///
135    inline u_int revision(void) const { return revision_; }
136
137    ///
138    ///
139    ///
140    inline std::vector<u_int> total(const std::string& user) const 
141    { return accumulated(total_, user); }
142
143    ///
144    /// @return resulting Stats
145    ///
146    Stats& operator+=(const Stats&);
147
148  private:
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
154    ///
155    /// Copy constructor (not implemented)
156    ///
157    Stats(const Stats& other);
158
159    ///
160    /// @return accumulated vector of total
161    ///
162    std::vector<u_int> accumulated(const Map_&) const;
163
164    ///
165    /// @return accumulated vector of stats_[user]
166    ///
167    std::vector<u_int> accumulated(const Map_&, 
168                                   const std::string& user) const;
169
170    ///
171    /// @brief adding a line to user from revision to the stats
172    ///
173    void add(const std::string& user, const u_int& revision,
174             const Parser::line_type&); 
175
176
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
179
180    std::set<std::string> authors_;
181    Map_ code_;
182    Map_ comments_;
183    Map_ empty_;
184    Map_ total_;
185  };
186}} // end of namespace svndigest end of namespace theplu
187
188#endif
Note: See TracBrowser for help on using the repository browser.