Skip to content

Commit

Permalink
Have xy model support var map units
Browse files Browse the repository at this point in the history
  • Loading branch information
keithvetter committed Jan 29, 2025
1 parent 73b74f2 commit 2ca95e3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
25 changes: 25 additions & 0 deletions koviz/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ using namespace std;
#include "libkoviz/trick_types.h"
#include "libkoviz/session.h"
#include "libkoviz/versionnumber.h"
#include "libkoviz/mapvalue.h"

QStandardItemModel* createVarsModel(Runs* runs);
bool writeTrk(const QString& ftrk, const QString &timeName,
Expand Down Expand Up @@ -430,6 +431,30 @@ int main(int argc, char *argv[])
QStringList timeNames = getTimeNames(timeName);
timeName = timeNames.at(0);


// Check to ensure time isn't scaled or biased via the map
foreach (QString key, varMap.keys() ) {
foreach (QString val, varMap.value(key)) {
MapValue mapval(val);
foreach ( timeName, timeNames ) {
if ( mapval.name() == timeName ) {
if ( mapval.bias() != 0.0 ) {
fprintf(stderr, "koviz [error]: var map is attempting "
"to bias time. Koviz doesn't not "
"support this.\n");
exit(-1);
}
if ( mapval.scale() != 1.0 ) {
fprintf(stderr, "koviz [error]: var map is attempting "
"to scale time. Koviz doesn't not "
"support this.\n");
exit(-1);
}
}
}
}
}

// Exclude and Filter patterns
QString excludePattern = opts.excludePattern;
if ( excludePattern.isEmpty() && session ) {
Expand Down
28 changes: 27 additions & 1 deletion libkoviz/datamodel_xy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

XYModel::XYModel(const QStringList& timeNames,
double timeMatchTolerance,
const QHash<QString,QStringList>& varMap,
DataModel *xModel, const QString& xName,
DataModel *yModel, const QString& yName,
QObject *parent) :
DataModel(timeNames, QString(), QString(), parent),
_timeNames(timeNames),
_timeMatchTolerance(timeMatchTolerance),
_varMap(varMap),
_xModel(xModel),_xName(xName),
_yModel(yModel),_yName(yName),
_nrows(0), _ncols(3), _iteratorTimeIndex(0), _data(0)
Expand Down Expand Up @@ -38,7 +40,7 @@ void XYModel::_init()
_yParam->setUnit(_yModel->param(ycol)->unit());

int xTimeCol = -1;
_tParam = new Parameter;
_tParam = new Parameter; // _tParam derived from xModel
bool isXTimeFound = false;
foreach (QString timeName, _timeNames) {
int ncols = _xModel->columnCount();
Expand All @@ -60,6 +62,18 @@ void XYModel::_init()
fprintf(stderr, "koviz [error]: Could not find associated time for "
"x parameter \"%s\"\n", _xName.toLatin1().constData());
}
foreach (QString key, _varMap.keys() ) {
foreach (QString val, _varMap.value(key)) {
MapValue mapval(val);
if ( mapval.name() == _tParam->name() ) {
// Note: mapval.scale/bias not used/supported for time
if ( _tParam->unit() == "--" && !mapval.unit().isEmpty() ) {
// Override time unit with map unit
_tParam->setUnit(mapval.unit());
}
}
}
}

int yTimeCol = -1;
QString yTimeName;
Expand All @@ -85,6 +99,18 @@ void XYModel::_init()
fprintf(stderr, "koviz [error]: Could not find associated time for "
"y parameter \"%s\"\n", _yName.toLatin1().constData());
}
foreach (QString key, _varMap.keys() ) {
foreach (QString val, _varMap.value(key)) {
MapValue mapval(val);
if ( mapval.name() == yTimeName ) {
// Note: mapval.scale/bias not used/supported for time
if ( yTimeUnit == "--" && !mapval.unit().isEmpty() ) {
// Override time unit with map unit
yTimeUnit = mapval.unit();
}
}
}
}

_iteratorTimeIndex = new XYModelIterator(0,this,0,1,2);

Expand Down
3 changes: 3 additions & 0 deletions libkoviz/datamodel_xy.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "datamodel.h"
#include "parameter.h"
#include "unit.h"
#include "mapvalue.h"

class XYModel;
class XYModelIterator;
Expand All @@ -29,6 +30,7 @@ class XYModel : public DataModel

explicit XYModel(const QStringList &timeNames,
double timeMatchTolerance,
const QHash<QString,QStringList>& varMap,
DataModel *xModel, const QString &xName,
DataModel *yModel, const QString &yName,
QObject *parent = 0);
Expand All @@ -50,6 +52,7 @@ class XYModel : public DataModel

QStringList _timeNames;
double _timeMatchTolerance;
const QHash<QString,QStringList> _varMap;
DataModel* _xModel;
const QString _xName;
DataModel* _yModel;
Expand Down
2 changes: 1 addition & 1 deletion libkoviz/runs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ CurveModel *Runs::curveModel(int row,
const Parameter* xParam = xModel->param(xcol);
int ycol = _paramColumn(yModel,yName);
const Parameter* yParam = yModel->param(ycol);
model = new XYModel(_timeNames,_timeMatchTolerance,
model = new XYModel(_timeNames,_timeMatchTolerance, _varMap,
xModel,xParam->name(),
yModel,yParam->name());
_xyModels.append(model);
Expand Down

0 comments on commit 2ca95e3

Please sign in to comment.