From 8c1bf3cf8d64e6b10e5d279759b5d5c663b104d6 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 15 Oct 2014 22:00:49 +0000 Subject: [PATCH] improved RSGraph class. Used it for Turtle statistics and bandwidth statistics as well git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7612 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- .../src/gui/common/RSGraphWidget.cpp | 58 ++++++++++++++++- retroshare-gui/src/gui/common/RSGraphWidget.h | 19 +++++- retroshare-gui/src/gui/graphframe.h | 6 +- .../src/gui/statistics/BwCtrlWindow.cpp | 35 ++++------- .../src/gui/statistics/BwCtrlWindow.h | 43 +++---------- .../src/gui/statistics/BwCtrlWindow.ui | 14 ++--- .../src/gui/statistics/DhtWindow.cpp | 7 --- retroshare-gui/src/gui/statistics/DhtWindow.h | 2 - .../src/gui/statistics/StatisticsWindow.h | 2 + .../gui/statistics/TurtleRouterStatistics.cpp | 15 ----- .../gui/statistics/TurtleRouterStatistics.h | 29 ++++----- .../gui/statistics/TurtleRouterStatistics.ui | 18 ++---- retroshare-gui/src/gui/statistics/bwgraph.h | 45 ++++++++++++++ retroshare-gui/src/gui/statistics/dhtgraph.h | 62 ++++++++++++++----- .../src/gui/statistics/turtlegraph.h | 54 ++++++++++++++++ retroshare-gui/src/retroshare-gui.pro | 3 +- 16 files changed, 267 insertions(+), 145 deletions(-) create mode 100644 retroshare-gui/src/gui/statistics/bwgraph.h create mode 100644 retroshare-gui/src/gui/statistics/turtlegraph.h diff --git a/retroshare-gui/src/gui/common/RSGraphWidget.cpp b/retroshare-gui/src/gui/common/RSGraphWidget.cpp index 9190b38ba..980b6b436 100644 --- a/retroshare-gui/src/gui/common/RSGraphWidget.cpp +++ b/retroshare-gui/src/gui/common/RSGraphWidget.cpp @@ -65,6 +65,32 @@ void RSGraphSource::start() int RSGraphSource::n_values() const { return _points.size() ; } +QString RSGraphSource::displayName(int i) const +{ + std::map > >::const_iterator it = _points.begin(); + + int n=0; + for(it = _points.begin();it!=_points.end() && nfirst) ; +} + +QString RSGraphSource::displayValue(float v) const +{ + return QString::number(v,'g',2) + " " + unitName() ; +} + +void RSGraphSource::getCurrentValues(std::vector& vals) const +{ + std::map > >::const_iterator it = _points.begin(); + + for(it = _points.begin();it!=_points.end();++it) + vals.push_back(it->second.back().second) ; +} + void RSGraphSource::getDataPoints(int index,std::vector& pts) const { pts.clear() ; @@ -222,6 +248,9 @@ void RSGraphWidget::paintEvent(QPaintEvent *) /* Paint the rsDHT/allDHT totals */ paintTotals(); + if(_flags & RSGRAPH_FLAGS_SHOW_LEGEND) + paintLegend() ; + /* Stop the painter */ _painter->end(); } @@ -229,7 +258,7 @@ void RSGraphWidget::paintEvent(QPaintEvent *) QColor RSGraphWidget::getColor(int i) { // shuffle the colors a little bit - int h = (i*44497)%359 ; + int h = (i*86243)%359 ; return QColor::fromHsv(h,128+127*(i&1),255) ; } @@ -430,8 +459,10 @@ void RSGraphWidget::paintScale() scale = pixelsToValue(i * paintStep); + QString text = _source->displayValue(scale) ; + _painter->setPen(SCALE_COLOR); - _painter->drawText(QPointF(5, pos+0.5*FONT_SIZE), tr("%1 %2").arg(scale, 0, 'f', _precision_digits).arg(unit_name)); + _painter->drawText(QPointF(5, pos+0.5*FONT_SIZE), text); _painter->setPen(GRID_COLOR); _painter->drawLine(QPointF(SCALE_WIDTH, pos), QPointF(_rec.width(), pos)); } @@ -440,3 +471,26 @@ void RSGraphWidget::paintScale() _painter->drawLine(SCALE_WIDTH, top, SCALE_WIDTH, bottom); } +void RSGraphWidget::paintLegend() +{ + int bottom = _rec.height(); + + std::vector vals ; + _source->getCurrentValues(vals) ; + + for(uint i=0;idisplayName(i) + " (" + _source->displayValue(vals[i]) + " )"; + + QPen oldPen = _painter->pen(); + _painter->setPen(QPen(getColor(i), Qt::SolidLine)); + _painter->drawLine(QPointF(SCALE_WIDTH+10.0, pos), QPointF(SCALE_WIDTH+30.0, pos)); + _painter->setPen(oldPen); + + _painter->setPen(SCALE_COLOR); + _painter->drawText(QPointF(SCALE_WIDTH + 40,pos + 0.5*FONT_SIZE), text) ; + } +} + diff --git a/retroshare-gui/src/gui/common/RSGraphWidget.h b/retroshare-gui/src/gui/common/RSGraphWidget.h index 2cab8690f..aedec2663 100644 --- a/retroshare-gui/src/gui/common/RSGraphWidget.h +++ b/retroshare-gui/src/gui/common/RSGraphWidget.h @@ -59,19 +59,29 @@ public: void stop() ; void clear() ; - virtual int n_values() const ; + virtual QString unitName() const { return "" ; }// overload to give your own unit name (KB/s, Users, etc) + + int n_values() const ; + + // Might be overloaded in order to show a fancy digit number with adaptive units. + // The default is to return v + unitName() + virtual QString displayValue(float v) const ; + + // return the vector of last values up to date + virtual void getCurrentValues(std::vector& vals) const ; // Returns the n^th interpolated value at the given time in floating point seconds backward. virtual void getDataPoints(int index, std::vector& pts) const ; + // returns the name to give to the nth entry in the graph + virtual QString displayName(int index) const ; + // Sets the maximum time for keeping values. Units=seconds. void setCollectionTimeLimit(qint64 msecs) ; // Sets the time period for collecting new values. Units=milliseconds. void setCollectionTimePeriod(qint64 msecs) ; - virtual QString unitName() const =0;// overload to give your own unit name (KB/s, Users, etc) - protected slots: // Calls the internal source for a new data points; called by the timer. You might want to overload this // if the collection system needs it. Otherwise, the default method will call getValues() @@ -102,6 +112,7 @@ class RSGraphWidget: public QFrame static const uint32_t RSGRAPH_FLAGS_LOG_SCALE_Y = 0x0002 ;// log scale in Y static const uint32_t RSGRAPH_FLAGS_ALWAYS_COLLECT = 0x0004 ;// keep collecting while not displayed static const uint32_t RSGRAPH_FLAGS_PAINT_STYLE_PLAIN = 0x0008 ;// use plain / line drawing style + static const uint32_t RSGRAPH_FLAGS_SHOW_LEGEND = 0x0010 ;// show legend in the graph /** Bandwidth graph style. */ enum GraphStyle @@ -149,6 +160,8 @@ class RSGraphWidget: public QFrame /** Paints the rsdht/alldht totals. */ void paintTotals(); /** Paints the scale in the graph. */ + void paintLegend(); + /** Paints the scale in the graph. */ void paintScale(); QColor getColor(int i) ; diff --git a/retroshare-gui/src/gui/graphframe.h b/retroshare-gui/src/gui/graphframe.h index cc6597124..f7bcadf3b 100644 --- a/retroshare-gui/src/gui/graphframe.h +++ b/retroshare-gui/src/gui/graphframe.h @@ -1,7 +1,7 @@ /**************************************************************** - * This file is distributed under the following license: - * - * Copyright (c) 2006-2007, crypton + * This file is distributed under the following license: + * + * Copyright (c) 2006-2007, crypton * Copyright (c) 2006, Matt Edman, Justin Hipple * * This program is free software; you can redistribute it and/or diff --git a/retroshare-gui/src/gui/statistics/BwCtrlWindow.cpp b/retroshare-gui/src/gui/statistics/BwCtrlWindow.cpp index 171ddc9c8..2ba3e3442 100644 --- a/retroshare-gui/src/gui/statistics/BwCtrlWindow.cpp +++ b/retroshare-gui/src/gui/statistics/BwCtrlWindow.cpp @@ -20,6 +20,7 @@ ****************************************************************/ #include "BwCtrlWindow.h" +#include "gui/common/RSGraphWidget.h" #include "ui_BwCtrlWindow.h" #include #include @@ -37,14 +38,21 @@ #include #include +class BWListDelegate: public QAbstractItemDelegate +{ +public: + BWListDelegate(QObject *parent=0); + virtual ~BWListDelegate(); + void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const; + QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const; +}; + BWListDelegate::BWListDelegate(QObject *parent) : QAbstractItemDelegate(parent) { - ; } BWListDelegate::~BWListDelegate(void) { - ; } void BWListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const @@ -163,31 +171,25 @@ QSize BWListDelegate::sizeHint(const QStyleOptionViewItem & /*option*/, const QM return QSize(50,17); } - BwCtrlWindow::BwCtrlWindow(QWidget *parent) : RsAutoUpdatePage(1000,parent) { setupUi(this); - BWDelegate = new BWListDelegate(); bwTreeWidget->setItemDelegate(BWDelegate); - /* Set header resize modes and initial section sizes Peer TreeView*/ + /* Set header resize modes and initial section sizes Peer TreeView*/ QHeaderView * _header = bwTreeWidget->header () ; _header->resizeSection ( COLUMN_RSNAME, 170 ); - - } BwCtrlWindow::~BwCtrlWindow() { - } void BwCtrlWindow::updateDisplay() { - /* do nothing if locked, or not visible */ if (RsAutoUpdatePage::eventsLocked() == true) { @@ -205,12 +207,7 @@ void BwCtrlWindow::updateDisplay() return; } - RsAutoUpdatePage::lockAllEvents(); - - //std::cerr << "BwCtrlWindow::update()" << std::endl; updateBandwidth(); - - RsAutoUpdatePage::unlockAllEvents() ; } void BwCtrlWindow::updateBandwidth() @@ -223,7 +220,7 @@ void BwCtrlWindow::updateBandwidth() std::map rateMap; std::map::iterator it; - rsConfig->getTotalBandwidthRates(totalRates); + rsConfig->getTotalBandwidthRates(totalRates); rsConfig->getAllBandwidthRates(rateMap); /* insert */ @@ -231,8 +228,6 @@ void BwCtrlWindow::updateBandwidth() peerTreeWidget->addTopLevelItem(item); peerTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); - updateGraph(totalRates.mRateIn,totalRates.mRateOut); - /* do Totals */ item -> setData(COLUMN_PEERID, Qt::DisplayRole, tr("TOTALS")); item -> setData(COLUMN_RSNAME, Qt::DisplayRole, tr("Totals")); @@ -369,10 +364,4 @@ void BwCtrlWindow::updateBandwidth() } } -/** Adds new data to the graph. */ -void BwCtrlWindow::updateGraph(qreal bytesRead, qreal bytesWritten) -{ - /* Graph only cares about kilobytes */ - frmGraph->addPoints(bytesRead/*/1024.0*/, bytesWritten/*/1024.0*/); -} diff --git a/retroshare-gui/src/gui/statistics/BwCtrlWindow.h b/retroshare-gui/src/gui/statistics/BwCtrlWindow.h index 8e9248ac6..2a77c5520 100644 --- a/retroshare-gui/src/gui/statistics/BwCtrlWindow.h +++ b/retroshare-gui/src/gui/statistics/BwCtrlWindow.h @@ -1,6 +1,3 @@ -#ifndef RSBWCTRL_WINDOW_H -#define RSBWCTRL_WINDOW_H - /**************************************************************** * RetroShare is distributed under the following license: * @@ -22,11 +19,14 @@ * Boston, MA 02110-1301, USA. ****************************************************************/ +#pragma once + #include #include #include "RsAutoUpdatePage.h" +#include "gui/common/RSGraphWidget.h" #include "ui_BwCtrlWindow.h" // Defines for download list list columns @@ -48,47 +48,22 @@ class QModelIndex; class QPainter; +class BWListDelegate ; -class BWListDelegate: public QAbstractItemDelegate { - - Q_OBJECT - -public: - BWListDelegate(QObject *parent=0); - ~BWListDelegate(); - void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const; - QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const; - -private: - -public slots: - -signals: -}; - -class BwCtrlWindow : public RsAutoUpdatePage, public Ui::BwCtrlWindow { +class BwCtrlWindow : public RsAutoUpdatePage, public Ui::BwCtrlWindow +{ Q_OBJECT public: BwCtrlWindow(QWidget *parent = 0); ~BwCtrlWindow(); - void updateBandwidth(); + void updateBandwidth(); public slots: - virtual void updateDisplay() ; + virtual void updateDisplay() ; - /** Adds new data to the graph */ - void updateGraph(qreal bytesRead, qreal bytesWritten); - protected: - -private: - - - BWListDelegate *BWDelegate; + BWListDelegate *BWDelegate; }; - -#endif // RSBWCTRL_WINDOW_H - diff --git a/retroshare-gui/src/gui/statistics/BwCtrlWindow.ui b/retroshare-gui/src/gui/statistics/BwCtrlWindow.ui index 5166fb4d1..f0d9abc70 100644 --- a/retroshare-gui/src/gui/statistics/BwCtrlWindow.ui +++ b/retroshare-gui/src/gui/statistics/BwCtrlWindow.ui @@ -84,7 +84,7 @@ - + 120 @@ -99,12 +99,6 @@ Qt::NoContextMenu - - QFrame::Box - - - QFrame::Plain - @@ -112,9 +106,9 @@ - GraphFrame - QFrame -
gui/graphframe.h
+ BWGraph + QWidget +
gui/statistics/bwgraph.h
1
diff --git a/retroshare-gui/src/gui/statistics/DhtWindow.cpp b/retroshare-gui/src/gui/statistics/DhtWindow.cpp index b7ad05a21..1fd46ed98 100644 --- a/retroshare-gui/src/gui/statistics/DhtWindow.cpp +++ b/retroshare-gui/src/gui/statistics/DhtWindow.cpp @@ -695,10 +695,3 @@ void DhtWindow::getDHTStatus() // } // } } - -/** Adds new data to the graph. */ -void DhtWindow::updateGraph(qreal rsDHT, qreal allDHT) -{ -// ui.frmGraph->addPoints(rsDHT, allDHT); -} - diff --git a/retroshare-gui/src/gui/statistics/DhtWindow.h b/retroshare-gui/src/gui/statistics/DhtWindow.h index 8a6c819a8..d95d50cb1 100644 --- a/retroshare-gui/src/gui/statistics/DhtWindow.h +++ b/retroshare-gui/src/gui/statistics/DhtWindow.h @@ -42,8 +42,6 @@ public: public slots: virtual void updateDisplay() ; - void updateGraph(qreal rsDHT, qreal allDHT); - protected: //void changeEvent(QEvent *e); diff --git a/retroshare-gui/src/gui/statistics/StatisticsWindow.h b/retroshare-gui/src/gui/statistics/StatisticsWindow.h index 30c225b33..71c8ee794 100644 --- a/retroshare-gui/src/gui/statistics/StatisticsWindow.h +++ b/retroshare-gui/src/gui/statistics/StatisticsWindow.h @@ -22,6 +22,8 @@ * Boston, MA 02110-1301, USA. ****************************************************************/ +#pragma once + #include namespace Ui { diff --git a/retroshare-gui/src/gui/statistics/TurtleRouterStatistics.cpp b/retroshare-gui/src/gui/statistics/TurtleRouterStatistics.cpp index ab7cbd834..dc0f1e988 100644 --- a/retroshare-gui/src/gui/statistics/TurtleRouterStatistics.cpp +++ b/retroshare-gui/src/gui/statistics/TurtleRouterStatistics.cpp @@ -242,7 +242,6 @@ void TurtleRouterStatistics::updateDisplay() //updateTunnelRequests(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ; _tst_CW->updateTunnelStatistics(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ; _tst_CW->update(); - updateTunnelGraph(); } QString TurtleRouterStatistics::getPeerName(const RsPeerId &peer_id) @@ -355,17 +354,3 @@ void TurtleRouterStatisticsWidget::resizeEvent(QResizeEvent *event) QWidget::resizeEvent(event); update(); } - -void TurtleRouterStatistics::updateTunnelGraph() -{ - TurtleTrafficStatisticsInfo info ; - rsTurtle->getTrafficStatistics(info) ; - - updateGraph(info.tr_up_Bps,info.tr_dn_Bps,info.data_dn_Bps,info.data_up_Bps,info.unknown_updn_Bps); -} - -void TurtleRouterStatistics::updateGraph(qreal bytesTrup, qreal bytesTrdown, qreal bytesDatadown, qreal bytesDataup, qreal bytesunknownupdn) -{ - /* Graph only cares about kilobytes */ - frmGraph->addPoints(bytesTrup/1024.0, bytesTrdown/1024.0, bytesDatadown/1024.0, bytesDataup/1024.0, bytesunknownupdn/1024.0 ); -} diff --git a/retroshare-gui/src/gui/statistics/TurtleRouterStatistics.h b/retroshare-gui/src/gui/statistics/TurtleRouterStatistics.h index bf005e80c..995556a5c 100644 --- a/retroshare-gui/src/gui/statistics/TurtleRouterStatistics.h +++ b/retroshare-gui/src/gui/statistics/TurtleRouterStatistics.h @@ -31,28 +31,23 @@ class TurtleRouterStatisticsWidget ; class TurtleRouterStatistics: public RsAutoUpdatePage, public Ui::TurtleRouterStatistics { - Q_OBJECT + Q_OBJECT - public: - TurtleRouterStatistics(QWidget *parent = NULL) ; - ~TurtleRouterStatistics(); - - // Cache for peer names. - static QString getPeerName(const RsPeerId& peer_id) ; - - public slots: - void updateTunnelGraph(); - void updateGraph(qreal bytesTrup, qreal bytesTrdown, qreal bytesDatadown, qreal bytesDataup, qreal bytesunknownupdn); +public: + TurtleRouterStatistics(QWidget *parent = NULL) ; + ~TurtleRouterStatistics(); + // Cache for peer names. + static QString getPeerName(const RsPeerId& peer_id) ; - private: - - void processSettings(bool bLoad); - bool m_bProcessSettings; +private: - virtual void updateDisplay() ; + void processSettings(bool bLoad); + bool m_bProcessSettings; - TurtleRouterStatisticsWidget *_tst_CW ; + virtual void updateDisplay() ; + + TurtleRouterStatisticsWidget *_tst_CW ; } ; class TurtleRouterStatisticsWidget: public QWidget diff --git a/retroshare-gui/src/gui/statistics/TurtleRouterStatistics.ui b/retroshare-gui/src/gui/statistics/TurtleRouterStatistics.ui index aa91713d3..aa6abc60a 100644 --- a/retroshare-gui/src/gui/statistics/TurtleRouterStatistics.ui +++ b/retroshare-gui/src/gui/statistics/TurtleRouterStatistics.ui @@ -47,8 +47,8 @@ 0 0 - 638 - 255 + 640 + 248 @@ -59,7 +59,7 @@ - + 120 @@ -74,12 +74,6 @@ Qt::NoContextMenu - - QFrame::Box - - - QFrame::Plain - @@ -90,9 +84,9 @@ - GraphFrameTunnel - QFrame -
gui/graphframetunnel.h
+ TurtleGraph + QWidget +
gui/statistics/turtlegraph.h
1
diff --git a/retroshare-gui/src/gui/statistics/bwgraph.h b/retroshare-gui/src/gui/statistics/bwgraph.h new file mode 100644 index 000000000..d49c4685d --- /dev/null +++ b/retroshare-gui/src/gui/statistics/bwgraph.h @@ -0,0 +1,45 @@ +#pragma once + +#include "retroshare/rsconfig.h" +#include + +class BWGraphSource: public RSGraphSource +{ +public: + virtual void getValues(std::map& values) const + { + RsConfigDataRates totalRates; + rsConfig->getTotalBandwidthRates(totalRates); + + values.insert(std::make_pair(std::string("Bytes in"),(float)totalRates.mRateIn)) ; + values.insert(std::make_pair(std::string("Bytes out"),(float)totalRates.mRateOut)) ; + } + + virtual QString unitName() const { return tr("KB/s"); } +}; + +class BWGraph: public RSGraphWidget +{ + public: + BWGraph(QWidget *parent) + : RSGraphWidget(parent) + { + BWGraphSource *src = new BWGraphSource() ; + + src->setCollectionTimeLimit(30*60*1000) ; // 30 mins + src->setCollectionTimePeriod(1000) ; // collect every second + src->start() ; + + addSource(src) ; + + setTimeScale(1.0f) ; // 1 pixels per second of time. + setScaleParams(2) ; + + resetFlags(RSGRAPH_FLAGS_LOG_SCALE_Y) ; + resetFlags(RSGRAPH_FLAGS_PAINT_STYLE_PLAIN) ; + + setFlags(RSGRAPH_FLAGS_SHOW_LEGEND) ; + } +}; + + diff --git a/retroshare-gui/src/gui/statistics/dhtgraph.h b/retroshare-gui/src/gui/statistics/dhtgraph.h index b40cfa3e5..337513c5c 100644 --- a/retroshare-gui/src/gui/statistics/dhtgraph.h +++ b/retroshare-gui/src/gui/statistics/dhtgraph.h @@ -26,26 +26,56 @@ #include #include -#define HOR_SPC 2 /** Space between data points */ -#define SCALE_WIDTH 75 /** Width of the scale */ -#define MINUSER_SCALE 2000 /** 2000 users is the minimum scale */ -#define SCROLL_STEP 4 /** Horizontal change on graph update */ +#include +#include +#include "dhtgraph.h" -#define BACK_COLOR Qt::white -#define SCALE_COLOR Qt::black -#define GRID_COLOR Qt::black -#define RSDHT_COLOR Qt::magenta -#define ALLDHT_COLOR Qt::yellow +class DHTGraphSource: public RSGraphSource +{ + public: + virtual int n_values() const + { + return 1 ; + } + virtual void getValues(std::map& values) const + { + RsConfigNetStatus config; + rsConfig->getConfigNetStatus(config); + + if (config.DHTActive && config.netDhtOk) + { + values.insert(std::make_pair(std::string("RS Net size"),(float)config.netDhtRsNetSize)) ; + //values.insert(std::make_pair(std::string("GLobal Net size"),(float)config.netDhtNetSize)) ; + } + else + { + values.insert(std::make_pair(std::string("RS Net size"),0.0f)) ; + //values.insert(std::make_pair(std::string("GLobal Net size"),0.0f)) ; + } + } + + virtual QString unitName() const { return tr("users"); } +}; -#define FONT_SIZE 11 class DhtGraph : public RSGraphWidget { -public: - DhtGraph(QWidget *parent = 0); + public: + DhtGraph(QWidget *parent = 0) + : RSGraphWidget(parent) + { + DHTGraphSource *src = new DHTGraphSource() ; - /** Show the respective lines and counters. */ - bool _showRSDHT; - bool _showALLDHT; + src->setCollectionTimeLimit(30*60*1000) ; // 30 mins + src->setCollectionTimePeriod(1000) ; // collect every second + src->start() ; + + addSource(src) ; + + setTimeScale(1.0f) ; // 1 pixels per second of time. + setScaleParams(0) ; + + resetFlags(RSGRAPH_FLAGS_LOG_SCALE_Y) ; + setFlags(RSGRAPH_FLAGS_PAINT_STYLE_PLAIN) ; + } }; - diff --git a/retroshare-gui/src/gui/statistics/turtlegraph.h b/retroshare-gui/src/gui/statistics/turtlegraph.h new file mode 100644 index 000000000..7d3155f9e --- /dev/null +++ b/retroshare-gui/src/gui/statistics/turtlegraph.h @@ -0,0 +1,54 @@ +#pragma once + +#include "retroshare/rsturtle.h" +#include + +class TurtleGraphSource: public RSGraphSource +{ + public: + virtual void getValues(std::map& values) const + { + TurtleTrafficStatisticsInfo info ; + rsTurtle->getTrafficStatistics(info) ; + + values.insert(std::make_pair(QObject::tr("TR up").toStdString(),(float)info.tr_up_Bps)) ; + values.insert(std::make_pair(QObject::tr("TR dn").toStdString(),(float)info.tr_dn_Bps)) ; + values.insert(std::make_pair(QObject::tr("Data up").toStdString(),(float)info.data_up_Bps)) ; + values.insert(std::make_pair(QObject::tr("Data dn").toStdString(),(float)info.data_dn_Bps)) ; + values.insert(std::make_pair(QObject::tr("Data forward").toStdString(),(float)info.unknown_updn_Bps)) ; + } + + virtual QString displayValue(float v) const + { + if(v < 1000) + return QString::number(v,'g',2) + " B/s" ; + else if(v < 1000*1024) + return QString::number(v/1024.0,'g',2) + " KB/s" ; + else + return QString::number(v/(1024.0*1024),'g',2) + " MB/s" ; + } +}; + +class TurtleGraph: public RSGraphWidget +{ + public: + TurtleGraph(QWidget *parent) + : RSGraphWidget(parent) + { + TurtleGraphSource *src = new TurtleGraphSource() ; + + src->setCollectionTimeLimit(30*60*1000) ; // 30 mins + src->setCollectionTimePeriod(1000) ; // collect every second + src->start() ; + + addSource(src) ; + + setTimeScale(1.0f) ; // 1 pixels per second of time. + setScaleParams(2) ; + + resetFlags(RSGRAPH_FLAGS_LOG_SCALE_Y) ; + resetFlags(RSGRAPH_FLAGS_PAINT_STYLE_PLAIN) ; + } +}; + + diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index 9b181ef29..f7bb1a9c9 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -344,6 +344,8 @@ HEADERS += rshare.h \ gui/statistics/TurtleRouterDialog.h \ gui/statistics/TurtleRouterStatistics.h \ gui/statistics/dhtgraph.h \ + gui/statistics/bwgraph.h \ + gui/statistics/turtlegraph.h \ gui/FileTransfer/TransferUserNotify.h \ gui/plugins/PluginInterface.h \ gui/im_history/ImHistoryBrowser.h \ @@ -684,7 +686,6 @@ SOURCES += main.cpp \ gui/FileTransfer/xprogressbar.cpp \ gui/statistics/TurtleRouterDialog.cpp \ gui/statistics/TurtleRouterStatistics.cpp \ - gui/statistics/dhtgraph.cpp \ gui/statistics/GlobalRouterStatistics.cpp \ gui/FileTransfer/DetailsDialog.cpp \ gui/FileTransfer/TransferUserNotify.cpp \