Click here to Skip to main content
15,868,141 members
Articles / Programming Languages / SQL
Technical Blog

Video Games Statistics Using Web API 2 and SQL Server Reporting Services

Rate me:
Please Sign up or sign in to vote.
4.33/5 (2 votes)
15 Jun 2015CPOL2 min read 6.2K   6  
Video Games Statistics Using Web API 2 and SQL Server Reporting Services

Note: Remember you can click/touch over the images in order to enlarge them.

Implementing your own statistics is incredibly useful since you can customize and track all the data you want, you can track any action in your game and create reports based on the data you have captured, reports that will be very useful to analyze game status, players behavior and to make decisions based on your findings.

By combining SQL Reporting Services with Web API 2, you can create a cross platform system.

The only other required component is the actual client which will send the data, in Unity we can take advantage of the WWW class to build the message and post the data to the server.

First, in the server project, we implement a class to handle our data, in this case, we created "GameSessionStatsModel", since we are tracking per session data.

Then we implement the actual Controller, we named it "GameStatsController".

We now proceed to implement the Post action.

In this action, we mark the parameter with [FromBody] because we have the data in the body of the message we receive, you could have it with [FromUri] instead in case you are sending the data in the URL.

Now, if you are using Unity, you can take advantage of coroutines, and the WWW class.

In this method, we create an instance of the WWWForm, we specify that the Content-Type is going to be in json format with the frm.headers["Content-Type"].

To add the field we need to send, we use the .AddFields methods of the WWWForm instance object,

the name of the string must match the exact name of the properties in the class GameSessionStatsModel implemented before.

Then we build the URL we need to send, by default Web API 2 will be [serverUrl]/api/[controller]

Since our controller class is named "GameStatsController" our URL will be [serverUrl]/api/GameStats.

Note: Replace serverurl with your correct URL.

Then, we create an instance of the WWW class, we send the URL and the form as parameters in the constructor, and we use the yield keyword to execute the request and wait for a response to be received, since in our code we are constantly updating data, we also use WaitForSeconds, with the desired amount of seconds, in this case we are using 5 seconds for testing purposes.

Now, let's go to the reports.

Use the Business Intelligence templates to create a Reporting project in Visual Studio, and create a new empty report.

Design Mode

 

Preview Mode

In this case, we created a report to see how many sessions exist for each single platform we send data from.

Hopefully it has been useful to you.

License

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


Written By
CEO PTI Costa Rica
Costa Rica Costa Rica
Eduardo is an individual with knowledge is multiple academic fields,
where the two main are System Engineering and Psychology.
This not only allows Eduardo to work in the IT fields, but also give him the knowledge and abilities required to understand people behavior, and the factors involved that could affect a person, and even more than understand them, his Psychology studies give him the tools to help the individuals that require it.

Eduardo has also some knowledge in he videogame development field, and using tools such as
3ds max and Unity 3d.

Eduardo's main goal is actually to become a videogame profesional.

Profile:
* Bachellor in System Ingeneering
* 8+ years of experience

Linkedin profile: https://cr.linkedin.com/in/pticostarica

Comments and Discussions

 
-- There are no messages in this forum --