reintroduce facility to skip over outlier data due to corrupted data

This commit is contained in:
Axel Kohlmeyer
2024-08-17 21:28:56 -04:00
parent 87abcc6f0f
commit e4b9da147a

View File

@ -345,15 +345,34 @@ ChartViewer::ChartViewer(const QString &title, int _index, QWidget *parent) :
void ChartViewer::add_data(int step, double data)
{
QSettings settings;
auto updchart = settings.value("updchart", "500").toInt();
if (last_step < step) {
last_step = step;
// do not add data that deviates by more than 5 sigma from the average
// over the last 5 to 20 data items. this is a hack to work around
// getting corrupted data from lammps_get_last_thermo()
const auto &points = series->points();
const auto count = points.count();
if (count > 4) {
double ysum = 0.0;
double ysumsq = 0.0;
int first = count - 20;
if (first < 0) first = 0;
for (int i = first; i < count; ++i) {
double val = points[i].y();
ysum += val;
ysumsq += val * val;
}
const double num = count - first;
const double avg = ysum / num;
const double avgsq = ysumsq / num;
if (fabs(data - avg) > (5.0 * sqrt(avgsq - (avg * avg)))) return;
}
series->append(step, data);
if (last_update.msecsTo(QTime::currentTime()) > updchart) {
QSettings settings;
// update the chart display only after at least updchart milliseconds have passed
if (last_update.msecsTo(QTime::currentTime()) > settings.value("updchart", "500").toInt()) {
last_update = QTime::currentTime();
reset_zoom();
}