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

Add list_name in JSON file #357

Merged
merged 1 commit into from
Sep 18, 2019
Merged

Conversation

qlands
Copy link
Contributor

@qlands qlands commented Sep 7, 2019

Rework of PR #354 because I messed up the code with reverts and such....

We can continue the discussion here :-)

@codecov-io
Copy link

codecov-io commented Sep 7, 2019

Codecov Report

Merging #357 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #357      +/-   ##
==========================================
+ Coverage   82.51%   82.52%   +0.01%     
==========================================
  Files          23       23              
  Lines        3255     3257       +2     
  Branches      758      758              
==========================================
+ Hits         2686     2688       +2     
  Misses        433      433              
  Partials      136      136
Impacted Files Coverage Δ
pyxform/survey_element.py 90.36% <ø> (ø) ⬆️
pyxform/xls2json.py 77.95% <100%> (+0.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a9fd520...948b6e2. Read the comment docs.

@qlands
Copy link
Contributor Author

qlands commented Sep 16, 2019

Hi,

We looked at the suggestion of @lognaturel to name the list using a hash based on the values.

Some context: We are creating a small tool that makes data dictionaries in HTML format out of the JSON output of pyxform. This helps users to navigate though very extensive ODK forms particularly those who use the data but did not created the form. Ideally if a user clicks on a select variable it will take him to a page showing the list of values.

The hash option could be used to generate a first version of the dictionary but if in subsequent versions of the same ODK a choice list_name changes it values (form example by adding NA) it would be very difficult to locate the list in HTML dictionary to add NA as an option.

Having the list_name in the JSON will help us a lot because we would be able to check if the list_name already exists in the HTML dictionary and if so add those options that are new.

@ukanga
Copy link
Contributor

ukanga commented Sep 18, 2019

Would having a "choices" attribute at the top-level suffice? I noticed we have it when there exists a choice_filter, we could make that behaviour consistent even when there is no choice_filter.

{
  "name": "yes_no",
  "type": "survey",
  "title": "yes_no",
  "id_string": "yes_no",
  "sms_keyword": "yes_no",
  "default_language": "default",
  "version": "201909180243",
  "choices": {
    "yes_no": [
      {
        "name": "1",
        "label": "Yes"
      },
      {
        "name": "2",
        "label": "No"
      }
    ],
    "fruit": [
      {
        "name": "mango",
        "choice": "yes",
        "label": "Mango"
      },
      {
        "name": "orange",
        "choice": "no",
        "label": "Orange"
      },
      {
        "name": "watermelon",
        "choice": "no",
        "label": "Watermelon"
      }
    ]
  },
  "children": [
    {
      "name": "your_choice",
      "label": "Your choice is?",
      "type": "select one",
      "children": [
        {
          "name": "1",
          "label": "Yes"
        },
        {
          "name": "2",
          "label": "No"
        }
      ]
    },
    {
      "name": "fruit",
      "label": "Fruit",
      "type": "select one",
      "itemset": "fruit",
      "choice_filter": "choice=${your_choice}",
      "children": [
        {
          "name": "mango",
          "label": "Mango"
        },
        {
          "name": "orange",
          "label": "Orange"
        },
        {
          "name": "watermelon",
          "label": "Watermelon"
        }
      ]
    },
    {
      "name": "meta",
      "type": "group",
      "control": {
        "bodyless": true
      },
      "children": [
        {
          "name": "instanceID",
          "type": "calculate",
          "bind": {
            "readonly": "true()",
            "calculate": "concat('uuid:', uuid())"
          }
        }
      ]
    }
  ]
}

This is not present when there is no choice filter.

{
  "name": "yes_no",
  "type": "survey",
  "title": "yes_no",
  "id_string": "yes_no",
  "sms_keyword": "yes_no",
  "default_language": "default",
  "version": "201909172025",
  "children": [
    {
      "name": "your_choice",
      "label": "Your choice is?",
      "type": "select one",
      "children": [
        {
          "name": "1",
          "label": "Yes"
        },
        {
          "name": "2",
          "label": "No"
        }
      ]
    },
    {
      "name": "meta",
      "type": "group",
      "control": {
        "bodyless": true
      },
      "children": [
        {
          "name": "instanceID",
          "type": "calculate",
          "bind": {
            "readonly": "true()",
            "calculate": "concat('uuid:', uuid())"
          }
        }
      ]
    }
  ]
}

@qlands
Copy link
Contributor Author

qlands commented Sep 18, 2019

Hiving the choices at the top does not solve the issue because you cannot link a simple select_one or multi_select with the items in choices. For example the variable "your_choice" you don't know that is linked to the choices called "yes_no". You might guess it by its values, but we end up with the problem I described before.

Exactly, is not present when there is no choice filter. Thus I request to add it with a key called list_name but we can rename it to "itemset" if this does not make conflicts with third-party installations. My guess is that is safer to name it list_name and leave itemset when a choice filter is used.

@ukanga ukanga merged commit 2b74199 into XLSForm:master Sep 18, 2019
DavisRayM added a commit to onaio/onadata that referenced this pull request Feb 28, 2020
As of PyXForm v1.0.0 the 'list_name' field has been added to a forms
generated JSON. More Info: XLSForm/pyxform#357
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 2, 2020
As of PyXForm v1.0.0 the 'list_name' field has been added to a forms
generated JSON. More Info: XLSForm/pyxform#357
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 2, 2020
As of PyXForm v1.0.0 the 'list_name' field has been added to a forms
generated JSON. More Info: XLSForm/pyxform#357
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 2, 2020
As of PyXForm v1.0.0 the 'list_name' field has been added to a forms
generated JSON. More Info: XLSForm/pyxform#357
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 2, 2020
As of PyXForm v1.0.0 the 'list_name' field has been added to a forms
generated JSON. More Info: XLSForm/pyxform#357
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 3, 2020
As of PyXForm v1.0.0 the 'list_name' field has been added to a forms
generated JSON. More Info: XLSForm/pyxform#357
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 3, 2020
As of PyXForm v1.0.0 the 'list_name' field has been added to a forms
generated JSON. More Info: XLSForm/pyxform#357
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 13, 2020
As of PyXForm v1.0.0 the 'list_name' field has been added to a forms
generated JSON. More Info: XLSForm/pyxform#357
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 27, 2020
As of PyXForm v1.0.0 the 'list_name' field has been added to a forms
generated JSON. More Info: XLSForm/pyxform#357
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 27, 2020
As of PyXForm v1.0.0 the 'list_name' field has been added to a forms
generated JSON. More Info: XLSForm/pyxform#357
DavisRayM added a commit to onaio/onadata that referenced this pull request Mar 27, 2020
As of PyXForm v1.0.0 the 'list_name' field has been added to a forms
generated JSON. More Info: XLSForm/pyxform#357
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants