Changeset 1290 for trunk/lib/Node.cc


Ignore:
Timestamp:
Nov 12, 2010, 5:01:35 AM (11 years ago)
Author:
Peter Johansson
Message:

closes #457. Lifting out plotting functions in Stats into a new class
StatsPlotter?. In same manner lifting out print functions from
Node/Directory/File? into a new hierarchy
NodePrinter/DirectoryPrinter/FilePrinter?. To accomplish these splits
without to much recoding some friendships are introduced. These new
classes are only needed for svndigest (not svncopyright) and are
therefore placed in a library named libsvndigest together with Graph
class and first_page functions. Remaining functionality, shared
between svncopyright and svndigest, are located in libsvndigest_core
and linked into both binaries.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Node.cc

    r1264 r1290  
    105105      os << name() << " (<i>link</i>)";
    106106    // there is no output for nodes when user has zero contribution
    107     else if (user!="all" && !tiny_stats_(stats_type,user,LineTypeParser::total))
     107    else if (user!="all"
     108             && !tiny_stats()(stats_type,user,LineTypeParser::total))
    108109      os << name();
    109     else if (!Configuration::instance().output_file() && !this->dir())
     110    else if (!Configuration::instance().output_file() && !dir())
    110111      os << name();
    111112    else
     
    124125
    125126
    126   void Node::html_tabletd(std::ostream& os, const std::string& stats_type,
     127  void Node::html_tabletd(std::ostream& os,
     128                          const std::string& stats_type,
    127129                          const std::string& user,
    128130                          LineTypeParser::line_type lt) const
    129131  {
    130     os << "<td>" << tiny_stats_(stats_type, user, lt);
    131     if (user!="all" && tiny_stats_(stats_type, user, lt))
    132       os << " (" << percent(tiny_stats_(stats_type, user, lt),
    133                             tiny_stats_(stats_type, "all", lt)) << "%)";
     132    os << "<td>" << tiny_stats()(stats_type, user, lt);
     133    if (user!="all" && tiny_stats()(stats_type, user, lt))
     134      os << " (" << percent(tiny_stats()(stats_type, user, lt),
     135                            tiny_stats()(stats_type, "all", lt)) << "%)";
    134136    os << "</td>\n";
    135137  }
     
    163165
    164166
    165   std::string Node::output_dir(void) const
    166   {
    167     return output_dir_;
    168   }
    169 
    170 
    171   void Node::path_anchor(std::ostream& os) const
    172   {
    173     os << "<h2 class=\"path\">\n";
    174     std::vector<std::string> words;
    175     words.reserve(level_+1);
    176     std::string word;
    177     words.push_back(Node::project_);
    178     std::stringstream ss(local_path());
    179     while(getline(ss,word,'/'))
    180       if (!word.empty()) // ignore double slash in path
    181         words.push_back(word);
    182     if (words.size()==1)
    183       os << anchor("index.html", Node::project_,0, "View " + Node::project_);
    184     else {
    185       for (size_t i=0; i<words.size()-1; ++i){
    186         os << anchor("index.html", words[i], level_-i, "View " + words[i]);
    187         os << "<span class=\"sep\">/</span>";
    188       }
    189       os << anchor(href(), words.back(), level_+2-words.size(),
    190              "View " + words.back());
    191     }
    192     os << "\n</h2>\n";
    193   }
    194 
    195 
    196   void Node::print(const bool verbose) const
    197   {
    198     if (ignore())
    199       return;
    200     if (!Configuration::instance().output_file() && !this->dir())
    201       return;
    202     if (verbose)
    203       std::cout << "Printing output for '" << path_ << "'" << std::endl;
    204     const SVNlog& log = this->log();
    205     typedef std::map<std::string, Stats*>::const_iterator iter;
    206 
    207     const iter end(stats_.stats().end());
    208     for (iter i=stats_.stats().begin();i!=end; ++i){
    209       print_core(i->first, "all", "total", log);
    210       print_core(i->first, "all", "code", log);
    211       print_core(i->first, "all", "comments", log);
    212       print_core(i->first, "all", "empty", log);
    213       for (std::set<std::string>::const_iterator j=i->second->authors().begin();
    214          j!=i->second->authors().end(); ++j) {
    215         print_core(i->first, *j, "total", log);
    216         print_core(i->first, *j, "code", log);
    217         print_core(i->first, *j, "comments", log);
    218         print_core(i->first, *j, "empty", log);
    219       }
    220     }
    221     print_core(verbose);
    222   }
    223 
    224 
    225   void Node::print_author_summary(std::ostream& os,
    226                                   const Stats& stats,
    227                                   const std::string& line_type,
    228                                   const SVNlog& log) const
    229   {
    230     HtmlStream hs(os);
    231     os << "<h3>Author Summary</h3>";
    232     os << "<table class=\"listings\">\n";
    233     os << "<thead>\n";
    234     os << "<tr>\n";
    235     os << "<th>Author</th>\n";
    236     os << "<th>Lines</th>\n";
    237     os << "<th>Code</th>\n";
    238     os << "<th>Comments</th>\n";
    239     os << "<th>Other</th>\n";
    240     os << "<th>Revision</th>\n";
    241     os << "<th>Date</th>\n";
    242     os << "</tr>\n</thead>\n";
    243     os << "<tbody>\n";
    244 
    245     std::string color("light");
    246     if (!dir()) {
    247       os << "<tr class=\"" << color << "\">\n";
    248       os << "<td class=\"directory\" colspan=\"7\">";
    249       os << anchor("index.html", "../");
    250       os << "</td>\n</tr>\n";
    251     }
    252 
    253     // print authors
    254     const std::string timefmt("%Y-%m-%d  %H:%M");
    255     for (std::set<std::string>::const_iterator i=stats.authors().begin();
    256          i!=stats.authors().end(); ++i){
    257       if (color=="dark")
    258         color="light";
    259       else
    260         color="dark";
    261       os << "<tr class=\"" << color << "\"><td>";
    262       os << anchor(*i+"/"+line_type+"/"+output_path()
    263                    ,*i, level_+2, "View statistics for "+*i);
    264       os << "</td><td>" << stats.lines(*i)
    265          << "</td><td>" << stats.code(*i)
    266          << "</td><td>" << stats.comments(*i)
    267          << "</td><td>" << stats.empty(*i);
    268       if (log.exist(*i)) {
    269         const Commitment& lc(log.latest_commit(*i));
    270         os << "</td>" << "<td>" << trac_revision(lc.revision())
    271            << "</td>" << "<td>";
    272         hs << Date(lc.date())(timefmt);
    273       }
    274       else {
    275         os << "</td>" << "<td>N/A"
    276            << "</td>" << "<td>N/A";
    277       }
    278       os << "</td></tr>\n";
    279     }
    280 
    281     os << "<tr class=\"" << color << "\">\n";
    282     os << "<td>";
    283     if (dir())
    284       if (local_path().empty())
    285         os << anchor("all/"+line_type+"/index.html"
    286                      ,"Total", level_+2, "View statistics for all");
    287       else
    288         os << anchor("all/"+line_type+"/"+local_path()+"/index.html"
    289                      ,"Total", level_+2, "View statistics for all");
    290     else
    291       os << anchor("all/"+line_type+"/"+local_path()+".html"
    292                    ,"Total", level_+2, "View statistics for all");
    293     os << "</td>\n";
    294     os << "<td>" << stats.lines() << "</td>\n";
    295     os << "<td>" << stats.code() << "</td>\n";
    296     os << "<td>" << stats.comments() << "</td>\n";
    297     os << "<td>" << stats.empty() << "</td>\n";
    298     const Commitment& lc(log.latest_commit());
    299     os << "<td>" << trac_revision(lc.revision()) << "</td>\n";
    300     os << "<td>";
    301     hs << Date(lc.date())(timefmt);
    302     os << "</td>\n";
    303     os << "</tr>\n";
    304     os << "</tbody>\n";
    305     os << "</table>\n";
    306   }
    307 
    308  
    309167  const StatsCollection& Node::stats(void) const
    310168  {
     
    324182  }
    325183
    326 
    327   std::string Node::url(void) const
    328   {
    329     return svninfo_.url();
    330   }
    331 
    332184}} // end of namespace svndigest and namespace theplu
Note: See TracChangeset for help on using the changeset viewer.