Skip to content

Commit

Permalink
Merge pull request #348 from praekeltfoundation/add-skip-page
Browse files Browse the repository at this point in the history
Add skip result and skip threshold
  • Loading branch information
HawkiesZA authored Jul 30, 2024
2 parents 80fa8be + 2d59e19 commit ea73e94
Show file tree
Hide file tree
Showing 16 changed files with 224 additions and 76 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!--
## Unreleased
- Add skip threshold and skip high result page
-->

## v1.2.0
Expand Down
8 changes: 8 additions & 0 deletions home/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ class AssessmentViewSet(BaseAPIViewSet):
"medium_result_page",
"medium_inflection",
"low_result_page",
"skip_threshold",
"skip_high_result_page",
"generic_error",
"questions",
]
Expand All @@ -246,6 +248,8 @@ class AssessmentViewSet(BaseAPIViewSet):
"medium_inflection",
"low_result_page",
"low_inflection",
"skip_threshold",
"skip_high_result_page",
"generic_error",
"questions",
]
Expand Down Expand Up @@ -274,6 +278,10 @@ def get_queryset(self):
assessment.medium_result_page = latest_revision.medium_result_page
assessment.medium_inflection = latest_revision.medium_inflection
assessment.low_result_page = latest_revision.low_result_page
assessment.skip_threshold = latest_revision.skip_threshold
assessment.skip_high_result_page = (
latest_revision.skip_high_result_page
)
assessment.generic_error = latest_revision.generic_error
assessment.questions = latest_revision.questions

Expand Down
8 changes: 8 additions & 0 deletions home/export_assessments.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class ExportRow:
medium_result_page: str | None
medium_inflection: str | None
low_result_page: str | None
skip_threshold: str | None
skip_high_result_page: str | None
generic_error: str
question: str
explainer: str
Expand Down Expand Up @@ -83,6 +85,10 @@ def perform_export(self) -> Iterable[ExportRow]:
medium_result_page=getattr(item.medium_result_page, "slug", None),
medium_inflection=getattr(item, "medium_inflection", None),
low_result_page=getattr(item.low_result_page, "slug", None),
skip_threshold=getattr(item, "skip_threshold", "0.0"),
skip_high_result_page=getattr(
item.skip_high_result_page, "slug", None
),
generic_error=item.generic_error,
question=question.value["question"],
explainer=question.value["explainer"],
Expand Down Expand Up @@ -161,6 +167,8 @@ def _set_xlsx_styles(wb: Workbook, sheet: Worksheet) -> None:
"medium_result_page": 120,
"medium_inflection": 110,
"low_result_page": 110,
"skip_threshold": 110,
"skip_high_result_page": 110,
"generic_error": 370,
"question": 370,
"explainer": 370,
Expand Down
14 changes: 14 additions & 0 deletions home/import_assessments.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def create_shadow_assessment_from_row(
high_result_page=row.high_result_page,
medium_result_page=row.medium_result_page,
low_result_page=row.low_result_page,
skip_high_result_page=row.skip_high_result_page,
high_inflection=(
None if row.high_inflection == "" else float(row.high_inflection)
),
Expand All @@ -164,6 +165,9 @@ def create_shadow_assessment_from_row(
if row.medium_inflection == ""
else float(row.medium_inflection)
),
skip_threshold=(
0.0 if row.skip_threshold == "" else float(row.skip_threshold)
),
generic_error=row.generic_error,
tags=row.tags,
)
Expand Down Expand Up @@ -219,6 +223,8 @@ class ShadowAssessment:
low_result_page: str
high_inflection: float | None
medium_inflection: float | None
skip_threshold: float
skip_high_result_page: str
generic_error: str
questions: list[ShadowQuestionBlock] = field(default_factory=list)
tags: list[str] = field(default_factory=list)
Expand Down Expand Up @@ -259,6 +265,12 @@ def add_field_values_to_assessment(self, assessment: Assessment) -> None:
if self.low_result_page == ""
else get_content_page_id_from_slug(self.low_result_page)
)
assessment.skip_high_result_page_id = (
None
if self.skip_high_result_page == ""
else get_content_page_id_from_slug(self.skip_high_result_page)
)
assessment.skip_threshold = self.skip_threshold
assessment.generic_error = self.generic_error
assessment.questions = self.questions_as_streamfield

