From b57d89788fc0e0c1829782fc677a707d179359c0 Mon Sep 17 00:00:00 2001 From: "A. Svensson" Date: Mon, 23 Feb 2015 18:18:34 +0100 Subject: [PATCH] Store player history in redis. --- .../management/commands/update_population.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/gameservers/management/commands/update_population.py b/src/gameservers/management/commands/update_population.py index cc8e299..e0cf262 100755 --- a/src/gameservers/management/commands/update_population.py +++ b/src/gameservers/management/commands/update_population.py @@ -1,11 +1,12 @@ #!/usr/bin/env python -from django.core.management.base import BaseCommand - -from gameservers.models import Server, PopulationHistory - import re import logging +import time + +from django.core.management.base import BaseCommand + +from gameservers.models import Server, PlayerHistory import requests from bs4 import BeautifulSoup @@ -98,6 +99,8 @@ class Command(BaseCommand): def handle(self, *args, **kwargs): parser = ServerParser() servers = parser.run() + history = PlayerHistory() + now = time.time() for data in servers: # TODO: do bulk insert instead! @@ -110,10 +113,9 @@ class Command(BaseCommand): ) ) - pop = PopulationHistory.objects.create( - server=server, - players=data['player_count'], - ) + # Update the player history + history.add_point(server, now, data['player_count']) + history.trim_points(server) if __name__ == '__main__':