Skip to content

Commit ae0af55

Browse files
authored
Merge pull request #6198 from Raushan998/feat/add_volunteer_graph
[##6174] added metrics for logged contacts
2 parents c9d519b + ac5d77a commit ae0af55

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

app/controllers/health_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ def monthly_unique_users_graph_data
5353
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)
5454
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)
5555
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)
56+
monthly_logged_counts_of_volunteers = CaseContact.joins(supervisor_volunteer: :volunteer).group_by_month(:created_at, format: "%b %Y").distinct.count(:creator_id)
5657

5758
monthly_line_graph_combined_data = first_day_of_last_12_months.map do |month|
5859
[
5960
month,
6061
monthly_counts_of_volunteers[month] || 0,
6162
monthly_counts_of_supervisors[month] || 0,
62-
monthly_counts_of_casa_admins[month] || 0
63+
monthly_counts_of_casa_admins[month] || 0,
64+
monthly_logged_counts_of_volunteers[month] || 0
6365
]
6466
end
6567

app/javascript/src/display_app_metric.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ function createLineChartForCaseContacts (chartElement, dataset) {
170170
}
171171

172172
function createLineChartForUniqueUsersMonthly (chartElement, dataset) {
173-
const datasetLabels = ['Total Volunteers', 'Total Supervisors', 'Total Admins']
173+
const datasetLabels = ['Total Volunteers', 'Total Supervisors', 'Total Admins', 'Total logged Volunteers']
174174
return createLineChart(chartElement, dataset, 'Monthly Active Users', datasetLabels)
175175
}
176176

177177
function createLineChart (chartElement, dataset, chartTitle, datasetLabels) {
178178
const ctx = chartElement.getContext('2d')
179179
const allMonths = extractChartData(dataset, 0)
180180
const datasets = []
181-
const colors = ['#308af3', '#48ba16', '#FF0000']
181+
const colors = ['#308af3', '#48ba16', '#FF0000', '#FFA500']
182182

183183
for (let i = 1; i < dataset[0].length; i++) {
184184
const data = extractChartData(dataset, i)

spec/requests/health_spec.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ def setup
104104
volunteer2 = create(:user, type: "Volunteer")
105105
supervisor = create(:user, type: "Supervisor")
106106
casa_admin = create(:user, type: "CasaAdmin")
107+
supervisor_volunteer1 = create(:supervisor_volunteer, is_active: true)
108+
supervisor_volunteer2 = create(:supervisor_volunteer, is_active: true)
107109

108110
create(:login_activity, user: volunteer1, created_at: 11.months.ago, success: true)
109111
create(:login_activity, user: volunteer2, created_at: 11.months.ago, success: true)
@@ -113,6 +115,10 @@ def setup
113115
create(:login_activity, user: volunteer2, created_at: 9.months.ago, success: true)
114116
create(:login_activity, user: supervisor, created_at: 9.months.ago, success: true)
115117
create(:login_activity, user: casa_admin, created_at: 9.months.ago, success: true)
118+
create(:case_contact, creator_id: supervisor_volunteer1.volunteer_id, created_at: 11.months.ago)
119+
create(:case_contact, creator_id: supervisor_volunteer1.volunteer_id, created_at: 11.months.ago)
120+
create(:case_contact, creator_id: supervisor_volunteer2.volunteer_id, created_at: 11.months.ago)
121+
create(:case_contact, creator_id: supervisor_volunteer1.volunteer_id, created_at: 10.months.ago)
116122
end
117123

118124
it "returns monthly unique users data for volunteers, supervisors, and admins in the last year" do
@@ -128,9 +134,9 @@ def setup
128134
expect(chart_data).to be_an(Array)
129135
expect(chart_data.length).to eq(12)
130136

131-
expect(chart_data[0]).to eq([11.months.ago.strftime("%b %Y"), 2, 1, 1])
132-
expect(chart_data[1]).to eq([10.months.ago.strftime("%b %Y"), 1, 0, 0])
133-
expect(chart_data[2]).to eq([9.months.ago.strftime("%b %Y"), 1, 1, 1])
137+
expect(chart_data[0]).to eq([11.months.ago.strftime("%b %Y"), 2, 1, 1, 2])
138+
expect(chart_data[1]).to eq([10.months.ago.strftime("%b %Y"), 1, 0, 0, 1])
139+
expect(chart_data[2]).to eq([9.months.ago.strftime("%b %Y"), 1, 1, 1, 0])
134140
end
135141

136142
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
146152
expect(chart_data).to be_an(Array)
147153
expect(chart_data.length).to eq(12)
148154

149-
expect(chart_data[0]).to eq([11.months.ago.strftime("%b %Y"), 2, 1, 1])
150-
expect(chart_data[1]).to eq([10.months.ago.strftime("%b %Y"), 1, 0, 0])
151-
expect(chart_data[2]).to eq([9.months.ago.strftime("%b %Y"), 1, 1, 1])
155+
expect(chart_data[0]).to eq([11.months.ago.strftime("%b %Y"), 2, 1, 1, 2])
156+
expect(chart_data[1]).to eq([10.months.ago.strftime("%b %Y"), 1, 0, 0, 1])
157+
expect(chart_data[2]).to eq([9.months.ago.strftime("%b %Y"), 1, 1, 1, 0])
152158
end
153159
end
154160
end

0 commit comments

Comments
 (0)