13,800,409 members
alternative version

#### Stats

1.6K views
2 bookmarked
Posted 17 Nov 2018
Licenced CPOL

# HoopDream

, 17 Nov 2018
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.

## 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.

2. Save the player stats
3. Calculate Player ranking
4. Display the ranking on screen
5. 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()
Store.Instance.CreateDatabaseObjects()

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.

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

Yes. For a list of all the json files that NBA releases for each day: Visit data.nba.net [^]

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.

## Share

 Founder Arkitech EBC Corporation 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...

 First Prev Next
 Source and project not downloadable Member 1150234818-Nov-18 16:23 Member 11502348 18-Nov-18 16:23
 Re: Source and project not downloadable Terence Wallace19-Nov-18 4:40 Terence Wallace 19-Nov-18 4:40
 Re: Source and project not downloadable Terence Wallace19-Nov-18 13:26 Terence Wallace 19-Nov-18 13:26
 Re: Source and project not downloadable Member 1150234822-Nov-18 0:32 Member 11502348 22-Nov-18 0:32
 Last Visit: 15-Dec-18 13:50     Last Update: 15-Dec-18 13:50 Refresh 1