source: trunk/lib/ClassicStats.cc @ 529

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

moving stuff to base class, Stats

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1// $Id: ClassicStats.cc 529 2007-12-25 13:10:25Z peter $
2
3/*
4  Copyright (C) 2005 Peter Johansson
5  Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson
6
7  This file is part of svndigest, http://trac.thep.lu.se/svndigest
8
9  svndigest is free software; you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13
14  svndigest is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22  02111-1307, USA.
23*/
24
25#include "ClassicStats.h"
26
27#include "Functor.h"
28#include "GnuplotFE.h"
29#include "SVNblame.h"
30#include "SVNinfo.h"
31#include "utility.h"
32
33#include <algorithm>
34#include <cassert>
35#include <cstdlib>
36#include <fstream>
37#include <iostream>
38#include <iterator>
39#include <map>
40#include <numeric>
41#include <string>
42#include <sstream>
43#include <unistd.h>
44#include <utility>
45#include <vector>
46
47
48namespace theplu{
49namespace svndigest{
50
51
52  ClassicStats::ClassicStats(const std::string& path)
53    : Stats(path)
54  {
55  }
56
57
58  ClassicStats::ClassicStats(const ClassicStats& other)
59  : Stats(other)
60  {
61  }
62
63
64  void ClassicStats::add(const std::string& user, const u_int& rev, 
65                         const Parser::line_type& lt)
66  {
67    assert(user.size());
68    add_author(user);
69
70    std::vector<u_int>* total = &(total_[user]);
71    assert(total);
72    if (total->size() < rev+1){
73      total->reserve(revision() + 1);
74      total->insert(total->end(), rev - total->size(), 0);
75      total->push_back(1);
76    }
77    else
78      ++(*total)[rev];
79
80    std::vector<u_int>* code = &(code_[user]);
81    assert(code);
82    if (code->size() < rev+1){
83      code->reserve(revision() + 1);
84      code->insert(code->end(), rev - code->size(), 0);
85      if (lt == Parser::code)
86        code->push_back(1);
87      else 
88        code->push_back(0);
89    }
90    else if (lt == Parser::code)
91      ++(*code)[rev];
92
93    std::vector<u_int>* comments = &(comments_[user]);
94    assert(comments);
95    if (comments->size() < rev+1){
96      comments->reserve(revision() + 1);
97      comments->insert(comments->end(), rev - comments->size(), 0);
98      if (lt == Parser::comment)
99        comments->push_back(1);
100      else 
101        comments->push_back(0);
102    }
103    else if (lt == Parser::comment)
104      ++(*comments)[rev];
105
106    std::vector<u_int>* other = &(other_[user]);
107    assert(other);
108    if (other->size() < rev+1){
109      other->reserve(revision() + 1);
110      other->insert(other->end(), rev - other->size(), 0);
111      if (lt == Parser::other)
112        other->push_back(1);
113      else 
114        other->push_back(0);
115    }
116    else if (lt == Parser::other)
117      ++(*other)[rev];
118  }
119
120
121  void ClassicStats::do_parse(const std::string& path)
122  {
123    Parser parser(path);
124    std::vector<Parser::line_type>::const_iterator count=parser.type().begin();
125
126    SVNblame svn_blame(path);
127    while (svn_blame.valid()) {
128      add(svn_blame.author(), svn_blame.revision(), *count);
129      svn_blame.next_line();
130      ++count;
131    }
132  }
133
134
135}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.