Exemplo n.º 1
0
    def raw_serialization(self, context):
        game = Game.nearest_game()
        t0, tf = time_endpoints(game)

        meals_vs_hours = meals_per_hour(Game.nearest_game(),
                                        self.get_queryset())

        histogram = []
        for hour in xrange(len(meals_vs_hours)):
            t = t0 + timedelta(hours=hour)

            # Stop at the current time
            if t > settings.NOW():
                break

            histogram.append([json_format_time(t), meals_vs_hours[hour]])

        # Pre-game case
        if not histogram:
            histogram = [[json_format_time(t0), 0]]

        return [{
            "data": histogram,
            "color": "rgb(0, 128, 0)",
        }]
Exemplo n.º 2
0
    def save(self, commit=False):
        def grab(s):
            return self.cleaned_data[s]

        game = Game.nearest_game()
        player = Player.user_to_player(self.user, game)

        self.thread = Thread(
            game=game,
            team=grab('team'),
            title=grab('title'),
            slug=slugify(grab('title')),
        )

        self.thread.save()

        post = Post(
            author=player,
            thread=self.thread,
            body=grab('post_body'),
            created=settings.NOW(),
        )

        if commit:
            post.save()

        return self.thread
Exemplo n.º 3
0
def spitList(request, clan):
    if request.user.is_staff:
        clan = clan.replace("_", " ")
        context = {'clan': clan, 'players':Player.objects.all().filter(game=Game.nearest_game(), clan=clan)}
    else:
        context = {'clan': 'No Permission', 'players':[]}
    return render(request, 'main/spitList.html', context)
Exemplo n.º 4
0
 def get_queryset(self, *args, **kwargs):
     return (Meal.objects.filter(
         eater__game=Game.nearest_game()).select_related(
             'eater__user__first_name',
             'eater__user__last_name',
             'eaten__user__first_name',
             'eaten__user__last_name',
         ).order_by('time'))
Exemplo n.º 5
0
    def game(self):
        if self._game:
            return self._game
        try:
            self._game = Game.nearest_game()
        except Game.DoesNotExist:
            raise PermissionDenied("You need to create a game!")

        return self._game
Exemplo n.º 6
0
def spitList(request, clan):
    if request.user.is_staff:
        clan = clan.replace("_", " ")
        context = {
            'clan':
            clan,
            'players':
            Player.objects.all().filter(game=Game.nearest_game(), clan=clan)
        }
    else:
        context = {'clan': 'No Permission', 'players': []}
    return render(request, 'main/spitList.html', context)
Exemplo n.º 7
0
    def get_context_data(self, **kwargs):
        context = super(PlayerListView, self).get_context_data(**kwargs)
        context['game_season'] = Game.nearest_game().season()

        context['schools'] = School.objects.all().annotate(
            num_players=Count('player_set')
        ).order_by('-num_players')

        context['years'] = map(str, sorted(set([p.grad_year for p in Player.current_players()])))
        context['school'] = self.kwargs.get('school', '')
        context['gradyear'] = self.kwargs.get('gradyear', '')

        return context
Exemplo n.º 8
0
    def get_context_data(self, **kwargs):
        context = super(PlayerListView, self).get_context_data(**kwargs)
        context['game_season'] = Game.nearest_game().season()

        context['schools'] = School.objects.all().annotate(
            num_players=Count('player_set')).order_by('-num_players')

        context['years'] = map(
            str, sorted(set([p.grad_year for p in Player.current_players()])))
        context['school'] = self.kwargs.get('school', '')
        context['gradyear'] = self.kwargs.get('gradyear', '')

        return context
Exemplo n.º 9
0
    def raw_serialization(self, context):
        game = Game.nearest_game()

        t0, tf = time_endpoints(game)

        players = Player.current_players().all()
        meals = Meal.objects.select_related('eaten').all()
        eaten_zombies = set([m.eaten for m in meals])
        ozs = [p for p in players if p.team == 'Z' and p not in eaten_zombies]

        num_zombies = len(ozs)
        num_humans = len(players) - num_zombies

        human_tally = []
        zombie_tally = []

        meals_vs_hours = meals_per_hour(game, self.get_queryset())
        for hour in xrange(len(meals_vs_hours)):
            t = t0 + timedelta(hours=hour)

            # Stop the graph at the current time
            if t > settings.NOW():
                break

            meal_count = meals_vs_hours[hour]

            num_humans -= meal_count
            num_zombies += meal_count

            human_tally.append([json_format_time(t), num_humans])
            zombie_tally.append([json_format_time(t), num_zombies])

        if not human_tally:
            human_tally = [[json_format_time(t0), num_humans]]

        if not zombie_tally:
            zombie_tally = [[json_format_time(t0), num_zombies]]

        return [
            {
                'label': 'humans',
                'data': human_tally,
                'color': 'rgb(128, 0, 0)'
            },
            {
                'label': 'zombies',
                'data': zombie_tally,
                'color': 'rgb(0, 128, 0)'
            },
        ]
Exemplo n.º 10
0
    def raw_serialization(self, context):
        game = Game.nearest_game()
        t0, tf = time_endpoints(game)

        meals_vs_hours = meals_per_hour(Game.nearest_game(), self.get_queryset())

        histogram = []
        for hour in xrange(len(meals_vs_hours)):
            t = t0 + timedelta(hours=hour)

            # Stop at the current time
            if t > settings.NOW():
                break

            histogram.append([json_format_time(t), meals_vs_hours[hour]])

        # Pre-game case
        if not histogram:
            histogram = [[json_format_time(t0), 0]]

        return [{
            "data": histogram,
            "color": "rgb(0, 128, 0)",
        }]
