Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

stats.C

Go to the documentation of this file.
00001 // $Id: stats_C-source.html,v 1.1 2001/04/16 17:43:03 dvermeir Exp $
00002 #include "stats.h"
00003 #include <algorithm> // min()
00004 
00005 // We copy the configuration into configuration_.
00006 Stats::Stats(const Configuration& c): configuration_(c) {
00007 }
00008 
00009 // Update the internal database with information from a LogRecord.
00010 void
00011 Stats::add(const LogRecord& r) {
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 DatePattern&  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(d.size(),max_level));
00026     for (unsigned int l=1;(l<=m);++l) 
00027       if (levels.count(l)) {
00028         DatePattern dp(d,l);
00029         ++dates_[dp];
00030         }
00031     }
00032     break;
00033 
00034   case Configuration::PATH: {
00035     const Path& path(r.path());
00036     unsigned int m(min(path.size(),max_level));
00037     for (unsigned int l=1; l<=m; ++l) 
00038       if (levels.count(l)) {
00039         Path pp(path,l);
00040         ++paths_[pp];
00041         }
00042     }
00043     break;
00044 
00045   case Configuration::DOMAIN: {
00046     const Domain& domain(r.domain());
00047     unsigned int sz(domain.size());
00048     unsigned int m(min(sz,max_level));
00049     for (unsigned int l=1; l<=m; ++l) {
00050       if (levels.count(l)) {
00051         Domain dom(domain,l);
00052         ++(domains_[dom]);
00053         }
00054       }
00055     }
00056     break;
00057 
00058   case Configuration::NONE: 
00059     break;
00060   }
00061 }
00062 
00063 // Print dates_ map to os.
00064 void
00065 Stats::print_dates(ostream& os) const {
00066 for (DateCount::const_iterator i=dates_.begin(); i!=dates_.end(); ++i) {
00067   const DatePattern& d((*i).first);
00068   os << d <<  "\t" << (*i).second << "\n";
00069   }
00070 }
00071 
00072 // Print paths_ map to os.
00073 void
00074 Stats::print_paths(ostream& os) const {
00075 for (PathCount::const_iterator i=paths_.begin(); i!=paths_.end(); ++i) {
00076   const Path& path((*i).first);
00077   os << path << "\t" << (*i).second << "\n";
00078   }
00079 }
00080 
00081 // Print domains_ map to os.
00082 void
00083 Stats::print_domains(ostream& os) const {
00084 for (DomainCount::const_iterator i=domains_.begin(); i!=domains_.end(); ++i) {
00085   const Domain& domain((*i).first);
00086   os << domain <<  "\t" << (*i).second << "\n";
00087   }
00088 }
00089 
00090 // Print internal database, depending on configuration.
00091 ostream&
00092 operator<<(ostream& os,const Stats& stats) {
00093 switch (stats.configuration_.format()) {
00094   case Configuration::DATE:
00095     stats.print_dates(os);
00096     break;
00097   case Configuration::PATH:
00098     stats.print_paths(os);
00099     break;
00100   case Configuration::DOMAIN:
00101     stats.print_domains(os);
00102     break;
00103   case Configuration::NONE:
00104     break;
00105   }
00106 return os;
00107 }

httpstats-stage04 [ 7 April, 2001]