InseeFr / Lunatic

Library of questionnaire components
https://inseefr.github.io/Lunatic/
MIT License
20 stars 21 forks source link

Bug for a computed variable in a loop #917

Closed romaintailhurat closed 5 months ago

romaintailhurat commented 5 months ago

Describe the bug

A calculated variable on a questionnaire is having a bad structure.

The computed variable T_MENAGE_PRINC from the TCM has in a problematic use case this form:

"T_MENAGE_PRINC": [
      1,
      0,
      [
        0,
        0
      ]
    ],

That is, instead of having n scalars in its array (here n = 3, because the loop have 3 iterations), we have the last index being an array of 2.

To Reproduce

In order to reproduce, i attach here two questionnaires:

To reproduce the issue:

  1. With srcv-buggy.json on the storybook 2.7
  2. Choose a number, for example 3 for this question image
  3. In the following question add a surname for each inhabitants
  4. You can skip answers until the birthdate that should make the individuals adult (use 2000 for example) image
  5. Skip everything until the pairwise question in which everyone is a housemate ("colocataire") image
  6. Skip to the "other house" question and answer "No" for everyone image
  7. At last, we arrived to the "test" Sequence which display various variables including T_MENAGE_PRINC and we can see the last one is not working (because of the structure highlighted above) image

Source questionnaires

srcv-bug.zip

Grafikart commented 5 months ago

@romaintailhurat Quel est la différence entre les 2 json ? Que représente la variable T_MENAGE_PRINC ?

romaintailhurat commented 5 months ago

La variable T_MENAGE_PRINC est une variable de boucle sur chaque habitant du logement pour déterminer s'il fait partie du ménage principal, sa valeur est 1 ou 0. Le code VTL:

if ($T_TYPE_MEN_LOG$ = 1 or $T_TYPE_MEN_LOG$ = 2 or $T_TYPE_MEN_LOG$ = 3 or $T_TYPE_MEN_LOG$ = 5) then 1
else if ($T_TYPE_MEN_LOG$ = 4) then (
    if ($PRENOM$ = $PRENOMREF$) then 1
    else 0)
else (
    if $T_NB_MEN_FINAL$ = 1 then 1
    else (
        if (nvl($T_MP$,"1") = "1") then 1
        else 0))
romaintailhurat commented 5 months ago

Le premier JSON (srcv-buggy.json) correspond au questionnaire qui porte le bug, sa construction dans Pogues est la suivante:

image

En vert, le module qui contient les variables calculées (dont T_MENAGE_PRINC). En rouge, la séquence dans laquelle on affiche les variables (et dans laquelle on constate le bug).

Les deux modules qui suivnet TCM_THL_DET_PROXY ainsi que la séquence test sont dans des boucles liées à la boucle des prénoms (issue de TCM_THL_DET_PROXY).

Le second questionnaire (dans lequel on ne constate pas le problème) a la structure suivante - elle reprend l'idée du questionnaire problématique en le simplifiant:

image

romaintailhurat commented 5 months ago

Pour information: dans les deux cas, on utilise le module TCM_THL_DET_PROXY qui inclut le Pairwise.