Skip to content

Commit

Permalink
updated hunt2.html and major profiling improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dlareau committed Jan 4, 2016
1 parent f361edf commit 2a6156b
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 77 deletions.
22 changes: 22 additions & 0 deletions huntserver/migrations/0033_auto_20160104_1317.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('huntserver', '0032_auto_20151221_1242'),
]

operations = [
migrations.AlterUniqueTogether(
name='solve',
unique_together=set([('puzzle', 'team')]),
),
migrations.AlterUniqueTogether(
name='unlock',
unique_together=set([('puzzle', 'team')]),
),
]
9 changes: 9 additions & 0 deletions huntserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,21 @@ class Solve(models.Model):
puzzle = models.ForeignKey(Puzzle)
team = models.ForeignKey(Team)
submission = models.ForeignKey(Submission, blank=True)

class Meta:
unique_together = ('puzzle', 'team',)

def __unicode__(self):
return self.team.team_name + " => " + self.puzzle.puzzle_name

class Unlock(models.Model):
puzzle = models.ForeignKey(Puzzle)
team = models.ForeignKey(Team)
time = models.DateTimeField()

class Meta:
unique_together = ('puzzle', 'team',)

def __unicode__(self):
return self.team.team_name + ": " + self.puzzle.puzzle_name

Expand Down
123 changes: 58 additions & 65 deletions huntserver/templates/hunt2.html
Original file line number Diff line number Diff line change
@@ -1,73 +1,66 @@
{% extends "base.html" %}
{% block title %}Puzzles!{% endblock title %}

{% block includes %}
<link rel="stylesheet" type="text/css" media='screen and (max-width: 1200px)' href="/protected/huntserver/low-width.css">
<style>
body {
padding-bottom: 0px;
}
</style>
{% endblock %}

{% block content %}
<div id='container'>
<div id='content-left'>
<h1 class="title">Unlocked Puzzles</h1>
<a href='/objects/' >
<p style="margin-top: -10px;"> Click here for unlocked objects </p>
</a>
<div id="puzzles">
<table>
<thead>
<tr>
<th style='width: 80px;'>Solved?</th>
<th style='width: 100px;'>Answer</th>
<th style='width: 320px;'>Puzzle Name/Link</th>
</tr>
</thead>
<tbody>
{% for puzzle in puzzles %}
<tr id='puzzle{{ puzzle.puzzle_number }}' class='puzzle'>
<td>
{% if puzzle in team.solved.all %}
<img src="{{ STATIC_URL }}huntserver/checkmark.png" alt="Solved"></img>
{% else %}
<img src="{{ STATIC_URL }}huntserver/red_x.png" alt="Solved"></img>
{% endif %}
</td>
<td>
{% if puzzle in team.solved.all %}
{{ puzzle.answer|upper }}
{% endif %}
</td>
<td>
<a href='/puzzle/{{ puzzle.puzzle_id }}/' >
<p class="puzzle-name">P{{puzzle.puzzle_number}} - {{ puzzle.puzzle_name }}</p>
</a>
</td>
</div>
{% endfor %}
</tbody>
</table>
<div class="container">
<div class="row">
<div class="content col-md-6">
<h1 class="title">Unlocked Puzzles</h1>
<a href='/objects/' >
<p style="margin-top: -5px;"> Click here for unlocked objects </p>
</a>
<div id="puzzles">
<table>
<thead>
<tr>
<th style='width: 80px;'>Solved?</th>
<th style='width: 100px;'>Answer</th>
<th style='width: 320px;'>Puzzle Name/Link</th>
</tr>
</thead>
<tbody>
{% for puzzle in puzzles %}
<tr id='puzzle{{ puzzle.puzzle_number }}' class='puzzle'>
<td>
{% if puzzle in solved %}
<img src="{{ STATIC_URL }}huntserver/checkmark.png" alt="Solved"></img>
{% else %}
<img src="{{ STATIC_URL }}huntserver/red_x.png" alt="Solved"></img>
{% endif %}
</td>
<td>
{% if puzzle in solved %}
{{ puzzle.answer|upper }}
{% endif %}
</td>
<td>
<a href='/puzzle/{{ puzzle.puzzle_id }}/' >
<p class="puzzle-name">P{{puzzle.puzzle_number}} - {{ puzzle.puzzle_name }}</p>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<p>For assistance, email <a href="mailto:dlareau@cmu.edu">dlareau@cmu.edu</a> or try our new <a href="/chat/"> Chat Feature</a>.</p>
</div>
<p>For assistance, email <a href="mailto:dlareau@cmu.edu">dlareau@cmu.edu</a> or try our new <a href="/chat/"> Chat Feature</a>.</p>
</div>
<div id='content-right'>
<div id='plot'>
{% if puzzles|length > 12 %}
Some helpful maps:
{% else %}
A helpful map:
{% endif %}
<img src="{{ STATIC_URL }}huntserver/plot1.png" alt="plot1.png" width="450px"></img>
{% if puzzles|length > 12 %}
<br>
<br>
This will help your journey to the second castle:
<img src="{{ STATIC_URL }}huntserver/plot2.png" alt="plot1.png" width="450px"></img>
{% endif %}
<div class="content col-md-5">
<div id='plot'>
{% if puzzles|length > 12 %}
Some helpful maps:
{% else %}
A helpful map:
{% endif %}
<img src="{{ STATIC_URL }}huntserver/plot1.png" alt="plot1.png" width="450px"></img>
{% if puzzles|length > 12 %}
<br>
<br>
This will help your journey to the second castle:
<img src="{{ STATIC_URL }}huntserver/plot2.png" alt="plot1.png" width="450px"></img>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock content %}
2 changes: 1 addition & 1 deletion huntserver/templates/progress.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h1>Puzzle Progress</h1>
<td id='p{{ cell.1 }}t{{ row.team.pk }}' class='available' data-date={{ cell.2 |date:"U"}}></td>
{% else %}
<td id='p{{ cell.1 }}t{{ row.team.pk }}' class='solved' >
{{ cell.0.submission.submission_time|time:"h:i a" }}
{{ cell.0|time:"h:i a" }}
</td>
{% endif %}
{% endfor %}
Expand Down
25 changes: 16 additions & 9 deletions huntserver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def hunt(request, hunt_num):

