Got involved with this project because I play ESPN/Yahoo Fantasy Sports. This tiny little application allows me to use math to calculate better Fantasy Pre-Draft order, roster lineup, and player scouting.
The first thing you should know about this project is that there are multiple documents available for the Python client of NBA statistics located at stats.nba.com. If you want to know more about work you check those out. Second, this work is solely dedicated to retrieve, store, view NBA data. There is no attempt here to provide for updating or editing this data to build your team.
If you're anything like me you have several teams active per year in any number of available leagues. With so many teams active, pretty much every Fantasy team will have completely full starting lineups for each day of the season. The problem is deciding which player to start and which player to bench for the best particular matchups.
Choosing which player to start and which player to bench is never going to be an exact science. However, using skills of building great technology we can utilize tools to better help us to decide.
Particular for this project I am using a formula to try and come up with the best players. The formula used here attempts to Calculate Standard Deviation for each player. This helps me to determine which player will probably give me the best matchup results.
Private Shared Function CalculateStandardDeviation ...
Dim average As Decimal = values.Average()
Dim sum As Decimal = CDec(values.Sum(Function(d)
Math.Pow(CDbl(d) - CDbl(average), 2)))
Dim result As Decimal = _
CDec(Math.Sqrt((CDbl(sum) / (values.Count() - 1))))
Return IIf(result > 0, result, 1)
The overall step-by-step process for the application is simple.
- Download player stats
- Save the player stats
- Calculate Player ranking
- Display the ranking on screen
- Refresh player stats (repeat 1-4)
Newtonsoft.Json is used to download the json dataset. To accomplish this a custom WebService has been implemented. The webservice simply sends a static query to the NBA Stats web service. It recieves and downloads the json dataset which is then translated into .NET class for easy data storage and retrival.
Friend Class WebService
Private Shared ReadOnly httpClient As New HttpClient()
Public Shared Sub Start()
Storage was made easier by utilizing the Arkitech Platform Framework (APF) The Arkitech Platform Framework (APF) is an object-relational mapper that enables .NET developers to work with relational data using domain-specific objects. It eliminates the need for most of the data-access code that developers usually need to write. APF is a software development framework that helps you build a maintainable business logic layer when buiding Windows Forms (WinForms) Microsoft SQL Server (MSSQL) data-oriented applications.
Using the APF allowed me to focus on designing simple POCO classes for easy data storage.
Public Class Player
Private _Reports As New List(Of Report)
Private _Rosters As New List(Of Roster)
<column(isprimarykey:=true, _="" isdbgenerated:="True)" playerid="" property="" public=""> _
Public Property IsPicked As Boolean
Public Overrides Property Name As String
Here we bring together information to help guide Fantasy player research and lineup optimization. The power is now in your hands to go off and become the next leaque leader of your NBA Fantasy Leagues.
Is there an NBA API for free that has live stats?
Yes. For a list of all the json files that NBA releases for each day: Visit data.nba.net [^]
Certain ideas and code examples for this article were sampled using code from one or more of the code samples below.