diff --git a/app/controllers/health_controller.rb b/app/controllers/health_controller.rb index 3df05cdfc3..45e4408248 100644 --- a/app/controllers/health_controller.rb +++ b/app/controllers/health_controller.rb @@ -53,13 +53,15 @@ def monthly_unique_users_graph_data monthly_counts_of_volunteers = LoginActivity.joins("INNER JOIN users ON users.id = login_activities.user_id AND login_activities.user_type = 'User'").where(users: {type: "Volunteer"}, success: true).group_by_month(:created_at, format: "%b %Y").distinct.count(:user_id) monthly_counts_of_supervisors = LoginActivity.joins("INNER JOIN users ON users.id = login_activities.user_id AND login_activities.user_type = 'User'").where(users: {type: "Supervisor"}, success: true).group_by_month(:created_at, format: "%b %Y").distinct.count(:user_id) monthly_counts_of_casa_admins = LoginActivity.joins("INNER JOIN users ON users.id = login_activities.user_id AND login_activities.user_type = 'User'").where(users: {type: "CasaAdmin"}, success: true).group_by_month(:created_at, format: "%b %Y").distinct.count(:user_id) - + monthly_logged_counts_of_volunteers = CaseContact.joins(:supervisor_volunteer).group_by_month(:created_at, format: "%b %Y").distinct.count(:creator_id) + monthly_line_graph_combined_data = first_day_of_last_12_months.map do |month| [ month, monthly_counts_of_volunteers[month] || 0, monthly_counts_of_supervisors[month] || 0, - monthly_counts_of_casa_admins[month] || 0 + monthly_counts_of_casa_admins[month] || 0, + monthly_logged_counts_of_volunteers[month] || 0 ] end diff --git a/app/javascript/src/display_app_metric.js b/app/javascript/src/display_app_metric.js index 91389daa30..4df412b94c 100644 --- a/app/javascript/src/display_app_metric.js +++ b/app/javascript/src/display_app_metric.js @@ -170,7 +170,7 @@ function createLineChartForCaseContacts (chartElement, dataset) { } function createLineChartForUniqueUsersMonthly (chartElement, dataset) { - const datasetLabels = ['Total Volunteers', 'Total Supervisors', 'Total Admins'] + const datasetLabels = ['Total Volunteers', 'Total Supervisors', 'Total Admins', 'Total logged Volunteers'] return createLineChart(chartElement, dataset, 'Monthly Active Users', datasetLabels) } @@ -178,7 +178,7 @@ function createLineChart (chartElement, dataset, chartTitle, datasetLabels) { const ctx = chartElement.getContext('2d') const allMonths = extractChartData(dataset, 0) const datasets = [] - const colors = ['#308af3', '#48ba16', '#FF0000'] + const colors = ['#308af3', '#48ba16', '#FF0000', '#FFA500'] for (let i = 1; i < dataset[0].length; i++) { const data = extractChartData(dataset, i) diff --git a/spec/requests/health_spec.rb b/spec/requests/health_spec.rb index 7c383780a7..88dcce8884 100644 --- a/spec/requests/health_spec.rb +++ b/spec/requests/health_spec.rb @@ -104,6 +104,8 @@ def setup volunteer2 = create(:user, type: "Volunteer") supervisor = create(:user, type: "Supervisor") casa_admin = create(:user, type: "CasaAdmin") + supervisor_volunteer1 = create(:supervisor_volunteer, is_active: true) + supervisor_volunteer2 = create(:supervisor_volunteer, is_active: true) create(:login_activity, user: volunteer1, created_at: 11.months.ago, success: true) create(:login_activity, user: volunteer2, created_at: 11.months.ago, success: true) @@ -113,6 +115,10 @@ def setup create(:login_activity, user: volunteer2, created_at: 9.months.ago, success: true) create(:login_activity, user: supervisor, created_at: 9.months.ago, success: true) create(:login_activity, user: casa_admin, created_at: 9.months.ago, success: true) + create(:case_contact, creator_id: supervisor_volunteer1.volunteer_id, created_at: 11.months.ago) + create(:case_contact, creator_id: supervisor_volunteer1.volunteer_id, created_at: 11.months.ago) + create(:case_contact, creator_id: supervisor_volunteer2.volunteer_id, created_at: 11.months.ago) + create(:case_contact, creator_id: supervisor_volunteer1.volunteer_id, created_at: 10.months.ago) end it "returns monthly unique users data for volunteers, supervisors, and admins in the last year" do @@ -128,9 +134,9 @@ def setup expect(chart_data).to be_an(Array) expect(chart_data.length).to eq(12) - expect(chart_data[0]).to eq([11.months.ago.strftime("%b %Y"), 2, 1, 1]) - expect(chart_data[1]).to eq([10.months.ago.strftime("%b %Y"), 1, 0, 0]) - expect(chart_data[2]).to eq([9.months.ago.strftime("%b %Y"), 1, 1, 1]) + expect(chart_data[0]).to eq([11.months.ago.strftime("%b %Y"), 2, 1, 1, 2]) + expect(chart_data[1]).to eq([10.months.ago.strftime("%b %Y"), 1, 0, 0, 1]) + expect(chart_data[2]).to eq([9.months.ago.strftime("%b %Y"), 1, 1, 1, 0]) end it "returns monthly unique users data for volunteers, supervisors, and admins in the last year (on the first of the month)" do @@ -146,9 +152,9 @@ def setup expect(chart_data).to be_an(Array) expect(chart_data.length).to eq(12) - expect(chart_data[0]).to eq([11.months.ago.strftime("%b %Y"), 2, 1, 1]) - expect(chart_data[1]).to eq([10.months.ago.strftime("%b %Y"), 1, 0, 0]) - expect(chart_data[2]).to eq([9.months.ago.strftime("%b %Y"), 1, 1, 1]) + expect(chart_data[0]).to eq([11.months.ago.strftime("%b %Y"), 2, 1, 1, 2]) + expect(chart_data[1]).to eq([10.months.ago.strftime("%b %Y"), 1, 0, 0, 1]) + expect(chart_data[2]).to eq([9.months.ago.strftime("%b %Y"), 1, 1, 1, 0]) end end end