Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 883bc4489e | |||
| 3ad4a21f5b | |||
| 3c1604c7af |
@@ -31,5 +31,9 @@ jobs:
|
||||
TAG=${{ inputs.tag }}
|
||||
fi
|
||||
IMAGE=gitea.home.hrajfrisbee.cz/${{ github.repository }}:$TAG
|
||||
docker build -f build/Dockerfile -t $IMAGE .
|
||||
docker build -f build/Dockerfile \
|
||||
--build-arg GIT_TAG=$TAG \
|
||||
--build-arg GIT_COMMIT=${{ github.sha }} \
|
||||
--build-arg BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
|
||||
-t $IMAGE .
|
||||
docker push $IMAGE
|
||||
|
||||
6
Makefile
6
Makefile
@@ -45,7 +45,11 @@ web-debug: $(PYTHON)
|
||||
FLASK_DEBUG=1 $(PYTHON) app.py
|
||||
|
||||
image:
|
||||
docker build -t fuj-management:latest -f build/Dockerfile .
|
||||
docker build -t fuj-management:latest \
|
||||
--build-arg GIT_TAG=$$(git describe --tags --always 2>/dev/null || echo "untagged") \
|
||||
--build-arg GIT_COMMIT=$$(git rev-parse --short HEAD) \
|
||||
--build-arg BUILD_DATE=$$(date -u +%Y-%m-%dT%H:%M:%SZ) \
|
||||
-f build/Dockerfile .
|
||||
|
||||
run:
|
||||
docker run -it --rm -p 5001:5001 -v $(CURDIR)/.secret:/app/.secret:ro fuj-management:latest
|
||||
|
||||
13
app.py
13
app.py
@@ -72,6 +72,13 @@ def warmup_cache():
|
||||
logger.info("Cache warmup complete.")
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
import json as _json
|
||||
_meta_path = Path(__file__).parent / "build_meta.json"
|
||||
BUILD_META = _json.loads(_meta_path.read_text()) if _meta_path.exists() else {
|
||||
"tag": "dev", "commit": "local", "build_date": ""
|
||||
}
|
||||
|
||||
warmup_cache()
|
||||
|
||||
@app.before_request
|
||||
@@ -101,7 +108,7 @@ def inject_render_time():
|
||||
"total": f"{total:.3f}",
|
||||
"breakdown": " | ".join(breakdown)
|
||||
}
|
||||
return dict(get_render_time=get_render_time)
|
||||
return dict(get_render_time=get_render_time, build_meta=BUILD_META)
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
@@ -113,6 +120,10 @@ def flush_cache_endpoint():
|
||||
deleted = flush_cache()
|
||||
return jsonify({"status": "ok", "deleted_files": deleted})
|
||||
|
||||
@app.route("/version")
|
||||
def version():
|
||||
return BUILD_META
|
||||
|
||||
@app.route("/fees")
|
||||
def fees():
|
||||
attendance_url = f"https://docs.google.com/spreadsheets/d/{ATTENDANCE_SHEET_ID}/edit"
|
||||
|
||||
@@ -24,6 +24,17 @@ COPY templates/ ./templates/
|
||||
COPY build/entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
ARG GIT_TAG=unknown
|
||||
ARG GIT_COMMIT=unknown
|
||||
ARG BUILD_DATE=unknown
|
||||
|
||||
LABEL org.opencontainers.image.version="${GIT_TAG}" \
|
||||
org.opencontainers.image.revision="${GIT_COMMIT}" \
|
||||
org.opencontainers.image.created="${BUILD_DATE}" \
|
||||
org.opencontainers.image.title="fuj-management"
|
||||
|
||||
RUN echo "{\"tag\": \"${GIT_TAG}\", \"commit\": \"${GIT_COMMIT}\", \"build_date\": \"${BUILD_DATE}\"}" > /app/build_meta.json
|
||||
|
||||
EXPOSE 5001
|
||||
|
||||
HEALTHCHECK --interval=60s --timeout=5s --start-period=5s \
|
||||
|
||||
@@ -10,8 +10,11 @@ from config import ATTENDANCE_SHEET_ID as SHEET_ID, JUNIOR_SHEET_GID
|
||||
EXPORT_URL = f"https://docs.google.com/spreadsheets/d/{SHEET_ID}/export?format=csv&gid=0"
|
||||
JUNIOR_EXPORT_URL = f"https://docs.google.com/spreadsheets/d/{SHEET_ID}/export?format=csv&gid={JUNIOR_SHEET_GID}"
|
||||
|
||||
FEE_FULL = 750 # CZK, for 2+ practices in a month
|
||||
FEE_SINGLE = 200 # CZK, for exactly 1 practice in a month
|
||||
ADULT_FEE_DEFAULT = 750 # CZK, for 2+ practices in a month
|
||||
ADULT_FEE_SINGLE = 200 # CZK, for exactly 1 practice in a month
|
||||
ADULT_FEE_MONTHLY_RATE = {
|
||||
"2026-03": 350
|
||||
}
|
||||
|
||||
JUNIOR_FEE_DEFAULT = 500 # CZK for 2+ practices
|
||||
JUNIOR_MONTHLY_RATE = {
|
||||
@@ -76,13 +79,13 @@ def group_by_month(dates: list[tuple[int, datetime]], merged_months: dict[str, s
|
||||
return months
|
||||
|
||||
|
||||
def calculate_fee(attendance_count: int) -> int:
|
||||
"""Apply fee rules: 0 → 0, 1 → 200, 2+ → 750."""
|
||||
def calculate_fee(attendance_count: int, month_key: str) -> int:
|
||||
"""Apply fee rules: 0 → 0, 1 → 200, 2+ → configured rate (default 750)."""
|
||||
if attendance_count == 0:
|
||||
return 0
|
||||
if attendance_count == 1:
|
||||
return FEE_SINGLE
|
||||
return FEE_FULL
|
||||
return ADULT_FEE_SINGLE
|
||||
return ADULT_FEE_MONTHLY_RATE.get(month_key, ADULT_FEE_DEFAULT)
|
||||
|
||||
|
||||
def calculate_junior_fee(attendance_count: int, month_key: str) -> str | int:
|
||||
@@ -186,7 +189,7 @@ def get_members_with_fees() -> tuple[list[tuple[str, str, dict[str, int]]], list
|
||||
for c in cols
|
||||
if c < len(row) and row[c].strip().upper() == "TRUE"
|
||||
)
|
||||
fee = calculate_fee(count) if tier == "A" else 0
|
||||
fee = calculate_fee(count, month_key) if tier == "A" else 0
|
||||
month_fees[month_key] = (fee, count)
|
||||
members.append((name, tier, month_fees))
|
||||
|
||||
|
||||
@@ -647,7 +647,7 @@
|
||||
{% set rt = get_render_time() %}
|
||||
<div class="footer"
|
||||
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
|
||||
render time: {{ rt.total }}s
|
||||
{{ build_meta.tag }}@{{ build_meta.commit }} | render time: {{ rt.total }}s
|
||||
<div id="perf-details" class="perf-breakdown">
|
||||
{{ rt.breakdown }}
|
||||
</div>
|
||||
|
||||
@@ -238,7 +238,7 @@
|
||||
{% set rt = get_render_time() %}
|
||||
<div class="footer"
|
||||
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
|
||||
render time: {{ rt.total }}s
|
||||
{{ build_meta.tag }}@{{ build_meta.commit }} | render time: {{ rt.total }}s
|
||||
<div id="perf-details" class="perf-breakdown">
|
||||
{{ rt.breakdown }}
|
||||
</div>
|
||||
|
||||
@@ -253,7 +253,7 @@
|
||||
{% set rt = get_render_time() %}
|
||||
<div class="footer"
|
||||
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
|
||||
render time: {{ rt.total }}s
|
||||
{{ build_meta.tag }}@{{ build_meta.commit }} | render time: {{ rt.total }}s
|
||||
<div id="perf-details" class="perf-breakdown">
|
||||
{{ rt.breakdown }}
|
||||
</div>
|
||||
|
||||
@@ -628,7 +628,7 @@
|
||||
{% set rt = get_render_time() %}
|
||||
<div class="footer"
|
||||
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
|
||||
render time: {{ rt.total }}s
|
||||
{{ build_meta.tag }}@{{ build_meta.commit }} | render time: {{ rt.total }}s
|
||||
<div id="perf-details" class="perf-breakdown">
|
||||
{{ rt.breakdown }}
|
||||
</div>
|
||||
|
||||
@@ -237,7 +237,7 @@
|
||||
{% set rt = get_render_time() %}
|
||||
<div class="footer"
|
||||
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
|
||||
render time: {{ rt.total }}s
|
||||
{{ build_meta.tag }}@{{ build_meta.commit }} | render time: {{ rt.total }}s
|
||||
<div id="perf-details" class="perf-breakdown">
|
||||
{{ rt.breakdown }}
|
||||
</div>
|
||||
|
||||
@@ -631,7 +631,7 @@
|
||||
{% set rt = get_render_time() %}
|
||||
<div class="footer"
|
||||
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
|
||||
render time: {{ rt.total }}s
|
||||
{{ build_meta.tag }}@{{ build_meta.commit }} | render time: {{ rt.total }}s
|
||||
<div id="perf-details" class="perf-breakdown">
|
||||
{{ rt.breakdown }}
|
||||
</div>
|
||||
|
||||
@@ -631,7 +631,7 @@
|
||||
{% set rt = get_render_time() %}
|
||||
<div class="footer"
|
||||
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
|
||||
render time: {{ rt.total }}s
|
||||
{{ build_meta.tag }}@{{ build_meta.commit }} | render time: {{ rt.total }}s
|
||||
<div id="perf-details" class="perf-breakdown">
|
||||
{{ rt.breakdown }}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user