How jaynik-s/nba_insights works
Main Components
• Frontend Interface:
• This is represented by the HTML templates (located in the templates folder such as cluster.html, compare.html, etc.) and static assets (from the static folder with style.css). These files form the web pages presented to users.
• Backend Logic:
• Flask Application: The central component is app.py, which handles routing, user input, and overall orchestration.
• Supporting Scripts:
▪ career_stats.py likely provides functions related to retrieving or processing player statistics.
▪ centroid_clustering.py contains the implementation and parameters for the K-Means clustering algorithm used in defining archetypes.
• Data Management:
• Data Files: The data folder holds essential files – archetype_centroids.json for clustering centroids and scaler/pca.pkl for the preprocessing model artifacts (scaler and PCA).
• External Services:
• nba_api: Acts as the external data provider for NBA player statistics.
• Visualization:
• Matplotlib is used (as mentioned in the README) to generate plots showing player coordinates relative to archetype centroids.
Mapping Relationships and Interactions
• User Interaction: A user initiates an action (like searching for a player or comparing players) via the frontend. Their input is sent to the Flask application.
• Request Handling: app.py receives the request and invokes helper modules like career_stats.py to fetch data from the nba_api.
• Data Processing Pipeline:
▪ After data is fetched, the information is transformed using preprocessing tools (loaded scaler.pkl and pca.pkl) following the steps outlined in the README.
▪ Clustering: centroid_clustering.py is used to compare the processed data with precomputed archetype centroids from archetype_centroids.json to determine the player's archetypes.
• Visualization: Based on the computed results, Matplotlib generates a visualization (graph) that is rendered on the webpage.
• Caching Mechanism: There is a caching system (involving player_stats_cache.json in the data folder) to reduce the number of API calls.
Architectural Patterns and Technologies
• Pattern: There is a clear separation of concerns (data retrieval, processing, and presentation). The use of Flask’s routing helps encapsulate different functionalities (such as player search and comparison).
• Technologies: Python libraries for data processing and visualization, Flask for web routing, nba_api for external data, and JSON/Pickle files for model and clustering parameters.
• Design Principle: Modularity is strongly favored, so each component (data retrieval, clustering, visualization) is handled by specific scripts/modules, making the system easier to maintain and extend.