Skip to content

Commit 5c68c50

Browse files
committed
saving current work
1 parent 6eb0762 commit 5c68c50

3 files changed

Lines changed: 65 additions & 23 deletions

File tree

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

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,48 @@ QString RSGraphSource::displayValue(float v) const
107107
return QString::number(v,'f',_digits) + " " + unitName() ;
108108
}
109109

110+
void RSGraphSource::getSlicedValues(uint min_secs_ago,uint max_secs_ago,std::vector<float>& vals) const
111+
{
112+
vals.clear();
113+
uint64_t max_ts = max_secs_ago*1000; // in _points the TS are w.r.t. now (in reverse) and in ms.
114+
uint64_t min_ts = min_secs_ago*1000;
115+
116+
std::cerr << "Collecting data between ts = " << min_ts << " and " << max_ts << std::endl;
117+
std::vector<std::pair<ZeroInitFloat,ZeroInitInt>> collected_vals;
118+
119+
for(const auto& lst:_points)
120+
{
121+
collected_vals.push_back(std::make_pair(0,0)); // init so that the value is mentionned in the list.
122+
auto& v(collected_vals.back());
123+
124+
std::cerr << " points string: \"" << lst.first << "\"" << std::endl;
125+
126+
for(const auto& p:lst.second)
127+
{
128+
if((uint64_t)p.first >= min_ts && (uint64_t)p.first <= max_ts)
129+
{
130+
v.first.v += p.second;
131+
v.second.v++;
132+
133+
std::cerr << " TS = " << p.first ;
134+
std::cerr << " data \"" << lst.first << "\": Found ts = " << p.first << ": adding." << std::endl;
135+
}
136+
}
137+
}
138+
139+
// now average values when multiple values have been collected.
140+
141+
std::cerr << "Computed values: " << collected_vals.size() << std::endl;
142+
143+
for(uint i=0;i<collected_vals.size();++i)
144+
{
145+
const auto& v(collected_vals[i]);
146+
147+
vals.push_back((v.second.v > 0)?(v.first.v/v.second.v):0.0);
148+
std::cerr << " \"" << displayName(i).toStdString() << "\" " << vals.back() << " (" << v.second.v << ")" << std::endl;
149+
}
150+
}
151+
110152
void RSGraphSource::getCumulatedValues(std::vector<float>& vals) const
111153
{
112154
for(std::map<std::string,ZeroInitFloat>::const_iterator it = _totals.begin();it!=_totals.end();++it)
@@ -627,25 +669,17 @@ void RSGraphWidget::paintTotals()
627669
axisY->setLabelFormat("%.1f");
628670
c->addAxis(axisY, Qt::AlignLeft);
629671

630-
std::vector<float> vals,tmp_vals;
631-
_source->getCumulatedValues(tmp_vals);
632-
633-
for(int i=0;i<_source->n_values();++i)
634-
if( _masked_entries.find(_source->displayName(i).toStdString()) == _masked_entries.end() )
635-
vals.push_back(tmp_vals[i]);
636-
637-
float total = 0.0;
638-
for(auto v:vals) total += v;
639-
640-
if(total != 0.0)
641-
for(auto& v:vals) v/=total;
672+
std::vector<float> vals;
673+
_source->getSlicedValues(0,5,vals);
642674

643675
auto pieSeries = new QtCharts::QPieSeries();
676+
644677
for(uint i=0;i<vals.size();++i)
645-
{
646-
QtCharts::QPieSlice *slice = pieSeries->append(_source->legend(i,vals[i],false),vals[i]);
647-
slice->setLabelVisible(true);
648-
}
678+
if( _masked_entries.find(_source->displayName(i).toStdString()) == _masked_entries.end() )
679+
{
680+
QtCharts::QPieSlice *slice = pieSeries->append(_source->legend(i,vals[i],false),vals[i]);
681+
slice->setLabelVisible(true);
682+
}
649683

650684
c->resize(_rec.width(),_rec.height());
651685
c->addSeries(pieSeries);

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,20 @@
4444
#define RSDHT_COLOR Qt::magenta
4545
#define ALLDHT_COLOR Qt::yellow
4646

47-
struct ZeroInitFloat
47+
template<typename T>
48+
struct t_ZeroInitVal
4849
{
49-
ZeroInitFloat() { v=0; }
50-
ZeroInitFloat(float f) { v=f; }
50+
t_ZeroInitVal() { v=0; }
51+
t_ZeroInitVal(T f) { v=f; }
5152

52-
float operator()() const { return v ; }
53-
float& operator()() { return v ; }
53+
T operator()() const { return v ; }
54+
T& operator()() { return v ; }
5455

55-
float v ;
56+
T& operator+=(const T& t) { v+=t.v; return *this; }
57+
T v ;
5658
};
59+
typedef t_ZeroInitVal<float> ZeroInitFloat;
60+
typedef t_ZeroInitVal<int> ZeroInitInt;
5761

5862
// This class provides a source value that the graph can retrieve on demand.
5963
// In order to use your own source, derive from RSGraphSource and overload the value() method.
@@ -86,6 +90,10 @@ class RSGraphSource: public QObject
8690
// return the vector of cumulated values up to date
8791
virtual void getCumulatedValues(std::vector<float>& vals) const;
8892

93+
// returns the vector of latest values with time stamp within the given ts. The returned vector
94+
// always has the size of n_values(), but some of the returned values may be zero (e.g. when data is missing).
95+
virtual void getSlicedValues(uint min_secs_ago,uint max_secs_ago,std::vector<float>& vals) const;
96+
8997
// returns what to display in the legend. Derive this to show additional info.
9098
virtual QString legend(int i, float v, bool show_value=true) const ;
9199

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
</widget>
157157
</item>
158158
<item>
159-
<widget class="QComboBox" name="data_CB"/>
159+
<widget class="RSComboBox" name="data_CB"/>
160160
</item>
161161
<item>
162162
<widget class="QCheckBox" name="logScale_CB">

0 commit comments

Comments
 (0)