Click here to Skip to main content
13,800,409 members
Click here to Skip to main content
Add your own
alternative version

Stats

1.6K views
26 downloads
2 bookmarked
Posted 17 Nov 2018
Licenced CPOL

HoopDream

, 17 Nov 2018
Rate this:
Please Sign up or sign in to vote.
A brief article on how to utilize NBA Stats API in a WinForm application

Introduction

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.

Technology Used

 

Background

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)

 End Function

Workflow

The overall step-by-step process for the application is simple.

  1. Download player stats
  2. Save the player stats
  3. Calculate Player ranking
  4. Display the ranking on screen
  5. Refresh player stats (repeat 1-4)

Download

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()
        Store.Instance.CreateDatabaseObjects()

        httpClient.DefaultRequestHeaders.Accept.Clear()
        httpClient.DefaultRequestHeaders.Accept.Add( _
                New MediaTypeWithQualityHeaderValue("application/json"))

        DownloadPage().Wait()
    End Sub

    ...
End Class

Storage

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.

Database Schema

Using the APF allowed me to focus on designing simple POCO classes for easy data storage.

 

 Public Class Player
     Inherits Entity


     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

     <column()>
     Public Overrides Property Name As String
</column()></column(isprimarykey:=true,...)

Summary

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.

Points of Interest

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 [^]

History

Version 0.0.0.1

References

Certain ideas and code examples for this article were sampled using code from one or more of the code samples below.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Terence Wallace
Founder Arkitech EBC Corporation
United States United States
MS, BBA, software developer, consultant, and trainer. Specializing in building data-centric applications designed for business, university, community & faith based organizations. Started developing Excel VBA macros and never looked back. Freelance developer utilizing VB.Net, SQL Server, Microsoft Access, and ASP.Net.

You may also be interested in...

Comments and Discussions

 
QuestionSource and project not downloadable Pin
Member 1150234818-Nov-18 16:23
memberMember 1150234818-Nov-18 16:23 
AnswerRe: Source and project not downloadable Pin
Terence Wallace19-Nov-18 4:40
memberTerence Wallace19-Nov-18 4:40 
AnswerRe: Source and project not downloadable Pin
Terence Wallace19-Nov-18 13:26
memberTerence Wallace19-Nov-18 13:26 
GeneralRe: Source and project not downloadable Pin
Member 1150234822-Nov-18 0:32
memberMember 1150234822-Nov-18 0:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.181214.1 | Last Updated 18 Nov 2018
Article Copyright 2018 by Terence Wallace
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid