❔ Smart way to code an insurance pricing calculation with explanation?
I'm refactoring a ~60% correct pricing method. To give you an idea its currently like 1000 lines of c# code, 1000 lines of sql queries and maybe about 7 involved tables.
The code and math is actually not heavily complicated. Its just a LOT of
"if there is a contract for this item in that table, its prio1. Otherwise look for an old contract in the other table with column = true, thats prio2, column = flase is prio3..."
"If there is a discount, apply the discount from that table, but only up to this total"
The heaviest mathemathical operation is actually just percentages.
Its important for users to see how the app ended up at the final number.
All I can think of is basically doing it manually. For every line of math, i just add an explanation after like this:
The code and math is actually not heavily complicated. Its just a LOT of
"if there is a contract for this item in that table, its prio1. Otherwise look for an old contract in the other table with column = true, thats prio2, column = flase is prio3..."
"If there is a discount, apply the discount from that table, but only up to this total"
The heaviest mathemathical operation is actually just percentages.
Its important for users to see how the app ended up at the final number.
All I can think of is basically doing it manually. For every line of math, i just add an explanation after like this:
if(contract.AllowDiscount && discountTotal < allowedDiscount)
price = price * (1-contract.Discount)
Console.WriteLine("Discount is below {allowedDiscount}. Reducing price by {contract.Discount}%")