@@ -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+
110152void 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);
0 commit comments