File size: 4,516 Bytes
e23172f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python3
"""Generate trifecta predictions for all Australian Gallops races."""
import json
from datetime import datetime

# Load race forms
with open('all_race_forms.json', 'r') as f:
    all_races = json.load(f)

def score_runner(run, track_cond):
    """Score a runner 0-100 based on trifecta model factors."""
    score = 0
    
    # Current Form: 20%
    form = run.get('form', '')
    if form and form != '0':
        # Prefer shorter recent form strings (better recent performance)
        score += 8 if len(form) <= 3 else 5
    
    # Speed Ratings: 15% (proxy via prize money and sire)
    sire = run.get('sire', '').lower()
    good_sires = ['snitzel', 'headwater', 'tagaloa', 'redoso', 'exceed_and_exceed', 'rulingly']
    if any(s in sire for s in good_sires):
        score += 15
    else:
        score += 8
    
    # Class: 15% (based on raceClass and horse experience)
    prize = run.get('careerPrizeMoney', '$0.00')
    try:
        prize_val = float(prize.replace('$', '').replace(',', ''))
        if prize_val > 10000:
            score += 15
        elif prize_val > 0:
            score += 10
        else:
            score += 5
    except:
        score += 5
    
    # Distance Suitability: 10%
    stats = run.get('stats', {})
    dist_stats = stats.get('distance', {})
    wins = dist_stats.get('wins', 0)
    starts = dist_stats.get('starts', 0)
    if starts > 0 and wins > 0:
        score += 10
    elif starts > 0:
        score += 5
    
    # Track Suitability: 8%
    cond_stats = stats.get('synthetic', {}) if 'Synthetic' in track_cond else stats.get('heavy', {}) if 'Heavy' in track_cond else stats.get('soft', {})
    if cond_stats.get('wins', 0) > 0:
        score += 8
    elif cond_stats.get('starts', 0) > 0:
        score += 4
    
    # Track Condition: 8%
    if cond_stats.get('places', 0) > 0:
        score += 8
    elif cond_stats.get('starts', 0) > 0:
        score += 4
    
    # Barrier: 5%
    barrier = run.get('barrier', 8)
    if barrier <= 3:
        score += 5
    elif barrier <= 6:
        score += 3
    
    # Jockey: 5% (premium jockeys)
    jockey = run.get('jockey', '').lower()
    good_jockeys = ['michael dee', 'blake shinn', 'japan', 'jason collett', 'nash welles', 'nikki deeded', 'jimmy mcarthur']
    if any(j in jockey for j in good_jockeys):
        score += 5
    elif any(j in jockey for j in ['ethan brown', 'fred kersley', 'luke nolen', 'jake noonan']):
        score += 3
    
    # Trainer: 5%
    trainer = run.get('trainer', '').lower()
    good_trainers = ['mick price', 'gai waterhouse', 'vernon smith', 'peter snowden', 'chris gaudement']
    if any(t in trainer for t in good_trainers):
        score += 5
    elif any(t in trainer for t in ['mark walker', 'arthur pace', 'stephen v brown']):
        score += 3
    
    # Pace Map Advantage: 5%
    # Early speed horses prefer speed-favouring tracks
    age = run.get('age', 3)
    if age == 3:
        score += 5  # Young horses often fresh
    else:
        score += 3
    
    return score

results = []
for race in all_races:
    track = race.get('track', 'Unknown')
    race_num = race.get('raceNumber', '?')
    race_name = race.get('raceName', 'Unknown')
    distance = race.get('distance', '?')
    cond = race.get('condition', '')
    
    runners = race.get('runners', [])
    non_scratched = [r for r in runners if not r.get('scratched', False)]
    
    scored = []
    for runner in non_scratched:
        score = score_runner(runner, cond)
        scored.append({
            'number': runner.get('number'),
            'name': runner.get('name'),
            'score': score,
            'jockey': runner.get('jockey')
        })
    
    scored.sort(key=lambda x: x['score'], reverse=True)
    
    results.append({
        'track': track,
        'race': race_num,
        'name': race_name,
        'distance': distance,
        'condition': cond,
        'predictions': scored[:4]  # Top 4
    })

# Output summary
print("\n=== AUSTRALIAN GALLOPS TRIFECTA PREDICTIONS - TODAY ===\n")
for r in results:
    preds = r['predictions']
    top3 = [f"{p['number']}-{p['name']}" for p in preds[:3]]
    top4 = [f"{p['number']}-{p['name']}" for p in preds[:4]]
    print(f"{r['track'].upper()} {r['race']} - {r['name']} ({r['distance']}, {r['condition']})")
    print(f"  Top 3: {' / '.join(top3)}")
    print(f"  Top 4: {' / '.join(top4)}")
    print()

# Save full results
with open('predictions.json', 'w') as f:
    json.dump(results, f, indent=2)