Expand Down Expand Up @@ -316,6 +328,8 @@ class AssessmentRow:
medium_result_page: str = ""
medium_inflection: str = ""
low_result_page: str = ""
skip_threshold: str = ""
skip_high_result_page: str = ""
generic_error: str = ""
question: str = ""
explainer: str = ""
Expand Down
34 changes: 34 additions & 0 deletions home/migrations/0079_assessment_skip_high_result_page_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 4.2.11 on 2024-07-29 13:34

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("home", "0078_alter_assessment_high_inflection_and_more"),
]

operations = [
migrations.AddField(
model_name="assessment",
name="skip_high_result_page",
field=models.ForeignKey(
blank=True,
help_text="The page to show a user if they skip a question",
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="assessment_high_skip",
to="home.contentpage",
),
),
migrations.AddField(
model_name="assessment",
name="skip_threshold",
field=models.FloatField(
default=0,
help_text="If a user skips equal to or greater than this many questions they will be presented with the skip page",
),
),
]
14 changes: 14 additions & 0 deletions home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,18 @@ class Assessment(DraftStateMixin, RevisionMixin, index.Indexed, ClusterableModel
blank=True,
null=True,
)
skip_threshold = models.FloatField(
help_text="If a user skips equal to or greater than this many questions they will be presented with the skip page",
default=0,
)
skip_high_result_page = models.ForeignKey(
ContentPage,
related_name="assessment_high_skip",
on_delete=models.CASCADE,
help_text="The page to show a user if they skip a question",
blank=True,
null=True,
)
generic_error = models.TextField(
help_text="If no error is specified for a question, then this is used as the "
"fallback"
Expand Down Expand Up @@ -1464,6 +1476,8 @@ class Assessment(DraftStateMixin, RevisionMixin, index.Indexed, ClusterableModel
APIField("medium_result_page", serializer=ContentPageSerializer()),
APIField("medium_inflection"),
APIField("low_result_page", serializer=ContentPageSerializer()),
APIField("skip_threshold"),
APIField("skip_high_result_page", serializer=ContentPageSerializer()),
APIField("generic_error"),
APIField("questions"),
]
Expand Down
12 changes: 6 additions & 6 deletions home/tests/import-export-data/assessment_less_simple.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
title,question_type,tags,slug,version,locale,high_result_page,high_inflection,medium_result_page,medium_inflection,low_result_page,generic_error,question,explainer,error,min,max,answers,scores,semantic_ids
Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know your blood pressure for a proper risk assessment,Sorry we don't understand.,,,"Once a week,Twice a week,Thrice a week","1.0,3.0,4.5","test-1,test-2,test-3"
Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",Have you been vaccinated against COVID-19?,We need to know if you have been vaccinated for a proper risk assessment,Sorry we didn't quite catch that.,,,"Yes,No","3.0,1.0","test-1,test-2"
Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How high is your temperature?,We need to know your temperature for a proper risk assessment. A very high temperature could suggest an infection is present.,Please choose the option that matches your answer.,,,"Between 37.5C and 38C,Between 38.1C and 40C,Between 40.1C and 41.1C","3.0,2.0,1.0","test-1,test-2,test-3"
Integer Type Question,integer_question,integer-type-question,integer-type-question,v1.0,en,high-inflection,5.0,medium-score,3.0,low-score,This is a generic error,How much do you weigh in kilograms?,We need to test integer type questions,Sorry your min and max weight should be between 40 and 500kg.,40,500,,,
Weather Trivia,integer_question,weather-trivia,weather-trivia,v1.0,en,,,,,,"Sorry, we didn't quite get that.",What's the coldest weather you're experienced?,We need to know some things,Your reply should be between {min} and {max},20,-70,,,
title,question_type,tags,slug,version,locale,high_result_page,high_inflection,medium_result_page,medium_inflection,low_result_page,skip_threshold,skip_high_result_page,generic_error,question,explainer,error,min,max,answers,scores,semantic_ids
Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,2.0,skip-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know your blood pressure for a proper risk assessment,Sorry we don't understand.,,,"Once a week,Twice a week,Thrice a week","1.0,3.0,4.5","test-1,test-2,test-3"
Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,2.0,skip-score,"Sorry, we didn't quite get that.",Have you been vaccinated against COVID-19?,We need to know if you have been vaccinated for a proper risk assessment,Sorry we didn't quite catch that.,,,"Yes,No","3.0,1.0","test-1,test-2"
Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,2.0,skip-score,"Sorry, we didn't quite get that.",How high is your temperature?,We need to know your temperature for a proper risk assessment. A very high temperature could suggest an infection is present.,Please choose the option that matches your answer.,,,"Between 37.5C and 38C,Between 38.1C and 40C,Between 40.1C and 41.1C","3.0,2.0,1.0","test-1,test-2,test-3"
Integer Type Question,integer_question,integer-type-question,integer-type-question,v1.0,en,high-inflection,5.0,medium-score,3.0,low-score,2.0,skip-score,This is a generic error,How much do you weigh in kilograms?,We need to test integer type questions,Sorry your min and max weight should be between 40 and 500kg.,40,500,,,
Weather Trivia,integer_question,weather-trivia,weather-trivia,v1.0,en,,,,,,2.0,skip-score,"Sorry, we didn't quite get that.",What's the coldest weather you're experienced?,We need to know some things,Your reply should be between {min} and {max},20,-70,,,
8 changes: 4 additions & 4 deletions home/tests/import-export-data/assessment_simple.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
title,question_type,tags,slug,version,locale,high_result_page,high_inflection,medium_result_page,medium_inflection,low_result_page,generic_error,question,explainer,error,min,max,answers,scores,semantic_ids
Health Assessment Simple,categorical_question,checker,Health-assessment-simple,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know your blood pressure for a proper risk assessment,Sorry we don't under stand.,,,"Once a week,Twice a week,Thrice a week","1.0,3.5,4.5","test-1,test-2,test-3"
Health Assessment Simple,age_question,checker,Health-assessment-simple,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know your blood pressure for a proper risk assessment,Sorry we don't under stand.,,,,,
Health Assessment Simple,multiselect_question,checker,Health-assessment-simple,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know your blood pressure for a proper risk assessment,Sorry we don't under stand.,,,"Once a week,Twice a week,Thrice a week","1.0,3.5,4.5","test-1,test-2,test-3"
title,question_type,tags,slug,version,locale,high_result_page,high_inflection,medium_result_page,medium_inflection,low_result_page,skip_threshold,skip_high_result_page,generic_error,question,explainer,error,min,max,answers,scores,semantic_ids
Health Assessment Simple,categorical_question,checker,Health-assessment-simple,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,2.0,skip-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know your blood pressure for a proper risk assessment,Sorry we don't under stand.,,,"Once a week,Twice a week,Thrice a week","1.0,3.5,4.5","test-1,test-2,test-3"
Health Assessment Simple,age_question,checker,Health-assessment-simple,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,2.0,skip-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know your blood pressure for a proper risk assessment,Sorry we don't under stand.,,,,,
Health Assessment Simple,multiselect_question,checker,Health-assessment-simple,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,2.0,skip-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know your blood pressure for a proper risk assessment,Sorry we don't under stand.,,,"Once a week,Twice a week,Thrice a week","1.0,3.5,4.5","test-1,test-2,test-3"
Loading

0 comments on commit ea73e94

Please sign in to comment.