If want to find out how to implement a quick telemetry system, or just want to me nosey about how I used Django to create a telemetry system for Polyology, then this post is for you.
One of the various tag lines is “Django makes it easier to build better Web Apps more quickly and with less code.” which I can’t help but agree with. It does take some time to setup and learn but once you know Django you’ll be able to quickly create and extend your telemetry system. It has solid documentation and a lovely tutorial for getting you started on their website (disclaimer – This article was written using Django 1.4).
Uploading data from the game
var formData = new FormData();
var xmlhttp = GetXMLRequest();
xmlhttp.open("POST", "/telemetry/", true);
Handling the data on the server
Django lets you define models, layouts of how information will be defined, this is a quick model for some generic telemetry. In this case it’s just a couple of short reference strings and an integer (and a cheeky increment function for later on).
levelset = models.CharField(max_length=32)
level = models.CharField(max_length=32)
stat = models.CharField(max_length=32)
value = models.IntegerField()
self.value = self.value + 1;
Then when a post comes in simply increment the existing telemetry, if it doesn’t exist add a new one.
if request.method == 'POST':
_set = request.POST['levelset']
_level = request.POST['level']
_stat = request.POST['stat']
if (_set and _level and _stat):
query = Telemetry.objects.get(levelset=_set, level=_level, stat=_stat)
newTelem = Telemetry(levelset=_set, level=_level, stat=_stat, value = 1)
Administrating the data
If you add a quick Admin class, saying what is displayable and filterable
list_display = ('stat', 'levelset', 'level', 'value')
list_filter = ('stat', 'levelset', 'level')
Django will give you a admin site, setting you add, edit, delete telemetry as well as filtering and sorting.
So that’s it, that’s most of the code for the telemetry, and you can just add new post calls and everything is just handled. Every indie dev out there should have a simple, extensible web framework for telemetry. If you don’t have one, I’d try Django and see what you think.
Finally I’d like to thank Mark Tully for introducing me to Django in the first place.