File size: 951 Bytes
1790bde
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
# Render startup: ensure API data exists, then start API.
set -e
export PYTHONUTF8=1 PYTHONIOENCODING=utf-8

cd "$(dirname "$0")/../.."

echo "-- Checking API data --"
DB_READY="$(python - <<'PY'
import sqlite3
from pathlib import Path

db = Path("data/worldcup.db")
if not db.exists():
    print("0")
else:
    try:
        with sqlite3.connect(db) as conn:
            n = conn.execute("SELECT COUNT(*) FROM model_runs").fetchone()[0]
        print("1" if n else "0")
    except Exception:
        print("0")
PY
)"

if [ "$DB_READY" != "1" ]; then
    echo "-- Building database and model outputs --"
    cd services/model
    python ingest.py
    if [ ! -f artifacts/dixon_coles.pkl ]; then
        python backtest.py
    fi
    python pipeline.py "${N_SIMS:-5000}"
    cd ../..
else
    echo "-- Using prebuilt database --"
fi

echo "-- Starting API --"
cd services/api
python -m uvicorn main:app --host 0.0.0.0 --port "${PORT:-8000}"