Skip to content

Commit

Permalink
Fixed issue where we converted string to numeric for bluesky plans. A…
Browse files Browse the repository at this point in the history
…dded bool delegate for True,False parameters for BlueSky
  • Loading branch information
Arthur Glowacki committed Dec 17, 2024
1 parent 37588fc commit 64a80d9
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 64 deletions.
54 changes: 32 additions & 22 deletions src/mvc/BlueskyComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ class BlueskyComm
for(auto itr: plan.parameters)
{
//logI<<itr.first.toStdString()<<" : "<<itr.second.default_val.toStdString()<<" :: "<<(int)(itr.second.kind)<< "\n";
if(itr.second.name == "detectors")
if(itr.name == "detectors")
{
QJsonArray inner_args; // need this for bluesky or it doesn't work
QStringList sarr = itr.second.default_val.split(",");
QStringList sarr = itr.default_val.split(",");
for(auto sitr : sarr)
{
inner_args.append(QJsonValue::fromVariant(sitr));
Expand All @@ -125,7 +125,7 @@ class BlueskyComm
}
//else if(itr.second.kind == BlueskyParamType::String && itr.second.default_val.length() > 0)
{
kwargs[itr.first] = itr.second.default_val;
kwargs[itr.name] = itr.default_val;
}
/*
else if(itr.second.kind == BlueskyParamType::Numeral && itr.second.default_val.length() > 0)
Expand Down Expand Up @@ -487,20 +487,21 @@ class BlueskyComm
QJsonArray params_obj = pobj["parameters"].toArray();
for( auto itr2 : params_obj)
{
BlueskyParam bsparam;
QJsonObject param = itr2.toObject();
if(param.contains("name"))
{
plans[pobj["name"].toString()].parameters[param["name"].toString()].name = param["name"].toString();
bsparam.name = param["name"].toString();
if(param.contains("default"))
{
if(param["default"].toString() != "None")
{
plans[pobj["name"].toString()].parameters[param["name"].toString()].default_val = param["default"].toString();
bsparam.default_val = param["default"].toString();
}
}
if(param.contains("description"))
{
plans[pobj["name"].toString()].parameters[param["name"].toString()].description = param["description"].toString();
bsparam.description = param["description"].toString();
}
}
if(param.contains("kind"))
Expand All @@ -512,16 +513,17 @@ class BlueskyComm
switch (tval)
{
case 1:
plans[pobj["name"].toString()].parameters[param["name"].toString()].kind = BlueskyParamType::Numeral;
break;
bsparam.kind = BlueskyParamType::Numeral;
break;
case 3:
plans[pobj["name"].toString()].parameters[param["name"].toString()].kind = BlueskyParamType::String;
break;
bsparam.kind = BlueskyParamType::String;
break;
default:
break;
break;
}
}
}
plans[pobj["name"].toString()].parameters.push_back(bsparam);
}
}
}
Expand Down Expand Up @@ -608,7 +610,7 @@ class BlueskyComm
{
bsp.default_val = kwargs.value(pitr).toString();
}
plan.parameters[pitr] = bsp;
plan.parameters.push_back(bsp);
}
}
if(param.contains("kwargs"))
Expand All @@ -618,7 +620,7 @@ class BlueskyComm
{
BlueskyParam bsp;
bsp.name = pitr;

/*
if(kwargs.value(pitr).isDouble())
{
double p = kwargs.value(pitr).toDouble();
Expand All @@ -630,7 +632,9 @@ class BlueskyComm
bsp.default_val = kwargs.value(pitr).toString();
bsp.kind = BlueskyParamType::String;
}
plan.parameters[pitr] = bsp;
*/
bsp.default_val = kwargs.value(pitr).toString();
plan.parameters.push_back(bsp);
}
}
if(param.contains("user"))
Expand Down Expand Up @@ -687,7 +691,7 @@ class BlueskyComm
{
BlueskyParam bsp;
bsp.name = pitr;

/*
if(kwargs.value(pitr).isDouble())
{
double p = kwargs.value(pitr).toDouble();
Expand All @@ -696,10 +700,12 @@ class BlueskyComm
}
else if( kwargs.value(pitr).isString() )
{
bsp.default_val = kwargs.value(pitr).toString();
c
bsp.kind = BlueskyParamType::String;
}
running_plan.parameters[pitr] = bsp;
*/
bsp.default_val = kwargs.value(pitr).toString();
running_plan.parameters.push_back(bsp);
}
}
if(running_item.contains("kwargs"))
Expand All @@ -709,7 +715,7 @@ class BlueskyComm
{
BlueskyParam bsp;
bsp.name = pitr;

/*
if(kwargs.value(pitr).isDouble())
{
double p = kwargs.value(pitr).toDouble();
Expand All @@ -721,7 +727,9 @@ class BlueskyComm
bsp.default_val = kwargs.value(pitr).toString();
bsp.kind = BlueskyParamType::String;
}
running_plan.parameters[pitr] = bsp;
*/
bsp.default_val = kwargs.value(pitr).toString();
running_plan.parameters.push_back(bsp);
}
}
if(running_item.contains("user"))
Expand Down Expand Up @@ -854,7 +862,7 @@ class BlueskyComm
{
bsp.default_val = kwargs.value(pitr).toString();
}
plan.parameters[pitr] = bsp;
plan.parameters.push_back(bsp);
}
}
if(param.contains("kwargs"))
Expand All @@ -864,7 +872,7 @@ class BlueskyComm
{
BlueskyParam bsp;
bsp.name = pitr;

/*
if(kwargs.value(pitr).isDouble())
{
double p = kwargs.value(pitr).toDouble();
Expand All @@ -876,7 +884,9 @@ class BlueskyComm
bsp.default_val = kwargs.value(pitr).toString();
bsp.kind = BlueskyParamType::String;
}
plan.parameters[pitr] = bsp;
*/
bsp.default_val = kwargs.value(pitr).toString();
plan.parameters.push_back(bsp);
}
}
if(param.contains("result"))
Expand Down
2 changes: 1 addition & 1 deletion src/mvc/BlueskyPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct BlueskyPlan
QString type;
QString description;
QString module;
std::unordered_map<QString, BlueskyParam> parameters;
std::vector<BlueskyParam> parameters;
BlueskyResult result;
QString uuid;
QString user;
Expand Down
4 changes: 2 additions & 2 deletions src/mvc/LiveMapsElementsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,15 +411,15 @@ void LiveMapsElementsWidget::saveHistory()
out << "Name,Type,";
for(auto & itr: _finished_scans.at(0).parameters)
{
out<<itr.second.name<<",";
out<<itr.name<<",";
}
out << "exit_status,time_start,time_stop,msg\r\n";
for(auto &itr: _finished_scans)
{
out<<itr.name<<","<<itr.type<<",";
for(auto & itr2: itr.parameters)
{
out<<itr2.second.default_val<<",";
out<<itr2.default_val<<",";
}
QDateTime dateTime1 = QDateTime::fromSecsSinceEpoch(itr.result.time_start, Qt::UTC);
QDateTime dateTime2 = QDateTime::fromSecsSinceEpoch(itr.result.time_stop, Qt::UTC);
Expand Down
54 changes: 32 additions & 22 deletions src/mvc/ScanQueueTableModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ class ScanQueueTableModel : public QAbstractTableModel
_headers[0] = "Type";
_last_finished_idx = 0;
}

//---------------------------------------------------------------------------

int rowCount(const QModelIndex& parent = QModelIndex()) const override
{
return _data.size();
}

//---------------------------------------------------------------------------

int columnCount(const QModelIndex& parent = QModelIndex()) const override
{
if(_data.size() > 0)
Expand Down Expand Up @@ -156,17 +160,10 @@ class ScanQueueTableModel : public QAbstractTableModel
{
return rowData.result.msg;
}

int idx = 0;
for( auto itr: rowData.parameters)
else
{
if(idx == section -1 )
{
return itr.second.default_val;
}
idx++;
return rowData.parameters.at(section-1).default_val;
}

}
else if (role == Qt::BackgroundRole)
{
Expand All @@ -179,9 +176,18 @@ class ScanQueueTableModel : public QAbstractTableModel
return QColor(Qt::darkGreen);
}
}
else if (role == Qt::EditRole)
{
if(section > 0 && section <= parms_size)
{
return rowData.parameters.at(section-1).default_val;
}
}
return QVariant();
}

//---------------------------------------------------------------------------

QVariant headerData(int section, Qt::Orientation orientation, int role) const override
{
// Check this is DisplayRole
Expand All @@ -194,7 +200,7 @@ class ScanQueueTableModel : public QAbstractTableModel
{
return _headers[section];
}
else
else if (section > 0)
{
if(_data.size() > 0)
{
Expand All @@ -217,14 +223,9 @@ class ScanQueueTableModel : public QAbstractTableModel
{
return "msg";
}
int idx = 0;
for( auto itr: rowData.parameters)
else if (parms_size > (section -1) )
{
if(idx == section -1 )
{
return itr.second.name;
}
idx++;
return rowData.parameters.at(section-1).name;
}
}
return QVariant(" ");
Expand Down Expand Up @@ -261,22 +262,29 @@ class ScanQueueTableModel : public QAbstractTableModel

//---------------------------------------------------------------------------

void setAvailScans(std::map<QString, BlueskyPlan> * avail_scans)
{
_avail_scans = avail_scans;
}

//---------------------------------------------------------------------------

void setAllData(std::vector<BlueskyPlan> &finished_plans, std::vector<BlueskyPlan> &queued_plans, BlueskyPlan &running_plan)
{
_last_finished_idx = finished_plans.size();
beginResetModel();
_data.clear();
for(auto itr : finished_plans)
{
_data.append(itr);
_data.push_back(itr);
}
if(running_plan.type.length() > 0)
{
_data.append(running_plan);
_data.push_back(running_plan);
}
for(auto itr : queued_plans)
{
_data.append(itr);
_data.push_back(itr);
}
endResetModel();
}
Expand All @@ -295,7 +303,7 @@ class ScanQueueTableModel : public QAbstractTableModel
if(idx == index.column() && value.toString().length() >0)
{
// this will be refreshed from qserver
itr.second.default_val = value.toString();
itr.default_val = value.toString();
emit planChanged(_data.at(index.row()));
return false; // return false to make sure we get this value from qserver
}
Expand All @@ -318,7 +326,9 @@ class ScanQueueTableModel : public QAbstractTableModel

private:
int _last_finished_idx;
QList<BlueskyPlan> _data;
std::vector<BlueskyPlan> _data;

std::map<QString, BlueskyPlan> *_avail_scans;

QString _headers[4];
};
Expand Down
9 changes: 9 additions & 0 deletions src/mvc/ScanQueueWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,15 @@ void ScanQueueWidget::updateQueuedItems(std::vector<BlueskyPlan> &finished_plans

//---------------------------------------------------------------------------

void ScanQueueWidget::setAvailScans(std::map<QString, BlueskyPlan> * avail_scans)
{
_avail_scans = avail_scans;
_scan_dialog.setAvailScans(avail_scans);
_scan_queue_table_model->setAvailScans(avail_scans);
}

//---------------------------------------------------------------------------

void ScanQueueWidget::newDataArrived(const QString& data)
{
//_te_qs_console->insertPlainText(data);
Expand Down
2 changes: 1 addition & 1 deletion src/mvc/ScanQueueWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ScanQueueWidget : public QWidget

void updateQueuedItems( std::vector<BlueskyPlan> &finished_plans, std::vector<BlueskyPlan> &queued_plans, BlueskyPlan &running_plan);

void setAvailScans(std::map<QString, BlueskyPlan> * avail_scans) { _avail_scans = avail_scans; _scan_dialog.setAvailScans(avail_scans);}
void setAvailScans(std::map<QString, BlueskyPlan> * avail_scans);

signals:
void queueNeedsToBeUpdated();
Expand Down
Loading

0 comments on commit 64a80d9

Please sign in to comment.