Changeset 1290 for trunk/lib/Stats.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/Stats.cc

    r1280 r1290  
    2727#include "Configuration.h"
    2828#include "Functor.h"
    29 #include "Graph.h"
    3029#include "SVNblame.h"
    3130#include "SVNinfo.h"
     
    404403    assert(comment_or_copy_stats().size());
    405404    assert(other_stats().size());
    406   }
    407 
    408 
    409   std::string Stats::plot(const std::string& filename,
    410                           const std::string& linetype) const
    411   {
    412     const std::string& format = Configuration::instance().image_format();
    413     if (format=="none")
    414       return filename;
    415     plot(filename, linetype, format);
    416     const std::string& anchor_format =
    417       Configuration::instance().image_anchor_format();
    418 
    419     if (format!=anchor_format)
    420       plot(filename, linetype, anchor_format);
    421     return filename;
    422   }
    423 
    424 
    425   void Stats::plot(const std::string& filename,
    426                    const std::string& linetype,
    427                    const std::string& format) const
    428   {
    429     Graph gp(filename+"."+format, format);
    430     const Author2Vector* stat=NULL;
    431     if (linetype=="total")
    432       stat = &total_stats();
    433     else if (linetype=="code")
    434       stat = &code_stats();
    435     else if (linetype=="comments")
    436       stat = &comment_or_copy_stats();
    437     else if (linetype=="empty")
    438       stat = &other_stats();
    439     assert(stat);
    440     assert(stat->size());
    441     assert(stat->find("all")!=stat->end());
    442     const SumVector& total=get_vector(*stat, "all");   
    443     double yrange_max=1.03 * max_element(total) +1.0;
    444     gp.ymax(yrange_max);
    445 
    446     typedef std::vector<std::pair<std::string, SumVector> > vec_type;
    447     vec_type author_cont;
    448     author_cont.reserve(stat->size());
    449     for (std::set<std::string>::const_iterator i=authors_.begin();
    450          i != authors_.end(); ++i) {
    451       assert(stat->find(*i)!=stat->end());
    452       const SumVector& vec = get_vector(*stat,*i);
    453       if (max_element(vec)) {
    454         author_cont.push_back(std::make_pair(*i,vec));
    455       }
    456     }
    457 
    458     LessReversed<SumVector> lr;
    459     PairSecondCompare<std::string, SumVector, LessReversed<SumVector> >
    460       compare(lr);
    461     std::sort(author_cont.begin(), author_cont.end(), compare);
    462 
    463     vec_type::iterator end(author_cont.end());
    464     vec_type::iterator i(author_cont.begin());
    465     const vec_type::size_type maxauthors=8;
    466     int authskip=author_cont.size()-maxauthors;
    467     if (authskip>1) {
    468       // only use others if there is more than 1 author to be skipped,
    469       // there is no reason to add only 1 author to others.
    470       vec_type::iterator j(i);
    471       i+=authskip;
    472       SumVector others;
    473       sum(j, i, others, PairValuePlusAssign<std::string, SumVector>());
    474       unsigned char r, g, b;
    475       std::string label("others");
    476       Colors::instance().get_color(label, r,g,b);
    477       gp.current_color(r,g,b);
    478       gp.plot(others, label, others.back());
    479     }
    480     for ( ; i!=end; ++i) {
    481       unsigned char r, g, b;
    482       Colors::instance().get_color(i->first,r,g,b);
    483       gp.current_color(r,g,b);
    484       gp.plot(i->second, i->first, get_back(*stat, i->first));
    485     }
    486     gp.current_color(255,0,0);
    487     gp.plot(total, "total", get_back(*stat, "all"));
    488   }
    489 
    490 
    491   void Stats::plot_summary(const std::string& filename) const
    492   {
    493     const std::string& format = Configuration::instance().image_format();
    494     if (format=="none")
    495       return;
    496     plot_summary(filename, format);
    497     const std::string& anchor_format =
    498       Configuration::instance().image_anchor_format();
    499 
    500     if (format!=anchor_format)
    501       plot_summary(filename, anchor_format);
    502   }
    503 
    504 
    505   void Stats::plot_summary(const std::string& filename,
    506                            const std::string& format) const
    507   {
    508     Graph gp(filename+"."+format, format);
    509     const SumVector& total = get_vector(total_stats(), "all");
    510     double yrange_max=1.03*max_element(total)+1;
    511     gp.ymax(yrange_max);
    512    
    513     const SumVector& x(get_vector(code_stats(), "all"));
    514     gp.current_color(255,255,0);
    515     gp.plot(x, "code", x.back());
    516 
    517     const SumVector& y = get_vector(comment_or_copy_stats(), "all");
    518     gp.current_color(0,0,255);
    519     gp.plot(y, "comment", y.back());
    520 
    521     const SumVector& z = get_vector(other_stats(), "all");
    522     gp.current_color(0,255,0);
    523     gp.plot(z, "other", z.back());
    524 
    525     gp.current_color(255,0,0);
    526     gp.plot(total, "total", total.back());
    527405  }
    528406
Note: See TracChangeset for help on using the changeset viewer.