source: trunk/lib/Stats.h @ 399

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

fixes #200. shading is done linearly on x-axis in plot, which mean on time default and on revs when --revisions are used

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