Skip to content

Store excel formulae for calculated intervention data rows/cells #351

@bgsandan

Description

@bgsandan

Whilst the definitive values for the intervention calculations should be the ones in the database (re-calculated on updates to the individual values in intervention_data via @andy-bevan's script, we should also encode the relationships in a manner that they can be sent to the front-end.

This will allow (for example), fields that contain totals to be updated in the UI on the fly when values are updated (multiplying no. of factories by number of inspections etc).

To facilitate this, the intention is to utilise jsonLogic (http://jsonlogic.com) to encode the relationships in a format that can be sent in the API response and parsed and calculated on the front-end. @bgsandan has already managed to demonstrate a proof-of-concept of automatically converting an Excel formula e.g. =(D57+D60+D63)*D73+D70*D74 into its jsonLogic representation which can then utilised in the front-end:

{  "+": [
    {
      "*": [
        {
          "+": [
            {
              "+": [
                {
                  "var": "row57.year0"
                },
                {
                  "var": "row60.year0"
                }
              ]
            },
            {
              "var": "row63.year0"
            }
          ]
        },
        {
          "var": "row73.year0"
        }
      ]
    },
    {
      "*": [
        {
          "var": "row70.year0"
        },
        {
          "var": "row74.year0"
        }
      ]
    }
  ]
}

If the database can store the input formulae for fields with field types of totals or calculatedvalues then these formulae can be exposed in the appropriate views allowing this conversion to jsonLogic to be handled at the API layer.

See https://kwvmxgit.ad.nerc.ac.uk/-/snippets/125 / https://kwvmxgit.ad.nerc.ac.uk/-/snippets/126 for more info

Metadata

Metadata

Assignees

No one assigned

    Labels

    2023-Sprint-1Priority::1User story that we want to focus onarea::costingsRelated to costs of micronutrient programs and internventions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions