ddrake / Integrated_Farm_Budget_Tool

Other
1 stars 0 forks source link

Consider using AJAX with Sensitivity and Detailed Budget #184

Closed ddrake closed 10 months ago

ddrake commented 10 months ago

I think we'll still want to compute all data at once for Sensitivity, but I think it might not be too difficult to generate, render and serve the tables one at a time via AJAX. We could do something similar for the Detailed budget, i.e. first serve the current budget, then use AJAX to switch to baseline or diff or switch back. Instead of storing all rendered tables in the database (along with the data used for diffs), we would store only the last selected (so it would be available for printing). This should greatly reduce database bloat. I think the download times could be reduced quite a bit this way too.

ddrake commented 10 months ago

This worked out great for sensitivity. Because the tables have different layouts depending on the crop and report type, I made it so that the first request generates all the data, but only builds the table for farm cash flow which is rendered in html (no ajax). Then if you change any setting, the data is just loaded from the database (not re-computed) and one new table corresponding to the settings is generated and rendered in JSON. Then in Javascript, we build the table in the DOM and replace the old table with it. It's much faster now, and even though I now have to store the diff data, the database should stay small because were only saving one generated table at a time instead of hundreds of tables.

For the detailed budget, that approach won't work as well. The Javascript to construct the revenue table and budget table would be quite complicated. But since the format of the detailed budget and revenue table is the same for baseline, variance and current, I think we can simply send the formatted number strings in Json and just replace the inner html of each td element. As for the database, I think we only need to store the baseline data, current data (as we are already), and the formatted table numbers, which will be much less than what we're currently storing.

ddrake commented 10 months ago

This is all complete in commit b2044e4.