Class: Workarea::Reports::ReviewsByUser
- Inherits:
-
Object
- Object
- Workarea::Reports::ReviewsByUser
- Includes:
- Report
- Defined in:
- app/queries/workarea/reports/reviews_by_user.rb
Instance Method Summary collapse
- #aggregation ⇒ Object
- #filter_results ⇒ Object
- #group_by_email ⇒ Object
- #project_fields ⇒ Object
- #project_used_fields ⇒ Object
Instance Method Details
#aggregation ⇒ Object
9 10 11 |
# File 'app/queries/workarea/reports/reviews_by_user.rb', line 9 def aggregation [filter_results, project_used_fields, group_by_email, project_fields] end |
#filter_results ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'app/queries/workarea/reports/reviews_by_user.rb', line 13 def filter_results { '$match' => { 'created_at' => { '$gte' => starts_at, '$lte' => ends_at }, **approval_query } } end |
#group_by_email ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/queries/workarea/reports/reviews_by_user.rb', line 33 def group_by_email { '$group' => { '_id' => '$email', 'user_id' => { '$max' => '$user_id' }, 'reviews' => { '$sum' => 1 }, 'verified' => { '$sum' => { '$cond' => { 'if' => '$verified', 'then' => 1, 'else' => 0 } } }, 'rating_tally' => { '$sum' => '$rating' } } } end |
#project_fields ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/queries/workarea/reports/reviews_by_user.rb', line 45 def project_fields { '$project' => { 'email' => 1, 'user_id' => 1, 'reviews' => 1, 'verified' => 1, 'average_rating' => { '$divide' => ['$rating_tally', '$reviews'] }, 'activity_score' => { '$sum' => ['$reviews', { '$multiply' => ['$verified', 0.75] }] } } } end |
#project_used_fields ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'app/queries/workarea/reports/reviews_by_user.rb', line 22 def project_used_fields { '$project' => { 'email' => 1, 'user_id' => 1, 'rating' => 1, 'verified' => 1 } } end |