-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmockbackend.py
47 lines (39 loc) · 1.55 KB
/
mockbackend.py
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
43
44
45
46
47
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import random
import datetime
app = FastAPI()
# Enable CORS for frontend requests
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Change this to your frontend domain in production
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
def generate_dummy_data(num_participants=100, num_levels=5):
leaderboard_data = {}
participants = [f"codegolf-test-user{i}" for i in range(1, num_participants + 1)]
for level in range(1, num_levels + 1):
submissions = []
for _ in range(random.randint(20, 50)): # Random number of submissions per level
repo_name = random.choice(participants)
code_len = random.randint(0, 1000) # Random code length
dtime = datetime.datetime.utcnow() - datetime.timedelta(minutes=random.randint(0, 10000))
verification = random.choice([True, False, None])
submissions.append({
"repo_name": repo_name,
"code_len": code_len,
"dtime": dtime.isoformat(),
"verification": verification
})
leaderboard_data[str(level)] = sorted(submissions, key=lambda x: x['code_len'])
return leaderboard_data
# Generate random leaderboard data
leaderboard_data = generate_dummy_data()
@app.get("/codegolf/api/leaderboard")
async def get_leaderboard():
return leaderboard_data
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="127.0.0.1", port=8000)