Skip to content
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
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

Standard runs #161

wants to merge 22 commits into from

Conversation

marzece
Copy link

@marzece marzece commented May 31, 2018

Add basic standard run editor. I've tested with a local copy of orca and things seem to behave as expected.

Copy link

@tlatorre-uchicago tlatorre-uchicago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a few comments. The big thing that I think is necessary is to add some server side verification of the type of the values entered. I think this shouldn't be too hard to add using wtforms which is what is used for the channel database, pmtic resistors, and the mtca+ crate mapping.

minard/views.py Outdated
new_values = {k:int(v) if type(v)==float and v.is_integer() else v for k,v in new_values.iteritems()}
if not new_values:
flash("No new values given. Update not performed", "danger")
elif(passw != app.config["SECRET_KEY"]):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

believe it or not SECRET_KEY is already taken. It's used by flask to generate some sort of cryptographic tokens for sessions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that's why I used it, I thought that was what was used for the WTFForms validate?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the password for the channeldb etc. is a password in the postgres database, so minard doesn't handle checking that at all, it just passes it to the database. The SECRET_KEY is a very long string of random characters.

doc = dict(orca_db.get(uuid))
for k, v in new_values.iteritems():
doc[k] = v
doc["_id"] = uuid4().hex

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked how the standard runs are saved in Orca and they don't explicitly include an id version. @mastbaum or @jcaravaca can you confirm that this is kosher?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know a document always has an id field, if it doesn't couch creates one for a document. The python couchdb library recommends the client create the hash though b/c if the libraries POST request fails and retries you can end up posting the same document multiple times.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok that makes sense.

for k, v in new_values.iteritems():
doc[k] = v
doc["_id"] = uuid4().hex
doc["time_stamp"] = time()

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?

Copy link
Author

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

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.

doc["_id"] = uuid4().hex
doc["time_stamp"] = time()

if not doc.has_key("run_version") or not bool(doc["run_version"]):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the bool check for? Is that just to see if it's zero?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that was left over from debugging, I can remove it

doc["run_type"] = doc["run_type"].upper()
doc["run_version"] = doc["run_version"].upper()
try:
del doc["_rev"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to add a comment explaining this.

minard/views.py Outdated
info = request.form.get("info")
passw = request.form.get("password")
new_values = [x[:-8] for x in request.form.keys() if x[-8:] == "_replace"]
new_values = {x:request.form[x+"_value"] for x in new_values}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The python running on minard is python 2.6 which unfortunately doesn't support this syntax for creating dictionaries.

minard/views.py Outdated
new_values = {k:True if v.lower() == 'true' else v for k,v in new_values.iteritems() if v}
new_values = {k:False if v.lower() == 'false' else v for k,v in new_values.iteritems()}
new_values = {k:float(v) if v.isdigit() else v for k,v in new_values.iteritems()}
new_values = {k:int(v) if type(v)==float and v.is_integer() else v for k,v in new_values.iteritems()}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to have some server side verification of all of the values here. Do I understand that currently I could add "foo" as the trigger mask and it would get saved as a string? I'm not sure what Orca does in that case. You can use wtforms to do this validation. It's used by the channel database here:

class ChannelStatusForm(Form):
and here: https://github.com/snoplus/minard/blob/master/minard/views.py#L372.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that verification would be good, but I didn't want to get to bogged down figuring out whats valid input for all ~50 standard run settings. I figured making it expert only might be good enough because the most common use case for this (I suspect) will be copy/pasting settings from one run to another. That being said I can take a crack at adding validation this weekend, it may not be as time consuming as I expect.

And I looked into using WTFForms, the issue I ran into with that is (I think) it requires you know the fields you want ahead of time, but since couch is so amorphous the fields can change pretty easily. I could just implement a set of forms for the current standard run settings, but that will then mean we have to update this webpage whenever we add/remove some standard run setting. Maybe there's some way to dynamically create forms, if so that'd be the best of both worlds.

# 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 = sorted(sr_view.rows, key=lambda x: x.key[1] + x.key[2])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here it would probably be best only to show the latest version (or even better have a drop down menu on the standard runs page which allows you to select which standard run version). The reason is that there are a lot of older standard runs from previous versions that don't show up in Orca but do show up on the page and I think that might be confusing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, I had that at first but I removed it so I could test on old unused runs. I'll add it back in.

@marzece
Copy link
Author

marzece commented Jun 7, 2018

I think I've addressed all comments now. Let me know if there's anything further. Also this update will require two new settings for the config file. One for the couchdb detector expert username and another for the couchdb run version (which should be 2)

@tlatorre-uchicago
Copy link

Ok, can you email me the details of the couchdb detector expert name?

One weird issue that I ran into when testing it out. I opened up the "SUPERNOVA - NO_N100" standard run and I tried entering "foo" into the CAEN_coincidenceLevel field and then submitting and I got this error:

  • MTC_PulserRate: Number must be between 0.04 and 390000

but the form has the pulser rate set to 10.00. In addition, the CAEN coincidenceLevel field now shows "None" as the current value instead of 0.

@marzece
Copy link
Author

marzece commented Jun 10, 2018

There was some issues creating the new couch user. Should probably work that out before merging. I'm not sure about the MTC_PulserRate/CAEN_Coincedence thing. I'll look into it a bit.

@tannerbk
Copy link

The TUBII settings are wrong again for most run types after some cable swaps and it would be nice to make the CAEN channel offsets (y-axis) the same for all run-types. Once this is merged I'd suggest we make those changes right away.

@marzece
Copy link
Author

marzece commented Dec 17, 2018

Andy and I tested this out a bit today and worked out (somewhat) the couch permissions stuff. After some testing this seems to be working well enough, so I think it can be merged now. I mentioned this in an earlier comment but this change requires two new fields in the settings file. Those are as follows
ORCA_STANDARD_RUN_VERSION = 2
COUCH_DETECTOR_EXPERT_NAME = ""
the expert username I'll send offline.

@tlatorre-uchicago
Copy link

Has the issue I mentioned earlier been fixed? Would also be nice if you could squash all the commits into one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants