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

Support conditional branching for task progression #2255

Merged
merged 22 commits into from
Mar 5, 2024

Conversation

sufyanAbbasi
Copy link
Contributor

@sufyanAbbasi sufyanAbbasi commented Feb 23, 2024

Fixes #1955

  • Adds support for
  • Adds Conditions and Expression classes and converters from JSON config (see spec here: [Create/edit survey] Allow organizers to add conditional tasks ground-platform#1478)
  • Supports all, any, and one match types for lists of expressions and selections in tasks.
  • Refactors saving task position to current task ID and dynamically calculates the task sequence on Previous/Next.
  • Handles dynamically moving between tasks based on conditions.
  • Progress bar shows dynamic position on the task sequence.
  • Used the following configuration (minus acls) to verify that tasks progress as expected.:
  • Test when the last task in the progression is conditional.
{
  "title": "A conditional survey",
  "jobs": {
    "qKxHiyBN9KqWhVXWp11W": {
      "dataCollectorsCanAdd": [
        "points",
        "polygons"
      ],
      "index": 1,
      "tasks": {
        "RyWKlphglHQzcmuqEPlk": {
          "required": false,
          "id": "RyWKlphglHQzcmuqEPlk",
          "type": "draw_area",
          "label": "Only if you picked x and y",
          "condition": {
            "matchType": "MATCH_ALL",
            "expressions": [
              {
                "expressionType": "ANY_OF_SELECTED",
                "taskId": "GqEBDoAoEnPbMmRbje5c",
                "optionIds": [
                  "MFOdfshBZSieX5dddPfj"
                ]
              },
              {
                "expressionType": "ANY_OF_SELECTED",
                "taskId": "GqEBDoAoEnPbMmRbje5c",
                "optionIds": [
                  "Po2zyacw6FVFE6gaL8km"
                ]
              }
            ]
          },
          "addLoiTask": false,
          "index": 3
        },
        "myaWTKIBVd38e1TLfiDs": {
          "required": false,
          "addLoiTask": false,
          "label": "Only if you picked x",
          "index": 2,
          "condition": {
            "expressions": [
              {
                "expressionType": "ANY_OF_SELECTED",
                "taskId": "GqEBDoAoEnPbMmRbje5c",
                "optionIds": [
                  "MFOdfshBZSieX5dddPfj"
                ]
              }
            ],
            "matchType": "MATCH_ALL"
          },
          "type": "drop_pin",
          "id": "myaWTKIBVd38e1TLfiDs"
        },
        "trmOruwBVL1uaiUNAJ4D": {
          "index": 5,
          "label": "Did you get to the end?",
          "id": "trmOruwBVL1uaiUNAJ4D",
          "type": "text_field",
          "addLoiTask": false,
          "required": false
        },
        "GqEBDoAoEnPbMmRbje5c": {
          "label": "Pick an choice, any or all choices!",
          "options": {
            "Po2zyacw6FVFE6gaL8km": {
              "code": "",
              "index": 1,
              "label": "y"
            },
            "MFOdfshBZSieX5dddPfj": {
              "label": "x",
              "code": "",
              "index": 0
            },
            "rVbIQmFIajZvnlSIl7n3": {
              "index": 2,
              "code": "",
              "label": "z"
            }
          },
          "index": 1,
          "cardinality": "select_multiple",
          "type": "multiple_choice",
          "id": "GqEBDoAoEnPbMmRbje5c",
          "required": false,
          "hasOtherOption": true,
          "addLoiTask": false
        },
        "wKK9LEHjo9oWeu1i71Ek": {
          "id": "wKK9LEHjo9oWeu1i71Ek",
          "type": "drop_pin",
          "label": "Pick your current location",
          "index": 0,
          "required": true,
          "addLoiTask": true
        },
        "UjSOau5djBlhTKkGgRZQ": {
          "index": 4,
          "label": "Why did you pick x, y, and z?",
          "type": "text_field",
          "required": false,
          "addLoiTask": false,
          "id": "UjSOau5djBlhTKkGgRZQ",
          "condition": {
            "expressions": [
              {
                "expressionType": "ALL_OF_SELECTED",
                "optionIds": [
                  "MFOdfshBZSieX5dddPfj",
                  "Po2zyacw6FVFE6gaL8km",
                  "rVbIQmFIajZvnlSIl7n3"
                ],
                "taskId": "GqEBDoAoEnPbMmRbje5c"
              }
            ],
            "matchType": "MATCH_ALL"
          }
        },
        "n296k4Rz8gkZAMNVULDU": {
          "type": "text_field",
          "addLoiTask": false,
          "index": 6,
          "label": "(Secret end if you picked z) Did you actually get to the end?",
          "condition": {
            "expressions": [
              {
                "expressionType": "ANY_OF_SELECTED",
                "taskId": "GqEBDoAoEnPbMmRbje5c",
                "optionIds": [
                  "rVbIQmFIajZvnlSIl7n3"
                ]
              }
            ],
            "matchType": "MATCH_ALL"
          },
          "required": false
        }
      },
      "strategy": "AD_HOC",
      "name": "Pick various options to test conditions",
      "id": "qKxHiyBN9KqWhVXWp11W",
      "defaultStyle": {
        "color": "#F37C22"
      }
    }
  },
...
}

@gino-m

@sufyanAbbasi sufyanAbbasi marked this pull request as ready for review February 27, 2024 04:25
# Conflicts:
#	ground/src/main/java/com/google/android/ground/persistence/local/room/converter/ConverterExt.kt
Copy link
Collaborator

@gino-m gino-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few initial comments, review still WIP.

@gino-m gino-m changed the title Support conditional branching for task progression. Support conditional branching for task progression Feb 29, 2024
@sufyanAbbasi sufyanAbbasi requested a review from gino-m March 5, 2024 00:16
Copy link
Collaborator

@gino-m gino-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@shobhitagarwal1612
Copy link
Member

[ktfmt] Invalid formatting for: /workspace/ground/src/main/java/com/google/android/ground/ui/datacollection/DataCollectionFragment.kt
[ktfmt] Invalid formatting for: /workspace/ground/src/main/java/com/google/android/ground/ui/datacollection/DataCollectionViewModel.kt
[ktfmt] Invalid formatting for: /workspace/ground/src/main/java/com/google/android/ground/persistence/local/room/converter/ConverterExt.kt

@sufyanAbbasi
Copy link
Contributor Author

sufyanAbbasi commented Mar 5, 2024

Fixed those last minute code formatting, sorry about that! Doing one more test to make sure and then merging.

Working as intended! Ready to ship!!

@gino-m
Copy link
Collaborator

gino-m commented Mar 5, 2024

W000t!!!

@gino-m gino-m merged commit b70c871 into master Mar 5, 2024
4 checks passed
@gino-m gino-m deleted the sufy/1995/conditional-branches branch March 5, 2024 20:08
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.

[Data collection tasks] Support conditional tasks
3 participants