Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
35a7e21
Replace Player Tracking frontend with AFL Dashboard implementation
ishita230702 Sep 5, 2025
1d73763
Replace Player Tracking frontend with cleaned version
ishita230702 Sep 13, 2025
0d421c4
Update oauth.ts
ishita230702 Sep 14, 2025
f33d1a5
Code Clean Refactored
BinilTomJose1278 Sep 15, 2025
6013b82
Player stats refactored
BinilTomJose1278 Sep 15, 2025
b5fb7ec
Add backend + tracking_code + frontend, ignore node_modules
TOMINJOSE88 Sep 17, 2025
31cf3ac
Add requirements.txt and README.md for player tracking and backend se…
TOMINJOSE88 Sep 21, 2025
7251ac5
player tracking updated
TOMINJOSE88 Sep 21, 2025
0cd0f15
updated storage.py
TOMINJOSE88 Sep 21, 2025
957a2c0
Create Standards and Code Guide .md
ishita230702 Sep 21, 2025
49b267b
Create Frontend Setup.md
ishita230702 Sep 21, 2025
51a8e70
Update VideoAnalysisTab.tsx with polished UI
ishita230702 Sep 21, 2025
36c9ba1
Update PlayerPerformanceTab.tsx with polished UI
ishita230702 Sep 21, 2025
fd35b44
Update CrowdMonitorTab.tsx with polished Ui
ishita230702 Sep 21, 2025
1ff101c
Update DashboardHeader.tsx
ishita230702 Sep 21, 2025
8c5c1dd
Update AFLDashboard.tsx ny hiding teams tab for future use
ishita230702 Sep 21, 2025
a2f04bf
Removing demo access and apple login
ishita230702 Sep 21, 2025
47f4ea5
Reports tab fetches the completed analysis in downloadale format
ishita230702 Sep 21, 2025
485a495
Update ReportsTab.tsx
ishita230702 Sep 21, 2025
6adf4bd
Update ReportsTab.tsx
ishita230702 Sep 22, 2025
4f0921d
updated
ishita230702 Sep 22, 2025
f6f36b0
Update ReportsTab.tsx
ishita230702 Sep 22, 2025
bf5726b
Update Reports.tsx
ishita230702 Sep 22, 2025
991a3b2
Create pdf.ts
ishita230702 Sep 22, 2025
45bce1a
Update pdf.ts
ishita230702 Sep 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Node
node_modules/
.vite/

# Python
__pycache__/
*.pyc
*.pyo


# Python virtual environments
venv/
venv*/
*/venv*/
*/venv310/

# Env
.env

# Generated data/outputs
backend/data/
backend/analytics/
backend/uploads/
backend/heatmaps/

# OS junk
*.log
*.DS_Store
Thumbs.db

# Generated analytics
tracking_code/analytics/
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
📄 README.md (Backend Service)
# ⚡ Backend Service (FastAPI + PostgreSQL)

This backend service manages:
- Video uploads
- Player tracking inference (calls Player Tracking microservice)
- Crowd monitoring inference (calls external API provided by Son Tung Bui)
- Authentication (JWT)
- Analytics storage in PostgreSQL

---

## ⚙️ Requirements

- **Python 3.10** (recommended)
- **PostgreSQL 15** (via Docker or local installation)

---

## 📦 Setup Instructions

