165 |
24 Aug 06 |
jari |
1 |
#ifndef _theplu_svndigest_stats_ |
165 |
24 Aug 06 |
jari |
2 |
#define _theplu_svndigest_stats_ |
165 |
24 Aug 06 |
jari |
3 |
|
84 |
13 Mar 06 |
jari |
// $Id$ |
14 |
30 Dec 05 |
peter |
5 |
|
84 |
13 Mar 06 |
jari |
6 |
/* |
84 |
13 Mar 06 |
jari |
Copyright (C) 2005 Peter Johansson |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2006 Jari Häkkinen, Peter Johansson |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2007 Peter Johansson |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2010, 2012, 2023 Peter Johansson |
84 |
13 Mar 06 |
jari |
12 |
|
687 |
04 Aug 08 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
84 |
13 Mar 06 |
jari |
14 |
|
149 |
12 Aug 06 |
jari |
svndigest is free software; you can redistribute it and/or modify it |
84 |
13 Mar 06 |
jari |
under the terms of the GNU General Public License as published by |
693 |
11 Sep 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
84 |
13 Mar 06 |
jari |
(at your option) any later version. |
84 |
13 Mar 06 |
jari |
19 |
|
149 |
12 Aug 06 |
jari |
svndigest is distributed in the hope that it will be useful, but |
84 |
13 Mar 06 |
jari |
WITHOUT ANY WARRANTY; without even the implied warranty of |
149 |
12 Aug 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
84 |
13 Mar 06 |
jari |
General Public License for more details. |
84 |
13 Mar 06 |
jari |
24 |
|
84 |
13 Mar 06 |
jari |
You should have received a copy of the GNU General Public License |
693 |
11 Sep 08 |
jari |
along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
84 |
13 Mar 06 |
jari |
27 |
*/ |
84 |
13 Mar 06 |
jari |
28 |
|
552 |
08 Jan 08 |
peter |
29 |
#include "LineTypeParser.h" |
1194 |
03 Oct 10 |
peter |
30 |
#include "Vector.h" |
118 |
03 Jul 06 |
peter |
31 |
|
164 |
23 Aug 06 |
jari |
32 |
#include <subversion-1/svn_types.h> |
129 |
02 Aug 06 |
jari |
33 |
|
14 |
30 Dec 05 |
peter |
34 |
#include <map> |
482 |
13 Oct 07 |
peter |
35 |
#include <istream> |
118 |
03 Jul 06 |
peter |
36 |
#include <set> |
34 |
12 Jan 06 |
jari |
37 |
#include <string> |
14 |
30 Dec 05 |
peter |
38 |
#include <vector> |
14 |
30 Dec 05 |
peter |
39 |
|
14 |
30 Dec 05 |
peter |
40 |
namespace theplu{ |
149 |
12 Aug 06 |
jari |
41 |
namespace svndigest{ |
14 |
30 Dec 05 |
peter |
42 |
|
14 |
30 Dec 05 |
peter |
43 |
/// |
14 |
30 Dec 05 |
peter |
/// Class taking care of statistics from svn. |
14 |
30 Dec 05 |
peter |
45 |
/// |
14 |
30 Dec 05 |
peter |
46 |
class Stats |
14 |
30 Dec 05 |
peter |
47 |
{ |
14 |
30 Dec 05 |
peter |
48 |
public: |
1478 |
29 May 12 |
peter |
49 |
/// |
1478 |
29 May 12 |
peter |
/// @brief Default Constructor |
34 |
12 Jan 06 |
jari |
51 |
/// |
80 |
10 Mar 06 |
jari |
52 |
explicit Stats(const std::string& path); |
34 |
12 Jan 06 |
jari |
53 |
|
487 |
13 Oct 07 |
peter |
54 |
/** |
487 |
13 Oct 07 |
peter |
\brief Destructor |
487 |
13 Oct 07 |
peter |
56 |
*/ |
487 |
13 Oct 07 |
peter |
57 |
virtual ~Stats(void); |
487 |
13 Oct 07 |
peter |
58 |
|
60 |
16 Jan 06 |
peter |
59 |
/// |
118 |
03 Jul 06 |
peter |
/// @return set of authors |
112 |
29 Jun 06 |
peter |
61 |
/// |
487 |
13 Oct 07 |
peter |
62 |
const std::set<std::string>& authors(void) const; |
118 |
03 Jul 06 |
peter |
63 |
|
112 |
29 Jun 06 |
peter |
64 |
/// |
1478 |
29 May 12 |
peter |
/// \return number of code lines for \a user for latest revision. |
118 |
03 Jul 06 |
peter |
66 |
/// |
1478 |
29 May 12 |
peter |
67 |
unsigned int code(const std::string& user="all") const; |
118 |
03 Jul 06 |
peter |
68 |
|
118 |
03 Jul 06 |
peter |
69 |
|
118 |
03 Jul 06 |
peter |
70 |
/// |
1478 |
29 May 12 |
peter |
/// \return number of comments lines for \a user for latest revision. |
118 |
03 Jul 06 |
peter |
72 |
/// |
1478 |
29 May 12 |
peter |
73 |
unsigned int comments(const std::string& user="all") const; |
118 |
03 Jul 06 |
peter |
74 |
|
118 |
03 Jul 06 |
peter |
75 |
/// |
1478 |
29 May 12 |
peter |
/// \return number of empty lines for \a user for latest revision. |
118 |
03 Jul 06 |
peter |
77 |
/// |
1478 |
29 May 12 |
peter |
78 |
unsigned int empty(const std::string& user="all") const; |
118 |
03 Jul 06 |
peter |
79 |
|
118 |
03 Jul 06 |
peter |
80 |
/// |
701 |
23 Nov 08 |
peter |
/// \return revison node was modified |
118 |
03 Jul 06 |
peter |
82 |
/// |
487 |
13 Oct 07 |
peter |
83 |
svn_revnum_t last_changed_rev(void) const; |
202 |
10 Sep 06 |
peter |
84 |
|
202 |
10 Sep 06 |
peter |
85 |
/// |
701 |
23 Nov 08 |
peter |
/// \return number of lines for \a user for latest revision |
345 |
19 May 07 |
peter |
87 |
/// |
1478 |
29 May 12 |
peter |
88 |
unsigned int lines(const std::string& user="all") const; |
345 |
19 May 07 |
peter |
89 |
|
482 |
13 Oct 07 |
peter |
90 |
/** |
482 |
13 Oct 07 |
peter |
Load object from a stream. |
1124 |
07 Jul 10 |
peter |
92 |
|
1124 |
07 Jul 10 |
peter |
\a latest_ver is set to true if cache_file is latest version; |
1124 |
07 Jul 10 |
peter |
otherwise it is set to false. |
1124 |
07 Jul 10 |
peter |
95 |
|
664 |
13 Jun 08 |
peter |
\return revision the cache represents - 0 if failed |
482 |
13 Oct 07 |
peter |
97 |
*/ |
1124 |
07 Jul 10 |
peter |
98 |
svn_revnum_t load_cache(std::istream&, bool& latest_ver); |
482 |
13 Oct 07 |
peter |
99 |
|
487 |
13 Oct 07 |
peter |
100 |
/** |
704 |
24 Nov 08 |
peter |
Do the parsing for \a path. Revisions from \a rev will be parsed. |
487 |
13 Oct 07 |
peter |
102 |
*/ |
701 |
23 Nov 08 |
peter |
103 |
void parse(const std::string& path, svn_revnum_t rev=0); |
14 |
30 Dec 05 |
peter |
104 |
|
454 |
18 Aug 07 |
peter |
105 |
/** |
487 |
13 Oct 07 |
peter |
Send Stats to a stream. |
454 |
18 Aug 07 |
peter |
107 |
*/ |
454 |
18 Aug 07 |
peter |
108 |
void print(std::ostream&) const; |
454 |
18 Aug 07 |
peter |
109 |
|
345 |
19 May 07 |
peter |
110 |
/// |
23 |
02 Jan 06 |
peter |
/// @brief Clear all statistics |
23 |
02 Jan 06 |
peter |
112 |
/// |
1478 |
29 May 12 |
peter |
113 |
void reset(void); |
14 |
30 Dec 05 |
peter |
114 |
|
1194 |
03 Oct 10 |
peter |
115 |
/** |
1194 |
03 Oct 10 |
peter |
set vectors in stats_ to size \a rev |
1194 |
03 Oct 10 |
peter |
117 |
*/ |
1194 |
03 Oct 10 |
peter |
118 |
void resize(svn_revnum_t rev); |
1194 |
03 Oct 10 |
peter |
119 |
|
74 |
07 Mar 06 |
jari |
120 |
/// |
399 |
27 Jun 07 |
peter |
/// \return latest revision for whole project |
74 |
07 Mar 06 |
jari |
122 |
/// |
1194 |
03 Oct 10 |
peter |
123 |
svn_revnum_t revision(void) const; |
112 |
29 Jun 06 |
peter |
124 |
|
528 |
25 Dec 07 |
peter |
125 |
/** |
1478 |
29 May 12 |
peter |
\brief set (greatest) revision to be ignored |
1478 |
29 May 12 |
peter |
127 |
*/ |
1478 |
29 May 12 |
peter |
128 |
void ignore_rev(svn_revnum_t rev); |
1478 |
29 May 12 |
peter |
129 |
|
1478 |
29 May 12 |
peter |
130 |
/** |
528 |
25 Dec 07 |
peter |
\return resulting Stats |
528 |
25 Dec 07 |
peter |
132 |
*/ |
528 |
25 Dec 07 |
peter |
133 |
Stats& operator+=(const Stats&); |
528 |
25 Dec 07 |
peter |
134 |
|
552 |
08 Jan 08 |
peter |
135 |
/** |
552 |
08 Jan 08 |
peter |
\return number of lines for \a author and \a linetype from |
552 |
08 Jan 08 |
peter |
revision \a rev. |
528 |
25 Dec 07 |
peter |
138 |
|
552 |
08 Jan 08 |
peter |
\throw if \a author does not exist |
552 |
08 Jan 08 |
peter |
140 |
*/ |
642 |
31 May 08 |
peter |
141 |
size_t operator()(int linetype, std::string author, svn_revnum_t rev) const; |
528 |
25 Dec 07 |
peter |
142 |
|
487 |
13 Oct 07 |
peter |
143 |
protected: |
1194 |
03 Oct 10 |
peter |
144 |
typedef std::map<std::string, SumVector> Author2Vector; |
528 |
25 Dec 07 |
peter |
145 |
typedef Author2Vector::iterator A2VIter; |
528 |
25 Dec 07 |
peter |
146 |
typedef Author2Vector::const_iterator A2VConstIter; |
487 |
13 Oct 07 |
peter |
147 |
|
1194 |
03 Oct 10 |
peter |
148 |
std::vector<Author2Vector> stats_; // from linetype to a2v |
1194 |
03 Oct 10 |
peter |
149 |
|
703 |
24 Nov 08 |
peter |
150 |
/** |
1194 |
03 Oct 10 |
peter |
151 |
*/ |
1194 |
03 Oct 10 |
peter |
152 |
void add(const std::vector<std::map<std::string, SparseVector> >& data); |
1194 |
03 Oct 10 |
peter |
153 |
|
487 |
13 Oct 07 |
peter |
154 |
void add_author(std::string); |
1478 |
29 May 12 |
peter |
155 |
void add_authors(std::set<std::string>::const_iterator, |
487 |
13 Oct 07 |
peter |
156 |
std::set<std::string>::const_iterator); |
487 |
13 Oct 07 |
peter |
157 |
|
552 |
08 Jan 08 |
peter |
// references to data |
1478 |
29 May 12 |
peter |
159 |
inline Author2Vector& code_stats(void) |
552 |
08 Jan 08 |
peter |
160 |
{ return stats_[LineTypeParser::code]; } |
1478 |
29 May 12 |
peter |
161 |
inline Author2Vector& other_stats(void) |
552 |
08 Jan 08 |
peter |
162 |
{ return stats_[LineTypeParser::other]; } |
1478 |
29 May 12 |
peter |
163 |
inline Author2Vector& comment_or_copy_stats(void) |
552 |
08 Jan 08 |
peter |
164 |
{ return stats_[LineTypeParser::comment_or_copy]; } |
1478 |
29 May 12 |
peter |
165 |
inline Author2Vector& total_stats(void) |
552 |
08 Jan 08 |
peter |
166 |
{ return stats_[LineTypeParser::total]; } |
552 |
08 Jan 08 |
peter |
167 |
|
552 |
08 Jan 08 |
peter |
// const references to data |
552 |
08 Jan 08 |
peter |
169 |
inline const Author2Vector& code_stats(void) const |
552 |
08 Jan 08 |
peter |
170 |
{ return stats_[LineTypeParser::code]; } |
552 |
08 Jan 08 |
peter |
171 |
inline const Author2Vector& other_stats(void) const |
552 |
08 Jan 08 |
peter |
172 |
{ return stats_[LineTypeParser::other]; } |
552 |
08 Jan 08 |
peter |
173 |
inline const Author2Vector& comment_or_copy_stats(void) const |
552 |
08 Jan 08 |
peter |
174 |
{ return stats_[LineTypeParser::comment_or_copy]; } |
552 |
08 Jan 08 |
peter |
175 |
inline const Author2Vector& total_stats(void) const |
552 |
08 Jan 08 |
peter |
176 |
{ return stats_[LineTypeParser::total]; } |
552 |
08 Jan 08 |
peter |
177 |
|
468 |
30 Aug 07 |
peter |
178 |
/** |
1478 |
29 May 12 |
peter |
const access to ignore_rev_ |
1478 |
29 May 12 |
peter |
180 |
*/ |
1478 |
29 May 12 |
peter |
181 |
const svn_revnum_t& ignore_rev(void) const; |
1478 |
29 May 12 |
peter |
182 |
|
1478 |
29 May 12 |
peter |
183 |
/** |
487 |
13 Oct 07 |
peter |
add range [\a first, \a last) to \a map |
487 |
13 Oct 07 |
peter |
185 |
*/ |
1478 |
29 May 12 |
peter |
186 |
void map_add(Author2Vector::const_iterator first, |
528 |
25 Dec 07 |
peter |
187 |
Author2Vector::const_iterator last, |
528 |
25 Dec 07 |
peter |
188 |
Author2Vector& map); |
454 |
18 Aug 07 |
peter |
189 |
|
528 |
25 Dec 07 |
peter |
190 |
std::set<std::string> authors_; |
528 |
25 Dec 07 |
peter |
191 |
|
1478 |
29 May 12 |
peter |
192 |
const SumVector& get_vector(const Author2Vector&, |
1194 |
03 Oct 10 |
peter |
193 |
const std::string& user) const; |
487 |
13 Oct 07 |
peter |
194 |
private: |
1122 |
07 Jul 10 |
peter |
/// one liner used in cache file to validate that cache file was |
1122 |
07 Jul 10 |
peter |
/// created current configuration |
1122 |
07 Jul 10 |
peter |
197 |
std::string config_code_; |
1122 |
07 Jul 10 |
peter |
198 |
|
1194 |
03 Oct 10 |
peter |
199 |
void add(SumVector& vec, svn_revnum_t rev, unsigned int n); |
611 |
20 Apr 08 |
peter |
200 |
|
703 |
24 Nov 08 |
peter |
201 |
/** |
1478 |
29 May 12 |
peter |
\return config_code unless ignore_rev_!=0 in which case |
1478 |
29 May 12 |
peter |
ignore_rev_ is appended to returned string |
1478 |
29 May 12 |
peter |
204 |
*/ |
1478 |
29 May 12 |
peter |
205 |
std::string config_code(void) const; |
1478 |
29 May 12 |
peter |
206 |
|
1478 |
29 May 12 |
peter |
207 |
/** |
703 |
24 Nov 08 |
peter |
Parse statistics for fundamental categories, i.e., code, |
703 |
24 Nov 08 |
peter |
comment, empty, and copyright for each author. Ignore revisions |
703 |
24 Nov 08 |
peter |
earlier than \a first_rev. |
703 |
24 Nov 08 |
peter |
211 |
*/ |
703 |
24 Nov 08 |
peter |
212 |
virtual void do_parse(const std::string&, svn_revnum_t first_rev)=0; |
1478 |
29 May 12 |
peter |
213 |
|
1122 |
07 Jul 10 |
peter |
/// load cache file version 7 |
1122 |
07 Jul 10 |
peter |
215 |
svn_revnum_t load_cache7(std::istream&); |
1122 |
07 Jul 10 |
peter |
/// load cache file version 8 |
1122 |
07 Jul 10 |
peter |
217 |
svn_revnum_t load_cache8(std::istream&); |
1611 |
12 Feb 23 |
peter |
/// load cache file version 9 |
1611 |
12 Feb 23 |
peter |
219 |
svn_revnum_t load_cache9(std::istream&); |
1122 |
07 Jul 10 |
peter |
220 |
|
529 |
25 Dec 07 |
peter |
// Change this string if cache format is changed in such a way |
529 |
25 Dec 07 |
peter |
// that all old cache files are obsolete. |
1478 |
29 May 12 |
peter |
223 |
inline std::string cache_check_str(void) const |
1611 |
12 Feb 23 |
peter |
224 |
{return "CACHE FILE VERSION 9";} |
1611 |
12 Feb 23 |
peter |
225 |
inline std::string cache_check_str7(void) const |
1478 |
29 May 12 |
peter |
226 |
{return "CACHE FILE VERSION 7";} |
1003 |
02 Jan 10 |
peter |
227 |
|
537 |
27 Dec 07 |
peter |
228 |
void calc_all(void); |
537 |
27 Dec 07 |
peter |
229 |
void calc_total(void); |
589 |
12 Apr 08 |
jari |
230 |
unsigned int get_back(const Author2Vector&, std::string user) const; |
529 |
25 Dec 07 |
peter |
231 |
void load(std::istream& is, Author2Vector& m); |
1003 |
02 Jan 10 |
peter |
232 |
/** |
1003 |
02 Jan 10 |
peter |
Finds the largets element by iterating through the entire |
1003 |
02 Jan 10 |
peter |
vector. Inherited classes should implement their own version |
1003 |
02 Jan 10 |
peter |
when it is possible to get the largest element in faster than |
1003 |
02 Jan 10 |
peter |
in linear time. |
1003 |
02 Jan 10 |
peter |
237 |
|
1478 |
29 May 12 |
peter |
\return the largest largest element in \a v. |
1003 |
02 Jan 10 |
peter |
239 |
*/ |
1478 |
29 May 12 |
peter |
240 |
virtual unsigned int max_element(const SumVector& v) const; |
1003 |
02 Jan 10 |
peter |
241 |
|
529 |
25 Dec 07 |
peter |
242 |
void print(std::ostream& os, const Author2Vector& m) const; |
487 |
13 Oct 07 |
peter |
243 |
|
1478 |
29 May 12 |
peter |
244 |
svn_revnum_t ignore_rev_; |
129 |
02 Aug 06 |
jari |
245 |
svn_revnum_t revision_; // Should be the latest revision for whole project |
129 |
02 Aug 06 |
jari |
246 |
svn_revnum_t last_changed_rev_; // Should be the latest revision for file |
80 |
10 Mar 06 |
jari |
247 |
|
528 |
25 Dec 07 |
peter |
// using compiler generated copy constructor |
528 |
25 Dec 07 |
peter |
//Stats(const Stats&); |
528 |
25 Dec 07 |
peter |
// no assignment |
528 |
25 Dec 07 |
peter |
251 |
Stats& operator=(const Stats&); |
528 |
25 Dec 07 |
peter |
252 |
|
1290 |
12 Nov 10 |
peter |
253 |
friend class StatsPlotter; |
14 |
30 Dec 05 |
peter |
254 |
}; |
149 |
12 Aug 06 |
jari |
255 |
}} // end of namespace svndigest end of namespace theplu |
14 |
30 Dec 05 |
peter |
256 |
|
1478 |
29 May 12 |
peter |
257 |
#endif |