Skip to content

Commit

Permalink
support $qpath and use it for inserting analysis fields
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaberetta committed Aug 12, 2022
1 parent 4da4ec9 commit 028cc7a
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 48 deletions.
3 changes: 3 additions & 0 deletions src/formpack/schema/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(

self.data_type = data_type
self.section = section
self.qpath = kwargs.get('qpath', '')
self.can_format = can_format
self.tags = kwargs.get('tags', [])
self.analysis_question = False
Expand Down Expand Up @@ -193,6 +194,7 @@ def from_json_definition(
The FormField instance matching this definiton.
"""
name = definition['name']
qpath = definition.get('$qpath', '')
tags = definition.get('tags', [])
labels = cls._extract_json_labels(definition, translations)
appearance = definition.get('appearance')
Expand Down Expand Up @@ -271,6 +273,7 @@ def from_json_definition(
'tags': tags,
'data_type': data_type,
'hierarchy': hierarchy,
'qpath': qpath,
'section': section,
'choice': choice,
'or_other': or_other,
Expand Down
4 changes: 2 additions & 2 deletions src/formpack/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _map_sections_to_analysis_fields(
self, survey_field: FormField
) -> List[FormField]:
_fields = []
for analysis_field in self.fields_by_source[survey_field.name]:
for analysis_field in self.fields_by_source[survey_field.qpath]:
analysis_field.section = survey_field.section
analysis_field.source_field = survey_field
_fields.append(analysis_field)
Expand All @@ -152,7 +152,7 @@ def insert_analysis_fields(
_fields = []
for field in fields:
_fields.append(field)
if field.name in self.fields_by_source:
if field.qpath in self.fields_by_source:
_fields += self._map_sections_to_analysis_fields(field)
return _fields

Expand Down
12 changes: 6 additions & 6 deletions tests/fixtures/analysis_form/analysis_form.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,27 @@
},
{
"type": "text",
"name": "name_of_clerk/comment",
"name": "clerk_details-name_of_clerk/comment",
"path": [
"name_of_clerk",
"clerk_details-name_of_clerk",
"comment"
],
"label": [
"Comment on the name of the clerk"
],
"source": "name_of_clerk"
"source": "clerk_details-name_of_clerk"
},
{
"type": "text",
"name": "name_of_shop/comment",
"name": "clerk_details-name_of_shop/comment",
"path": [
"name_of_shop",
"clerk_details-name_of_shop",
"comment"
],
"label": [
"Comment on the name of the shop"
],
"source": "name_of_shop"
"source": "clerk_details-name_of_shop"
}
],
"translations": [
Expand Down
5 changes: 4 additions & 1 deletion tests/fixtures/analysis_form/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
"type": "audio",
"name": "record_a_note",
"$qpath": "record_a_note",
"label": [
"Record a clerk saying something",
"Registri oficiston dirantan ion"
Expand All @@ -13,6 +14,7 @@
{
"type": "begin_group",
"name": "clerk_details",
"$qpath": "clerk_details",
"label": [
"Some details of the clerk",
"Kelkaj detaloj de la oficisto"
Expand All @@ -21,6 +23,7 @@
{
"type": "text",
"name": "name_of_clerk",
"$qpath": "clerk_details-name_of_clerk",
"label": [
"What is the clerk's name?",
""
Expand Down Expand Up @@ -64,7 +67,7 @@
},
"acme_timestamp": "2021-11-01Z"
},
"name_of_clerk": {
"clerk_details-name_of_clerk": {
"comment": "Sounds like an interesting person"
}
}
Expand Down
5 changes: 4 additions & 1 deletion tests/fixtures/analysis_form/v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
"type": "audio",
"name": "record_a_note",
"$qpath": "record_a_note",
"label": [
"Record a clerk saying something",
"Registri oficiston dirantan ion"
Expand All @@ -13,6 +14,7 @@
{
"type": "begin_group",
"name": "clerk_details",
"$qpath": "clerk_details",
"label": [
"Some details of the clerk",
"Kelkaj detaloj de la oficisto"
Expand All @@ -21,6 +23,7 @@
{
"type": "text",
"name": "name_of_shop",
"$qpath": "clerk_details-name_of_shop",
"label": [
"What is the shop's name?",
"Kio estas la nomo de la butiko?"
Expand Down Expand Up @@ -59,7 +62,7 @@
},
"acme_timestamp": "2021-11-01Z"
},
"name_of_shop": {
"clerk_details-name_of_shop": {
"comment": "Pretty cliche"
}
}
Expand Down
24 changes: 12 additions & 12 deletions tests/fixtures/analysis_form_advanced/analysis_form.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"additional_fields": [
{
"type": "transcript",
"name": "record_a_note/transcript",
"path": ["record_a_note", "transcript"],
"source": "record_a_note",
"name": "clerk_interactions-record_a_note/transcript",
"path": ["clerk_interactions-record_a_note", "transcript"],
"source": "clerk_interactions-record_a_note",
"languages": ["en"],
"settings": {
"mode": "auto",
Expand All @@ -19,34 +19,34 @@
{
"type": "select_multiple",
"select_from_list_name": "record_a_note_tones",
"name": "record_a_note/tone_of_voice",
"path": ["record_a_note", "tone_of_voice"],
"name": "clerk_interactions-record_a_note/tone_of_voice",
"path": ["clerk_interactions-record_a_note", "tone_of_voice"],
"label": [
"How was the tone of the clerk's voice?",
"Kiel estis la tono de la voĉo de la oficisto?"
],
"source": "record_a_note"
"source": "clerk_interactions-record_a_note"
},
{
"type": "text",
"name": "goods_sold/comment",
"path": ["goods_sold", "comment"],
"name": "clerk_interactions-goods_sold/comment",
"path": ["clerk_interactions-goods_sold", "comment"],
"label": [
"Comment on the goods sold at the store",
"Komentu la varojn venditajn en la vendejo"
],
"source": "goods_sold"
"source": "clerk_interactions-goods_sold"
},
{
"type": "select_one",
"select_from_list_name": "goods_sold_ratings",
"name": "goods_sold/rating",
"path": ["goods_sold", "rating"],
"name": "clerk_interactions-goods_sold/rating",
"path": ["clerk_interactions-goods_sold", "rating"],
"label": [
"Rate the quality of the goods sold at the store",
"Komentu la varojn vendojn en la vendejo"
],
"source": "goods_sold"
"source": "clerk_interactions-goods_sold"
}
],
"additional_choices": [
Expand Down
13 changes: 8 additions & 5 deletions tests/fixtures/analysis_form_advanced/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
"type": "begin_group",
"name": "clerk_interactions",
"$qpath": "clerk_interactions",
"label": [
"Clerk interactions",
"Komizo-interagoj"
Expand All @@ -13,6 +14,7 @@
{
"type": "audio",
"name": "record_a_note",
"$qpath": "clerk_interactions-record_a_note",
"label": [
"Record a clerk saying something",
"Registri oficiston dirantan ion"
Expand All @@ -21,6 +23,7 @@
{
"type": "select_multiple goods",
"name": "goods_sold",
"$qpath": "clerk_interactions-goods_sold",
"label": [
"What are some goods sold at the store?",
"Kio estas iuj varoj venditaj en la vendejo?"
Expand Down Expand Up @@ -78,14 +81,14 @@
}
],
"_supplementalDetails": {
"record_a_note": {
"clerk_interactions-record_a_note": {
"transcript": {
"value": "Hello how may I help you?",
"languageCode": "en"
},
"tone_of_voice": "excited confused"
},
"goods_sold": {
"clerk_interactions-goods_sold": {
"comment": "Not much diversity",
"rating": "3"
}
Expand All @@ -101,14 +104,14 @@
}
],
"_supplementalDetails": {
"record_a_note": {
"clerk_interactions-record_a_note": {
"transcript": {
"value": "Thank you for your business",
"languageCode": "en"
},
"tone_of_voice": "anxious excited"
},
"goods_sold": {
"clerk_interactions-goods_sold": {
"rating": "2"
}
}
Expand All @@ -123,7 +126,7 @@
}
],
"_supplementalDetails": {
"goods_sold": {
"clerk_interactions-goods_sold": {
"rating": "3"
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/analysis_form_repeat_groups/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
"type": "text",
"name": "enumerator_name",
"$qpath": "enumerator_name",
"label": [
"What is your name?",
"Kio estas via nomo?"
Expand All @@ -13,6 +14,7 @@
{
"type": "begin_repeat",
"name": "stores",
"$qpath": "stores",
"label": [
"Stores",
"Vendejoj"
Expand All @@ -21,6 +23,7 @@
{
"type": "text",
"name": "store_name",
"$qpath": "stores-store_name",
"label": [
"What is the store name?",
"Kio estas la nomo de la vendejo?"
Expand All @@ -29,6 +32,7 @@
{
"type": "begin_group",
"name": "recordings",
"$qpath": "stores-recordings",
"label": [
"Recordings",
"Registradoj"
Expand All @@ -37,6 +41,7 @@
{
"type": "begin_repeat",
"name": "record_interactions",
"$qpath": "stores-recordings-record_interactions",
"label": [
"Record interactions",
"Registri interagojn"
Expand All @@ -45,6 +50,7 @@
{
"type": "audio",
"name": "record_a_note",
"$qpath": "stores-recordings-record_interactions-record_a_note",
"label": [
"Record a clerk saying something",
"Registri oficiston dirantan ion"
Expand All @@ -56,6 +62,7 @@
{
"type": "begin_repeat",
"name": "record_ambient_noises",
"$qpath": "stores-recordings-record_ambient_noises",
"label": [
"Record ambient noises",
"Registri ĉirkaŭajn bruojn"
Expand All @@ -64,6 +71,7 @@
{
"type": "audio",
"name": "record_a_noise",
"$qpath": "stores-recordings-record_ambient_noises-record_a_noise",
"label": [
"Record some abient noise",
"Registru iun ĉirkaŭan bruon"
Expand Down
Loading

0 comments on commit 028cc7a

Please sign in to comment.