Skip to content

Commit 820b262

Browse files
authored
Merge pull request #48 from ISISComputingGroup/Ticket6464_make_json_bourne_more_reliable
Add default option for getting from inst_details
2 parents dfd4148 + 6e40ac2 commit 820b262

File tree

3 files changed

+81
-20
lines changed

3 files changed

+81
-20
lines changed

external_webpage/instrument_information_collator.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def collate(self):
205205
206206
"""
207207
instrument_config = InstrumentConfig(self.reader.read_config())
208+
error_statuses = []
208209

209210
try:
210211
# read blocks
@@ -214,19 +215,28 @@ def collate(self):
214215
json_from_dataweb_archive = self.reader.get_json_from_dataweb_archive()
215216
dataweb_blocks = self.web_page_parser.extract_blocks(json_from_dataweb_archive)
216217

218+
except Exception as e:
219+
error_string = "Failed to read block archiver"
220+
error_statuses.append(error_string)
221+
logger.error(f"{error_string}: " + str(e))
222+
blocks = {}
223+
dataweb_blocks = {}
224+
225+
try:
217226
json_from_instrument_archive = self.reader.get_json_from_instrument_archive()
218227
instrument_blocks = self.web_page_parser.extract_blocks(json_from_instrument_archive)
219228

220229
inst_pvs = format_blocks(self._get_inst_pvs(instrument_blocks))
221-
222230
except Exception as e:
223-
logger.error("Failed to read blocks: " + str(e))
224-
raise e
231+
error_string = "Failed to read instrument archiver"
232+
error_statuses.append(error_string)
233+
logger.error(f"{error_string}: " + str(e))
234+
inst_pvs = {}
225235

226236
try:
227237
set_rc_values_for_blocks(blocks, dataweb_blocks)
228238
except Exception as e:
229-
logging.error("Error in setting rc values for blocks: " + str(e))
239+
logger.error("Error in setting rc values for blocks: " + str(e))
230240

231241
# get block visibility from config
232242
for block_name, block in blocks.items():
@@ -237,4 +247,6 @@ def collate(self):
237247
return {
238248
"config_name": instrument_config.name,
239249
"groups": groups,
240-
"inst_pvs": inst_pvs}
250+
"inst_pvs": inst_pvs,
251+
"error_statuses": error_statuses
252+
}

front_end/default.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
<body>
1818
<div id = "top_bar"></div>
19+
<div id="error_status"></div>
1920
<div id="config_name"></div>
2021
<table cellpadding="30" style="width:100%">
2122
<tr>

front_end/display_blocks.js

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
var PORT = 60000;
22
var HOST = "http://dataweb.isis.rl.ac.uk"
3+
var DEFAULT_PV_VALUE = "UNKNOWN";
34

45
var instrument = getURLParameter("Instrument");
56
var nodeInstTitle = document.createElement("H2");
67
var nodeConfigTitle = document.createElement("H2");
8+
var nodeErrorStatus = document.createElement("H3");
9+
nodeErrorStatus.style.color = "RED";
710
var instrumentState;
811
var showHidden;
912
var timeout = 4000;
@@ -143,6 +146,40 @@ function refresh() {
143146
});
144147
}
145148

149+
/**
150+
* Build the error status list from the given error statuses.
151+
*/
152+
function buildErrorStatusList(errorStatuses) {
153+
nodeErrorStatusList = document.createElement("UL");
154+
for (var statusIndex in errorStatuses) {
155+
var status = errorStatuses[statusIndex];
156+
buildErrorStatusListElement(status, nodeErrorStatusList)
157+
}
158+
nodeErrorStatus.appendChild(nodeErrorStatusList);
159+
}
160+
161+
/**
162+
* Build an error status list element and add it to the node given.
163+
*/
164+
function buildErrorStatusListElement(errorStatus, nodeErrorStatusList) {
165+
nodeErrorStatusListELement = document.createElement("LI");
166+
nodeErrorStatusListELement.appendChild(document.createTextNode(errorStatus));
167+
nodeErrorStatusList.appendChild(nodeErrorStatusListELement);
168+
}
169+
170+
/**
171+
* Parses error statuses and displays them.
172+
*/
173+
function setErrorStatus(instrumentState) {
174+
clear(nodeErrorStatus);
175+
if (instrumentState.error_statuses.length > 0) {
176+
var textNode = "Problems were encountered when retrieving data from the instrument:";
177+
nodeErrorStatus.appendChild(document.createTextNode(textNode));
178+
buildErrorStatusList(instrumentState.error_statuses);
179+
document.getElementById("error_status").appendChild(nodeErrorStatus);
180+
}
181+
}
182+
146183
/**
147184
* Parses fetched instrument data into a human-readable html page.
148185
*/
@@ -170,21 +207,32 @@ function parseObject(obj) {
170207
document.getElementById("config_name").appendChild(nodeConfigTitle);
171208

172209
setVisibilityMode('block');
210+
211+
// Write error status
212+
setErrorStatus(instrumentState);
173213
}
174214

175215

176216
function clearBox(elementID){
177217
document.getElementById(elementID).innerHTML = "";
178218
}
179219

220+
function get_inst_pv_value(inst_details, pv) {
221+
try {
222+
return inst_details["inst_pvs"][pv]["value"] || DEFAULT_PV_VALUE;
223+
} catch(err) {
224+
return DEFAULT_PV_VALUE;
225+
}
226+
}
227+
180228
/**
181229
* creates a Title at the top looking similar to the IBEX GUI
182230
*/
183231
function createTitle(inst_details){
184232
clearBox("top_bar");
185233
document.body.style.padding = '20px'
186234
document.getElementById("top_bar").innerHTML = "<div id = \"inst_name\"></div><table style=\"width:100%\"><tr id = table_part><th id = \"next_part\" style = \"padding: 10px; width:33%; background-color:lightgrey ; border: black 2px solid\";></th></tr></table>";
187-
runStatus = inst_details["inst_pvs"]["RUNSTATE"]["value"];
235+
runStatus = get_inst_pv_value(inst_details, "RUNSTATE");
188236

189237
colour = getColourFromRunState(runStatus);
190238

@@ -197,33 +245,33 @@ function createTitle(inst_details){
197245
blockListClass.value = "text-center";
198246
title.setAttributeNode(blockListClass);
199247
document.getElementById("inst_name").appendChild(title);
200-
addItemToTable("Title", inst_details["inst_pvs"]["TITLE"]["value"]);
201-
addItemToTable("Users", inst_details["inst_pvs"]["_USERNAME"]["value"]);
248+
addItemToTable("Title", get_inst_pv_value(inst_details, "TITLE"));
249+
addItemToTable("Users", get_inst_pv_value(inst_details, "_USERNAME"));
202250

203251
newPartOfTable();
204252
try {
205253
// after upgrade script
206-
addItemToTable(inst_details["inst_pvs"]["1:1:LABEL"]["value"], inst_details["inst_pvs"]["1:1:VALUE"]["value"]);
207-
addItemToTable(inst_details["inst_pvs"]["2:1:LABEL"]["value"], inst_details["inst_pvs"]["2:1:VALUE"]["value"]);
208-
addItemToTable(inst_details["inst_pvs"]["3:1:LABEL"]["value"], inst_details["inst_pvs"]["3:1:VALUE"]["value"]);
254+
addItemToTable(get_inst_pv_value(inst_details, "1:1:LABEL"), get_inst_pv_value(inst_details, "1:1:VALUE"));
255+
addItemToTable(get_inst_pv_value(inst_details, "2:1:LABEL"), get_inst_pv_value(inst_details, "2:1:VALUE"));
256+
addItemToTable(get_inst_pv_value(inst_details, "3:1:LABEL"), get_inst_pv_value(inst_details, "3:1:VALUE"));
209257

210258
newPartOfTable();
211259

212-
addItemToTable(inst_details["inst_pvs"]["2:2:LABEL"]["value"], inst_details["inst_pvs"]["2:2:VALUE"]["value"]);
213-
addItemToTable(inst_details["inst_pvs"]["1:2:LABEL"]["value"], inst_details["inst_pvs"]["1:2:VALUE"]["value"]);
214-
addItemToTable(inst_details["inst_pvs"]["3:2:LABEL"]["value"], inst_details["inst_pvs"]["3:2:VALUE"]["value"]);
260+
addItemToTable(get_inst_pv_value(inst_details, "2:2:LABEL"), get_inst_pv_value(inst_details, "2:2:VALUE"));
261+
addItemToTable(get_inst_pv_value(inst_details, "1:2:LABEL"), get_inst_pv_value(inst_details, "1:2:VALUE"));
262+
addItemToTable(get_inst_pv_value(inst_details, "3:2:LABEL"), get_inst_pv_value(inst_details, "3:2:VALUE"));
215263
} catch(err) {
216264
// before upgrade script
217265

218-
addItemToTable("Good / Raw Frames", inst_details["inst_pvs"]["GOODFRAMES"]["value"]+"/"+inst_details["inst_pvs"]["RAWFRAMES"]["value"]);
219-
addItemToTable("Current / Total", inst_details["inst_pvs"]["BEAMCURRENT"]["value"]+"/"+inst_details["inst_pvs"]["TOTALUAMPS"]["value"]);
220-
addItemToTable("Monitor Counts", inst_details["inst_pvs"]["MONITORCOUNTS"]["value"]);
266+
addItemToTable("Good / Raw Frames", get_inst_pv_value(inst_details, "GOODFRAMES")+"/"+get_inst_pv_value(inst_details, "RAWFRAMES"));
267+
addItemToTable("Current / Total", get_inst_pv_value(inst_details, "BEAMCURRENT")+"/"+get_inst_pv_value(inst_details, "TOTALUAMPS"));
268+
addItemToTable("Monitor Counts", get_inst_pv_value(inst_details, "MONITORCOUNTS"));
221269

222270
newPartOfTable();
223271

224-
addItemToTable("Start Time", inst_details["inst_pvs"]["STARTTIME"]["value"]);
225-
addItemToTable("Run Time", inst_details["inst_pvs"]["RUNDURATION_PD"]["value"]);
226-
addItemToTable("Period", inst_details["inst_pvs"]["PERIOD"]["value"]+"/"+inst_details["inst_pvs"]["NUMPERIODS"]["value"]);
272+
addItemToTable("Start Time", get_inst_pv_value(inst_details, "STARTTIME"));
273+
addItemToTable("Run Time", get_inst_pv_value(inst_details, "RUNDURATION_PD"));
274+
addItemToTable("Period", get_inst_pv_value(inst_details, "PERIOD")+"/"+get_inst_pv_value(inst_details, "NUMPERIODS"));
227275

228276
}
229277

0 commit comments

Comments
 (0)