source: trunk/lib/Stats.h @ 244

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

removed gnuplot titles fixes #165

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.0 KB
Line 
1#ifndef _theplu_svndigest_stats_
2#define _theplu_svndigest_stats_
3
4// $Id: Stats.h 244 2007-04-28 14:45:20Z 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    void parse(const std::string&);
95
96    ///
97    /// Create statistics graph.
98    ///
99    std::string plot(const std::string&, const std::string&) const;
100
101    ///
102    /// @brief Clear all statistics
103    ///
104    inline void reset(void) 
105    { 
106      code_.clear(); comments_.clear(); empty_.clear(); total_.clear(); 
107      authors_.clear();}
108
109    ///
110    ///
111    ///
112    inline u_int revision(void) const { return revision_; }
113
114    ///
115    ///
116    ///
117    inline u_int lines(void) const { return accumulated(total_).back(); }
118
119    ///
120    ///
121    ///
122    inline u_int lines(const std::string& user) const 
123    { return accumulated(total_, user).back(); }
124
125    ///
126    ///
127    ///
128    inline std::vector<u_int> total(const std::string& user) const 
129    { return accumulated(total_, user); }
130
131    ///
132    /// @return resulting Stats
133    ///
134    Stats& operator+=(const Stats&);
135
136  private:
137    // Peter, if the vector is sparse make it a map
138    typedef std::map<std::string, std::vector<u_int> > Map_;
139    typedef Map_::iterator MapIter_;
140    typedef Map_::const_iterator MapConstIter_;
141
142    ///
143    /// Copy constructor (not implemented)
144    ///
145    Stats(const Stats& other);
146
147    ///
148    /// @return accumulated vector of total
149    ///
150    std::vector<u_int> accumulated(const Map_&) const;
151
152    ///
153    /// @return accumulated vector of stats_[user]
154    ///
155    std::vector<u_int> accumulated(const Map_&, 
156                                   const std::string& user) const;
157
158    ///
159    /// @brief adding a line to user from revision to the stats
160    ///
161    void add(const std::string& user, const u_int& revision,
162             const Parser::line_type&); 
163
164
165    svn_revnum_t revision_; // Should be the latest revision for whole project
166    svn_revnum_t last_changed_rev_; // Should be the latest revision for file
167
168    std::set<std::string> authors_;
169    Map_ code_;
170    Map_ comments_;
171    Map_ empty_;
172    Map_ total_;
173  };
174}} // end of namespace svndigest end of namespace theplu
175
176#endif
Note: See TracBrowser for help on using the repository browser.