### 1. Clone the repository
```bash
git clone https://github.com/<your-repo>.git
cd afl-redback-orion/Player_Tracking/afl_player_tracking_and_crowd_monitoring/backend

2. Create a virtual environment
py -3.10 -m venv venv
.\venv\Scripts\activate # (Windows)
# or
source venv/bin/activate # (Linux/Mac)

3. Upgrade pip
python -m pip install --upgrade pip

4. Install dependencies
pip install -r requirements.txt

🗄️ Run PostgreSQL in Docker

Run PostgreSQL locally in Docker:

docker run --name afl-postgres ^
-e POSTGRES_USER=postgres ^
-e POSTGRES_PASSWORD=postgres ^
-e POSTGRES_DB=aflvision ^
-p 5432:5432 ^
-d postgres:15

⚙️ Environment Variables

Create a .env file inside the backend/ folder:

# Database connection
DATABASE_URL=postgresql+psycopg2://postgres:postgres@localhost:5432/aflvision

# JWT secret key
JWT_SECRET=your-secret-key

🌐 Configure Crowd Monitoring API

Open:

backend/routes/crowd.py


Update this line with the API URL provided by Son Tung Bui:

CROWD_API_URL = "https://<provided-api-url>/analyze_frame/"

🚀 Run the Backend

Start the FastAPI server:

uvicorn main:app --reload --port 8000


Backend will run at:

http://127.0.0.1:8000


Swagger docs available at:

http://127.0.0.1:8000/docs

🧪 Example Workflow

Upload a video via backend → stored in uploaded_videos/.

Backend calls:

Player Tracking Service (http://127.0.0.1:8001)

Crowd Monitoring API (Son Tung Bui’s endpoint).

PostgreSQL stores analytics + user data.

Results available via API endpoints.

🛠️ Notes

Ensure PostgreSQL is running before starting backend.

Update CROWD_API_URL whenever Son Tung Bui provides a new endpoint (e.g., ngrok link).

Works best when combined with Player Tracking Service.
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
# Player Tracking Analysis System

This system implements the player tracking logic from the Week 5-6 notebook, providing a comprehensive backend API for analyzing player movement data, generating heatmaps, and computing player statistics.

## Features

### 🎯 **Core Functionality**
- **CSV Upload & Processing**: Handle tracking data in the same format as the notebook
- **Player Statistics**: Calculate distance, speed, participation, and intensity metrics
- **Heatmap Generation**: Create movement heatmaps for individual players
- **Movement Path Analysis**: Extract detailed movement trajectories
- **Real-time Processing**: Fast analysis with configurable parameters

### 📊 **Player Metrics Computed**
- **Frame Count**: Total frames each player appears in
- **Total Distance**: Cumulative movement in pixels
- **Average Speed**: Mean movement speed (pixels/second)
- **Max Speed**: Peak movement speed
- **Participation Score**: Time presence ratio
- **Intensity Score**: Average confidence level
- **Confidence Statistics**: Min, max, and average confidence

### 🗺️ **Heatmap Generation**
- **Field Scaling**: Automatically scales to AFL oval dimensions (165m x 135m)
- **Configurable Grid**: Adjustable resolution (default: 200x150 cells)
- **Gaussian Smoothing**: Configurable sigma for visual appeal
- **Confidence Weighting**: Heatmap intensity based on detection confidence

## API Endpoints

### 📤 **Upload & Processing**
```
POST /api/v1/tracking/upload-csv
```
Upload a tracking CSV file and get basic dataset information.

### 📈 **Player Statistics**
```
POST /api/v1/tracking/player-stats
```
Upload CSV file to get comprehensive statistics for all players in the dataset.

### 🗺️ **Heatmap Generation**
```
POST /api/v1/tracking/generate-heatmap
```
Generate a heatmap for a specific player with configurable parameters.

### 🖼️ **Heatmap Retrieval**
```
GET /api/v1/tracking/heatmap/{filename}
```
Retrieve a generated heatmap image.

### 🏃 **Movement Analysis**
```
POST /api/v1/tracking/player-movement/{player_id}
```
Upload CSV file to get detailed movement path data for a specific player.

### 📋 **Player Information**
```
POST /api/v1/tracking/available-players
```
Upload CSV file to get list of all available player IDs in the dataset.

### 🧹 **Cleanup**
```
DELETE /api/v1/tracking/cleanup-heatmaps
```
Remove all generated heatmap files.

## CSV Format Requirements

The system expects CSV files with the following columns:

| Column | Type | Description |
|--------|------|-------------|
| `frame_id` | int | Frame number from video |
| `player_id` | int | Unique player identifier |
| `timestamp_s` | float | Timestamp in seconds |
| `x1, y1` | int | Top-left bounding box coordinates |
| `x2, y2` | int | Bottom-right bounding box coordinates |
| `cx, cy` | int | Center coordinates (auto-calculated if missing) |
| `w, h` | int | Bounding box width and height |
| `confidence` | float | Detection confidence (0.0-1.0) |

## Usage Examples

### 1. **Upload and Process CSV**
```bash
curl -X POST "http://localhost:8000/api/v1/tracking/upload-csv" \
-H "Content-Type: multipart/form-data" \
-F "file=@tracking.csv"
```

### 2. **Get Player Statistics**
```bash
curl -X POST "http://localhost:8000/api/v1/tracking/player-stats" \
-H "Content-Type: multipart/form-data" \
-F "file=@tracking.csv"
```

### 3. **Generate Player Heatmap**
```bash
curl -X POST "http://localhost:8000/api/v1/tracking/generate-heatmap" \
-H "Content-Type: multipart/form-data" \
-F "player_id=1" \
-F "file=@tracking.csv" \
-F "field_length=165" \
-F "field_width=135" \
-F "nx=200" \
-F "ny=150" \
-F "sigma=2.0"
```

### 4. **Get Movement Path**
```bash
curl -X POST "http://localhost:8000/api/v1/tracking/player-movement/1" \
-H "Content-Type: multipart/form-data" \
-F "file=@tracking.csv"
```

## Configuration Options

### **Heatmap Parameters**
- `field_length`: Field length in meters (default: 165)
- `field_width`: Field width in meters (default: 135)
- `nx`: Grid resolution in X direction (default: 200)
- `ny`: Grid resolution in Y direction (default: 150)
- `sigma`: Gaussian smoothing parameter (default: 2.0)

### **Performance Tuning**
- **Grid Resolution**: Higher values (400x300) for detailed analysis, lower (100x75) for faster processing
- **Smoothing**: Higher sigma (3.0-5.0) for smoother visuals, lower (1.0-2.0) for sharper details

## Integration with Frontend

The system is designed to work seamlessly with React frontends:

1. **Upload Interface**: Drag & drop CSV files
2. **Player Selection**: Dropdown with available player IDs
3. **Real-time Analysis**: Instant statistics and heatmap generation
4. **Visual Dashboard**: Display heatmaps, movement paths, and metrics

## Error Handling

The system includes comprehensive error handling for:
- **Invalid CSV Format**: Missing columns or wrong data types
- **File Processing Errors**: Corrupted or unreadable files
- **Player Not Found**: Invalid player ID requests
- **Memory Issues**: Large dataset handling

## Performance Considerations

- **Large Datasets**: Optimized for datasets with 1000+ frames
- **Memory Usage**: Efficient pandas operations with minimal memory overhead
- **Heatmap Generation**: Fast processing with matplotlib optimization
- **File Storage**: Automatic cleanup of generated heatmaps

## Dependencies

- **pandas**: Data processing and analysis
- **numpy**: Numerical computations
- **matplotlib**: Heatmap visualization
- **scipy**: Gaussian filtering
- **PIL**: Image processing
- **fastapi**: Web framework

## Testing

Use the included `sample_tracking.csv` file to test the system:

```bash
# Test with sample data
curl -X POST "http://localhost:8000/api/v1/tracking/upload-csv" \
-H "Content-Type: multipart/form-data" \
-F "file=@sample_tracking.csv"
```

## Future Enhancements

- **Batch Processing**: Handle multiple CSV files simultaneously
- **Advanced Analytics**: Acceleration, direction changes, player interactions
- **Real-time Streaming**: Process live video feeds
- **Machine Learning**: Predictive movement patterns
- **Export Formats**: JSON, CSV, and image exports
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[
{
"frame": 0,
"count": 0,
"heatmap": "crowd_heatmaps\\8703ba69-e28a-4c3f-9e45-81ba616dec15_heatmap_0.png"
},
{
"frame": 30,
"count": 0,
"heatmap": "crowd_heatmaps\\8703ba69-e28a-4c3f-9e45-81ba616dec15_heatmap_30.png"
},
{
"frame": 60,
"count": 0,
"heatmap": "crowd_heatmaps\\8703ba69-e28a-4c3f-9e45-81ba616dec15_heatmap_60.png"
},
{
"frame": 90,
"count": 0,
"heatmap": "crowd_heatmaps\\8703ba69-e28a-4c3f-9e45-81ba616dec15_heatmap_90.png"
},
{
"frame": 120,
"count": 0,
"heatmap": "crowd_heatmaps\\8703ba69-e28a-4c3f-9e45-81ba616dec15_heatmap_120.png"
},
{
"frame": 150,
"count": 0,
"heatmap": "crowd_heatmaps\\8703ba69-e28a-4c3f-9e45-81ba616dec15_heatmap_150.png"
},
{
"frame": 180,
"count": 0,
"heatmap": "crowd_heatmaps\\8703ba69-e28a-4c3f-9e45-81ba616dec15_heatmap_180.png"
},
{
"frame": 210,
"count": 0,
"heatmap": "crowd_heatmaps\\8703ba69-e28a-4c3f-9e45-81ba616dec15_heatmap_210.png"
},
{
"frame": 240,
"count": 0,
"heatmap": "crowd_heatmaps\\8703ba69-e28a-4c3f-9e45-81ba616dec15_heatmap_240.png"
},
{
"frame": 270,
"count": 0,
"heatmap": "crowd_heatmaps\\8703ba69-e28a-4c3f-9e45-81ba616dec15_heatmap_270.png"
},
{
"frame": 300,
"count": 0,
"heatmap": "crowd_heatmaps\\8703ba69-e28a-4c3f-9e45-81ba616dec15_heatmap_300.png"
}
]
Binary file not shown.

This file was deleted.

Loading