I'm building a reporting tool with three core layers:
- Extract data from a database
- Transform this data to compute business metrics
- Display these metrics in a report (a heavily formatted Excel export in this case)
My challenge is that there seems to be some irreducible complexity in the task, and I'm finding it very challenging to avoid spaghetti code. In particular, I want to avoid tight coupling between my data engineering and my UI work.
To give a high-level example:
- Calculate metric "change in sales" as (Sales Today - Sales Yesterday)
- Format the output as a currency, i.e. f'${x:,.2f}'
- Set the font colour to green if > 10
- Set the font colour to red if < -10
And to illustrate my challenges, suppose the business says "we've changed our mind":
Calculate metric "change in sales" as (Sales Today / Sales Yesterday - 1)
Format the output as a percentage change, i.e. f'{x:.0%}'
Set the font colour to 'green' if > 0.10
Set the font colour to 'red' if < -0.10
Set the background to 'blue' if Sales Yesterday = 0, and display the most recent "change in sales" that could be calculated for the store and show the date of this on hover.
I'm not sure how to leverage good software engineering to make these near-daily changes "easy". I either bundle calculation & business logic in one big "metric" object (tight coupling of calculation and display) or I commit myself to modify a formatting pipeline each time the calculation changes, and the data pipeline each time a display requirement needs data extrinsic to the final value (e.g. date last calculated in the example above).
Any ideas on how to address this?