本文整理汇总了C++中Stat::add方法的典型用法代码示例。如果您正苦于以下问题:C++ Stat::add方法的具体用法?C++ Stat::add怎么用?C++ Stat::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stat
的用法示例。
在下文中一共展示了Stat::add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read
virtual bool read(ConnectionReader& connection) {
double now = Time::now();
Bottle b;
bool ok = b.read(connection);
if (ok) {
mutex.wait();
ct++;
if (ct>1) {
double dt = now - lastTime;
period.add(dt);
}
lastTime = now;
printf("Period is %g +/- %g (%d)\n",
period.mean(),
period.deviation(),
ct);
mutex.post();
}
return ok;
}
示例2: paintEvent
void Graph::paintEvent(QPaintEvent *e)
{
VtlWidget::paintEvent(e);
QPainter p(this);
Interval iv = currentInterval();
p.setTransform(wtr);
if(!noScale)
{
p.setPen(cText);
QRect rs(0, topScale ? h:-lh, w, lh);
p.fillRect(rs, cScale);
drawTextEx(p, rs, Qt::AlignLeft|Qt::AlignVCenter,
QDateTime::fromTime_t(iv.t1).toString(timeFormat), reverse, 1);
drawTextEx(p, rs, Qt::AlignRight|Qt::AlignVCenter,
QDateTime::fromTime_t(iv.t2).toString(timeFormat), reverse, 1);
}
p.fillRect(0, 0, w, h, cBack);
p.setPen(cGrid);
for(int i = 0; i <= nTimeLines; i++) { int x = i*w/nTimeLines; p.drawLine(x, 0, x, h); }
for(int i = 0; i <= nValLines; i++) { int y = i*h/nValLines; p.drawLine(0, y, w, y); }
int scaleX = w + sh + 1;
int *curScaleWidth = scaleWidth.begin();
QRect rScales(scaleX, 0, scalesWidth, h);
p.fillRect(rScales, cScale);
p.setClipRect(QRectF(-1, -1, w + 2 + sh, h + 2));
for(QList<Plot>::iterator plot = plots.begin(); plot != plots.end(); ++plot)
{
if(!plot->sourcer()) continue;
const RingBuf<Stat> &st = stats[plot->sourcer()];
Stat total;
for(RingBuf<Stat>::citerator s = st.begin(); s != st.end(); ++s) total.add(*s);
//int pc = plot->precission();
float s1 = plot->minScale(), s2 = plot->maxScale(), ds = s2 - s1;
if(plot->autoScale())
{
float as1 = total.min, as2 = total.max, ads = as2 - as1;
if(ads)
{
ds *= 0.01f*plot->autoScalePercent();
if(ads < ds)
{
float as = 0.5*(as1 + as2), k = ds/ads;
as1 = as + k*(as1 - as);
as2 = as + k*(as2 - as);
}
//float t = pow(10, pc - 2);
s1 = qMax(s1, floorf(/*t*/as1)/*t*/);
s2 = qMin(s2, ceilf(/*t*/as2)/*t*/);
ds = s2 - s1;
}
}
if(ds) switch(md)
{
case Average:
{
QVector<QPointF> points;
int x = 0;
float y = NAN;
p.setPen(plot->color);
for(RingBuf<Stat>::citerator s = st.begin(); s != st.end(); ++s, ++x)
{
if(s->n)
{
if(y == y) points << QPointF(x, y); else points.clear();
y = (h - 1)*(s->sum/s->n - s1)/ds;
points << QPointF(x, y);
}
else if(s != st.end() - 1)
{
p.drawPolyline(points);
y = NAN;
}
}
if(plot->sourcer()->getReliability() == 1)
{
y = (h - 1)*(plot->sourcer()->value() - s1)/ds;
points << QPointF(w, y);
p.setBrush(plot->color);
p.drawPolygon(QPolygonF() << QPointF(w, y) <<
QPointF(w + sh, y + 2) << QPointF(w + sh, y - 2));
}
p.drawPolyline(points);
}
break;
case MinMax:
{
QVector<QPointF> lines;
int x = 0;
float y1 = NAN, y2 = NAN;
p.setPen(plot->color);
for(RingBuf<Stat>::citerator s = st.begin(); s != st.end(); ++s, ++x)
{
if(s->n)
//.........这里部分代码省略.........