Class: Workarea::Reports::ReviewsByUser

Inherits:
Object
  • Object
show all
Includes:
Report
Defined in:
app/queries/workarea/reports/reviews_by_user.rb

Instance Method Summary collapse

Instance Method Details

#aggregationObject



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_resultsObject



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_emailObject



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_fieldsObject



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_fieldsObject



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