Commit aeb9cf54 authored by Hubert Denkmair's avatar Hubert Denkmair

add veggie factor to stats

parent b4e05e9c
from django.core.management.base import BaseCommand, CommandError
from django.db.models import Count
from django.db.models import Count, Sum
from core.models import SnakeGame, SnakeVersion
from django.contrib.auth.models import User
......@@ -34,3 +34,8 @@ class Command(BaseCommand):
for k in sorted(deaths, key=lambda v: v[0], reverse=True)[:10]:
print(k[0], ": ", k[1])
print()
print("top ten veggies:")
for v in SnakeGame.objects.values('user__username').annotate(veggie_factor=Sum('natural_food_consumed')/(Sum('carrison_food_consumed')+Sum('hunted_food_consumed'))).order_by('-veggie_factor')[:10]:
print(v['veggie_factor'], v['user__username'])
print()
......@@ -54,6 +54,7 @@ class UserProfile(models.Model):
self.viewer_key = random.getrandbits(63)
super(UserProfile, self).save(*args, **kwargs)
class SnakeGame(models.Model):
snake_version = models.ForeignKey(SnakeVersion, on_delete=models.CASCADE)
user = models.ForeignKey(User, null=True, on_delete=models.SET_NULL)
......@@ -84,6 +85,7 @@ class ServerCommand(models.Model):
def create_key():
return str(uuid.uuid4())
class ApiKey(models.Model):
MAX_KEYS_PER_USER = 20
user = models.ForeignKey(User, on_delete=models.CASCADE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment