Skip to content

Commit 83bbbc9

Browse files
authored
Merge pull request #170 from fraz3alpha/fix-v-index-role-grouping
Group volunteer roles before stats and challenges
2 parents 4d01497 + 6a04fc6 commit 83bbbc9

File tree

1 file changed

+71
-44
lines changed

1 file changed

+71
-44
lines changed

browser-extensions/common/js/lib/challenges.js

Lines changed: 71 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,64 @@
11

2+
/*
3+
* Some volunteer roles have changed names, or a role has been deprecated,
4+
* or it makes sense to know a role by another name. This attempts to do that.
5+
* This has lots of problems, such as the ability to display them in a language
6+
* other than English, but that's how it currently works.
7+
*/
8+
9+
volunteer_roles_map = [
10+
{"shortname": "equipment-storage", "name": "Equipment Storage and Delivery"},
11+
{"shortname": "comms-person", "name": "Communications Person"},
12+
{"shortname": "volunteer-coordinator", "name": "Volunteer Co-ordinator"},
13+
{"shortname": "event-day-course-check", "name": "Event Day Course Check"},
14+
{"shortname": "setup", "name": "Pre-event Setup"},
15+
{"shortname": "car-park-marshal", "name": "Car Park Marshal"},
16+
{"shortname": "first-timers-briefing", "name": "First Timers Briefing"},
17+
{"shortname": "sign-language", "name": "Sign Language Support"},
18+
{"shortname": "marshal", "name": "Marshal"},
19+
{"shortname": "tail-walker", "name": "Tail Walker"},
20+
{"shortname": "run-director", "name": "Run Director"},
21+
{"shortname": "lead-bike", "name": "Lead Bike"},
22+
{"shortname": "pacer", "name": "Pacer", "matching-roles": ["Pacer (5k only)"]},
23+
{"shortname": "vi-guide", "name": "Guide Runner", "matching-roles": ["VI Guide"]},
24+
{"shortname": "photographer", "name": "Photographer"},
25+
{"shortname": "timer", "name": "Timer", "matching-roles": ["Timekeeper", "Backup Timer"]},
26+
{"shortname": "funnel-manager", "name": "Funnel Manager"},
27+
{"shortname": "finish-tokens", "name": "Finish Tokens & Support", "matching-roles": ["Finish Tokens", "Finish Token Support"]},
28+
{"shortname": "barcode-scanning", "name": "Barcode Scanning"},
29+
{"shortname": "manual-entry", "name": "Number Checker"},
30+
{"shortname": "close-down", "name": "Post-event Close Down"},
31+
{"shortname": "results-processing", "name": "Results Processor"},
32+
{"shortname": "token-sorting", "name": "Token Sorting"},
33+
{"shortname": "run-report-writer", "name": "Run Report Writer"},
34+
{"shortname": "other", "name": "Other"},
35+
{"shortname": "warm-up-leader", "name": "Warm Up Leader", "matching-roles": ["Warm Up Leader (junior events only)"]},
36+
]
37+
38+
function group_volunteer_data(volunteer_data) {
39+
// Populate the results with the above
40+
41+
grouped_volunteer_data = []
42+
43+
volunteer_roles_map.forEach(function (role) {
44+
grouped_volunteer_data[role["name"]] = 0
45+
if (role["matching-roles"] !== undefined){
46+
for (var i=0; i<role["matching-roles"].length; i++) {
47+
if (role["matching-roles"][i] in volunteer_data) {
48+
grouped_volunteer_data[role["name"]] += volunteer_data[role["matching-roles"][i]]
49+
}
50+
}
51+
} else {
52+
if (role.name in volunteer_data) {
53+
// console.log("Completed "+role.name+" "+volunteer_data[role.name]+" times")
54+
grouped_volunteer_data[role["name"]] = volunteer_data[role.name]
55+
}
56+
}
57+
})
58+
59+
return grouped_volunteer_data
60+
}
61+
262
/*
363
* These functions provide a way to generate the data relating to challenge
464
* based on the results provided to them. This includes if the challenge
@@ -131,51 +191,14 @@ function generate_volunteer_challenge_data(data) {
131191

132192
if (data.volunteer_data) {
133193
volunteer_data = data.volunteer_data
134-
var volunteer_roles = [
135-
{"shortname": "equipment-storage", "name": "Equipment Storage and Delivery"},
136-
{"shortname": "comms-person", "name": "Communications Person"},
137-
{"shortname": "volunteer-coordinator", "name": "Volunteer Co-ordinator"},
138-
{"shortname": "event-day-course-check", "name": "Event Day Course Check"},
139-
{"shortname": "setup", "name": "Pre-event Setup"},
140-
{"shortname": "car-park-marshal", "name": "Car Park Marshal"},
141-
{"shortname": "first-timers-briefing", "name": "First Timers Briefing"},
142-
{"shortname": "sign-language", "name": "Sign Language Support"},
143-
{"shortname": "marshal", "name": "Marshal"},
144-
{"shortname": "tail-walker", "name": "Tail Walker"},
145-
{"shortname": "run-director", "name": "Run Director"},
146-
{"shortname": "lead-bike", "name": "Lead Bike"},
147-
{"shortname": "pacer", "name": "Pacer", "matching-roles": ["Pacer (5k only)"]},
148-
{"shortname": "vi-guide", "name": "Guide Runner", "matching-roles": ["VI Guide"]},
149-
{"shortname": "photographer", "name": "Photographer"},
150-
{"shortname": "timer", "name": "Timer", "matching-roles": ["Timekeeper", "Backup Timer"]},
151-
{"shortname": "funnel-manager", "name": "Funnel Manager"},
152-
{"shortname": "finish-tokens", "name": "Finish Tokens & Support", "matching-roles": ["Finish Tokens", "Finish Token Support"]},
153-
{"shortname": "barcode-scanning", "name": "Barcode Scanning"},
154-
{"shortname": "manual-entry", "name": "Number Checker"},
155-
{"shortname": "close-down", "name": "Post-event Close Down"},
156-
{"shortname": "results-processing", "name": "Results Processor"},
157-
{"shortname": "token-sorting", "name": "Token Sorting"},
158-
{"shortname": "run-report-writer", "name": "Run Report Writer"},
159-
{"shortname": "other", "name": "Other"},
160-
{"shortname": "warm-up-leader", "name": "Warm Up Leader", "matching-roles": ["Warm Up Leader (junior events only)"]},
161-
]
194+
195+
volunteer_roles = group_volunteer_data(volunteer_data)
162196

163197
// Populate the results with the above
164-
volunteer_roles.forEach(function (role) {
198+
volunteer_roles_map.forEach(function (role) {
165199
var this_role_data = create_data_object(role, "volunteer")
166200
this_role_data.summary_text = ""
167-
this_role_data.subparts_completed_count = 0
168-
if (role["matching-roles"] !== undefined){
169-
for (var i=0; i<role["matching-roles"].length; i++) {
170-
if (role["matching-roles"][i] in volunteer_data) {
171-
this_role_data.subparts_completed_count += volunteer_data[role["matching-roles"][i]]
172-
}
173-
}
174-
}
175-
if (role.name in volunteer_data) {
176-
// console.log("Completed "+role.name+" "+volunteer_data[role.name]+" times")
177-
this_role_data.subparts_completed_count = volunteer_data[role.name]
178-
}
201+
this_role_data.subparts_completed_count = volunteer_roles[role["name"]]
179202
if (this_role_data.subparts_completed_count > 0) {
180203
this_role_data.summary_text = "x"+this_role_data.subparts_completed_count
181204
this_role_data.complete = true
@@ -359,15 +382,19 @@ function generate_stat_p_index(parkrun_results) {
359382
// E.g. If you have volunteered in 4 different roles at least 4 times, your v-index
360383
// is 4.
361384
function generate_stat_v_index(volunteer_data) {
385+
386+
volunteer_roles = group_volunteer_data(volunteer_data)
387+
362388
var v_index = 0
363-
var descending_tally = Object.keys(volunteer_data).sort(function(a, b) {
364-
return volunteer_data[b] - volunteer_data[a]
389+
var descending_tally = Object.keys(volunteer_roles).sort(function(a, b) {
390+
return volunteer_roles[b] - volunteer_roles[a]
365391
})
366392
// Iterate through the roles, and as long as the number of times we have
367393
// volunteered in the role is greater than the index value, increment the
368394
// v-index
369395
descending_tally.forEach(function(role_name, index) {
370-
if (volunteer_data[role_name] > index) {
396+
// console.log("index: " + index + " is " + role_name + " which has been completed " + volunteer_roles[role_name] + " times")
397+
if (volunteer_roles[role_name] > index) {
371398
v_index += 1
372399
}
373400
})

0 commit comments

Comments
 (0)