Spaces:
Sleeping
Sleeping
File size: 1,288 Bytes
fd77217 f3fb497 fd77217 f3fb497 fd77217 f3fb497 fd77217 | 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 | import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import os
from pathlib import Path
def generate_player_graph():
OUTPUT_DIR = Path("outputs")
csv_path = OUTPUT_DIR / 'metadata.csv'
output_image_path = OUTPUT_DIR / 'player_stats_graph.png'
if not os.path.exists(csv_path):
print(f"CSV file not found: {csv_path}")
return None
# Read CSV
df = pd.read_csv(csv_path)
# Extract data
times = df['time_seconds'].values
speeds = df['speed_yds_sec'].values
accels = df['accel_yds_sec2'].values
# Caps
SPEED_CAP = 9.0 # yd/sec
ACCEL_CAP = 6.5 # yd/sec^2
# Create plot
fig, ax = plt.subplots(figsize=(10, 6))
# Plot speed and acceleration
ax.plot(times, speeds, label='Speed (yards/sec)', color='blue', marker='o')
ax.plot(times, accels, label='Acceleration (yards/sec²)', color='red', marker='x')
# Labels and title
ax.set_xlabel('Time (seconds)')
ax.set_ylabel('Value')
ax.set_title('Player Speed and Acceleration Over Time')
ax.legend()
ax.grid(True)
# Save figure
plt.savefig(output_image_path, dpi=300, bbox_inches='tight')
plt.close()
print(f'Graph saved to {output_image_path}')
return str(output_image_path) |