-
Notifications
You must be signed in to change notification settings - Fork 19
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
Move FFQ's from sample to source #459
Move FFQ's from sample to source #459
Conversation
added parameter to the get the recent timestamp records
@@ -540,8 +538,7 @@ def get_vioscreen_sample_to_user(self): | |||
WHERE vio_id IS NOT NULL""") | |||
return {r[0]: r[1] for r in cur.fetchall()} | |||
|
|||
def create_vioscreen_id(self, account_id, source_id, | |||
vioscreen_ext_sample_id): | |||
def create_vioscreen_id(self, account_id, source_id): |
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.
We need to adjust the logic on this function, since a given source can have more than one vioscreen ID associated. Since users will unlock access using a registration code, go ahead and add activation_code as a column to the vioscreen_registry table (column type = varchar). Then, you need to pass the registration_code into get_vioscreen_id_if_exists. If it doesn't, create the new record in vioscreen_registry, including the registration_code.
VioscreenDietaryScoreRepo, VioscreenSupplementsRepo, | ||
VioscreenFoodComponentsRepo, VioscreenEatingPatternsRepo, | ||
VioscreenMPedsRepo, VioscreenFoodConsumptionRepo | ||
) | ||
|
||
|
||
def _get_session_by_account_details(account_id, source_id, sample_id): | ||
def _get_session_by_account_details(account_id, source_id): |
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.
Please update all of the functions in _vioscreen.py that call get_vioscreen_id_if_exists to include the new optional parameters (both in how they call that function and their own function definition) so we can update the full stack of functions to work with the intended logic. Also, please update the parameters in the YAML file accordingly.
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.
Given that a source can have multiple sessions, will this function now return an iterable? If so then the functions which call it most likely all need to be updated to handle multiple sessions.
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.
No, it should be updated to to use the switching logic between sample_id, registration_code, timestamp, or default to most recent.
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.
Added a few comments
@cassidysymons, is there going to be a need to migrate existing data in anyway?
VioscreenDietaryScoreRepo, VioscreenSupplementsRepo, | ||
VioscreenFoodComponentsRepo, VioscreenEatingPatternsRepo, | ||
VioscreenMPedsRepo, VioscreenFoodConsumptionRepo | ||
) | ||
|
||
|
||
def _get_session_by_account_details(account_id, source_id, sample_id): | ||
def _get_session_by_account_details(account_id, source_id): |
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.
Given that a source can have multiple sessions, will this function now return an iterable? If so then the functions which call it most likely all need to be updated to handle multiple sessions.
|
||
|
||
def get_vioscreens(account_id, source_id): | ||
"""Obtain a vioscreen ID if it exists""" |
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.
I believe this should note that multiple vioscreen IDs may be returned
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. @SyedAli-789 please clarify the comment for this function.
application/json: | ||
schema: | ||
type: | ||
object |
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.
I believe this is inaccurate, isn't the return an array of object?
if rows is None or len(rows) == 0: | ||
return None | ||
else: | ||
return rows |
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.
Can this return instances of the VioscreenSession
model?
@wasade Not that I'm aware of. We're leaving the sample_id column in place and providing a way to search for Vioscreen sessions for historical records using that column. |
@cassidysymons, thanks. We currently pull out sample <-> vioscreen ID associations to construct FFQ metadata suitable for analysis (see #461) -- it's going to be important that that method remain correct in light of the changes here. |
Ah sorry, clicked the wrong button |
VioscreenDietaryScoreRepo, VioscreenSupplementsRepo, | ||
VioscreenFoodComponentsRepo, VioscreenEatingPatternsRepo, | ||
VioscreenMPedsRepo, VioscreenFoodConsumptionRepo | ||
) | ||
|
||
|
||
def _get_session_by_account_details(account_id, source_id, sample_id): | ||
def _get_session_by_account_details(account_id, source_id): |
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.
No, it should be updated to to use the switching logic between sample_id, registration_code, timestamp, or default to most recent.
|
||
|
||
def get_vioscreens(account_id, source_id): | ||
"""Obtain a vioscreen ID if it exists""" |
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. @SyedAli-789 please clarify the comment for this function.
if now.month > 10: | ||
delta = relativedelta(month=1, year=now.year+1) | ||
else: | ||
delta = relativedelta(month=now.month+2) |
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.
Please back out this change, the code as is - delta = relativedelta(months=now.month+2) - is a more concise approach.
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.
reverted the changes
"GROUP BY vioscreen_registry.vio_id, " | ||
"ag_login_surveys.creation_time " | ||
"ORDER BY ag_login_surveys.creation_time DESC ", | ||
(account_id, source_id)) | ||
rows = cur.fetchall() |
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.
Should this be a fetchone
?
"AND vioscreen_registry.source_id = %s " | ||
"AND deleted=false " | ||
"AND ag_login_surveys.creation_time >= %s" | ||
"GROUP BY vioscreen_registry.vio_id, " |
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.
Since we're returning the most recent survey below, is the GROUP BY
needed?
"WHERE vioscreen_registry.account_id = %s " | ||
"AND vioscreen_registry.source_id = %s " | ||
"AND deleted=false " | ||
"GROUP BY vioscreen_registry.vio_id, " |
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.
Same here
@@ -1656,3 +1656,24 @@ def _get_vioscreen_status(self, survey_id): | |||
if row is None: | |||
return None | |||
return row[0] | |||
|
|||
def get_vioscreen_sessions(self, account_id, source_id): |
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.
Can a unit test for this method be added?
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.
@SyedAli-789 Please add unit tests for this function to repo/test/test_vioscreen.py. There should be one test that reflects the result of no rows being found and one test that reflects the result of one or more results being found.
cur.execute("SELECT * FROM vioscreen_sessions WHERE" | ||
"username IN" | ||
"(SELECT vio_id FROM vioscreen_registry WHERE " | ||
"account_id=%s AND " | ||
"source_id=%s)", | ||
(account_id, source_id)) |
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.
I think this is the same as
SELECT vs.*
FROM vioscreen_sessions vs
JOIN vioscreen_registry vr ON vs.username = vr.vio_id
WHERE account_id=%s AND source_id=%s
No description provided.