Skip to content

Commit 538447e

Browse files
authored
Merge pull request #1 from CnCNet/feature/build
Feature/build
2 parents 7fead00 + f66240e commit 538447e

File tree

5 files changed

+132
-7649
lines changed

5 files changed

+132
-7649
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.github
2+
build

.github/workflows/cd.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Build
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- 'main'
8+
tags:
9+
- 'v*'
10+
11+
jobs:
12+
build-and-push:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Extract metadata (tags, labels)
22+
id: meta
23+
uses: docker/metadata-action@v5
24+
with:
25+
images: ghcr.io/${{ github.repository }}
26+
tags: |
27+
type=ref,event=branch
28+
type=ref,event=pr
29+
type=semver,pattern={{version}}
30+
type=semver,pattern={{major}}.{{minor}}
31+
type=raw,value=latest,enable={{is_default_branch}}
32+
33+
- name: Log in to GHCR
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ghcr.io
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Build and push
41+
uses: docker/build-push-action@v6
42+
with:
43+
context: .
44+
file: Dockerfile
45+
push: ${{ github.event_name != 'pull_request' }}
46+
tags: ${{ steps.meta.outputs.tags }}
47+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
1-
FROM ubuntu:22.04
2-
3-
ENV DEBIAN_FRONTEND=noninteractive
1+
# -------- Build Stage --------
2+
FROM ubuntu:22.04 AS build
43

