Repository navigation
Automatically assign sample ids - #75
ljones37oet wants to merge 7 commits into
Conversation
After sample event is created, if the value of the sample ID event option is 'auto', set it to the last sample ID assigned in the cruise + 1. I think this will probably fail because of the different websocket messages sent when you click on the event modal v. when you submit, but pushing to test
…ple ID The most recent event will be the empty one for this event created when the user clicked the event button, and there could also be other draft events like that too. Also, the mongo events are sorted by time the event button was clicked, but sample IDs are sorted by when event was submitted, so the order might not be 100% the same.
Used unittest instead of pytest to match OpenRVDAS
|
This has been a feature request for some time and I've been debating how best to implement it. Most of the groups requesting this feature would like to see the field populated with the suggested next ID number and have the option to change it prior to submission. I like what you've come up with but I think my preference is to implemented this within the HAPI server routes. My current thoughts are to add several new parameters to event template event_options such as:
In the case of auto increment, the most recent use of the event_option would be saved back to the event_template record. When the event is triggered the value is incremented (and saved) as it is pushed to the client. When the event is submitted the templates uid will be included in the API call. If the template matching the uid has auto-incremented event_option fields then the auto-incremented value(s) submitted with the event are saved back to the template record as the last value used. I'm hoping that with this approach the user will see the auto-incremented ID when submitting the event and have the option to manually override it. It should also gracefully handle rapid use of the template, i.e. 3 people click it in rapid succession. In this case each template click will generate an incremented value. It's certainly not fool-proof but I'm hopeful it will meet most of the user's needs. As for extending the python_sealog wrapper... I see no issue with those changes. |
|
@webbpinner thanks for reviewing! That sounds good to me! I agree that it would be better to be able to see/edit the automated ID before you submit the event. We tested this on the last dive of the cruise that I was on in July, and it worked fine. The Nautilus will be sampling again in another week or two, so we're going to do some more user testing. A downside with assigning IDs before submission is that you would end up in a gap in the IDs if two people had the sample event modal open at the same time (e.g. they both went to log the same event) and the person who clicked first canceled. The person who does end up submitting the event would just need to know that they have to manually set the value. Another reason I did it this way is that there were no js changes that had to be compiled. Our internet in the middle of the ocean is too slow to update npm packages without a lot of hassle, so we don't really want to pull in client-side changes from github during the season. If the change were ready by the late fall, we could implement it while the ship is in port. |
|
There will always be edge-cases but I think a gap is preferred to a malformed IDs or worse, duplicates. Implementing this the way I described is going to take awhile so I think the auto_action approach in the short-term was the best approach. |
Uses an auto action to automatically assign the next available sample ID to sample events.
When a SAMPLE* event is submitted with the SAMPLEID* value "auto"*, the auto action retrieves the last 5* sample events for the cruise and find the maximum sample ID value. It then updates the sample ID of the event to this maximum + 1. You can't just check the most recent sample event because that will usually be the empty event created when you click an event button. Checking multiple events also allows for the case where multiple people are logging samples at the same time, though it is important to note that IDs are assigned in the order that events are submitted, not in the order that they are created.
* customizable
How to implement:
PATTERN_SAMPLE_ID, unless for some reason their cruise IDs also start with "NA"Notes:
Preview:

Event template example:
After submitting event:
