Skip to content

Commit

Permalink
Removed running queue. Put that data into scan queue. Scan queue not …
Browse files Browse the repository at this point in the history
…gets history and queued scans. Shows running scan as green background
  • Loading branch information
Arthur Glowacki committed Oct 16, 2024
1 parent 8eeb775 commit e0b4a81
Show file tree
Hide file tree
Showing 10 changed files with 373 additions and 93 deletions.
201 changes: 197 additions & 4 deletions src/mvc/BlueskyComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ class BlueskyComm : public QThread
{
return ret;
}
running_plan.name = "";
running_plan.type = "";
running_plan.uuid = "";
zmq::message_t message;
QByteArray msg_arr = gen_send_mesg("queue_get", nullptr);
Expand Down Expand Up @@ -658,11 +658,29 @@ class BlueskyComm : public QThread
QJsonObject running_item = reply["running_item"].toObject();
if(running_item.contains("name"))
{
running_plan.name = running_item["name"].toString();
running_plan.type = running_item["name"].toString();
}
if(running_item.contains("args"))
{
//running_plan.name = running_item["args"].toString();
QJsonObject kwargs = running_item["args"].toObject();
for(auto pitr : kwargs.keys())
{
BlueskyParam bsp;
bsp.name = pitr;

if(kwargs.value(pitr).isDouble())
{
double p = kwargs.value(pitr).toDouble();
bsp.default_val = QString::number(p);
bsp.kind = BlueskyParamType::Numeral;
}
else if( kwargs.value(pitr).isString() )
{
bsp.default_val = kwargs.value(pitr).toString();
bsp.kind = BlueskyParamType::String;
}
running_plan.parameters[pitr] = bsp;
}
}
if(running_item.contains("kwargs"))
{
Expand All @@ -671,7 +689,18 @@ class BlueskyComm : public QThread
{
BlueskyParam bsp;
bsp.name = pitr;
bsp.default_val = kwargs[pitr].toString();

if(kwargs.value(pitr).isDouble())
{
double p = kwargs.value(pitr).toDouble();
bsp.default_val = QString::number(p);
bsp.kind = BlueskyParamType::Numeral;
}
else if( kwargs.value(pitr).isString() )
{
bsp.default_val = kwargs.value(pitr).toString();
bsp.kind = BlueskyParamType::String;
}
running_plan.parameters[pitr] = bsp;
}
}
Expand All @@ -683,6 +712,14 @@ class BlueskyComm : public QThread
{
running_plan.uuid = running_item["item_uid"].toString();
}
if(running_item.contains("properties"))
{
QJsonObject props = running_item["properties"].toObject();
if(props.contains("time_start"))
{
running_plan.result.time_start = props["time_start"].toDouble();
}
}
}
/*
if(reply.contains("plan_queue_uid"))
Expand All @@ -695,6 +732,162 @@ class BlueskyComm : public QThread

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

bool get_scan_history(QString &msg, std::vector<BlueskyPlan> &finished_plans)
{
bool ret = false;
if(_zmq_comm_socket == nullptr)
{
return ret;
}
zmq::message_t message;
QByteArray msg_arr = gen_send_mesg("history_get", nullptr);
_zmq_comm_socket->send(msg_arr.data(), msg_arr.length());

_zmq_comm_socket->recv(&message);

QJsonObject reply = QJsonDocument::fromJson(QString::fromUtf8((char*)message.data(), message.size()).toUtf8()).object();
if(reply.contains("success"))
{
QString strReply = reply["success"].toString();
if(strReply.length() > 0)
{
if(strReply == "true")
{
ret = true;
}
}
else
{
ret = reply["success"].toBool();
}
}
if(reply.contains("items"))
{
/*
{'name': 'count',
'args': [['det1', 'det2']],
'kwargs': {'num': 10, 'delay': 1},
'item_type': 'plan',
'user': 'qserver-cli',
'user_group': 'primary',
'item_uid': 'f66d959f-12e2-43a5-a67d-01b3d40b4f43'}
*/
finished_plans.clear();
QJsonArray items = reply["items"].toArray();
for( auto itr2 : items)
{
BlueskyPlan plan;
QJsonObject param = itr2.toObject();
if(param.contains("name"))
{
plan.type = param["name"].toString();
}
if(param.contains("args"))
{
QJsonObject kwargs = param["args"].toObject();
for(auto pitr : kwargs.keys())
{
BlueskyParam bsp;
bsp.name = pitr;
if(kwargs.value(pitr).isDouble())
{
double p = kwargs.value(pitr).toDouble();
bsp.default_val = QString::number(p);
}
else if( kwargs.value(pitr).isString() )
{
bsp.default_val = kwargs.value(pitr).toString();
}
plan.parameters[pitr] = bsp;
}
}
if(param.contains("kwargs"))
{
QJsonObject kwargs = param["kwargs"].toObject();
for(auto pitr : kwargs.keys())
{
BlueskyParam bsp;
bsp.name = pitr;

if(kwargs.value(pitr).isDouble())
{
double p = kwargs.value(pitr).toDouble();
bsp.default_val = QString::number(p);
bsp.kind = BlueskyParamType::Numeral;
}
else if( kwargs.value(pitr).isString() )
{
bsp.default_val = kwargs.value(pitr).toString();
bsp.kind = BlueskyParamType::String;
}
plan.parameters[pitr] = bsp;
}
}
if(param.contains("result"))
{
/*
{'exit_status': 'completed',
'run_uids': ['ab6e2ebc-effb-4385-8988-fff128e592c1'],
'scan_ids': [5],
'time_start': 1729088124.896845,
'time_stop': 1729088129.916682,
'msg': '',
'traceback': ''}}],
*/
QJsonObject result = param["result"].toObject();
if(result.contains("exit_status"))
{
plan.result.exit_status = result["exit_status"].toString();
}
if(result.contains("msg"))
{
plan.result.msg = result["msg"].toString();
}
if(result.contains("traceback"))
{
plan.result.traceback = result["traceback"].toString();
}
if(result.contains("time_start"))
{
plan.result.time_start = result["time_start"].toDouble();
}
if(result.contains("time_stop"))
{
plan.result.time_stop = result["time_stop"].toDouble();
}
if(result.contains("run_uids"))
{
QJsonArray runs = result["run_uids"].toArray();
if(runs.size() > 0)
{
plan.result.run_uids = runs.at(0).toString();
}
}
}
if(param.contains("user"))
{
plan.user = param["user"].toString();
}
if(param.contains("meta"))
{
QJsonObject meta = param["meta"].toObject();
if(meta.contains("name"))
{
plan.name = meta["name"].toString();
}
}
if(param.contains("item_uid"))
{
plan.uuid = param["item_uid"].toString();
}
finished_plans.push_back(plan);
}
}
return ret;
}

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

