Add Elorasmus: pairwise Elo ranking of CTU exchange schools #1
6 changed files with 305 additions and 0 deletions
9
.dockerignore
Normal file
9
.dockerignore
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
# keep the image to: package.json, server/, public/
|
||||||
|
.git
|
||||||
|
.env
|
||||||
|
var/
|
||||||
|
research/
|
||||||
|
scripts/
|
||||||
|
test/
|
||||||
|
data/
|
||||||
|
*.md
|
||||||
35
.env.example
Normal file
35
.env.example
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
# Elorasmus configuration. Copy to .env (git-ignored), then `chmod 600 .env`.
|
||||||
|
# Every variable is optional; the values below are the defaults.
|
||||||
|
|
||||||
|
# ---- network (compose) ----
|
||||||
|
# Host interface and port the container is published on. Loopback = only this machine
|
||||||
|
# (use a reverse proxy, VPN or `ssh -L` to reach it). 0.0.0.0 = all interfaces.
|
||||||
|
ELORASMUS_BIND=127.0.0.1
|
||||||
|
ELORASMUS_PORT=8317
|
||||||
|
|
||||||
|
# ---- login ----
|
||||||
|
# Password (min 8 chars) to require a login. Empty = no login (fine on loopback/VPN only).
|
||||||
|
AUTH_PASSWORD=
|
||||||
|
# Signs session cookies (min 32 chars). Empty = generated once, stored in the data volume.
|
||||||
|
SESSION_SECRET=
|
||||||
|
# How long a login lasts, in days.
|
||||||
|
SESSION_DAYS=180
|
||||||
|
# Secure cookie flag: auto (when the request arrived over HTTPS) | true | false
|
||||||
|
COOKIE_SECURE=auto
|
||||||
|
# true when running behind a reverse proxy that sets X-Forwarded-For/-Proto/-Host.
|
||||||
|
TRUST_PROXY=false
|
||||||
|
|
||||||
|
# ---- app ----
|
||||||
|
# Serve under a sub-path, e.g. /elorasmus/, if your proxy routes a path to the app.
|
||||||
|
BASE_PATH=/
|
||||||
|
APP_TITLE=Elorasmus
|
||||||
|
# Default stay length (months) for cost totals; changeable in the app's settings.
|
||||||
|
STAY_MONTHS=5
|
||||||
|
# Elo: starting rating; K-factor for a school's first games (max) decaying to (min).
|
||||||
|
ELO_INITIAL=1500
|
||||||
|
ELO_K_MAX=48
|
||||||
|
ELO_K_MIN=16
|
||||||
|
# EUR->CZK rate for the CZK display. Empty = the CNB rate stored with the research data.
|
||||||
|
EUR_CZK=
|
||||||
|
# Log one line per request (method, path, status, time). No cookies or bodies are logged.
|
||||||
|
LOG_REQUESTS=false
|
||||||
54
AGENTS.md
Normal file
54
AGENTS.md
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
# AGENTS.md: Elorasmus
|
||||||
|
|
||||||
|
Project specifics for anyone (human or agent) working in this repo. The box-wide rules live in
|
||||||
|
the global instructions; this file covers only this project.
|
||||||
|
|
||||||
|
## What this is
|
||||||
|
|
||||||
|
A mobile-first web app for ranking CTU FEL exchange partner schools by pairwise picks (Elo).
|
||||||
|
The user hosts it themselves with `compose.yaml`. See README.md for the user-facing docs.
|
||||||
|
|
||||||
|
## Stack and ports
|
||||||
|
|
||||||
|
- Node ≥ 22 (image pinned to `node:26.13.0-alpine3.24`). **No npm dependencies**: keep it that way
|
||||||
|
unless there is a strong reason.
|
||||||
|
- Front end: plain ES modules in `public/js/`, no build step.
|
||||||
|
- Dev port: **8317** (`ELORASMUS_PORT=8317`). On the dev box, bind to loopback only; preview via
|
||||||
|
`ssh -p 14922 -L 8317:localhost:8317 <host>`.
|
||||||
|
- Node isn't installed on the dev box: run tests in the pinned image (see README.md,
|
||||||
|
Development).
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
```sh
|
||||||
|
podman run --rm -v "$PWD":/app:Z,ro -w /app docker.io/library/node:26.13.0-alpine3.24 node --test test/
|
||||||
|
podman compose -p elorasmus up -d --build # serve on 127.0.0.1:8317
|
||||||
|
python3 -I scripts/validate_research.py # research files vs the contract
|
||||||
|
python3 -I scripts/build_data.py # rebuild public/data/schools.json
|
||||||
|
python3 -I scripts/parse_catalog.py <saved.html> data/catalog.json # new CTU catalogue
|
||||||
|
```
|
||||||
|
|
||||||
|
Rebuild `public/data/schools.json` after any change under `research/raw/` or `data/`, and
|
||||||
|
commit it: the container image serves it as is.
|
||||||
|
|
||||||
|
## Conventions
|
||||||
|
|
||||||
|
- **State is an append-only event log** (`match`, `drop`, `restore`, `review`, `undo`) in
|
||||||
|
`DATA_DIR/events.jsonl`. Ratings are never stored; clients replay the log. Don't add mutable
|
||||||
|
rating state on the server.
|
||||||
|
- **Escaping:** build HTML only with the `html` tagged template from `public/js/ui.js`. It escapes
|
||||||
|
interpolations, and research text is web-sourced. Links go through `safeUrl`/`extLink`.
|
||||||
|
- **CSP** is strict (`script-src 'self'; style-src 'self'`): no inline scripts, styles or
|
||||||
|
`style=""` attributes. Bar widths are `.w0`…`.w10` classes.
|
||||||
|
- Pure logic (`elo.js`, `pairing.js`, `metrics.js`) must stay DOM-free and covered by `test/`.
|
||||||
|
- Config comes only from environment variables (`server/config.js`). Document every new one in
|
||||||
|
`.env.example`, `README.md` and `compose.yaml` together.
|
||||||
|
- Research files follow `research/BRIEF.md`: never invent numbers, URLs or course names; use
|
||||||
|
`null` plus text and lower the `confidence` instead.
|
||||||
|
|
||||||
|
## Research status (update when it changes)
|
||||||
|
|
||||||
|
As of 2026-11-12, research covers most of the 170 schools; `scripts/build_data.py` prints the
|
||||||
|
count. Schools without research still appear, marked "research pending". The web-search
|
||||||
|
budget per session is limited (~200 calls), so later research relied on fetching official
|
||||||
|
pages directly.
|
||||||
20
Dockerfile
Normal file
20
Dockerfile
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Elorasmus: the server uses only Node's standard library, so there is no npm install step.
|
||||||
|
FROM docker.io/library/node:26.13.0-alpine3.24
|
||||||
|
|
||||||
|
ENV NODE_ENV=production \
|
||||||
|
HOST=0.0.0.0 \
|
||||||
|
PORT=8317 \
|
||||||
|
DATA_DIR=/data
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package.json ./
|
||||||
|
COPY server ./server
|
||||||
|
COPY public ./public
|
||||||
|
|
||||||
|
# /data holds picks, notes and settings. Owned by the image's unprivileged "node" user so a
|
||||||
|
# fresh named volume is writable (Docker and Podman both copy this ownership into it).
|
||||||
|
RUN mkdir -p /data && chown node:node /data
|
||||||
|
USER node
|
||||||
|
VOLUME ["/data"]
|
||||||
|
EXPOSE 8317
|
||||||
|
CMD ["node", "server/index.js"]
|
||||||
144
README.md
Normal file
144
README.md
Normal file
|
|
@ -0,0 +1,144 @@
|
||||||
|
# Elorasmus
|
||||||
|
|
||||||
|
Choose your exchange school by picking one of two, over and over. Each pick updates an
|
||||||
|
**Elo rating**, so a personal ranking of all 170 partner schools in CTU FEL's 2027/28 Master
|
||||||
|
catalogue builds up gradually. Every school card has researched data on
|
||||||
|
AI/robotics quality, money from CTU, living costs, travel, language rules, social life vs
|
||||||
|
solitude, nature (climbing, hiking, ocean, skiing), safety and stability, with sources.
|
||||||
|
|
||||||
|
Built for phones: one screen per decision, pick buttons where your thumb is, dark mode, and it
|
||||||
|
can be added to the home screen.
|
||||||
|
|
||||||
|
## Run it
|
||||||
|
|
||||||
|
You need Docker with the compose plugin, or Podman with `podman compose`.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cp .env.example .env && chmod 600 .env
|
||||||
|
docker compose up -d --build # or: podman compose up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
Open <http://localhost:8317>. Picks, notes and settings are stored in the `elorasmus-data`
|
||||||
|
volume.
|
||||||
|
|
||||||
|
**Set a password before the app is reachable from anywhere but this machine.** This reads it
|
||||||
|
from a hidden prompt, writes it to `.env` without showing it, and prints only its length:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
read -rsp 'Password (8+ chars, no single quote): ' PW; echo
|
||||||
|
sed -i '/^AUTH_PASSWORD=/d' .env && printf "AUTH_PASSWORD='%s'\n" "$PW" >> .env
|
||||||
|
echo "stored, ${#PW} chars"; unset PW
|
||||||
|
docker compose up -d # restart with the new setting
|
||||||
|
```
|
||||||
|
|
||||||
|
### Getting to it from your phone
|
||||||
|
|
||||||
|
By default the container is published on `127.0.0.1` only. Pick one of these:
|
||||||
|
|
||||||
|
- **Reverse proxy with HTTPS (recommended).** Put Caddy, nginx or Traefik in front, set
|
||||||
|
`TRUST_PROXY=true`, and keep `AUTH_PASSWORD` set. Minimal Caddyfile:
|
||||||
|
```
|
||||||
|
elo.example.com {
|
||||||
|
reverse_proxy 127.0.0.1:8317
|
||||||
|
}
|
||||||
|
```
|
||||||
|
To serve it under a path (`example.com/elorasmus/`), set `BASE_PATH=/elorasmus/` and proxy
|
||||||
|
that path without stripping it.
|
||||||
|
- **VPN (Tailscale, WireGuard).** Set `ELORASMUS_BIND` to the VPN interface's IP (or `0.0.0.0`
|
||||||
|
behind a firewall) and open `http://<vpn-ip>:8317` on the phone.
|
||||||
|
- **SSH tunnel** (desktop): `ssh -L 8317:localhost:8317 <server>`, then open
|
||||||
|
<http://localhost:8317>.
|
||||||
|
|
||||||
|
Then use your phone browser's "Add to Home Screen" to get an app icon.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
All settings are environment variables. With compose, put them in `.env`; `.env.example`
|
||||||
|
documents each one.
|
||||||
|
|
||||||
|
| Variable | Default | What it does |
|
||||||
|
|---|---|---|
|
||||||
|
| `ELORASMUS_BIND` | `127.0.0.1` | Host interface the port is published on (compose only) |
|
||||||
|
| `ELORASMUS_PORT` | `8317` | Host port (compose only) |
|
||||||
|
| `AUTH_PASSWORD` | *(empty)* | Require a login with this password (min 8 chars). Empty = no login |
|
||||||
|
| `SESSION_SECRET` | *(generated)* | Signs login cookies (min 32 chars). If empty, generated once and kept in the data volume |
|
||||||
|
| `SESSION_DAYS` | `180` | How long a login lasts |
|
||||||
|
| `COOKIE_SECURE` | `auto` | Secure cookie flag: `auto` (if the request was HTTPS), `true`, `false` |
|
||||||
|
| `TRUST_PROXY` | `false` | Honour `X-Forwarded-For/-Proto/-Host` from a reverse proxy |
|
||||||
|
| `BASE_PATH` | `/` | Serve under a sub-path, e.g. `/elorasmus/` |
|
||||||
|
| `APP_TITLE` | `Elorasmus` | Name shown in the header and the browser tab |
|
||||||
|
| `STAY_MONTHS` | `5` | Default stay length for cost totals (changeable in the app) |
|
||||||
|
| `ELO_INITIAL` | `1500` | Starting rating |
|
||||||
|
| `ELO_K_MAX` / `ELO_K_MIN` | `48` / `16` | K-factor for a school's first games, decaying to the minimum over 15 games |
|
||||||
|
| `EUR_CZK` | *(from data)* | Override the EUR→CZK rate for the CZK display |
|
||||||
|
| `LOG_REQUESTS` | `false` | One log line per request (no cookies or bodies) |
|
||||||
|
| `HOST`, `PORT`, `DATA_DIR` | `127.0.0.1`, `8317`, `./var` | Only when running without a container (the image sets `0.0.0.0`, `8317`, `/data`) |
|
||||||
|
|
||||||
|
## Using it
|
||||||
|
|
||||||
|
- **Compare**: the main screen. Two schools, a row-by-row comparison (the better value is
|
||||||
|
tinted in that school's colour), highlights and red flags, then **A**, **=** (too close to
|
||||||
|
call) or **B**. *Skip* shows another pair; *Undo* reverts the last action. Tap a school for
|
||||||
|
everything known about it. On a keyboard: ←/→ pick, ↓ tie, space skip, z undo.
|
||||||
|
- **Triage**: an optional quick pass through all schools (Keep / Drop). Schools with obvious
|
||||||
|
problems come first: a language you don't speak, an unrelated subject area, or an unsafe
|
||||||
|
country.
|
||||||
|
- **Ranking**: your Elo leaderboard with search, region and agreement filters, and other sort
|
||||||
|
orders (research quality, cheapest, nature). Dropped schools can be restored.
|
||||||
|
- **Settings**: stay length, EUR/CZK, the Erasmus+ fewer-opportunities top-up, host
|
||||||
|
scholarships, your languages, theme, and backup export/import.
|
||||||
|
|
||||||
|
How the pairs are chosen: rarely compared schools come first, then close contests between
|
||||||
|
similarly rated schools, plus 10% random pairs so nothing gets stuck. That gets a usable top 10
|
||||||
|
with far fewer picks than random pairs would need. A school's first picks move its rating a lot
|
||||||
|
(K=48), later ones fine-tune it (K→16).
|
||||||
|
|
||||||
|
## About the data
|
||||||
|
|
||||||
|
- **Catalogue**: `data/catalog.json`, parsed from a saved copy of the CTU Mobility catalogue
|
||||||
|
(FEL, Master, 2027/28): 186 agreements at 170 schools.
|
||||||
|
- **Research**: one file per school in `research/raw/schools/`, written to the contract in
|
||||||
|
`research/BRIEF.md` (scoring anchors, sources, confidence) and checked by
|
||||||
|
`scripts/validate_research.py`. Country-level stability, visas and Czech MFA advisories are
|
||||||
|
in `research/raw/countries.json`; grants, exchange rate and selection rules are in
|
||||||
|
`research/raw/funding.json`.
|
||||||
|
- **Money from CTU**: Erasmus+ uses the latest published Czech rates (2026/27: €660, €600 or
|
||||||
|
€540 per month by country group; 2027/28 is not published yet). Non-European agreements use
|
||||||
|
CTU's stipend (15,000 CZK/month for the USA, Canada, Australia and Argentina, 13,000 CZK
|
||||||
|
elsewhere). Switzerland depends on a Swiss parliament vote in December 2026.
|
||||||
|
- Everything was gathered from public web sources in November 2026 and **can be wrong or out of
|
||||||
|
date**. Every section shows its sources and a confidence level. Check money, language rules
|
||||||
|
and deadlines with the FEL international office before you apply.
|
||||||
|
|
||||||
|
Rebuild the app's data after changing research:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
python3 -I scripts/validate_research.py # structural checks
|
||||||
|
python3 -I scripts/build_data.py # -> public/data/schools.json
|
||||||
|
```
|
||||||
|
|
||||||
|
## Backups
|
||||||
|
|
||||||
|
*Settings → Export backup* downloads everything (picks, notes, settings) as JSON, and *Import*
|
||||||
|
restores it (the server first keeps a copy in `DATA_DIR/backups/`). Server-side state is plain
|
||||||
|
files in the volume: `events.jsonl` (the pick log), `notes.json` and `settings.json`.
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
No npm dependencies: the server uses only Node's standard library, and the front end is plain
|
||||||
|
ES modules.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm test # Node >= 22, or without Node installed:
|
||||||
|
podman run --rm -v "$PWD":/app:Z,ro -w /app docker.io/library/node:26.13.0-alpine3.24 node --test test/
|
||||||
|
node server/index.js # http://127.0.0.1:8317, data in ./var
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
server/ HTTP server, config (env), auth, event store, static files
|
||||||
|
public/ the app: index.html, css/, js/ (elo.js, pairing.js, metrics.js are pure + tested), views/
|
||||||
|
data/ parsed CTU catalogue
|
||||||
|
research/ brief, per-region assignments, raw research files
|
||||||
|
scripts/ parse_catalog.py, validate_research.py, build_data.py, make_icons.py
|
||||||
|
test/ node:test suites (logic + HTTP API)
|
||||||
|
```
|
||||||
43
compose.yaml
Normal file
43
compose.yaml
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
# Elorasmus. Run with `docker compose up -d --build` or `podman compose up -d --build`.
|
||||||
|
# Configuration: copy .env.example to .env (chmod 600) and edit. Every variable is optional.
|
||||||
|
services:
|
||||||
|
elorasmus:
|
||||||
|
build: .
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
# Loopback by default: reach it via a reverse proxy, VPN or SSH tunnel.
|
||||||
|
# ELORASMUS_BIND=0.0.0.0 publishes on all interfaces; set AUTH_PASSWORD before doing that.
|
||||||
|
- "${ELORASMUS_BIND:-127.0.0.1}:${ELORASMUS_PORT:-8317}:8317"
|
||||||
|
environment:
|
||||||
|
AUTH_PASSWORD: ${AUTH_PASSWORD:-}
|
||||||
|
SESSION_SECRET: ${SESSION_SECRET:-}
|
||||||
|
SESSION_DAYS: ${SESSION_DAYS:-180}
|
||||||
|
COOKIE_SECURE: ${COOKIE_SECURE:-auto}
|
||||||
|
TRUST_PROXY: ${TRUST_PROXY:-false}
|
||||||
|
BASE_PATH: ${BASE_PATH:-/}
|
||||||
|
APP_TITLE: ${APP_TITLE:-Elorasmus}
|
||||||
|
STAY_MONTHS: ${STAY_MONTHS:-5}
|
||||||
|
ELO_INITIAL: ${ELO_INITIAL:-1500}
|
||||||
|
ELO_K_MAX: ${ELO_K_MAX:-48}
|
||||||
|
ELO_K_MIN: ${ELO_K_MIN:-16}
|
||||||
|
EUR_CZK: ${EUR_CZK:-}
|
||||||
|
LOG_REQUESTS: ${LOG_REQUESTS:-false}
|
||||||
|
volumes:
|
||||||
|
- elorasmus-data:/data
|
||||||
|
# Hardening: the app only writes to /data.
|
||||||
|
read_only: true
|
||||||
|
tmpfs:
|
||||||
|
- /tmp
|
||||||
|
cap_drop:
|
||||||
|
- ALL
|
||||||
|
security_opt:
|
||||||
|
- no-new-privileges:true
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:8317/healthz').then(r=>process.exit(r.ok?0:1),()=>process.exit(1))"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 3
|
||||||
|
start_period: 10s
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
elorasmus-data:
|
||||||
Loading…
Add table
Add a link
Reference in a new issue