help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
sports-analysis
RSK World
sports-analysis
Sports Analysis Dataset - Game Footage + Player Tracking + Event Annotations + OpenCV + Video Analysis
sports-analysis
  • .github
  • assets
  • data
  • docs
  • examples
  • scripts
  • .gitignore577 B
  • ADVANCED_FEATURES.md7.1 KB
  • CHANGELOG.md3.5 KB
  • CONTRIBUTING.md1 KB
  • DATA_SUMMARY.md4.1 KB
  • ERROR_CHECK_REPORT.md3.6 KB
  • GITHUB_RELEASE_GUIDE.md4.3 KB
  • LICENSE1.3 KB
  • PROJECT_SUMMARY.md3.8 KB
  • README.md2.7 KB
  • RELEASE_NOTES.md5.6 KB
  • api.html10.3 KB
  • config.json1.6 KB
  • dashboard.html9.6 KB
  • explorer.html8.8 KB
  • index.html95.9 KB
  • package.json1.3 KB
  • server.js7.9 KB
  • sports-analysis.png2.7 MB
  • sports-analysis.zip13.6 KB
  • sports-analysis.zip.info514 B
server.js
server.js
Raw Download
Find: Go to:
/*
RSK World
Founder: Molla Samser
Designer & Tester: Rima Khatun
Email: help@rskworld.in
Phone: +91 93305 39277
Address: Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India, 713147
Website: https://rskworld.in/
*/

const express = require('express');
const fs = require('fs').promises;
const path = require('path');
const cors = require('cors');

const app = express();
const PORT = 3000;

// Middleware
app.use(cors());
app.use(express.json());
app.use(express.static('.'));

// Helper function to load JSON files
async function loadJSON(filePath) {
    try {
        const data = await fs.readFile(filePath, 'utf8');
        return JSON.parse(data);
    } catch (error) {
        console.error(`Error loading ${filePath}:`, error.message);
        return null;
    }
}

// Helper function to parse CSV
async function parseCSV(filePath) {
    try {
        const data = await fs.readFile(filePath, 'utf8');
        const lines = data.split('\n').filter(line => line.trim() && !line.startsWith('#'));
        const headers = lines[0].split(',');
        const result = [];
        
        for (let i = 1; i < lines.length; i++) {
            const values = lines[i].split(',');
            const obj = {};
            headers.forEach((header, index) => {
                obj[header.trim()] = values[index] ? values[index].trim() : '';
            });
            result.push(obj);
        }
        
        return result;
    } catch (error) {
        console.error(`Error loading CSV ${filePath}:`, error.message);
        return [];
    }
}

// API Routes

// Get all games
app.get('/api/games', async (req, res) => {
    try {
        const metadata = await loadJSON(path.join(__dirname, 'data', 'metadata', 'games_metadata.json'));
        if (!metadata || !metadata.games) {
            return res.status(404).json({ success: false, error: 'Games data not found' });
        }
        
        res.json({
            success: true,
            count: metadata.games.length,
            data: metadata.games
        });
    } catch (error) {
        res.status(500).json({ success: false, error: error.message });
    }
});

// Get specific game
app.get('/api/games/:gameId', async (req, res) => {
    try {
        const { gameId } = req.params;
        const metadata = await loadJSON(path.join(__dirname, 'data', 'metadata', 'games_metadata.json'));
        
        if (!metadata || !metadata.games) {
            return res.status(404).json({ success: false, error: 'Games data not found' });
        }
        
        const game = metadata.games.find(g => g.game_id === gameId);
        
        if (!game) {
            return res.status(404).json({ success: false, error: 'Game not found' });
        }
        
        res.json({ success: true, data: game });
    } catch (error) {
        res.status(500).json({ success: false, error: error.message });
    }
});

