Skip to content

Commit e2c83a4

Browse files
authored
Merge pull request #226 from fraz3alpha/combine-tourist-challenges
Combine tourist challenges
2 parents 577e724 + 5b2bcd2 commit e2c83a4

File tree

10 files changed

+237
-139
lines changed

10 files changed

+237
-139
lines changed

.travis.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# based on https://jekyllrb.com/docs/continuous-integration/travis-ci/
33
language: ruby
4-
rvm: 2.3.3
4+
rvm: 2.6.3
55

66
env:
77
- EXTENSION_BUILD_ID=$TRAVIS_BUILD_NUMBER EXTENSION_BUILD_VERSION=$TRAVIS_TAG
@@ -12,8 +12,11 @@ before_script:
1212
- chmod +x ./build/extension-chrome/build.sh
1313
- chmod +x ./build/extension-firefox/build.sh
1414
- npm install -g web-ext
15-
- gem uninstall -i $(rvm gemdir)@global -ax bundler || true
16-
- gem install bundler -v 1.16.1
15+
# - gem uninstall -i $(rvm gemdir)@global -ax bundler || true
16+
# - gem install bundler -v 1.16.1
17+
18+
before_install:
19+
- gem install bundler
1720

1821
script:
1922
# Only build the staging website if the github token is available, which means
@@ -54,3 +57,10 @@ deploy:
5457
repo: fraz3alpha/running-challenges
5558

5659
sudo: false # route your build to the container-based infrastructure for a faster build
60+
61+
addons:
62+
apt:
63+
packages:
64+
- libcurl4-openssl-dev
65+
66+
cache: bundler # caching bundler gem packages will speed up build

