Repository Name: psl-cricket-analytics
Description: Comprehensive statistical analysis toolkit for Pakistan Super League cricket data with automated batting and bowling performance metrics, visualization generation, and detailed reporting capabilities.
This repository provides a complete suite of Python scripts for analyzing Pakistan Super League (PSL) cricket match data. The toolkit processes ball-by-ball JSON data to generate comprehensive statistical insights, professional visualizations, and detailed LaTeX reports for batting and bowling performance analysis.
- Comprehensive Data Processing: Parse and analyze ball-by-ball PSL match data from JSON files
- Batting Analysis: Detailed statistics including runs, averages, strike rates, boundaries, consistency metrics
- Bowling Analysis: Complete bowling metrics including wickets, economy rates, dot ball percentages, strike rates
- Pakistani Player Focus: Specialized analysis for Pakistani players with minimum match qualification filters
- Automated Visualization: Generate publication-quality charts and graphs automatically
- LaTeX Report Generation: Professional PDF reports with detailed statistical analysis
- Player performance aggregation across multiple seasons
- Strike rate vs average correlation analysis
- Boundary hitting patterns and preferences
- Consistency and reliability metrics
- Match-winning performance identification
- Comparative analysis across player cohorts
- Milestone achievement tracking (50s, 100s)
- Career trajectory projections
- Multi-panel batting performance dashboards (12 charts)
- Multi-panel bowling analysis dashboards (9 charts)
- Top performance bar charts for individual players
- Radar charts for multi-dimensional player comparison
- Strike rate distribution analysis
- Economy rate and wicket-taking visualizations
- Boundary percentage analysis
- Consistency and reliability metrics
- Python 3.7 or higher
- pip package manager
pip install pandas matplotlib seaborn numpyThe scripts expect match data in JSON format following the standard cricket data schema:
{
"info": {
"teams": ["Team A", "Team B"],
"dates": ["2016-02-04"],
"outcome": { "winner": "Team A" }
},
"innings": [
{
"team": "Team A",
"overs": [
{
"over": 0,
"deliveries": [
{
"batter": "Player Name",
"bowler": "Bowler Name",
"runs": { "batter": 4, "total": 4 }
}
]
}
]
}
]
}Place all JSON files in the psl_json/ directory.
Run comprehensive batting and bowling analysis on all matches:
python scripts/psl_general_analysis.pyOutput:
psl_batting_analysis.png- 9 batting visualizationspsl_bowling_analysis.png- 9 bowling visualizationspsl_batting_data.csv- Complete batting statisticspsl_bowling_data.csv- Complete bowling statistics- Console output with summary statistics
Generate detailed analysis for top Pakistani batters with minimum 20 matches:
python scripts/psl_pakistani_batters.pyOutput:
psl_top10_pakistani_batters_analysis.png- 12-chart dashboardpsl_top_performances_pakistani_batters.png- Top 5 scores visualizationpsl_radar_comparison_pakistani_batters.png- Multi-dimensional comparisonpsl_pakistani_batters_detailed_stats.csv- Complete statistics export- Console output with detailed rankings and analysis
After running the analysis scripts, compile the LaTeX report:
cd output/reports/
pdflatex psl_batting_deep_analysis.tex
pdflatex psl_batting_deep_analysis.tex # Run twice for table of contents- Average: Total runs divided by number of dismissals
- Strike Rate: (Total runs / Total balls faced) × 100
- Boundary Percentage: ((Fours × 4) + (Sixes × 6)) / Total Runs × 100
- Consistency: Standard deviation of individual scores (lower is better)
- Runs per Match: Total runs divided by matches played
- Dot Ball Percentage: Dot balls faced / Total balls faced × 100
- Conversion Rate: Percentage of innings resulting in 50+ scores
- Bowling Average: Total runs conceded / Wickets taken
- Economy Rate: (Total runs conceded / Balls bowled) × 6
- Strike Rate: Balls bowled / Wickets taken
- Dot Ball Percentage: Dot balls bowled / Total balls × 100
Edit the psl_pakistani_batters.py file:
num_matches = len(self.player_matches[player])
if num_matches < 20: # Change this value
continueUpdate the pakistani_players set in the analyzer class:
self.pakistani_players = {
'Babar Azam', 'Mohammad Rizwan',
# Add more player names here
}Modify chart parameters in the visualization functions:
plt.rcParams['figure.figsize'] = (14, 8) # Adjust figure size
sns.set_palette("husl") # Change color palette- psl_batting_analysis.png: Contains 9 charts analyzing runs distribution, strike rates, top scorers, boundaries, and consistency metrics
- psl_bowling_analysis.png: Contains 9 charts analyzing wickets, economy rates, dot balls, and bowling averages
- psl_top10_pakistani_batters_analysis.png: Comprehensive 12-chart dashboard for top 10 Pakistani batters
- psl_top_performances_pakistani_batters.png: Bar charts showing top 5 individual scores for each player
- psl_radar_comparison_pakistani_batters.png: Multi-dimensional radar chart comparing top 5 batters
- CSV exports: Contain complete statistics for all players, sortable and filterable for custom analysis
- LaTeX report: Professional publication-quality PDF report with detailed analysis and insights
Create a requirements.txt file with:
pandas>=1.3.0
matplotlib>=3.4.0
seaborn>=0.11.0
numpy>=1.21.0
Install all requirements:
pip install -r requirements.txtContributions are welcome. Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-analysis) - Commit your changes (
git commit -am 'Add new analysis feature') - Push to the branch (
git push origin feature/new-analysis) - Create a Pull Request
- Additional visualization types
- More detailed bowling analysis
- Team-level performance metrics
- Match outcome prediction models
- Player comparison algorithms
- Web dashboard interface
- Real-time data ingestion
- Large Datasets: For datasets with 100+ match files, processing may take 2-5 minutes
- Memory Usage: Typical memory usage is 200-500 MB depending on dataset size
- Visualization Generation: PNG files are saved at 300 DPI for publication quality
Issue: FileNotFoundError: psl_json directory not found
- Solution: Ensure the
psl_json/directory exists and contains JSON files
Issue: No Pakistani players found with minimum 20 matches
- Solution: Reduce the minimum match threshold or verify player name matching logic
Issue: Module not found: matplotlib
- Solution: Install required packages using
pip install -r requirements.txt
Issue: LaTeX compilation errors
- Solution: Ensure all visualization PNG files exist in the correct location before compiling
This project is licensed under the MIT License. See LICENSE file for details.
- Pakistan Super League for providing the context for cricket analytics
- Cricket data format standards maintained by the cricket data community
- Python data science community for excellent analytical libraries
For questions, suggestions, or bug reports, please open an issue on the GitHub repository.
If you use this toolkit in your research or analysis, please cite:
PSL Cricket Analytics Toolkit
https://github.com/hasnain1241/psl-cricket-analytics
cricsheet.org: https://cricsheet.org/matches
- Initial release with batting and bowling analysis
- Pakistani batters deep analysis module
- Comprehensive visualization suite
- LaTeX report generation
- CSV data export functionality
Last Updated: 2025