forked from tlatorre-uchicago/minard
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Standard runs #161
Open
marzece
wants to merge
22
commits into
snoplus:master
Choose a base branch
from
marzece:standard_runs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Standard runs #161
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a5d7bf7
WIP get started on standard run interface
marzece e7d20eb
get overview page for standard runs working okay
marzece 53bd774
add detail view for standard run
marzece a9ac6aa
implement updating standard runs
marzece 51f12c4
allow for trailing slash in some urls
marzece a885cbc
redo form layout and add meta-info inputs
marzece ab6bf43
change comment
marzece b56a205
add back button if standard run detail view
marzece 017dc07
minor changes
marzece 4696ffa
add link for standard runs to nav bar
marzece b61d71c
add template for SR overview (which I forgot to add to git)
marzece 4c48d46
Change page title
marzece 4e0e5d4
create new documents rather then new versions of existing ones
marzece 7d5d4e8
update timestamp for new documents
marzece 236555e
redirect to new standard run upon creation of one
marzece 25a0fe1
Add error checking for couchdb interactions
marzece b7e01d7
add some basic validation
marzece 90fc799
coerce types for new values
marzece d290e21
Only display standard runs matching orca's standard run version
marzece b8522de
remove dictionary list comprehesion for python 2.6
marzece f8eacba
move standard run password validation to couch DB
marzece 79e41e4
reimplement UI using wtforms and add validators
marzece File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import couchdb | ||
from .views import app | ||
from itertools import groupby | ||
from time import time | ||
from uuid import uuid4 | ||
from wtforms import Form, IntegerField, StringField, TextAreaField, PasswordField,\ | ||
DecimalField, BooleanField, validators | ||
|
||
def get_standard_runs(): | ||
# This number should match the version used by ORCA | ||
COUCH_DOC_VERSION = app.config["ORCA_STANDARD_RUN_VERSION"] | ||
url = "https://%s:%s@%s" % ("snoplus", app.config["COUCHDB_PASSWORD"], app.config["COUCHDB_HOSTNAME"]) | ||
couch = couchdb.Server(url) | ||
orca_db = couch['orca'] | ||
sr_view = orca_db.view("standardRuns/getStandardRunsWithVersion") | ||
# standard run keys are [doc-version, run name, run version, timestamp] | ||
# I want to groupby by run name then within that group all run versions sorted | ||
# by timestamp | ||
rows = filter(lambda x: x.key[0] == COUCH_DOC_VERSION, sr_view.rows) | ||
rows = sorted(rows, key=lambda x: x.key[1] + x.key[2]) | ||
groups = groupby(rows, lambda x: x.key[1] + x.key[2]) | ||
groups = [(x, list(y)) for x, y in groups] | ||
runs = [max(group, key=lambda x: x.key[3]) for _, group in groups] | ||
runs = sorted(runs, key=lambda x: x.key[1]) | ||
runs = [(x, list(y)) for x,y in groupby(runs, lambda x: x.key[1])] | ||
return runs | ||
|
||
def get_standard_run(uuid): | ||
url = "https://%s:%s@%s" % ("snoplus", app.config["COUCHDB_PASSWORD"], app.config["COUCHDB_HOSTNAME"]) | ||
couch = couchdb.Server(url) | ||
orca_db = couch['orca'] | ||
return orca_db.get(uuid) | ||
|
||
def update_standard_run(uuid, new_values): | ||
try: | ||
password = new_values.pop("password", None) | ||
except KeyError: | ||
raise RuntimeError("no password given") | ||
url = "https://%s:%s@%s" % (app.config["COUCH_DETECTOR_EXPERT_NAME"], | ||
password, | ||
app.config["COUCHDB_HOSTNAME"]) | ||
couch = couchdb.Server(url) | ||
try: | ||
orca_db = couch['orca'] | ||
except couchdb.http.Unauthorized: | ||
raise RuntimeError("Incorrect password given") | ||
|
||
doc = dict(orca_db.get(uuid)) | ||
for k, v in new_values.iteritems(): | ||
doc[k] = v | ||
doc["_id"] = uuid4().hex | ||
doc["time_stamp"] = time() | ||
|
||
if not doc.has_key("run_version") or not doc["run_version"]: | ||
raise RuntimeError("run_version must be present in new document") | ||
|
||
if not doc.has_key("run_type") or not doc["run_type"]: | ||
raise RuntimeError("run_type must be present in new document") | ||
|
||
doc["run_type"] = doc["run_type"].upper() | ||
doc["run_version"] = doc["run_version"].upper() | ||
|
||
# Remove revision field since we want to post a new document, not a | ||
# revision of an existing one. | ||
try: | ||
del doc["_rev"] | ||
except KeyError: | ||
pass | ||
|
||
new_uuid, _ = orca_db.save(doc) | ||
return new_uuid | ||
|
||
expected_fields = [ | ||
IntegerField("CAEN_acquisitionMode", [validators.NumberRange(min=0, max=0b111)]), | ||
IntegerField("CAEN_channelConfigMask"), | ||
IntegerField("CAEN_coincidenceLevel"), | ||
BooleanField("CAEN_countAllTriggers"), | ||
IntegerField("CAEN_customSize"), | ||
IntegerField("CAEN_dac_0", [validators.NumberRange(min=0, max=0xFFFF)]), | ||
IntegerField("CAEN_dac_1", [validators.NumberRange(min=0, max=0xFFFF)]), | ||
IntegerField("CAEN_dac_2", [validators.NumberRange(min=0, max=0xFFFF)]), | ||
IntegerField("CAEN_dac_3", [validators.NumberRange(min=0, max=0xFFFF)]), | ||
IntegerField("CAEN_dac_4", [validators.NumberRange(min=0, max=0xFFFF)]), | ||
IntegerField("CAEN_dac_5", [validators.NumberRange(min=0, max=0xFFFF)]), | ||
IntegerField("CAEN_dac_6", [validators.NumberRange(min=0, max=0xFFFF)]), | ||
IntegerField("CAEN_dac_7", [validators.NumberRange(min=0, max=0xFFFF)]), | ||
IntegerField("CAEN_enabledMask", [validators.NumberRange(min=0, max=0xFF)]), | ||
IntegerField("CAEN_eventSize"), | ||
IntegerField("CAEN_frontPanelControlMask"), | ||
BooleanField("CAEN_isCustomSize"), | ||
IntegerField("CAEN_postTriggerSetting"), | ||
IntegerField("CAEN_triggerOutMask"), | ||
IntegerField("CAEN_triggerSourceMask"), | ||
IntegerField("MTC_ESUMH_Threshold", [validators.NumberRange(min=0,max=4095)]), | ||
IntegerField("MTC_ESUML_Threshold", [validators.NumberRange(min=0,max=4095)]), | ||
IntegerField("MTC_GTMask", [validators.NumberRange(min=0, max=0x3FFFFFF)]), | ||
IntegerField("MTC_LockoutWidth", [validators.NumberRange(min=20, max=5000)]), | ||
IntegerField("MTC_N100H_Threshold", [validators.NumberRange(min=0, max=4095)]), | ||
IntegerField("MTC_N100L_Threshold", [validators.NumberRange(min=0, max=4095)]), | ||
IntegerField("MTC_N100M_Threshold", [validators.NumberRange(min=0, max=4095)]), | ||
IntegerField("MTC_N20LB_Threshold", [validators.NumberRange(min=0, max=4095)]), | ||
IntegerField("MTC_N20_Threshold", [validators.NumberRange(min=0, max=4095)]), | ||
IntegerField("MTC_OWLEH_Threshold", [validators.NumberRange(min=0, max=4095)]), | ||
IntegerField("MTC_OWLEL_Threshold", [validators.NumberRange(min=0, max=4095)]), | ||
IntegerField("MTC_OWLN_Threshold", [validators.NumberRange(min=0, max=4095)]), | ||
IntegerField("MTC_PrescaleValue", [validators.NumberRange(min=2, max=65536)]), | ||
BooleanField("MTC_PulserEnabled"), | ||
BooleanField("MTC_PulserMode"), | ||
DecimalField("MTC_PulserRate", [validators.NumberRange(min=0.04, max=390000)]), | ||
IntegerField("TUBii_CaenChannelMask", [validators.NumberRange(min=0, max=255)]), | ||
IntegerField("TUBii_CaenGainMask", [validators.NumberRange(min=0, max=255)]), | ||
IntegerField("TUBii_DGT_Bits", [validators.NumberRange(min=0, max=255)]), | ||
IntegerField("TUBii_LO_Bits", [validators.NumberRange(min=0, max=255)]), | ||
IntegerField("TUBii_MTCAMimic1_ThresholdInBits", [validators.NumberRange(min=0, max=4095)]), | ||
IntegerField("TUBii_TUBiiPGT_Rate", [validators.NumberRange(min=0)]), | ||
IntegerField("TUBii_asyncTrigMask"), | ||
IntegerField('TUBii_controlReg', [validators.NumberRange(min=0,max=255)]), | ||
IntegerField('TUBii_counterMask', [validators.NumberRange(min=0)]), | ||
IntegerField('TUBii_speakerMask', [validators.NumberRange(min=0)]), | ||
IntegerField('TUBii_syncTrigMask', [validators.NumberRange(min=0)]), | ||
IntegerField("run_type_word", [validators.NumberRange(min=0x0, max=0xFFFFFFF)]), | ||
StringField("run_version", [validators.DataRequired()]), | ||
StringField("type", [validators.DataRequired()]) | ||
] | ||
expected_fields = dict([(x.args[0], x) for x in expected_fields]) | ||
|
||
def create_form(fields): | ||
class SRSettingsForm(Form): | ||
name = StringField('Name', [validators.DataRequired()]) | ||
info = TextAreaField('Info', [validators.DataRequired()]) | ||
password = PasswordField('Password', [validators.DataRequired()]) | ||
|
||
# First create a form for the various fields in the couchDB doc | ||
for key, value in fields.iteritems(): | ||
# skip any fields that are already in the form | ||
if key.lower() in ["name", "info", "password"]: | ||
continue | ||
if expected_fields.has_key(key): | ||
field = expected_fields[key] | ||
setattr(SRSettingsForm, key, field) | ||
else: | ||
setattr(SRSettingsForm, key, StringField(key)) | ||
return SRSettingsForm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
{% extends "layout.html" %} | ||
{% block title %}Standard Run{% endblock %} | ||
{% block head %} | ||
{{ super() }} | ||
{% endblock %} | ||
{% block body %} | ||
{{ super() }} | ||
<div class="container"> | ||
{% if form %} | ||
{% if form.errors %} | ||
<ul class="errors"> | ||
{% for field_name, field_errors in form.errors|dictsort if field_errors %} | ||
{% for error in field_errors %} | ||
<li>{{ form[field_name].label }}: {{ error }}</li> | ||
{% endfor %} | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
<div class = "row"> | ||
<h2> | ||
<a href="{{url_for('standard_runs')}}"> | ||
<span class="glyphicon glyphicon-chevron-left"> </span> | ||
</a> | ||
{{ form.run_type.data }} - {{ form.run_version.data }} | ||
</h2> | ||
</div> | ||
{% if updater %} | ||
<div class = "row"> | ||
<h4> | ||
Last Updated By: {{ updater }} | ||
</h4> | ||
</div> | ||
{% endif %} | ||
{% if comments %} | ||
<div class="row"> | ||
<p> Notes: {{ comments }} </p> | ||
</div> | ||
{% endif %} | ||
<hr> | ||
<div class="row"> | ||
<div> | ||
<form action="{{url_for('standard_runs',uuid=uuid)}}" method="POST"> | ||
<table class="table table-striped"> | ||
<thead> | ||
<th> Setting </th> | ||
<th> Current Value </th> | ||
<th> New Value </th> | ||
</thead> | ||
{% for field in form %} | ||
{% if field.label.text.lower() not in ['name', 'password', 'info'] %} | ||
<tr> | ||
<td> {{ field.label }} </td> | ||
<td> {{ field.data }} </td> | ||
<td> {{ field()}} </td> | ||
</tr> | ||
{% endif %} | ||
{% endfor %} | ||
</table> | ||
<div class="form-group"> | ||
{{ form.name.label }} | ||
{{ form.name(class="form-control",style="width:500px") }} | ||
</div> | ||
<div class="form-group"> | ||
{{ form.info.label }} | ||
{{ form.info(class="form-control",style="width:500px") }} | ||
</div> | ||
<div class="form-group"> | ||
{{ form.password.label }} | ||
{{ form.password(class="form-control",style="width:500px") }} | ||
</div> | ||
<div class="row"> | ||
<button type="submit" class="btn btn-primary"> Submit </button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
{% else %} | ||
<p> No form provided...not sure how this happened. </p> | ||
{% endif %} | ||
</div> | ||
<br> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{% extends "layout.html" %} | ||
{% block title %}Standard Runs{% endblock %} | ||
{% block head %} | ||
{{ super() }} | ||
{% endblock %} | ||
{% block body %} | ||
{{ super() }} | ||
<div class="container"> | ||
{% if values %} | ||
<h1> Standard Runs </h1> | ||
<ul class="list-group"> | ||
{% for k, v in values %} | ||
<li class="list-group-item"> | ||
<h4>{{ k }}</h4> | ||
<div class="list-group"> | ||
{% for x in v %} | ||
<a class="list-group-item" href="{{url_for('standard_runs') }}/{{x.id}}" >{{ x.key[2] }} </a> | ||
{% endfor %} | ||
</div> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the same format that's used by the other standard runs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, the couch view that orca uses sorts by doc.time_stamp so this is the field that should be updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok. For some reason I thought the timestamps in couch were stored as text.