BuyMeACoffee

Buy Me A Coffee

jueves, 11 de junio de 2015

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.

Don't hesitate to contact us for our services:

US Phone: +1 (321) 200-0156
CR Phone: +(506) 8705-4494
Email: services@pticostarica.com

No hay comentarios.:

Publicar un comentario

Nota: sólo los miembros de este blog pueden publicar comentarios.