Exemplo n.º 11
0
def inject_outbreak_percentage(request):
    try:
        newest_game = Game.nearest_game()
    except Game.DoesNotExist:
        # Just return an arbitrary sane value
        return {'outbreak_percent': 96}

    players = Player.objects.filter(game=newest_game)
    humans = players.filter(team='H')

    nPlayers = players.count()

    if nPlayers > 0:
        percent = humans.count() * 100. / nPlayers
    else:
        percent = 100

    return {'outbreak_percent': min(96, percent)}
Exemplo n.º 12
0
    def raw_serialization(self, context):
        game = Game.nearest_game()

        t0, tf = time_endpoints(game)

        players = Player.current_players().all()
        meals = Meal.objects.select_related('eaten').all()
        eaten_zombies = set([m.eaten for m in meals])
        ozs = [p for p in players if p.team == 'Z' and p not in eaten_zombies]

        num_zombies = len(ozs)
        num_humans = len(players) - num_zombies

        human_tally = []
        zombie_tally = []

        meals_vs_hours = meals_per_hour(game, self.get_queryset())
        for hour in xrange(len(meals_vs_hours)):
            t = t0 + timedelta(hours=hour)

            # Stop the graph at the current time
            if t > settings.NOW():
                break

            meal_count = meals_vs_hours[hour]

            num_humans -= meal_count
            num_zombies += meal_count

            human_tally.append([json_format_time(t), num_humans])
            zombie_tally.append([json_format_time(t), num_zombies])

        if not human_tally:
            human_tally = [[json_format_time(t0), num_humans]]

        if not zombie_tally:
            zombie_tally = [[json_format_time(t0), num_zombies]]

        return [
            {'label': 'humans', 'data': human_tally, 'color': 'rgb(128, 0, 0)'},
            {'label': 'zombies', 'data': zombie_tally, 'color': 'rgb(0, 128, 0)'},
        ]
Exemplo n.º 13
0
    def raw_serialization(self, context):
        self.players = Player.current_players().filter(team='Z').select_related('user')
        self.names = {p: p.user.get_full_name() for p in self.players}
        self.meals = (Meal.objects.filter(eater__game=Game.nearest_game())
                      .select_related('eater', 'eaten'))

        self.possible_ozs = set(self.players)
        self.children = defaultdict(list)
        for m in self.meals:
            if m.eaten not in self.players:
                continue
            self.children[m.eater].append(m.eaten)
            self.possible_ozs.remove(m.eaten)

        ozs = [p for p in self.players if p in self.possible_ozs]

        return {
            "name": "Subject Zero",
            "children": map(self.traverse, ozs),
        }
Exemplo n.º 14
0
    def raw_serialization(self, context):
        self.players = Player.current_players().filter(
            team='Z').select_related('user')
        self.names = {p: p.user.get_full_name() for p in self.players}
        self.meals = (Meal.objects.filter(
            eater__game=Game.nearest_game()).select_related('eater', 'eaten'))

        self.possible_ozs = set(self.players)
        self.children = defaultdict(list)
        for m in self.meals:
            if m.eaten not in self.players:
                continue
            self.children[m.eater].append(m.eaten)
            self.possible_ozs.remove(m.eaten)

        ozs = [p for p in self.players if p in self.possible_ozs]

        return {
            "name": "Subject Zero",
            "children": map(self.traverse, ozs),
        }
Exemplo n.º 15
0
 def get_queryset(self):
     return Meal.objects.filter(eater__game=Game.nearest_game(),
                                time__isnull=False)
Exemplo n.º 16
0
 def _bounded_grad_year(grad_year):
     return abs(Game.nearest_game().start_date.year - grad_year) < 5
Exemplo n.º 17
0
 def get_queryset(self):
     game = Game.nearest_game()
     return Player.objects.filter(game=game)
Exemplo n.º 18
0
 def get_queryset(self):
     game = Game.nearest_game()
     return Player.objects.filter(game=game)
Exemplo n.º 19
0
 def get_queryset(self):
     game = Game.nearest_game()
     team = self.player.team
     return Plot.get_visible(game, team).select_related('mission')
Exemplo n.º 20
0
 def _bounded_grad_year(grad_year):
     return abs(Game.nearest_game().start_date.year - grad_year) < 5
Exemplo n.º 21
0
 def get_queryset(self, *args, **kwargs):
     return Meal.objects.filter(eater__game=Game.nearest_game()).select_related(
                    'eater__user__first_name', 'eater__user__last_name',
                    'eaten__user__first_name', 'eaten__user__last_name').order_by('time')
Exemplo n.º 22
0
 def get_queryset(self):
     return Meal.objects.filter(eater__game=Game.nearest_game(), time__isnull=False)
Exemplo n.º 23
0
 def get_queryset(self):
     return Player.objects.all().filter(game=Game.nearest_game())
Exemplo n.º 24
0
 def get_queryset(self):
     game = Game.nearest_game()
     return Player.objects.filter(game=game).select_related("user").annotate(meal_count=Count("meal_set"))