1 | #ifndef _theplu_svndigest_classic_stats_ |
---|
2 | #define _theplu_svndigest_classic_stats_ |
---|
3 | |
---|
4 | // $Id: ClassicStats.h 487 2007-10-13 22:20:17Z 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 "Stats.h" |
---|
30 | |
---|
31 | namespace theplu{ |
---|
32 | namespace svndigest{ |
---|
33 | |
---|
34 | /// |
---|
35 | /// Class taking care of statistics from svn. |
---|
36 | /// |
---|
37 | class ClassicStats : public Stats |
---|
38 | { |
---|
39 | public: |
---|
40 | /// |
---|
41 | /// @brief Default Constructor |
---|
42 | /// |
---|
43 | explicit ClassicStats(const std::string& path); |
---|
44 | |
---|
45 | /// |
---|
46 | /// |
---|
47 | /// |
---|
48 | inline u_int code(void) const { return accumulated(code_).back(); } |
---|
49 | |
---|
50 | /// |
---|
51 | /// |
---|
52 | /// |
---|
53 | inline u_int code(const std::string& user) const |
---|
54 | { return accumulated(code_, user).back(); } |
---|
55 | |
---|
56 | /// |
---|
57 | /// |
---|
58 | /// |
---|
59 | inline u_int comments(void) const { return accumulated(comments_).back(); } |
---|
60 | |
---|
61 | /// |
---|
62 | /// |
---|
63 | /// |
---|
64 | inline u_int comments(const std::string& user) const |
---|
65 | { return accumulated(comments_, user).back(); } |
---|
66 | |
---|
67 | /// |
---|
68 | /// |
---|
69 | /// |
---|
70 | inline u_int empty(void) const { return accumulated(empty_).back(); } |
---|
71 | |
---|
72 | /// |
---|
73 | /// |
---|
74 | /// |
---|
75 | inline u_int empty(const std::string& user) const |
---|
76 | { return accumulated(empty_, user).back(); } |
---|
77 | |
---|
78 | /// |
---|
79 | /// |
---|
80 | /// |
---|
81 | inline u_int lines(void) const { return accumulated(total_).back(); } |
---|
82 | |
---|
83 | /// |
---|
84 | /// |
---|
85 | /// |
---|
86 | inline u_int lines(const std::string& user) const |
---|
87 | { return accumulated(total_, user).back(); } |
---|
88 | |
---|
89 | /// |
---|
90 | /// Summary plot for the first page |
---|
91 | /// |
---|
92 | void plot_summary(const std::string& output) const; |
---|
93 | |
---|
94 | /// |
---|
95 | /// |
---|
96 | /// |
---|
97 | inline std::vector<u_int> total(const std::string& user) const |
---|
98 | { return accumulated(total_, user); } |
---|
99 | |
---|
100 | /// |
---|
101 | /// @return resulting Stats |
---|
102 | /// |
---|
103 | ClassicStats& operator+=(const ClassicStats&); |
---|
104 | |
---|
105 | private: |
---|
106 | // Peter, if the vector is sparse make it a map |
---|
107 | typedef std::map<std::string, std::vector<u_int> > Map_; |
---|
108 | typedef Map_::iterator MapIter_; |
---|
109 | typedef Map_::const_iterator MapConstIter_; |
---|
110 | |
---|
111 | /// using compiler generated copy |
---|
112 | //ClassicStats(const ClassicStats& other); |
---|
113 | |
---|
114 | /// |
---|
115 | /// @return accumulated vector of total |
---|
116 | /// |
---|
117 | std::vector<u_int> accumulated(const Map_&) const; |
---|
118 | |
---|
119 | /// |
---|
120 | /// @return accumulated vector of stats_[user] |
---|
121 | /// |
---|
122 | std::vector<u_int> accumulated(const Map_&, |
---|
123 | const std::string& user) const; |
---|
124 | |
---|
125 | /// |
---|
126 | /// @brief adding a line to user from revision to the stats |
---|
127 | /// |
---|
128 | void add(const std::string& user, const u_int& revision, |
---|
129 | const Parser::line_type&); |
---|
130 | |
---|
131 | /** |
---|
132 | Load object from a stream. |
---|
133 | |
---|
134 | \return true if successful |
---|
135 | */ |
---|
136 | bool do_load_cache(std::istream&); |
---|
137 | |
---|
138 | void do_parse(const std::string&); |
---|
139 | |
---|
140 | /// |
---|
141 | /// Create statistics graph. |
---|
142 | /// |
---|
143 | std::string do_plot(const std::string&, const std::string&) const; |
---|
144 | |
---|
145 | /** |
---|
146 | */ |
---|
147 | void do_print(std::ostream&) const; |
---|
148 | |
---|
149 | /// |
---|
150 | /// @brief Clear all statistics |
---|
151 | /// |
---|
152 | inline void do_reset(void) |
---|
153 | { |
---|
154 | code_.clear(); comments_.clear(); empty_.clear(); total_.clear(); |
---|
155 | } |
---|
156 | |
---|
157 | // Change this string if cache format is changed in such a way |
---|
158 | // that all old cache files are obsolete. |
---|
159 | inline std::string end_of_cache(void) const |
---|
160 | {return "END OF OK CACHE FILE VERSION 2";} |
---|
161 | |
---|
162 | |
---|
163 | std::vector<u_int> vector(std::string type, std::string user) const; |
---|
164 | /** |
---|
165 | Load map from stream |
---|
166 | */ |
---|
167 | void load(std::istream&, Map_&); |
---|
168 | |
---|
169 | void do_print(std::ostream& os, const Map_& map) const; |
---|
170 | |
---|
171 | Map_ code_; |
---|
172 | Map_ comments_; |
---|
173 | Map_ empty_; |
---|
174 | Map_ total_; |
---|
175 | }; |
---|
176 | }} // end of namespace svndigest end of namespace theplu |
---|
177 | |
---|
178 | #endif |
---|