micronutrientsupport / database-architecture

The Postgres database code for the MAPS tool
3 stars 0 forks source link

How to store formulas for calculations #272

Closed rbroth closed 1 year ago

rbroth commented 2 years ago

267

As previously discussed, although the database will be maintaining the 'canonical' values for various calculations (via @andy-bevan 's script), the front-end will need to do some calculations (e.g. , basic summing/multiplication of cell values, ensuring %age values sum to 100% etc.) within a given view when the user updates values.

What are your thoughts on the best way of encoding these requirements?

Obviously the rows have a row_name e.g. total_inspections_cost = annual_factory_inspections x factory_inspections_unit_cost. Should these relationships be stored in the db somewhere and returned to the front-end to parse, should the front-end 'know' these hardcoded somewhere, should it be something else - One for collaboration with the front-end guys here

rbroth commented 2 years ago

Difficult.

rbroth commented 2 years ago

For second point we'd have to do a lot of research. Might pay off though. Maye something like https://github.com/LesterLyu/fast-formula-parser

rbroth commented 2 years ago

Conclusion in meeting just now: hardcode some formulas in the frontend

bgsandan commented 1 year ago

Closing as superseded by #351