Skip to content

Commit

Permalink
[#rubyforgood#6174] added metrics for logged contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
Raushan Kumar Raman committed Jan 26, 2025
1 parent 4356348 commit 819275a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
6 changes: 4 additions & 2 deletions app/controllers/health_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions app/javascript/src/display_app_metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ 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)
}

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)
Expand Down
18 changes: 12 additions & 6 deletions spec/requests/health_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 819275a

Please sign in to comment.