File size: 1,743 Bytes
17cc850
 
631d5a9
 
 
17cc850
 
f070327
631d5a9
 
cbd6152
631d5a9
cbd6152
88ad163
 
 
17cc850
 
f070327
fd102bd
c4fe061
 
fd102bd
 
17cc850
8cc36f2
fd102bd
17cc850
 
 
 
 
88ad163
17cc850
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import requests
import json
import os
from dotenv import load_dotenv
load_dotenv() #loads the .env file

def test_optimize():
  url = "http://127.0.0.1:8000/optimize"
  token = os.getenv("HF_TOKEN")
  if not token:
    print("WARNING: HF_TOKEN is not set! Check your .env file or environment variables.")
  else:
    print(f"Token loaded (starts with: {token[:5]}...)")
  headers = {
    "Authorization": f"Bearer {token}",
  }
  payload = {
    "aptitudes": {
      "Turf": "B",
      "Dirt": "A",
      "Sprint": "B",
      "Mile": "A",
      "Medium": "A",
      "Long": "C",
    },
    "cutoff": "c",
    "preferredDistance": "Mile",
    "locked": {},
  }

  print(f"Sending request to {url}...")
  try:
    response = requests.post(url, json=payload, headers=headers)
    response.raise_for_status()

    data = response.json()

    # Save to file for review
    output_file = "response_sample.json"
    with open(output_file, "w", encoding="utf-8") as f:
      json.dump(data, f, indent=4, ensure_ascii=False)

    print(f"Success! Response saved to {output_file}")

    race_count = 0
    race_slots = data.get("slots", [])
    for race in race_slots:
      if race["race"] is not None:
        race_count += 1

    # Print a summary
    print("\n--- Optimization Summary ---")
    print(f"Status: {data.get('status')}")
    print(f"Races Scheduled: {race_count}")
    print(f"Epithets Achieved: {len(data.get('achievedEpithets', []))}")
    print(f"Total Stats: {data.get('statTotal')}")

  except requests.exceptions.ConnectionError:
    print(
      "Error: Could not connect to the server. Make sure 'python app.py' is running."
    )
  except Exception as e:
    print(f"Error: {e}")


if __name__ == "__main__":
  test_optimize()