Skip to content

Commit 3159f58

Browse files
committed
using same colors in legend and pie. Limited collection to 5 secs. Removed debug output
1 parent fb90a3a commit 3159f58

4 files changed

Lines changed: 51 additions & 16 deletions

File tree

retroshare-gui/src/gui/common/RSGraphWidget.cpp

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ RSGraphSource::~RSGraphSource()
7979
void RSGraphSource::clear()
8080
{
8181
_points.clear() ;
82+
#if QT_VERSION < 0x040700
83+
_time_orig_msecs = getCurrentMSecsSinceEpoch() ;
84+
#else
85+
_time_orig_msecs = QDateTime::currentMSecsSinceEpoch() ;
86+
#endif
8287
}
8388
void RSGraphSource::stop()
8489
{
@@ -121,36 +126,50 @@ void RSGraphSource::getSlicedValues(uint min_secs_ago,uint max_secs_ago,std::vec
121126
uint64_t max_ts = lst_it->second.back().first - min_secs_ago*1000; // in _points the TS are w.r.t. now (in reverse) and in ms.
122127
uint64_t min_ts = lst_it->second.back().first - max_secs_ago*1000;
123128

129+
#ifdef GRAPHWIDGET_DEBUG
124130
std::cerr << "Collecting data in \"" << lst_it->first << "\" between ts = " << min_ts << " and " << max_ts << std::endl;
131+
#endif
125132

126133
for(const auto& p:lst_it->second)
127134
{
135+
#ifdef GRAPHWIDGET_DEBUG
128136
std::cerr << " TS = " << p.first ;
129137
std::cerr << " data \"" << lst_it->first << "\": Found ts = " << p.first << ": value " << p.second ;
138+
#endif
130139

131140
if((uint64_t)p.first >= min_ts && (uint64_t)p.first <= max_ts)
132141
{
133142
v.first.v += p.second;
134143
v.second.v++;
135144

145+
#ifdef GRAPHWIDGET_DEBUG
136146
std::cerr << " Kept."<< std::endl;
147+
#endif
137148
}
149+
#ifdef GRAPHWIDGET_DEBUG
138150
else
139151
std::cerr << std::endl;
152+
#endif
140153
}
154+
#ifdef GRAPHWIDGET_DEBUG
141155
std::cerr << " total value = " << v.first.v << " -- " << v.second.v << std::endl;
156+
#endif
142157
}
143158

144159
// now average values when multiple values have been collected.
145160

161+
#ifdef GRAPHWIDGET_DEBUG
146162
std::cerr << "Computed values: " << collected_vals.size() << std::endl;
163+
#endif
147164

148165
for(uint i=0;i<collected_vals.size();++i)
149166
{
150167
const auto& v(collected_vals[i]);
151168

152169
vals.push_back((v.second.v > 0)?(v.first.v/v.second.v):0.0);
170+
#ifdef GRAPHWIDGET_DEBUG
153171
std::cerr << " \"" << displayName(i).toStdString() << "\" " << vals.back() << " (" << v.second.v << ")" << std::endl;
172+
#endif
154173
}
155174
}
156175

@@ -335,15 +354,16 @@ RSGraphWidget::RSGraphWidget(QWidget *parent)
335354
_time_scale = 5.0f ; // in pixels per second.
336355
_time_filter = 1.0f ;
337356
_timer = new QTimer ;
338-
QObject::connect(_timer,SIGNAL(timeout()),this,SLOT(updateIfPossible())) ;
339-
357+
_slice_proportion = 0.0;
340358

341359
_y_scale = 1.0f ;
342360
_timer->start(1000);
343361

344362
float FS = QFontMetricsF(font()).height();
345363
setMinimumHeight(12*FS);
346364
_graph_base = FS*GRAPH_BASE;
365+
366+
QObject::connect(_timer,SIGNAL(timeout()),this,SLOT(updateIfPossible())) ;
347367
}
348368

349369
void RSGraphWidget::updateIfPossible()
@@ -675,15 +695,27 @@ void RSGraphWidget::paintTotals()
675695
c->addAxis(axisY, Qt::AlignLeft);
676696

677697
std::vector<float> vals;
678-
_source->getSlicedValues(0,5,vals);
698+
699+
qint64 total_duration_secs = _source->totalCollectedTime()/1000.0;
700+
#ifdef GRAPHWIDGET_DEBUG
701+
std::cerr << "Total duration secs: " << total_duration_secs << std::endl;
702+
#endif
703+
//_source->getSlicedValues( total_duration_secs * _slice_proportion,total_duration_secs * _slice_proportion + 5,vals);
704+
_source->getSlicedValues( 0,5,vals);
705+
706+
float max_val = 0.0f;
707+
for(auto v:vals)
708+
max_val = std::max(max_val,v);
679709

680710
auto pieSeries = new QtCharts::QPieSeries();
681711

682712
for(uint i=0;i<vals.size();++i)
683713
if( _masked_entries.find(_source->displayName(i).toStdString()) == _masked_entries.end() )
684714
{
685715
QtCharts::QPieSlice *slice = pieSeries->append(_source->legend(i,vals[i],false),vals[i]);
686-
slice->setLabelVisible(true);
716+
717+
slice->setColor( getColor(_source->displayName(i).toStdString()) );
718+
slice->setLabelVisible(vals[i] > 0.05*max_val);
687719
}
688720

