Skip to content

Commit 513900e

Browse files
committed
Added blocking of run search button while streaming data.
1 parent bbc9ae9 commit 513900e

File tree

6 files changed

+55
-34
lines changed

6 files changed

+55
-34
lines changed

api/api/resources.py

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import codecs
1313
from bson.json_util import dumps
1414
from bson.objectid import ObjectId
15-
15+
import sys
1616
import logging
1717
logger = logging.getLogger('emo')
1818

@@ -638,7 +638,7 @@ def _create_obj(self, req):
638638
return ret_obj
639639

640640
def obj_create(self, bundle, **kwargs):
641-
return self.obj_update(bundle, kwargs)
641+
return self.obj_update(bundle)
642642

643643

644644

@@ -658,28 +658,38 @@ def obj_update(self, bundle, **kwargs):
658658
elif 'name' in request and 'detector' in request:
659659
searchDict['name'] = request['name']
660660
searchDict['detector'] = request['detector']
661+
else:
662+
doc = self._default(
663+
"ERROR",
664+
"Bad request. You must define a query of either id, number, or name/detector."
665+
)
666+
bundle.obj = rundoc(initial=doc)
667+
bundle = self.full_hydrate(bundle)
668+
return bundle.obj
661669

662670
# We REQUIRE the following format
663671
# {
664-
# "qname": a unique name for this check
672+
# "checkname": a unique name for this check
665673
# "version": the version info for this check
666674
# "checks": [] a list of string/bool pairs i.e. {"deadtime": true}
667675
# "extracted": a dictionary of any format of size < 100kB
668676
# }
669677

670678

671679
updateDict = {}
672-
if ( 'qname' not in request or 'checks' not in request
680+
if ( 'checkname' not in request or 'checks' not in request
673681
or 'version' not in request):
674682
doc = self._default(
675-
"ERROR",
676-
"Bad request. Require status, host, location, and type"
677-
)
683+
"ERROR",
684+
"Bad request. Require name, checks, and version."
685+
)
678686
bundle.obj = rundoc(initial=doc)
679687
bundle = self.full_hydrate(bundle)
680688
return bundle.obj
681689

682-
updateDict['qname'] = request['qname']
690+
updateDict['name'] = request['checkname']
691+
updateDict['user'] = bundle.request.user.username
692+
updateDict['date'] = datetime.datetime.now()
683693
updateDict['checks'] = request['checks']
684694
updateDict['version'] = request['version']
685695

@@ -696,46 +706,43 @@ def obj_update(self, bundle, **kwargs):
696706
updateDict['extracted'] = request['extracted']
697707

698708
# Enforce string/bool types for checks array
699-
for key, value in updateDict['checks']:
709+
for key, value in updateDict['checks'].items():
700710
extre = "test"
701-
if type(key) != type(extre) or type(value) != type(True):
702-
pass
703-
elif request['status'] == 'processed':
704-
if 'pax_version' not in request:
705-
return {"number": doc['number'],
706-
"ERROR": "pax_version must be provided for processed data"}
707-
updateDict['pax_version'] = request['pax_version']
711+
if type(key) != type(extre) or type(value) != type(True):
712+
doc = self._default(
713+
"ERROR",
714+
"Bad request. Checks field must be string/bool pairs."
715+
)
716+
bundle.obj = rundoc(initial=doc)
717+
bundle = self.full_hydrate(bundle)
718+
return bundle.obj
708719

709-
# Status needed for new entry
710-
updateDict['status'] = request['status']
711-
updateDict['creation_time'] = datetime.datetime.utcnow(),
712720

713-
# Now add a new entry
721+
714722
res = self._db()[settings.RUNS_DB_COLLECTION].update_one(
715723
searchDict,
716-
{"$push": {"data": updateDict}})
724+
{"$set": {"quality."+str(request['checkname']): updateDict}})
717725
doc = self._default(
718726
"Success",
719727
"Document updated",
720728
res
721-
)
729+
)
722730
bundle.obj = rundoc(initial=doc)
723731
bundle = self.full_hydrate(bundle)
724-
725732
return rundoc(initial=doc)
726733