public slots:
void run() override
{
Expand Down
19 changes: 19 additions & 0 deletions src/mvc/BlueskyPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@

enum class BlueskyParamType { Numeral = 1, String = 3 };

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

struct BlueskyResult
{
BlueskyResult()
{
time_start = 0.0;
time_stop = 0.0;
msg = "";
}
QString exit_status;
QString run_uids;
// 'scan_ids': [2],
double time_start;
double time_stop;
QString msg;
QString traceback;
};

//---------------------------------------------------------------------------
struct BlueskyParam
Expand Down Expand Up @@ -41,6 +59,7 @@ struct BlueskyPlan
QString description;
QString module;
std::unordered_map<QString, BlueskyParam> parameters;
BlueskyResult result;
QString uuid;
QString user;
};
Expand Down
22 changes: 15 additions & 7 deletions src/mvc/LiveMapsElementsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ void LiveMapsElementsWidget::createLayout()

_vlm_widget = new VLM_Widget();
_vlm_widget->setAvailScans(&_avail_scans);
connect(_vlm_widget, &VLM_Widget::onScanUpdated, this, &LiveMapsElementsWidget::queueScan);
connect(_vlm_widget, &VLM_Widget::onScanUpdated, this, &LiveMapsElementsWidget::callQueueScan);

_scan_queue_widget = new ScanQueueWidget();
_scan_queue_widget->setAvailScans(&_avail_scans);
connect(_scan_queue_widget, &ScanQueueWidget::queueNeedsToBeUpdated, this, &LiveMapsElementsWidget::getQueuedScans);
connect(_scan_queue_widget, &ScanQueueWidget::onOpenEnv, this, &LiveMapsElementsWidget::callOpenEnv);
connect(_scan_queue_widget, &ScanQueueWidget::onCloseEnv, this, &LiveMapsElementsWidget::callCloseEnv);
Expand All @@ -140,6 +141,7 @@ void LiveMapsElementsWidget::createLayout()
connect(_scan_queue_widget, &ScanQueueWidget::onMoveScanDown, this, &LiveMapsElementsWidget::callMoveScanDown);
connect(_scan_queue_widget, &ScanQueueWidget::onRemoveScan, this, &LiveMapsElementsWidget::callRemoveScan);
connect(_scan_queue_widget, &ScanQueueWidget::onPlanChanged, this, &LiveMapsElementsWidget::callUpdatePlan);
connect(_scan_queue_widget, &ScanQueueWidget::onAddScan, this, &LiveMapsElementsWidget::callQueueScan);

