-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore.py
68 lines (57 loc) · 2.72 KB
/
score.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import sys
import os
from statistics.script import championshipsum
project_root = os.path.dirname(os.path.abspath(__file__))
sys.path.append(project_root)
def read_standings(filename):
"""Reads standings from a file, returning a dictionary of drivers to their positions."""
with open(filename, 'r') as file:
standings = {line.strip(): idx + 1 for idx, line in enumerate(file.readlines())}
return standings
def calculate_scores(predictions, actuals, values):
"""Calculates scores based on the difference between predicted and actual positions."""
scores = {}
for driver, predicted_pos in predictions.items():
actual_pos = actuals.get(driver)
if actual_pos:
position_diff = abs(predicted_pos - actual_pos)
score = values.get(position_diff, 0) # 0 points for diffs > 10
scores[driver] = score
else:
scores[driver] = 0 # Driver not found in actual standings
return scores
def main(track, event_type):
values = {
0: 25, 1: 18, 2: 15, 3: 12, 4: 10, 5: 8,
6: 6, 7: 4, 8: 2, 9: 1, 10: 0
}
# File paths
actuals_path = f'standings/{track}/{event_type}/{event_type}-standings.txt'
prediction_jack_path = f'predictions/{track}/predictions-jack.txt'
prediction_cristian_path = f'predictions/{track}/predictions-cristian.txt'
# Check if files exist
if not os.path.exists(actuals_path) or not os.path.exists(prediction_jack_path) or not os.path.exists(prediction_cristian_path):
print("One or more required files are missing.")
return
# Read standings and predictions
actuals = read_standings(actuals_path)
predictions_jack = read_standings(prediction_jack_path)
predictions_cristian = read_standings(prediction_cristian_path)
# Calculate scores
score_jack = calculate_scores(predictions_jack, actuals, values)
score_cristian = calculate_scores(predictions_cristian, actuals, values)
# Sum up total scores and compare
total_score_jack = sum(score_jack.values())
total_score_cristian = sum(score_cristian.values())
print(f"Jack's total points: {total_score_jack}")
print(f"Cristian's total points: {total_score_cristian}")
if __name__ == '__main__':
import argparse
if len(sys.argv) > 1 and sys.argv[1] == "championship":
championshipsum.championship_total()
else:
parser = argparse.ArgumentParser(description='Calculate F1 prediction scores.')
parser.add_argument('track', type=str, help='Track location (e.g., china)')
parser.add_argument('event_type', choices=['race', 'sprint'], help='Type of event: race or sprint')
args = parser.parse_args()
main(args.track, args.event_type)