689721
c->resize(_rec.width(),_rec.height());
@@ -874,6 +906,10 @@ void RSGraphWidget::mouseMoveEvent(QMouseEvent *e)
874906
{
875907
if(_mousePressed)
876908
std::cerr << "e->x() = " << e->x() << std::endl;
909+
910+
setSliceProportion(e->x() / (float)width());
911+
updateIfPossible();
912+
877913
QFrame::mouseMoveEvent(e);
878914
}
879915
void RSGraphWidget::mouseReleaseEvent(QMouseEvent *e)

retroshare-gui/src/gui/common/RSGraphWidget.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ class RSGraphSource: public QObject
114114

115115
void setDigits(int d) { _digits = d ;}
116116

117+
// returns the total time of available data in ms
118+
qint64 totalCollectedTime() const { return getTime() ; }
119+
117120
protected slots:
118121
// Calls the internal source for a new data points; called by the timer. You might want to overload this
119122
// if the collection system needs it. Otherwise, the default method will call getValues()
@@ -181,7 +184,7 @@ class RSGraphWidget: public QFrame
181184
void setSource(RSGraphSource *gs) ;
182185
void setTimeScale(float pixels_per_second) ;
183186
void setViewMode(ViewMode m) ;
184-
void setSliceProportion(float f) ; // float between 0 and 1. 0 means newest 1 means oldest.
187+
void setSliceProportion(float f) { _slice_proportion = std::max(0.0f,std::min(f,1.0f)); } ; // float between 0 and 1. 0 means newest 1 means oldest.
185188

186189
/** Add data points. */
187190
//void addPoints(qreal rsDHT, qreal allDHT);
@@ -265,8 +268,9 @@ protected slots:
265268
std::set<std::string> _masked_entries ;
266269

267270
qreal _time_scale ; // horizontal scale in pixels per sec.
268-
qreal _time_filter ; // time filter. Goes from 0 to infinity. Will be converted into 1-1/(1+f)
269-
float _linewidthscale ;
271+
qreal _time_filter ; // time filter. Goes from 0 to infinity. Will be converted into 1-1/(1+f)
272+
float _linewidthscale ;
273+
float _slice_proportion; // part of the recorded data tht is averaged for pie charts. Goes between 0 (most recent) and 1 (oldest)
270274

271275
/** Show the respective lines and counters. */
272276
//bool _showRSDHT;

retroshare-gui/src/gui/statistics/BWGraph.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
void BWGraphSource::update()
3131
{
32-
#ifndef BWGRAPH_DEBUG
32+
#ifdef BWGRAPH_DEBUG
3333
std::cerr << "Updating BW graphsource..." << std::endl;
3434
#endif
3535

@@ -44,7 +44,7 @@ void BWGraphSource::update()
4444
auto& t = tmap[PeerSrvSubsrv(c)];
4545
t.cumulated_size += c.size;
4646
t.cumulated_count += c.count;
47-
#ifndef BWGRAPH_DEBUG
47+
#ifdef BWGRAPH_DEBUG
4848
std::cerr << "Pushing " << c.TS << " " << c.peer_id << " " << c.service_id << " " << (int)c.service_sub_id << " into cumulated map" << std::endl;
4949
#endif
5050
}
@@ -456,8 +456,6 @@ void BWGraphSource::convertTrafficClueToValues(const std::list<RSTrafficClueExt>
456456
total += *it;
457457

458458
vals[QString("Total").toStdString()] = select_value(total);
459-
std::cerr << "Total is " << total << std::endl;
460-
std::cerr << "Value is " << select_value(total) << std::endl;
461459
}
462460
break ;
463461
}
@@ -648,7 +646,6 @@ void BWGraphSource::setDirection(int dir)
648646

649647
void BWGraphSource::setTiming(int t)
650648
{
651-
std::cerr << "BWGraphSource: updating" << std::endl;
652649
if(t == _current_timing)
653650
return;
654651

@@ -657,7 +654,7 @@ void BWGraphSource::setTiming(int t)
657654
}
658655
void BWGraphSource::recomputeCurrentCurves()
659656
{
660-
#ifndef BWGRAPH_DEBUG
657+
#ifdef BWGRAPH_DEBUG
661658
std::cerr << "BWGraphSource: recomputing current curves." << std::endl;
662659
#endif
663660

@@ -708,7 +705,6 @@ BWGraph::BWGraph(QWidget *parent) : RSGraphWidget(parent)
708705
{
709706
_local_source = new BWGraphSource() ;
710707

711-
std::cerr << "creaitng new BWGraph Source " << (void*)_local_source << std::endl;
712708
_local_source->setCollectionTimeLimit(30*60*1000) ; // 30 mins
713709
_local_source->setCollectionTimePeriod(1000) ; // collect every second
714710
_local_source->setDigits(2) ;

retroshare-gui/src/gui/statistics/BandwidthStatsWidget.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ BandwidthStatsWidget::BandwidthStatsWidget(QWidget *parent)
4545
ui.service_CB->addItem(tr("All")) ;
4646

4747
ui.data_CB->addItem(tr("history (curves)")) ;
48-
ui.data_CB->addItem(tr("latest (pie)")) ;
48+
ui.data_CB->addItem(tr("last 5 secs. (pie)")) ;
4949

5050
ui.timing_CB->addItem(tr("real time")) ;
5151
ui.timing_CB->addItem(tr("cumulated")) ;
@@ -281,7 +281,6 @@ void BandwidthStatsWidget::updateDataSelection(int n)
281281

282282
void BandwidthStatsWidget::updateTimingSelection(int n)
283283
{
284-
std::cerr << "updating timing to " << n << " !" << std::endl;
285284
if(n==0)
286285
{
287286
ui.bwgraph_BW->setTiming(BWGraphSource::TIMING_INSTANT) ;

0 commit comments

Comments
 (0)