4+
# Install build dependencies
55
RUN apt-get update && apt-get install -y \
66
ca-certificates \
7-
build-essential \
87
git \
98
cmake \
109
ninja-build \
1110
libmysqlcppconn-dev \
12-
&& rm -rf /var/lib/apt/lists/*
11+
g++ \
12+
build-essential
13+
14+
COPY . /app
15+
16+
WORKDIR /app/build
17+
18+
# Build your application
19+
RUN cmake -G Ninja /app && ninja -j $(( $(nproc) / 2 ))
20+
21+
# -------- Runtime Stage --------
22+
FROM debian:bookworm-slim
23+
24+
# Install only runtime dependencies
25+
RUN apt-get update && apt-get install -y --no-install-recommends \
26+
libmysqlcppconn-dev && \
27+
apt-get clean && rm -rf /var/lib/apt/lists/*
1328

14-
RUN git clone https://github.com/CnCNet/cncnet-ladder-elo-computation.git /repos/cncnet-ladder-elo-computation && \
15-
mkdir build && \
16-
cd build && \
17-
cmake -G Ninja /repos/cncnet-ladder-elo-computation && \
18-
ninja -j $(( $(nproc) / 2 ))
29+
# Set workdir and copy the built binary
30+
WORKDIR /app
31+
COPY --from=build /app/build/elogen /app/elogen
1932

20-
WORKDIR /build
33+
# Run it
34+
ENTRYPOINT ["/app/elogen"]

README.md

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -134,53 +134,9 @@ To find the optimal _p_, we ran many simulations, updating ELOs daily and compar
134134

135135
The sweet spot is _p_ = **1.11**, giving reasonably good results in line with expectations.
136136

137-
## FAQ
138-
139-
_This section is still being created._
140-
141-
### What is the deviation?
142-
143-
The **deviation** indicates how accurate or uncertain your rating is. You’ll appear on the list of **active players** if your deviation drops below **60–70** (depending on your rating), and you'll be removed from the list if it rises above around **100**.
144-
145-
To lower your deviation, you need to provide **new information** about your skill level. Continuously beating much weaker opponents (which might boost your rating in other systems) doesn't help here — it's not new information. For example, you’re expected to win more than **99%** of the time against someone **1000 ELO** below you. So winning 20 games in a row against such an opponent won’t improve your rating — it might even **increase** your deviation due to the lack of meaningful data.
146-
147-
That’s one reason why Glicko-2 is hard to exploit. The best way to reduce your deviation is to play a variety of opponents **close to your skill level**.
148-
149-
---
150-
151-
### How many points do I gain or lose per game?
152-
153-
**Short answer:** It depends.
154-
155-
Games are submitted to the system in **daily batches**, not individually. Your rating is updated based on your **overall performance** for the day, rather than on a per-game basis. This method provides a more accurate and stable rating.
156-
157-
---
158-
159-
### I didn’t care about my rating before, but now I want to take it seriously. Can you reset it?
160-
161-
**No.** Your rating reflects your performance over roughly the **last 200–300 games**. Older games gradually lose their impact.
162-
163-
If you play **50 games a day for a week**, your rating will effectively reset itself through recent performance. The result will be the same as starting from scratch - just without creating a new account.
164-
165-
---
166-
167-
### How bad is a loss against a much weaker opponent?
168-
169-
A single loss isn’t a big deal — even if your opponent is far below you in rating. The expected win rate is never 100%, no matter how large the ELO gap is. So if you lose one game against someone **1000 ELO** below you, it's likely just the one game out of 100 that you were expected to lose anyway.
170-
171-
But the **second** loss is much more significant. That result suggests that your strength may have been overestimated, and the system will start adjusting your rating accordingly.
172-
173-
---
174-
175-
### How often is the list updated?
176-
177-
The list is updated once per day, with the daily cutoff at UTC+5.
178-
Your rating — as shown in the all-time leaderboard — reflects your status at the end of the previous day based on that time.
179-
180137
## Usage on CnCNet
181138

182-
Since ELO computation is processed in batches - to ensure higher accuracy - rather than after each game, this application needs to run once per day.
183-
The "ELO day" ends at UTC+5 for all players, so the best time to run it is between UTC+5 and UTC+6.
139+
Since ELO computation is processed in batches - to ensure higher accuracy - rather than after each game, this application needs to run once per day. The "ELO day" ends at UTC+5 for all players, so the best time to run it is between UTC+5 and UTC+6.
184140

185141
During the build of the Docker container, this repository is cloned and the app is compiled.
186142

@@ -190,6 +146,16 @@ During the build of the Docker container, this repository is cloned and the app
190146
docker build -t elogenerator .
191147
```
192148

149+
If packages cannot be fetched, change
150+
151+
RUN apt-get update && apt-get install -y \
152+
153+
to
154+
155+
RUN apt-get -o Acquire::ForceIPv4=true update && apt-get -o Acquire::ForceIPv4=true install -y \
156+
157+
in the `Dockerfile`.
158+
193159
When running the container, Docker must be provided with the path to the directory containing the rating files.
194160
This is usually:
195161

@@ -217,7 +183,7 @@ You can provide the environment variables `MYSQL_HOST`, `MYSQL_PASSWORD`, `MYSQL
217183
### Example 1:
218184

219185
```bash
220-
docker run -it --add-host=host.docker.internal:host-gateway -e MYSQL_PASSWORD=pass -e MYSQL_USER=user -v /home/cncnet/cncnet-ladder-api/cncnet-api/storage/app/rating:/data elogenerator /bin/bash -c "cd /build && ./elogen -H host.docker.internal -P 3307 --log-level info -o /data -m ra2"
186+
docker run -it --add-host=host.docker.internal:host-gateway -e MYSQL_PASSWORD=pass -e MYSQL_USER=user -v /home/cncnet/cncnet-ladder-api/cncnet-api/storage/app/rating:/data elogenerator -H host.docker.internal -P 3306 --log-level info -o /data -m ra2
221187
```
222188

223189
This will generate ELO for `ra2` and write the JSON files to `/home/cncnet/cncnet-ladder-api/cncnet-api/storage/app/rating`.
@@ -227,7 +193,51 @@ It connects to MySQL at the given host and port. User and password are provided
227193
### Example 2:
228194

229195
```bash
230-
docker run -it --add-host=host.docker.internal:host-gateway -e MYSQL_HOST=host.docker.internal -e MYSQL_PORT=3307 -e MYSQL_PASSWORD=pass -e MYSQL_USER=user -v /home/cncnet/cncnet-ladder-api/cncnet-api/storage/app/rating:/data elogenerator /bin/bash -c "cd /build && ./elogen -o /data -m blitz --tournament-games /repos/cncnet-ladder-elo-computation/data/blitz_ra2_worldseries.json"
196+
docker run -it --add-host=host.docker.internal:host-gateway -e MYSQL_HOST=host.docker.internal -e MYSQL_PORT=3307 -e MYSQL_PASSWORD=pass -e MYSQL_USER=user -v /home/cncnet/cncnet-ladder-api/cncnet-api/storage/app/rating:/data elogenerator -o /data -m blitz --tournament-games blitz_ra2_worldseries.json
231197
```
232198

233-
This will generate ELO for blitz, using environment variables only. It also includes the specified tournament game file from the repository.
199+
This will generate ELO for blitz, using environment variables only. It also includes the specified tournament game file. Since a tournament file is only used for blitz and not updated anymore, the layout of a tournament won't be explained here. Just throw `gameoverlay.cpp` at an AI and it will provide you an example JSON.
200+
201+
202+
## FAQ
203+
204+
_This section is still being created._
205+
206+
### What is the deviation?
207+
208+
The **deviation** indicates how accurate or uncertain your rating is. You’ll appear on the list of **active players** if your deviation drops below **60–70** (depending on your rating), and you'll be removed from the list if it rises above around **100**.
209+
210+
To lower your deviation, you need to provide **new information** about your skill level. Continuously beating much weaker opponents (which might boost your rating in other systems) doesn't help here — it's not new information. For example, you’re expected to win more than **99%** of the time against someone **1000 ELO** below you. So winning 20 games in a row against such an opponent won’t improve your rating — it might even **increase** your deviation due to the lack of meaningful data.
211+
212+
That’s one reason why Glicko-2 is hard to exploit. The best way to reduce your deviation is to play a variety of opponents **close to your skill level**.
213+
214+
---
215+
216+
### How many points do I gain or lose per game?
217+
218+
**Short answer:** It depends.
219+
220+
Games are submitted to the system in **daily batches**, not individually. Your rating is updated based on your **overall performance** for the day, rather than on a per-game basis. This method provides a more accurate and stable rating.
221+
222+
---
223+
224+
### I didn’t care about my rating before, but now I want to take it seriously. Can you reset it?
225+
226+
**No.** Your rating reflects your performance over roughly the **last 200–300 games**. Older games gradually lose their impact.
227+
228+
If you play **50 games a day for a week**, your rating will effectively reset itself through recent performance. The result will be the same as starting from scratch - just without creating a new account.
229+
230+
---
231+
232+
### How bad is a loss against a much weaker opponent?
233+
234+
A single loss isn’t a big deal — even if your opponent is far below you in rating. The expected win rate is never 100%, no matter how large the ELO gap is. So if you lose one game against someone **1000 ELO** below you, it's likely just the one game out of 100 that you were expected to lose anyway.
235+
236+
But the **second** loss is much more significant. That result suggests that your strength may have been overestimated, and the system will start adjusting your rating accordingly.
237+
238+
---
239+
240+
### How often is the list updated?
241+
242+
The list is updated once per day, with the daily cutoff at UTC+5.
243+
Your rating — as shown in the all-time leaderboard — reflects your status at the end of the previous day based on that time.

0 commit comments

Comments
 (0)