source: trunk/lib/Stats.h @ 482

Last change on this file since 482 was 482, checked in by Peter Johansson, 16 years ago

fixes #79 and #5. Only updating changed files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.0 KB
Line 
1#ifndef _theplu_svndigest_stats_
2#define _theplu_svndigest_stats_
3
4// $Id: Stats.h 482 2007-10-13 01:40:38Z 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 <istream>
35#include <set>
36#include <string>
37#include <vector>
38
39namespace theplu{
40namespace svndigest{
41
42  ///
43  /// Class taking care of statistics from svn.
44  ///
45  class Stats
46  {
47  public:
48    ///
49    /// @brief Default Constructor
50    ///
51    explicit Stats(const std::string& path);
52
53    ///
54    /// @return set of authors
55    ///
56    inline const std::set<std::string>& authors(void) const { return authors_; }
57
58    ///
59    ///
60    ///
61    inline u_int code(void) const { return accumulated(code_).back(); }
62
63    ///
64    ///
65    ///
66    inline u_int code(const std::string& user) const 
67    { return accumulated(code_, user).back(); }
68
69    ///
70    ///
71    ///
72    inline u_int comments(void) const { return accumulated(comments_).back(); }
73
74    ///
75    ///
76    ///
77    inline u_int comments(const std::string& user) const 
78    { return accumulated(comments_, user).back(); }
79
80    ///
81    ///
82    ///
83    inline u_int empty(void) const { return accumulated(empty_).back(); }
84
85    ///
86    ///
87    ///
88    inline u_int empty(const std::string& user) const 
89    { return accumulated(empty_, user).back(); }
90
91    ///
92    ///
93    ///
94    inline u_int last_changed_rev(void) const { return last_changed_rev_; }
95
96    ///
97    ///
98    ///
99    inline u_int lines(void) const { return accumulated(total_).back(); }
100
101    ///
102    ///
103    ///
104    inline u_int lines(const std::string& user) const 
105    { return accumulated(total_, user).back(); }
106
107    /**
108       Load object from a stream.
109       
110       \return true if successful
111     */
112    bool load_cache(std::istream&);
113
114    void parse(const std::string&);
115
116    ///
117    /// Create statistics graph.
118    ///
119    std::string plot(const std::string&, const std::string&) const;
120
121    ///
122    /// Create statistics graph.
123    ///
124    void plot_init(const std::string& output) const;
125
126    ///
127    /// Summary plot for the first page
128    ///
129    void plot_summary(const std::string& output) const;
130
131    /**
132     */
133    void print(std::ostream&) const;
134
135    ///
136    /// @brief Clear all statistics
137    ///
138    inline void reset(void) 
139    { 
140      code_.clear(); comments_.clear(); empty_.clear(); total_.clear(); 
141      authors_.clear();
142    }
143
144    ///
145    /// \return latest revision for whole project
146    ///
147    inline u_int revision(void) const { return revision_; }
148
149    ///
150    ///
151    ///
152    inline std::vector<u_int> total(const std::string& user) const 
153    { return accumulated(total_, user); }
154
155    ///
156    /// @return resulting Stats
157    ///
158    Stats& operator+=(const Stats&);
159
160  private:
161    // Peter, if the vector is sparse make it a map
162    typedef std::map<std::string, std::vector<u_int> > Map_;
163    typedef Map_::iterator MapIter_;
164    typedef Map_::const_iterator MapConstIter_;
165
166    ///
167    /// Copy constructor (not implemented)
168    ///
169    Stats(const Stats& other);
170
171    ///
172    /// @return accumulated vector of total
173    ///
174    std::vector<u_int> accumulated(const Map_&) const;
175
176    ///
177    /// @return accumulated vector of stats_[user]
178    ///
179    std::vector<u_int> accumulated(const Map_&, 
180                                   const std::string& user) const;
181
182    ///
183    /// @brief adding a line to user from revision to the stats
184    ///
185    void add(const std::string& user, const u_int& revision,
186             const Parser::line_type&); 
187
188    // Change this string if cache format is changed in such a way
189    // that all old cache files are obsolete.
190    inline std::string end_of_cache(void) const {return "END OF OK CACHE FILE";} 
191    inline std::string code_cache(void) const {return "CACHE CODE";} 
192    inline std::string comments_cache(void) const {return "CACHE COMMENTS";} 
193    inline std::string empty_cache(void) const {return "CACHE EMPTY";} 
194    inline std::string total_cache(void) const {return "CACHE TOTAL";} 
195   
196
197    /**
198       Load map from stream
199     */
200    void load(std::istream&, Map_&);
201
202    void print(std::ostream& os, const Map_& map) const;
203
204    svn_revnum_t revision_; // Should be the latest revision for whole project
205    svn_revnum_t last_changed_rev_; // Should be the latest revision for file
206
207    std::set<std::string> authors_;
208    Map_ code_;
209    Map_ comments_;
210    Map_ empty_;
211    Map_ total_;
212  };
213}} // end of namespace svndigest end of namespace theplu
214
215#endif
Note: See TracBrowser for help on using the repository browser.