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
Line 
1#ifndef _theplu_svndigest_stats_
2#define _theplu_svndigest_stats_
3
4// $Id: Stats.h 454 2007-08-18 00:01:45Z 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     */
125    void print(std::ostream&) const;
126
127    ///
128    /// @brief Clear all statistics
129    ///
130    inline void reset(void) 
131    { 
132      code_.clear(); comments_.clear(); empty_.clear(); total_.clear(); 
133      authors_.clear();
134    }
135
136    ///
137    /// \return latest revision for whole project
138    ///
139    inline u_int revision(void) const { return revision_; }
140
141    ///
142    ///
143    ///
144    inline std::vector<u_int> total(const std::string& user) const 
145    { return accumulated(total_, user); }
146
147    ///
148    /// @return resulting Stats
149    ///
150    Stats& operator+=(const Stats&);
151
152  private:
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
158    ///
159    /// Copy constructor (not implemented)
160    ///
161    Stats(const Stats& other);
162
163    ///
164    /// @return accumulated vector of total
165    ///
166    std::vector<u_int> accumulated(const Map_&) const;
167
168    ///
169    /// @return accumulated vector of stats_[user]
170    ///
171    std::vector<u_int> accumulated(const Map_&, 
172                                   const std::string& user) const;
173
174    ///
175    /// @brief adding a line to user from revision to the stats
176    ///
177    void add(const std::string& user, const u_int& revision,
178             const Parser::line_type&); 
179
180
181    void print(std::ostream& os, const Map_& map) const;
182
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
185
186    std::set<std::string> authors_;
187    Map_ code_;
188    Map_ comments_;
189    Map_ empty_;
190    Map_ total_;
191  };
192}} // end of namespace svndigest end of namespace theplu
193
194#endif
Note: See TracBrowser for help on using the repository browser.