次の 2 つのモデル とCompany
を使用して、次のResponse
ように企業ごとの合計回答数のクエリを作成しています。
@allResponses = Company.find(current_user_company_id).responses
これにより、次のようなデータが得られます。
[#<Response id: 1, company_id: 1, created_at: "2013-04-24 02:36:54", feedback_score: 10, feedback_explanation: "I really like the way you guys do xyz.", additional_data: "", updated_at: "2013-04-24 02:36:54">, #<Response id: 2, company_id: 1, created_at: "2013-04-25 03:51:07", feedback_score: 5, feedback_explanation: "customer service is spotty.", additional_data: "", updated_at: "2013-04-25 03:51:07">, #<Response id: 3, company_id: 1, created_at: "2013-04-25 03:52:04", feedback_score: 7, feedback_explanation: "You've got potential.", additional_data: "", updated_at: "2013-04-25 03:52:04">, #<Response id: 4, company_id: 1, created_at: "2013-04-25 03:52:18", feedback_score: 9, feedback_explanation: "Almost perfect.", additional_data: "", updated_at: "2013-04-25 03:52:18">]
このデータから次の 2 つの変数を取得したいと考えています。
@sumOfHighScores = some.thing.here #sum of feedback_scores that are greater than 8
@sumOfLowScores = some.thing.here.too #sum of feedback_scores that are less than 7