browser-extensions/common/js/content-scripts/content-script-athleteeventresultshistory.js

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,13 @@ function add_badges(div_id, data) {
198198
data.challenge_results.running_results.forEach(function(result) {
199199
var badge = get_running_badge(result)
200200
if (badge) {
201-
badges.push(badge)
201+
if (Array.isArray(badge)) {
202+
$.each(badge, function(index, badgeInstance){
203+
badges.push(badgeInstance)
204+
})
205+
} else {
206+
badges.push(badge)
207+
}
202208
}
203209
})
204210
}
@@ -247,18 +253,35 @@ function add_badges(div_id, data) {
247253
function get_running_badge(result) {
248254
var badge_info = undefined
249255
// console.log(result)
250-
if (result.complete == true) {
251-
badge_info = {
252-
"name": result.name,
253-
"icon": browser.extension.getURL("/images/badges/"+result.badge_icon+".png"),
254-
"link": "#"+result.shortname
256+
257+
// If this challenge uses the badgesAwarded mechanism, then see if there are
258+
// any
259+
if (result.badgesAwarded !== undefined ) {
260+
if (result.badgesAwarded.length > 0) {
261+
badge_info = []
262+
$.each(result.badgesAwarded, function(index, badge) {
263+
badge_info.push({
264+
"name": badge.name,
265+
"icon": browser.extension.getURL("/images/badges/"+badge.badge_icon+".png"),
266+
// The link just goes to the top of the main table for the challenge, not the specific row.
267+
"link": "#"+result.shortname
268+
})
269+
})
255270
}
256-
} else if (result.partial_completion == true) {
271+
} else {
272+
if (result.complete == true) {
257273
badge_info = {
258-
"name": result.partial_completion_name,
259-
"icon": browser.extension.getURL("/images/badges/"+result.partial_completion_badge_icon+".png"),
260-
"link": "#"+result.shortname
274+
"name": result.name,
275+
"icon": browser.extension.getURL("/images/badges/"+result.badge_icon+".png"),
276+
"link": "#"+result.shortname
261277
}
278+
} else if (result.partial_completion == true) {
279+
badge_info = {
280+
"name": result.partial_completion_name,
281+
"icon": browser.extension.getURL("/images/badges/"+result.partial_completion_badge_icon+".png"),
282+
"link": "#"+result.shortname
283+
}
284+
}
262285
}
263286
return badge_info
264287
}

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

Lines changed: 128 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,55 @@ function generate_running_challenge_data(data) {
7272
if (data.parkrun_results) {
7373
challenge_data.push(challenge_tourist(data, {
7474
"shortname": "tourist",
75-
"name": "Tourist",
76-
"data": 20,
77-
"help": "Run at 20+ different parkrun locations anywhere in the world."}))
78-
challenge_data.push(challenge_tourist(data, {
79-
"shortname": "cowell-club",
80-
"name": "Cowell Club",
81-
"data": 100,
82-
"help": "Run at 100+ different parkrun locations anywhere in the world. Named after the first parkrunners to complete it. A quarter cowell is available at 25, half at 50, and three-quarter at 75."}))
75+
"name": "parkrun Tourism",
76+
"data": {
77+
// These stages should not overlap.
78+
// If a stage has more that item in the 'count' field, it is considered something
79+
// that you can progress towards in fractions, before being awarded the final one.
80+
// This allows for more club additions as the tourism bug means that ever higher
81+
// achievements are being regularly recongnised.
82+
"stages": [
83+
{
84+
"shortname": "tourist",
85+
"name": "parkrun Tourist",
86+
"count": 20,
87+
"badge_icon": "runner-tourist"
88+
},
89+
{
90+
"shortname": "cowell",
91+
"name": "Cowell Club",
92+
"count": [
93+
{
94+
"count": 25,
95+
"name": "Quarter Cowell",
96+
"badge_icon": "runner-quarter-cowell-club"
97+
},
98+
{
99+
"count": 50,
100+
"name": "Half Cowell - a 'Cow'",
101+
"badge_icon": "runner-half-cowell-club"
102+
},
103+
{
104+
"count": 75,
105+
"name": "Three-Quarter Cowell",
106+
"badge_icon": "runner-three-quarter-cowell-club"
107+
},
108+
{
109+
"count": 100,
110+
"name": "Cowell",
111+
"badge_icon": "runner-cowell-club"
112+
}
113+
]
114+
},
115+
{
116+
"shortname": "freyne",
117+
"name": "Freyne Club",
118+
"count": 250,
119+
"badge_icon": "runner-freyne-club"
120+
}
121+
]
122+
},
123+
"help": "Run at different parkrun events all over the world! Get badges along your journey at 20,25,50,75,100, and 250 different events."}))
83124
challenge_data.push(challenge_start_letters(data, {
84125
"shortname": "alphabeteer",
85126
"name": "Alphabeteer",
@@ -1380,95 +1421,100 @@ function challenge_parkruns(data, params) {
13801421
// Complete x different parkruns (20 and 100 are standard)
13811422
function challenge_tourist(data, params) {
13821423

1383-
var parkrun_results = data.parkrun_results
1384-
1385-
var count = params.data
1386-
13871424
var o = create_data_object(params, "runner")
1388-
o.has_map = true
13891425

13901426
distinct_parkruns_completed = {}
13911427

1392-
// Add all the subparts to the list
1393-
for (i=0; i<count; i++) {
1394-
o.subparts.push("parkrun_"+i)
1395-
}
1396-
13971428
$.each(data.parkrun_results, function(index, parkrun_event) {
1398-
// parkrun_results.forEach(function (parkrun_event) {
1399-
var completed_so_far = Object.keys(distinct_parkruns_completed).length
1400-
// Ony do the first 20
1401-
if (completed_so_far < o.subparts.length) {
1402-
if (!(parkrun_event.name in distinct_parkruns_completed)) {
1403-
o.subparts_completed_count += 1
1404-
// Add it in for the next complete subpart
1405-
p = Object.create(parkrun_event)
1406-
p.subpart = o.subparts_completed_count
1407-
p.name = p.eventlink
1408-
p.info = p.datelink
1409-
o.subparts_detail.push(p)
1410-
1411-
// Add to the events done list, so that we can map them
1412-
if (!(parkrun_event.name in o.completed_qualifying_events)) {
1413-
o.completed_qualifying_events[parkrun_event.name] = get_parkrun_event_details(data, parkrun_event.name)
1414-
}
1415-
1416-
distinct_parkruns_completed[parkrun_event.name] = true
1417-
}
1418-
if (o.subparts_completed_count == o.subparts.length) {
1419-
o.complete = true
1420-
o.completed_on = parkrun_event.date
1421-
}
1429+
if (!(parkrun_event.name in distinct_parkruns_completed)) {
1430+
o.subparts_completed_count += 1
1431+
// Add it in for the next complete subpart
1432+
p = Object.create(parkrun_event)
1433+
p.subpart = o.subparts_completed_count
1434+
p.name = p.eventlink
1435+
p.info = p.datelink
1436+
o.subparts_detail.push(p)
1437+
1438+
// Add to the events done list, so that we can map them
1439+
if (!(parkrun_event.name in o.completed_qualifying_events)) {
1440+
o.completed_qualifying_events[parkrun_event.name] = get_parkrun_event_details(data, parkrun_event.name)
14221441
}
14231442

1443+
distinct_parkruns_completed[parkrun_event.name] = true
1444+
}
14241445
});
14251446

1426-
// If we haven't completed this challenge, try and find out what possible
1427-
// events would allow us to complete it.
1428-
if (o.complete == false) {
1429-
if (data.info.has_geo_data) {
1430-
if (data.info.has_home_parkrun && data.info.is_our_page) {
1431-
sorted_events = sort_events_by_distance(data.geo_data.data.events, get_home_parkrun(data))
1432-
$.each(sorted_events, function(index, event) {
1433-
// Only consider this if we haven't done it
1434-
if (!(event.name in o.completed_qualifying_events)) {
1435-
// If we still need a top-up to get to completion, add it to nearest events
1436-
if (Object.keys(o.nearest_qualifying_events).length + Object.keys(o.completed_qualifying_events).length < o.subparts.length) {
1437-
if (!(event.name in o.nearest_qualifying_events)) {
1438-
o.nearest_qualifying_events[event.name] = get_parkrun_event_details(data, event.name)
1439-
}
1440-
}
1441-
}
1442-
})
1443-
}
1444-
// Add any other qualifying events
1445-
$.each(data.geo_data.data.events, function(index, event) {
1446-
if (!(event.name in o.completed_qualifying_events) && !(event.name in o.nearest_qualifying_events)) {
1447-
if (!(event.name in o.all_qualifying_events)) {
1448-
o.all_qualifying_events[event.name] = get_parkrun_event_details(data, event.name)
1449-
}
1447+
var distinctParkrunsCompleteCount = Object.keys(distinct_parkruns_completed).length
1448+
1449+
var badgesAwarded = []
1450+
1451+
var gotAllBadges = true
1452+
1453+
// Iterate through each stage, and see if we can award any badges for full or partial completion
1454+
$.each(params.data.stages, function(index, stage){
1455+
if (Array.isArray(stage.count)) {
1456+
// This is a badge where you can get incremental completion
1457+
var currentBadge = undefined
1458+
$.each(stage.count, function(countIndex, countInfo){
1459+
// If we have crossed the threshold for this partial badge, add the details.
1460+
// This assumes that they are ordered by increasing value.
1461+
1462+
// Define this badge once so we can award it, or add it to a row
1463+
thisBadge = {
1464+
"name": countInfo.name,
1465+
"badge_icon": countInfo.badge_icon
1466+
}
1467+
if (distinctParkrunsCompleteCount >= countInfo.count) {
1468+
console.log("Awarding the badge for "+countInfo.name)
1469+
// Set the subpart detail to include the badge was awarded at this point
1470+
o.subparts_detail[countInfo.count-1]["badge"] = thisBadge
1471+
// Note this this badge was awarded
1472+
currentBadge = thisBadge
1473+
} else {
1474+
console.log("Failed to get the badge for "+countInfo.name + " needed "+countInfo.count+", got "+distinctParkrunsCompleteCount)
1475+
gotAllBadges = false
1476+
// Add an empty subpart line so that people can see the badges they can still get
1477+
o.subparts_detail.push({
1478+
"subpart": countInfo.count,
1479+
"badge": thisBadge
1480+
})
14501481
}
14511482
})
1483+
// Find the last badge we matched, and add that to the list of ones added by this challenge.
1484+
if (currentBadge !== undefined) {
1485+
badgesAwarded.push(currentBadge)
1486+
}
1487+
} else {
1488+
currentBadge = {
1489+
"name": stage.name,
1490+
"badge_icon": stage.badge_icon
1491+
}
1492+
// This badge has a single target to hit, see if we have done so.
1493+
if (distinctParkrunsCompleteCount >= stage.count) {
1494+
console.log("Awarding the badge for "+stage.name)
1495+
badgesAwarded.push(currentBadge)
1496+
// Set the subpart detail to include the badge was awarded at this point
1497+
o.subparts_detail[stage.count-1]["badge"] = currentBadge
1498+
} else {
1499+
console.log("Failed to get the badge for "+stage.name + " needed "+stage.count+", got "+distinctParkrunsCompleteCount)
1500+
gotAllBadges = false
1501+
// Add an empty subpart line so that people can see the badges they can still get
1502+
o.subparts_detail.push({
1503+
"subpart": stage.count,
1504+
"badge": currentBadge
1505+
})
1506+
}
14521507
}
1453-
}
1508+
})
14541509

1455-
// Work out if it is possible to have a partial completion
1456-
if (params.shortname == "cowell-club" && o.complete == false) {
1457-
if (o.subparts_completed_count >= 75) {
1458-
o.partial_completion = true
1459-
o.partial_completion_name = "Three-Quarter Cowell"
1460-
o.partial_completion_badge_icon = "runner-three-quarter-cowell-club"
1461-
} else if (o.subparts_completed_count >= 50) {
1462-
o.partial_completion = true
1463-
o.partial_completion_name = "Half Cowell"
1464-
o.partial_completion_badge_icon = "runner-half-cowell-club"
1465-
} else if (o.subparts_completed_count >= 25) {
1466-
o.partial_completion = true
1467-
o.partial_completion_name = "Quarter Cowell"
1468-
o.partial_completion_badge_icon = "runner-quarter-cowell-club"
1469-
}
1510+
o.badgesAwarded = badgesAwarded
1511+
1512+
if (gotAllBadges) {
1513+
o.complete = true
14701514
}
14711515

1516+
console.log(o)
1517+
14721518
// Return an object representing this challenge
14731519
return update_data_object(o)
14741520
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,11 @@ function get_challenge_header_row(challenge, data) {
177177
main_row.append($('<th></th>').text(challenge.summary_text))
178178
} else {
179179
if (challenge.subparts_completed_count !== undefined && challenge.subparts_count !== undefined){
180-
main_row.append($('<th></th>').text(challenge.subparts_completed_count+"/"+challenge.subparts_count))
180+
var progress = challenge.subparts_completed_count
181+
if (challenge.subparts_count > 0) {
182+
progress +="/"+challenge.subparts_count
183+
}
184+
main_row.append($('<th></th>').text(progress))
181185
}
182186
}
183187
if (challenge.complete) {
@@ -1094,7 +1098,13 @@ function generate_standard_table_entry(challenge, table, data) {
10941098
// Print the subparts
10951099
challenge.subparts_detail.forEach(function (subpart_detail) {
10961100
var subpart_row = $('<tr></tr>')
1097-
subpart_row.append($('<td></td>').text("-"))
1101+
if (subpart_detail["badge"] !== undefined) {
1102+
console.log("Adding a badge to the table - "+subpart_detail["badge"])
1103+
subpart_row.append($('<td></td>').append(get_challenge_icon(subpart_detail["badge"], 24, 24)))
1104+
} else {
1105+
subpart_row.append($('<td></td>').text("-"))
1106+
}
1107+
10981108
if (subpart_detail != null) {
10991109

11001110
subpart_row.append($('<td></td>').text(subpart_detail.subpart))

images/badges/256x256/badges.xcf

157 KB
Binary file not shown.
57.5 KB
Loading

website/Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ source "https://rubygems.org"
88
#
99
# This will help ensure the proper Jekyll version is running.
1010
# Happy Jekylling!
11-
gem "jekyll", "~> 3.7.4"
11+
gem "jekyll", "~> 4.0.0"
1212

1313
# This is the default theme for new Jekyll sites. You may change this to anything you like.
14-
gem "minima", "~> 2.0"
14+
gem "minima", "~> 2.5.1"
1515

1616
# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
1717
# uncomment the line below. To upgrade, run `bundle update github-pages`.

0 commit comments

Comments
 (0)