source: trunk/lib/Stats.h @ 530

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

For large projects, i.e. many files and many contributors, the statistics is typically not changing between tow revisisions for a specific file and author. Therefore, we are caching the 'differentiated' stats instead. This will be sparse (contain mostly zeros) so we can use a sparse notation and typically save disc space i.e. read/write time.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1#ifndef _theplu_svndigest_stats_
2#define _theplu_svndigest_stats_
3
4// $Id: Stats.h 530 2007-12-25 13:59:58Z 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/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       \brief Destructor
55    */
56    virtual ~Stats(void);
57
58    ///
59    /// @return set of authors
60    ///
61    const std::set<std::string>& authors(void) const;
62
63    ///
64    ///
65    ///
66    u_int code(const std::string& user="all") const; 
67
68
69    ///
70    ///
71    ///
72    u_int comments(const std::string& user="all") const; 
73
74    ///
75    ///
76    ///
77    u_int empty(const std::string& user="all") const; 
78
79    ///
80    ///
81    ///
82    svn_revnum_t last_changed_rev(void) const;
83
84    ///
85    ///
86    ///
87    u_int lines(const std::string& user="all") const; 
88
89    /**
90       Load object from a stream.
91       
92       \return true if successful
93     */
94    bool load_cache(std::istream&);
95
96    /**
97       Do the parsing
98    */
99    void parse(const std::string&);
100
101    ///
102    /// Create statistics graph.
103    ///
104    std::string plot(const std::string&, const std::string&) const;
105
106    ///
107    /// Plotting code, comment, other, and total in same plot (for
108    /// 'all' not individual authors).
109    ///
110    void plot_summary(const std::string& output) const;
111
112    /**
113       Send Stats to a stream.
114     */
115    void print(std::ostream&) const;
116
117    ///
118    /// @brief Clear all statistics
119    ///
120    void reset(void); 
121
122    ///
123    /// \return latest revision for whole project
124    ///
125    svn_revnum_t revision(void) const { return revision_; }
126
127    /**
128       \return resulting Stats
129    */
130    Stats& operator+=(const Stats&);
131
132
133
134  protected:
135    typedef std::map<std::string, std::vector<u_int> > Author2Vector;
136    typedef Author2Vector::iterator A2VIter;
137    typedef Author2Vector::const_iterator A2VConstIter;
138
139    void add_author(std::string);
140    void add_authors(std::set<std::string>::const_iterator, 
141                     std::set<std::string>::const_iterator);
142
143    /**
144       add range [\a first, \a last) to \a map
145     */
146    void map_add(Author2Vector::const_iterator first, 
147                 Author2Vector::const_iterator last,
148                 Author2Vector& map);
149
150    ///
151    /// Init statistics graph.
152    ///
153    void plot_init(const std::string& output) const;
154
155    Author2Vector total_;
156    Author2Vector code_;
157    Author2Vector comments_;
158    Author2Vector other_;
159    std::set<std::string> authors_;
160
161    const std::vector<u_int>& get_vector(const Author2Vector&, 
162                                         std::string user) const;
163  private:
164    void accumulate(std::vector<u_int>& vec) const;
165    void accumulate_stats(void);
166    virtual void do_parse(const std::string&)=0;
167   
168    // Change this string if cache format is changed in such a way
169    // that all old cache files are obsolete.
170    inline std::string end_of_cache(void) const 
171    {return "END OF OK CACHE FILE VERSION 3";} 
172    inline std::string code_cache(void) const {return "CACHE CODE";} 
173    inline std::string comments_cache(void) const {return "CACHE COMMENTS";} 
174    inline std::string other_cache(void) const {return "CACHE EMPTY";} 
175    inline std::string total_cache(void) const {return "CACHE TOTAL";} 
176
177   
178
179    u_int get_back(const Author2Vector&, std::string user) const;
180    void load(std::istream& is, Author2Vector& m);
181    void print(std::ostream& os, const Author2Vector& m) const;
182
183    svn_revnum_t revision_; // Should be the latest revision for whole project
184    svn_revnum_t last_changed_rev_; // Should be the latest revision for file
185
186
187    // using compiler generated copy constructor
188    //Stats(const Stats&);
189    // no assignment
190    Stats& operator=(const Stats&);
191
192  };
193}} // end of namespace svndigest end of namespace theplu
194
195#endif
Note: See TracBrowser for help on using the repository browser.