// Get events with filtering
app.get('/api/events', async (req, res) => {
    try {
        const { gameId, eventType, sport } = req.query;
        const metadata = await loadJSON(path.join(__dirname, 'data', 'metadata', 'games_metadata.json'));
        
        if (!metadata || !metadata.games) {
            return res.status(404).json({ success: false, error: 'Games data not found' });
        }
        
        let allEvents = [];
        
        for (const game of metadata.games) {
            if (gameId && game.game_id !== gameId) continue;
            if (sport && game.sport !== sport) continue;
            
            if (game.events_file) {
                const eventsData = await loadJSON(path.join(__dirname, game.events_file));
                if (eventsData && eventsData.events) {
                    const events = eventsData.events.map(event => ({
                        ...event,
                        game_id: game.game_id,
                        sport: game.sport,
                        date: game.date
                    }));
                    
                    allEvents = allEvents.concat(events);
                }
            }
        }
        
        if (eventType) {
            allEvents = allEvents.filter(e => e.event_type === eventType);
        }
        
        res.json({
            success: true,
            count: allEvents.length,
            data: allEvents
        });
    } catch (error) {
        res.status(500).json({ success: false, error: error.message });
    }
});

// Get tracking data for a game
app.get('/api/tracking/:gameId', async (req, res) => {
    try {
        const { gameId } = req.params;
        const metadata = await loadJSON(path.join(__dirname, 'data', 'metadata', 'games_metadata.json'));
        
        if (!metadata || !metadata.games) {
            return res.status(404).json({ success: false, error: 'Games data not found' });
        }
        
        const game = metadata.games.find(g => g.game_id === gameId);
        
        if (!game || !game.tracking_file) {
            return res.status(404).json({ success: false, error: 'Tracking data not found' });
        }
        
        const trackingData = await loadJSON(path.join(__dirname, game.tracking_file));
        
        if (!trackingData) {
            return res.status(404).json({ success: false, error: 'Tracking data not found' });
        }
        
        res.json({ success: true, data: trackingData });
    } catch (error) {
        res.status(500).json({ success: false, error: error.message });
    }
});

// Get statistics
app.get('/api/stats', async (req, res) => {
    try {
        const metadata = await loadJSON(path.join(__dirname, 'data', 'metadata', 'games_metadata.json'));
        
        if (!metadata || !metadata.games) {
            return res.status(404).json({ success: false, error: 'Data not found' });
        }
        
        const games = metadata.games;
        const sports = [...new Set(games.map(g => g.sport))];
        
        let totalEvents = 0;
        for (const game of games) {
            if (game.events_file) {
                const eventsData = await loadJSON(path.join(__dirname, game.events_file));
                if (eventsData && eventsData.events) {
                    totalEvents += eventsData.events.length;
                }
            }
        }
        
        const performanceData = await parseCSV(path.join(__dirname, 'data', 'annotations', 'performance_metrics_001.csv'));
        const uniquePlayers = new Set(performanceData.map(p => p.player_id));
        
        res.json({
            success: true,
            stats: {
                total_games: games.length,
                total_events: totalEvents,
                total_players: uniquePlayers.size || 16,
                sports: sports,
                total_duration_minutes: games.reduce((sum, g) => sum + (g.duration_minutes || 0), 0)
            }
        });
    } catch (error) {
        res.status(500).json({ success: false, error: error.message });
    }
});

// Get performance metrics
app.get('/api/performance/:gameId?', async (req, res) => {
    try {
        const { gameId } = req.params;
        const performanceData = await parseCSV(path.join(__dirname, 'data', 'annotations', 'performance_metrics_001.csv'));
        
        if (gameId && gameId === 'game_001') {
            res.json({ success: true, data: performanceData });
        } else if (!gameId) {
            res.json({ success: true, data: performanceData });
        } else {
            res.json({ success: true, data: [] });
        }
    } catch (error) {
        res.status(500).json({ success: false, error: error.message });
    }
});

// Start server
app.listen(PORT, () => {
    console.log(`Sports Analysis Dataset API Server running on http://localhost:${PORT}`);
    console.log(`API endpoints available at http://localhost:${PORT}/api`);
    console.log(`Dashboard: http://localhost:${PORT}/dashboard.html`);
});

239 lines•7.9 KB
javascript

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer