allegro/ralph_pricing — pull request #95 by mkurek (2014-01-24 13:49:06+00:00)
Title: Feature/improve reports performance

New beta version of pricing report by ventures (NOT for use on production right now - has to be tested (manually and automatically) if values are same as in current report).

TODO:
- add unit tests
- add blades calculation to fix assets costs

Changes description:
I've totally abandoned current report and connected with it methods/functions - they are extremely slow. New beta version makes much less sql queries and as many as possible calculations are made on the db side - grouping, summing, counting and so on.

General idea:
First step is ventures preparsing - for every venture it's id, name, department and other informations are saved.
Second step is calculation of assets costs per venture.
Then all usage type costs/counts per venture are calculated. First of all specified usage type total usage count (per venture) are calculated. Then, for every usage price period, calculation of cost of usages (per venture) in usage price period (intersected with report period) is processed.
The last step of caculation is to calculate extra costs per venture.
At the end every results are parsed again to fill missing usages per venture (with 0 - there may be situation where venture does not have any records in usage of specific type - it has to be filled before putting everything into result table).

Result of new report has the same format as old report, but there are no partial results (only progress has meaningful value).