727734
def _default(self, message, longer, return_value):
728735
doc = {
729736
"number": -1,
730-
"_id": -1,
737+
"_id": -1,
731738
"detector": "ret",
732-
"name": message,
739+
"name": message,
733740
"doc": {
734741
"message": longer,
735-
"success": message,
736-
"ret": return_value
737-
}
742+
"success": message,
743+
"ret": return_value
738744
}
745+
}
739746
return doc
740747

741748
def obj_delete_list(self, bundle, **kwargs):

components/emo/js/daqcontrol.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,9 @@ function GetHealth(pctarray, static_dir, update_time){
766766
image += " style='width:50px' class='center-block'>";
767767

768768
if(largest>.9)
769-
health="<strong style='color:red'>He's dead Jim</strong>";
769+
health="<strong style='color:red'>Dead</strong>";
770770
else if(largest > .7)
771-
health="<strong style='color:orange'>Danger</strong>";
771+
health="<strong style='color:orange'>Nearly dead</strong>";
772772
else if(largest > .5)
773773
health="<strong style='color:yellow;background-color:black;'>Warning</strong>";
774774
else if(largest > .2)

components/emo/js/emo_runs_streamer.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// REQUIRES SteamTable.js Mustache.js
22
function MakeRunsTable(div, url, templatediv, counterdiv){
3+
4+
// Don't allow further searches during this one
5+
$(".btn-search-runs").prop("disabled", true);
36

47
// The view describes how to make each row
58
//var template = $.trim($("#"+templatediv).html());
@@ -78,7 +81,10 @@ function MakeRunsTable(div, url, templatediv, counterdiv){
7881
"after_add": function(){
7982
//console.log(counterdiv);
8083
document.getElementById(counterdiv).innerHTML=this.data.length;
81-
}
84+
},
85+
"stop_streaming": function(){
86+
$(".btn-search-runs").prop("disabled", false);
87+
},
8288
};
8389
var options = {
8490
view: view, //View function to render table rows.

control/templates/control/controlPanelNew.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,10 @@ <h3>Muon Veto</h3>
487487
function UpdatePage( thechart ){
488488
$.getJSON(currentShifterUrl, function(data){
489489
document.superman = data['starting_user'];
490+
document.canstartruns = false;
491+
username = "{{ request.user.username }}";
492+
if(username == document.superman)
493+
document.canstartruns=true;
490494
});
491495
update_graphic(function(){
492496
DrawLogWindow( "message_panel", logUrl, function(){

emo/urls.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121
from django.contrib.auth.decorators import login_required
2222

2323
from tastypie.api import Api
24-
from api.api.resources import StatusResource, SlowControlResource, RunsResource
24+
from api.api.resources import StatusResource, SlowControlResource, RunsResource, QualityResource
2525
daqapi = Api(api_name="daq")
2626
daqapi.register(StatusResource())
2727
scapi = Api(api_name="history")
2828
scapi.register(SlowControlResource())
2929
runapi = Api(api_name="runs")
3030
runapi.register(RunsResource())
31+
qualityapi = Api(api_name="ui")
32+
qualityapi.register(QualityResource())
3133

3234
urlpatterns = [
3335

@@ -64,5 +66,7 @@
6466
url(r'^api/', include(daqapi.urls)),
6567
url(r'^sc_api/', include(scapi.urls)),
6668
url(r'^runs_api/',include(runapi.urls)),
69+
url(r'^qapi/', include(qualityapi.urls)),
6770
url(r'^online_monitor/', include('online_monitor.urls')),
71+
6872
]

runs/templates/runs/runs_new.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565
<div class="col-xs-8 col-sm-7" style="padding-left:130px;">Query:
6666
<input type="text" id="form_query"></input> </div>
6767
<div class="col-xs-1">
68-
<button class="btn btn-info btn-sm" onclick="RefreshTable()" style="height:30%;padding-left:50px;padding-right:50px;margin:8px;">Search</button>
69-
<button class="btn btn-warning btn-sm"
68+
<button class="btn btn-info btn-sm btn-search-runs" onclick="RefreshTable()" style="height:30%;padding-left:50px;padding-right:50px;margin:8px;">Search</button>
69+
<button class="btn btn-warning btn-sm btn-search-runs"
7070
onclick="ShowTransferErrors()">Show transfer errors</button>
7171

7272
</div>

0 commit comments

Comments
 (0)