puzzles = sorted(puzzle_list, key=lambda p: p.puzzle_number)

context = {'puzzles': puzzles, 'team': team}
context = {'puzzles': puzzles, 'team': team, 'solved': team.solved.all()}

# Each hunt should have a main template named hunt#.html (ex: hunt3.html)
return render(request, 'hunt' + str(hunt_num) + '.html', context)
Expand Down Expand Up @@ -213,7 +213,7 @@ def queue(request):

else:
hunt = Hunt.objects.get(hunt_number=settings.CURRENT_HUNT_NUM)
submissions = Submission.objects.filter(puzzle__hunt=hunt).order_by('pk')
submissions = Submission.objects.filter(puzzle__hunt=hunt).select_related('team', 'puzzle').order_by('pk')
form = SubmissionForm()
context = {'form': form, 'submission_list': submissions}
return render(request, 'queue.html', context)
Expand Down Expand Up @@ -242,17 +242,24 @@ def progress(request):
# The structure is messy, it was built part by part as features were added
sol_array = []
for team in teams:
# These are defined to reduce DB queries
solved = team.solved.all()
unlocked = team.unlocked.all()
solves = team.solve_set.select_related('submission')
unlocks = team.unlock_set.all()

# Basic team information for row headers
# The last element ('cells') is an array of the row's data
sol_array.append({'team':team, 'num':len(team.solved.all()), 'cells':[]})
sol_array.append({'team':team, 'num':len(solved), 'cells':[]})
# What goes in each cell (item in "cells") is based on puzzle status
for puzzle in puzzles:
# Solved => solve object and puzzle id
if(puzzle in team.solved.all()):
sol_array[-1]['cells'].append([team.solve_set.filter(puzzle=puzzle)[0], puzzle.puzzle_id])
if(puzzle in solved):
sol_array[-1]['cells'].append([solves.get(puzzle=puzzle).submission.submission_time,
puzzle.puzzle_id])
# Unlocked => Identify as unlocked, puzzle id, and unlock time
elif(puzzle in team.unlocked.all()):
unlock_time = team.unlock_set.filter(puzzle=puzzle)[0].time
elif(puzzle in unlocked):
unlock_time = unlocks.get(puzzle=puzzle).time
sol_array[-1]['cells'].append(["unlocked", puzzle.puzzle_id, unlock_time])
# Locked => Identify as locked and puzzle id
else:
Expand All @@ -271,7 +278,7 @@ def charts(request):
for puzzle in puzzles:
puzzle_info_dicts.append({
"name": puzzle.puzzle_name,
"locked": curr_hunt.team_set.count()-puzzle.unlocked_for.count(),
"locked": curr_hunt.team_set.count()-puzzle.unlocked_for.filter(unlock__puzzle__hunt=curr_hunt).count(),
"unlocked": puzzle.unlocked_for.count() - puzzle.solved_for.count(),
"solved": puzzle.solved_for.count()
})
Expand Down Expand Up @@ -356,4 +363,4 @@ def emails(request):
emails = []
for person in people:
emails.append(person.email)
return HttpResponse(", ".join(emails))
return HttpResponse(", ".join(emails))
5 changes: 3 additions & 2 deletions puzzlehunt_server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from secret_settings import *

""" PLEASE UPDATE BEFORE STARTING HUNT DEVELOPMENT """
CURRENT_HUNT_NUM = 1
CURRENT_HUNT_NUM = 2

""" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! """

Expand Down Expand Up @@ -46,6 +46,7 @@
'django.contrib.staticfiles',
'huntserver',
'ws4redis',
'debug_toolbar',
)

MIDDLEWARE_CLASSES = (
Expand Down Expand Up @@ -125,4 +126,4 @@
MEDIA_ROOT = os.path.join(BASE_DIR, "media/")
MEDIA_URL = '/media/'

PROTECTED_URL = '/protected/'
PROTECTED_URL = '/protected/'

0 comments on commit 2a6156b

Please sign in to comment.