Changeset 34 for trunk/lib


Ignore:
Timestamp:
Jan 12, 2006, 2:17:11 AM (16 years ago)
Author:
Jari Häkkinen
Message:

Started implementing gnuplot into Stats.

Location:
trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Stats.cc

    r23 r34  
    33#include "Stats.h"
    44#include "utility.h"
     5
     6#include <cstdio>
     7#include <fstream>
    58
    69#include <map>
     
    1518namespace svnstat{
    1619
    17   Stats::Stats()
    18   {
    19   }
    20 
     20  Gnuplot Stats::gnuplot_pipe_;
    2121
    2222  std::vector<u_int> Stats::accumulated(void) const
     
    5353      vec.resize(rev+1);
    5454      for (; i<rev; i++)
    55   vec[i]=0;
     55        vec[i]=0;
    5656      vec[rev]=1;
    5757    }
     
    6161
    6262  }
     63
     64  std::string Stats::plot(void) const
     65  {
     66    char name[]="svnstatXXXXXX";
     67    if (mkstemp(name) == -1) {
     68      std::cerr << "Failed to get unique filename: " << name << std::endl;
     69      exit(-1);
     70    }
     71    // Jari, temporary empty files are created that needs to be removed.
     72    std::string cmd=std::string("set term png; set output '")+name+".png'";
     73    gnuplot_pipe_.command(cmd);
     74    cmd="plot sin(x) t 'ddd' w lines";
     75    gnuplot_pipe_.command(cmd);
     76    return std::string(name)+".png";
     77  }
    6378
    6479  void Stats::print(std::ostream& os) const
     
    7994    os << "</table>\n";
    8095
    81     os << "<p>[Plot to be here.]</p>\n";         
     96    os << "<p><img src='" << plot() << "' alt='[svnstat plot]' border=0></p>\n";
    8297  }
    8398
  • trunk/lib/Stats.h

    r23 r34  
    44#define _theplu_svnstat_stats_
    55
     6#include "Gnuplot.h"
     7
    68#include <map>
     9#include <string>
    710#include <vector>
    811
     
    1821    ///
    1922    /// @brief Default Constructor
    20     ///
    21     Stats(void);
    22    
     23    ///
     24    inline Stats(void) {}
     25
    2326    ///
    2427    /// @brief adding a line to user from revision to the stats
    2528    ///
    2629    void add(const std::string& user, const u_int& revision);
     30
     31    std::string plot(void) const;
    2732
    2833    ///
     
    5762    std::vector<u_int> accumulated(const std::string& user);
    5863
     64    static Gnuplot gnuplot_pipe_;
    5965    // Peter, if the vector is sparse make it a map
    6066    typedef std::map<std::string, std::vector<u_int> > Map_;
Note: See TracChangeset for help on using the changeset viewer.