#include <stats.h>
Public Methods | |
Stats (const Configuration &) | |
The configuration is copied locally. More... | |
void | add (const LogRecord &) |
Add whatever is needed from a logrecord to the various Count maps (see below). More... | |
void | print_dates (ostream &) const |
Auxiliary functions for operator<<. More... | |
void | print_paths (ostream &) const |
void | print_domains (ostream &) const |
Private Types | |
typedef map<vector<int>,unsigned int> | DateCount |
Date statistics. More... | |
typedef map<vector<string>, unsigned int> | PathCount |
Path statistics. More... | |
typedef map<vector<string>, unsigned int> | DomainCount |
Domain statistics. More... | |
Private Attributes | |
DateCount | dates_ |
PathCount | paths_ |
DomainCount | domains_ |
Configuration | configuration_ |
Copy of the constructor parameter. | |
Friends | |
ostream& | operator<< (ostream &,const Stats &) |
Print stats information on ostream. |
Definition at line 13 of file stats.h.
|
Date statistics. The key of a DateCount map is a Date category vector, e.g. <1999>, <1999,6>, <1999,6,3>, <1999,6,3,10> (June 3, 1999 10:00), .. The value is the number of logrecords in this category that have been added . |
|
Path statistics. The key of a PathCount map is a path category vector, e.g. <""> ("/"), <"","a","b","c"> ("/a/b/c"). The value is the number of logrecords in this category that have been added . |
|
Domain statistics. The key of a DomainCount map is a domain category vector, e.g. <"be"> (*.be), <"be","ac","vub"> (*.vub.ac.be), <"be","ac","vub","tinf2"> (tinf2.vub.ac.be). The value is the number of logrecords in this category that have been added . |
|
The configuration is copied locally. It is used to decide what aspects of an added logrecord will be stored and what information will be printed. Definition at line 6 of file stats.C. 00006 : configuration_(c) { 00007 } |
|
Add whatever is needed from a logrecord to the various Count maps (see below). The decision on which map to add to depends on configuration_. Definition at line 11 of file stats.C. Referenced by main().
00011 { 00012 // What we do depends on the requested configuration format. 00013 /* It would be more efficient to make these actual data members 00014 of Stat. That way, they would only be ``computed'' once. 00015 */ 00016 set<unsigned int> levels(configuration_.levels()); 00017 unsigned int max_level(configuration_.max_level()); 00018 00019 switch (configuration_.format()) { 00020 00021 case Configuration::DATE: { 00022 const Date& d(r.date()); 00023 // We will have at most 4 components in a date vector. 00024 // This should become a symbolic constant in Configuration! 00025 unsigned int m(min(4u,max_level)); 00026 for (unsigned int l=1;(l<=m);++l) 00027 if (levels.count(l)) { 00028 vector<int> dv(l); 00029 switch (l) { 00030 case 4: dv[3] = d.hours(); 00031 case 3: dv[2] = d.day(); 00032 case 2: dv[1] = d.month(); 00033 case 1: dv[0] = d.year(); 00034 } 00035 ++dates_[dv]; 00036 } 00037 } 00038 break; 00039 00040 case Configuration::PATH: { 00041 const vector<string>& path(r.path()); 00042 unsigned int m(min(path.size(),max_level)); 00043 for (unsigned int l=1; l<=m; ++l) 00044 if (levels.count(l)) { 00045 vector<string> pv(l); 00046 for (unsigned int j=0;(j<l);++j) 00047 pv[j] = path[j]; 00048 ++paths_[pv]; 00049 } 00050 } 00051 break; 00052 00053 case Configuration::DOMAIN: { 00054 const vector<string>& domain(r.domain()); 00055 unsigned int sz(domain.size()); 00056 unsigned int m(min(sz,max_level)); 00057 for (unsigned int l=1; l<=m; ++l) { 00058 if (levels.count(l)) { 00059 // we should store the last l components of domain: 00060 // dom[0] <- domain[sz-0-1] 00061 // dom[1] <- domain[sz-1-1] 00062 // dom[2] <- domain[sz-2-1] 00063 // etc. 00064 vector<string> dom(l); 00065 for (unsigned int j=0;(j<l);++j) 00066 dom[j] = domain[sz-j-1]; 00067 ++(domains_[dom]); 00068 } 00069 } 00070 } 00071 break; 00072 } 00073 } |
|
Auxiliary functions for operator<<. They print the contents of the corresponding Count map (see below) on os. Definition at line 77 of file stats.C. Referenced by operator<<().
00077 { 00078 for (DateCount::const_iterator i=dates_.begin(); i!=dates_.end(); ++i) { 00079 const vector<int>& dv((*i).first); 00080 unsigned int sz(dv.size()); 00081 // Print in format year-month-day hours:00. 00082 if (sz>0) { 00083 os << dv[0] ; 00084 if (sz>1) { 00085 os << "-" << dv[1]; 00086 if (sz>2) { 00087 os << "-" << dv[2]; 00088 if (sz>3) 00089 os << " " << dv[3] << ":00"; 00090 } 00091 } 00092 os << "\t" << (*i).second << "\n"; 00093 } 00094 } 00095 } |
|
Definition at line 99 of file stats.C. Referenced by operator<<().
00099 { 00100 for (PathCount::const_iterator i=paths_.begin(); i!=paths_.end(); ++i) { 00101 const vector<string>& pv((*i).first); 00102 // E.g. <"","a","b"> is printed as "/a/b". 00103 for (unsigned int j=0; j<pv.size() ; ++j) { 00104 if ((j>0)||(pv.size()==1)) 00105 os << "/"; 00106 os << pv[j]; 00107 } 00108 os << "\t" << (*i).second << "\n"; 00109 } 00110 } |
|
Definition at line 114 of file stats.C. Referenced by operator<<().
00114 { 00115 for (DomainCount::const_iterator i=domains_.begin(); i!=domains_.end(); ++i) { 00116 const vector<string>& dv((*i).first); 00117 for (unsigned int j=0; j<dv.size() ; ++j) { 00118 if (j>0) 00119 os << "."; 00120 os << dv[j]; 00121 } 00122 os << "\t" << (*i).second << "\n"; 00123 } 00124 } |
|
Print stats information on ostream.
Definition at line 128 of file stats.C. 00128 { 00129 switch (stats.configuration_.format()) { 00130 case Configuration::DATE: 00131 stats.print_dates(os); 00132 break; 00133 case Configuration::PATH: 00134 stats.print_paths(os); 00135 break; 00136 case Configuration::DOMAIN: 00137 stats.print_domains(os); 00138 break; 00139 } 00140 return os; 00141 } |
|
|
|
|
|
|
|
Copy of the constructor parameter.
|