Spaces:
Sleeping
Sleeping
Download graph.py from prathmeshg/NFL_CV_DEMO: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/spaces/prathmeshg/NFL_CV_DEMO/resolve/main/graph.py
- Command line
-
hf download hf://spaces/prathmeshg/NFL_CV_DEMO/graph.py
-
curl -L -o graph.py https://huggingface.co/spaces/prathmeshg/NFL_CV_DEMO/resolve/main/graph.py
1.29 kB
| 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) |