[SERVER-32790] Add Weighted Average method to aggregation framework Created: 19/Jan/18 Updated: 06/Dec/22 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | 3.6.0 |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Yair Lenga | Assignee: | Backlog - Query Optimization |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | expression | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Assigned Teams: |
Query Optimization
|
| Participants: |
| Description |
|
Add '$weightedAverage' operator to the aggregation framework. Currently, MongoDB has the $avg operator. It simplify the calculation of simple averages. The request is to create built in operator for calculating weighted average - where the weight of each item is specified by a different field. Weighted average is used extensively in financial, statistical and scientific analysis of large data set. While it is technically possible to implement it based on existing operators (sum(...)), the implementation is error-prone, and correct handling of missing/non-numeric values make is difficult. Proposed operator: $weightedAvg($weight, $value) Should calculation
Calculation should ignore any record where w(I), or v(I) is not numeric. this is important, as the current replacement $sum($multiply($v1, $w1)) / sum($w1) does not handle missing values correctly, and require complex filtering. If possible, it will be nice to allow for multiple values to be calculated with the same pass. |