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

THDMI Japan Preparation #513

Merged
merged 2 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion microsetta_private_api/LEGACY/locale_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


available_locales = set([
'american_gut', 'british_gut', 'spanish_gut', 'spain_spanish_gut'])
'american_gut', 'british_gut', 'spanish_gut', 'spain_spanish_gut', 'japanese_gut'])


media_locale = {
Expand Down
104 changes: 104 additions & 0 deletions microsetta_private_api/LEGACY/locale_data/japanese_gut.py

Large diffs are not rendered by default.

1,191 changes: 1,191 additions & 0 deletions microsetta_private_api/db/patches/0113.sql

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion microsetta_private_api/localization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from microsetta_private_api.LEGACY.locale_data \
import (american_gut, british_gut, spanish_gut, spain_spanish_gut)
import (american_gut, british_gut, spanish_gut, spain_spanish_gut,
japanese_gut)

EN_US = "en_US"
EN_GB = "en_GB"
Expand Down Expand Up @@ -28,5 +29,9 @@
ES_ES: {
NEW_PARTICIPANT_KEY: spain_spanish_gut._NEW_PARTICIPANT,
LANG_NAME_KEY: "spain_spanish"
},
JA_JP: {
NEW_PARTICIPANT_KEY: japanese_gut._NEW_PARTICIPANT,
LANG_NAME_KEY: "japanese"
}
}
11 changes: 8 additions & 3 deletions microsetta_private_api/repo/admin_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,8 @@ def _generate_novel_barcodes(self, number_of_kits, number_of_samples,
kit_names):
"""Generate specified number of random barcodes for input kit names"""

total_barcodes = number_of_kits * number_of_samples

with self._transaction.cursor() as cur:
# get the maximum observed barcode.
# historically, barcodes were of the format NNNNNNNNN where each
Expand All @@ -827,9 +829,12 @@ def _generate_novel_barcodes(self, number_of_kits, number_of_samples,
# control character that cannot safely be considered a digit.
# this is *safe* for all prior barcodes as the first character
# has always been the "0" character.
total_barcodes = number_of_kits * number_of_samples
cur.execute("SELECT max(right(barcode,8)::integer) "
"FROM barcodes.barcode")
# Barcodes prefixed with X or 0 are designated by UC San Diego.
cur.execute(
"SELECT max(right(barcode,8)::integer) "
"FROM barcodes.barcode "
"WHERE barcode LIKE 'X%' OR barcode LIKE '0%'"
)
start_bc = cur.fetchone()[0] + 1
new_barcodes = ['X%0.8d' % (start_bc + i)
for i in range(total_barcodes)]
Expand Down
44 changes: 35 additions & 9 deletions microsetta_private_api/repo/survey_template_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ def get_survey_template(self, survey_id, language_tag):
localization.EN_US: "survey_question.american",
localization.EN_GB: "survey_question.british",
localization.ES_MX: "survey_question.spanish",
localization.ES_ES: "survey_question.spain_spanish"
localization.ES_ES: "survey_question.spain_spanish",
localization.JA_JP: "survey_question.japanese"
}

if language_tag not in tag_to_col:
Expand Down Expand Up @@ -183,7 +184,8 @@ def get_survey_template(self, survey_id, language_tag):

responses = self._get_question_valid_responses(question_id,
language_tag)
triggers = self._get_question_triggers(question_id)
triggers = self._get_question_triggers(question_id,
language_tag)

# Quick fix to correctly sort country names in Spanish
if (language_tag == localization.ES_MX or language_tag ==
Expand Down Expand Up @@ -215,8 +217,13 @@ def _get_group_localized_text(self, group_id, language_tag):
localization.EN_US: "american",
localization.EN_GB: "british",
localization.ES_MX: "spanish",
localization.ES_ES: "spain_spanish"
localization.ES_ES: "spain_spanish",
localization.JA_JP: "japanese"
}

if language_tag not in tag_to_col:
raise RepoException(f"{language_tag} is not supported.")

with self._transaction.cursor() as cur:
cur.execute("SELECT " +
tag_to_col[language_tag] + " " +
Expand All @@ -234,8 +241,12 @@ def _get_question_valid_responses(self, survey_question_id, language_tag):
localization.EN_GB: "survey_response.british",
localization.ES_MX: "survey_response.spanish",
localization.ES_ES: "survey_response.spain_spanish",
localization.JA_JP: "survey_response.japanese"
}

if language_tag not in tag_to_col:
raise RepoException(f"{language_tag} is not supported.")

with self._transaction.cursor() as cur:
cur.execute("SELECT " +
tag_to_col[language_tag] + " "
Expand All @@ -252,13 +263,28 @@ def _get_question_valid_responses(self, survey_question_id, language_tag):
"display_index", (survey_question_id,))
return [x[0] for x in cur.fetchall()]

def _get_question_triggers(self, survey_question_id):
def _get_question_triggers(self, survey_question_id, language_tag):
tag_to_col = {
localization.EN_US: "survey_response.american",
localization.EN_GB: "survey_response.british",
localization.ES_MX: "survey_response.spanish",
localization.ES_ES: "survey_response.spain_spanish",
localization.JA_JP: "survey_response.japanese"
}

if language_tag not in tag_to_col:
raise RepoException(f"{language_tag} is not supported.")

with self._transaction.cursor() as cur:
cur.execute("SELECT triggering_response, triggered_question "
"FROM "
"survey_question_triggers "
"WHERE "
"survey_question_id = %s ", (survey_question_id,))
cur.execute(
"SELECT " + tag_to_col[language_tag] + ", "
"sqt.triggered_question "
"FROM survey_response "
"INNER JOIN survey_question_triggers sqt "
"ON sqt.triggering_response = survey_response.american "
"WHERE sqt.survey_question_id = %s ",
(survey_question_id, )
)

rows = cur.fetchall()
return [SurveyTemplateTrigger(x[0], x[1]) for x in rows]
Expand Down
Loading