Skip to content

mikedbjones/maprun-results

Repository files navigation

maprun-results

This project automatically downloads separate results from multiple Maprun events, then combines points and time scores for each competitor. It then ranks competitors by overall number of points and time taken. The combined results in CSV and HTML format are stored locally, and optionally uploaded to a website using FTP, or to a Wordpress site using requests. If you run, or take part in, a Maprun series of events such as the Peak Raid Series, this tool can be useful in creating and viewing combined series results.

Usage

Local

First, configure events_info.json, specifying:

  • "file": json filename containing custom event names and results URLs (see peak_raid_2024.json for an example)
  • "html_name": name for html and csv files
  • "html_title": html title
  • "upload_type": "wordpress" or "ftp"

Ensure that, together with events_info.json, the events file itself (eg peak_raid_2024.json) is present in the local directory.

Optionally, export the following environment variables to enable FTP/Wordpress upload:

  • UPLOAD_ADDRESS (eg "ftp.mywebsitehost.com")
  • UPLOAD_DIRECTORY (eg "/public_html/maprun-results/")
  • UPLOAD_USERNAME
  • UPLOAD_PASSWORD
  • WORDPRESS_URL
  • WORDPRESS_USERNAME
  • WORDPRESS_PASSWORD

In bash, this would be achieved using:

export UPLOAD_ADDRESS="ftp.mywebsitehost.com"

Repeat for the others.

Now, in a python virtual environment, run the following commands:

pip install -r requirements.txt
python results.py

This will produce CSV and HTML files locally, which will also be uploaded to the specified upload location, if specified. This script could be run on a local machine with a cron schedule if desired. Or set it to run in the cloud (see AWS Lambda example below) and forget about it 😄!

AWS Lambda

Create and upload Docker image

Run the following commands to build the Docker image and upload to AWS ECR:

aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin [aws-account-id].dkr.ecr.us-east-1.amazonaws.com
docker build -t maprun-results .
docker tag maprun-results:latest [aws-account-id].dkr.ecr.us-east-1.amazonaws.com/maprun-results:latest
docker push [aws-account-id].dkr.ecr.us-east-1.amazonaws.com/maprun-results:latest

Create Lambda function

  • Configure an AWS Lambda function with this ECR image
  • Set the environment variables
  • Increase the timeout to at least 1 minute

Create EventBridge schedule

Finally configure an EventBridge schedule (eg once per hour), that will trigger the Lambda function. In the schedule target, copy and paste from events_info.json.

Example combined results

The repository is deployed on AWS for regular updates to Peak Raid series combined results: https://explorerevents.co.uk/peak-raid-maprun-2024-results/.