_tab_widget = new QTabWidget();
_tab_widget->addTab(_mapsElementsWidget, "Counts");
Expand Down Expand Up @@ -301,7 +303,11 @@ void LiveMapsElementsWidget::updateScansAvailable()
{
_scan_queue_widget->newDataArrived( msg );
}

else
{
_scan_queue_widget->setAvailScans(&_avail_scans);
_vlm_widget->setAvailScans(&_avail_scans);
}
}

//---------------------------------------------------------------------------
Expand All @@ -313,14 +319,16 @@ void LiveMapsElementsWidget::getQueuedScans()
{
updateIp();
}
if (false == _qserverComm->get_queued_scans(msg, _queued_scans, _running_scan))
if (false == _qserverComm->get_scan_history(msg, _finished_scans))
{
_scan_queue_widget->newDataArrived( msg );
}
else

if (false == _qserverComm->get_queued_scans(msg, _queued_scans, _running_scan))
{
_scan_queue_widget->updateQueuedItems(_queued_scans, _running_scan);
_scan_queue_widget->newDataArrived( msg );
}
_scan_queue_widget->updateQueuedItems(_finished_scans, _queued_scans, _running_scan);
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -409,7 +417,7 @@ void LiveMapsElementsWidget::callStopQueue()

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

void LiveMapsElementsWidget::queueScan(const BlueskyPlan& plan)
void LiveMapsElementsWidget::callQueueScan(const BlueskyPlan& plan)
{
QString msg;
if(_qserverComm == nullptr)
Expand Down Expand Up @@ -515,4 +523,4 @@ void LiveMapsElementsWidget::callUpdatePlan(const BlueskyPlan& plan)
getQueuedScans();
}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
4 changes: 3 additions & 1 deletion src/mvc/LiveMapsElementsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public slots:

void callUpdatePlan(const BlueskyPlan& plan);

void queueScan(const BlueskyPlan& plan);
void callQueueScan(const BlueskyPlan& plan);

protected:

Expand Down Expand Up @@ -116,6 +116,8 @@ public slots:

std::vector<BlueskyPlan> _queued_scans;

std::vector<BlueskyPlan> _finished_scans;

BlueskyPlan _running_scan;

data_struct::Stream_Block<float>* _last_packet;
Expand Down
Loading

0 comments on commit e0b4a81

Please sign in to comment.