Changeset 35


Ignore:
Timestamp:
Jan 12, 2006, 5:12:14 PM (16 years ago)
Author:
Jari Häkkinen
Message:

Continued fixing gnuplot.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Stats.cc

    r34 r35  
    2020  Gnuplot Stats::gnuplot_pipe_;
    2121
    22   std::vector<u_int> Stats::accumulated(void) const
     22  std::vector<double> Stats::accumulated(void) const
    2323  {
    2424    std::vector<u_int> sum;
    2525    if (map_.empty())
    26       return sum;
     26      return std::vector<double>();
    2727
    2828    // sum of all users
     
    3131
    3232    // calculate accumulated sum
    33     std::vector<u_int> accum(sum.size());
     33    std::vector<double> accum(sum.size());
    3434    std::partial_sum(sum.begin(),sum.end(),accum.begin());   
    3535    return accum;
    3636  }
    3737
    38   std::vector<u_int> Stats::accumulated(const std::string& user)
     38  std::vector<double> Stats::accumulated(const std::string& user) const
    3939  {
    40     std::vector<u_int> vec=map_[user];
    41     if (vec.empty())
    42       return vec;
    43     std::vector<u_int> accum(vec.size());
     40    if (!map_.count(user))
     41      return std::vector<double>();
     42    std::vector<u_int> vec=(map_.find(user))->second;
     43
     44    std::vector<double> accum(vec.size());
    4445    std::partial_sum(vec.begin(),vec.end(),accum.begin());
    4546    return accum;
     
    6566  {
    6667    char name[]="svnstatXXXXXX";
    67     if (mkstemp(name) == -1) {
     68    if (!strlen(mktemp(name))) {
    6869      std::cerr << "Failed to get unique filename: " << name << std::endl;
    6970      exit(-1);
     
    7273    std::string cmd=std::string("set term png; set output '")+name+".png'";
    7374    gnuplot_pipe_.command(cmd);
    74     cmd="plot sin(x) t 'ddd' w lines";
    75     gnuplot_pipe_.command(cmd);
     75    std::vector<double> x=accumulated();
     76    gnuplot_pipe_.plot_y(x);
     77    for (MapConstIter_ i= map_.begin(); i != map_.end(); i++) {
     78      x=accumulated(i->first);
     79      gnuplot_pipe_.plot_y(x);
     80    }
    7681    return std::string(name)+".png";
    7782  }
  • trunk/lib/Stats.h

    r34 r35  
    2929    void add(const std::string& user, const u_int& revision);
    3030
    31     std::string plot(void) const;
    32 
    3331    ///
    3432    /// @bief print statistics
     
    4644    Stats& operator+=(const Stats&);
    4745
     46    ///
     47    /// Jari, this is public. Naughty!
     48    ///
     49    /// @todo Make this non-public. The issues that gnuplot is started
     50    /// in cwd, but the main program makes a 'chdir' to another, and
     51    /// we cannot get gnuplot to change directory if it is
     52    /// private. Some redesign is needed.
     53    ///
     54    static Gnuplot gnuplot_pipe_;
     55
    4856  private:
    4957    ///
     
    5563    /// @return accumulated vector of total
    5664    ///
    57     std::vector<u_int> accumulated(void) const;
     65    std::vector<double> accumulated(void) const;
    5866
    5967    ///
    6068    /// @return accumulated vector of stats_[user]
    6169    ///
    62     std::vector<u_int> accumulated(const std::string& user);
     70    std::vector<double> accumulated(const std::string& user) const;
    6371
    64     static Gnuplot gnuplot_pipe_;
     72    std::string plot(void) const;
     73
    6574    // Peter, if the vector is sparse make it a map
    6675    typedef std::map<std::string, std::vector<u_int> > Map_;
  • trunk/test/tree.cc

    r33 r35  
    44
    55#include <string>
    6 #include <iostream>
     6#include <unistd.h>
    77
    88int main(const int argc,const char* argv[])
     
    1212  bool ok = true;
    1313
    14   system("ln -fns . testrepo");
     14  system("ln -fns .. testrepo");
    1515  Directory tree(std::string("testrepo"));
    1616
    1717  tree.purge();
    1818  tree.parse();
     19
    1920  ok = ok && !system("mkdir -p svnstat_output");
    20   tree.print("svnstat_output/");
     21  Stats::gnuplot_pipe_.command("cd 'svnstat_output'");
     22  chdir("svnstat_output");
     23  tree.print("./");
    2124 
    2225  return (ok ? 0 : -1);
Note: See TracChangeset for help on using the changeset viewer.