Skip to content

Commit

Permalink
Refactoring everything for Django 1.6
Browse files Browse the repository at this point in the history
This is quite the commit, but it basically just moves everything around
and makes it compatible with Django 1.6
  • Loading branch information
jolynch committed Jan 29, 2014
1 parent 75adbb2 commit 601dab6
Show file tree
Hide file tree
Showing 69 changed files with 184 additions and 473 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) 2011 by Julia Boortz and Joseph Lynch
Copyright (C) 2011-2014 by Joseph Lynch and Julia Boortz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.PHONY: all production web cmd test tests clean

export DJANGO_SETTINGS_MODULE := mittab.settings

all: production

production:
Expand Down
10 changes: 10 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mittab.settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion mittab/tab/admin.py → mittab/apps/tab/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin
from django import forms
from tab.models import *
from mittab.apps.tab.models import *

class RoundAdminForm(forms.ModelForm):
chair = forms.ModelChoiceField(queryset=Judge.objects.order_by('name'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from forms import DebaterForm
from errors import *
from models import *
import tab_logic
import mittab.lib.tab_logic

def view_debaters(request):
#Get a list of (id,debater_name) tuples
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from models import *
from django.db import models
from errors import *
from tab_logic import TabFlags
from mittab.libs.tab_logic import TabFlags


def view_judges(request):
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions mittab/tab/models.py → mittab/apps/tab/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#THE SOFTWARE.

from django.db import models
from django.contrib.localflavor.us.models import PhoneNumberField
from localflavor.us.models import PhoneNumberField
from django.core.exceptions import ValidationError

###NOTE All fields automatically have a id key created that act as primary keys
Expand All @@ -34,15 +34,15 @@ class School(models.Model):
name = models.CharField(max_length=50, unique = True)
def __unicode__(self):
return self.name

def delete(self):
team_check = Team.objects.filter(school=self)
judge_check = Judge.objects.filter(schools=self)
if len(team_check) == 0 and len(judge_check) == 0:
super(School, self).delete()
else:
raise Exception("School in use: [teams => %s,judges => %s]" % ([t.name for t in team_check], [j.name for j in judge_check]))

class Debater(models.Model):
name = models.CharField(max_length=30, unique = True)
#team_set is created by Team in the ManyToMany
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion mittab/tab/team_views.py → mittab/apps/tab/team_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from errors import *
from models import *
import tab_logic
from tab_logic import TabFlags, tot_speaks_deb, tot_ranks_deb, tot_speaks, tot_ranks
from mittab.apps.tab.tab_logic import TabFlags, tot_speaks_deb, tot_ranks_deb, tot_speaks, tot_ranks
from datetime import datetime

def view_teams(request):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion mittab/tab/views.py → mittab/apps/tab/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from forms import SchoolForm, RoomForm
from django.db import models
from models import *
from tab_logic import TabFlags
from mittab.libs.tab_logic import TabFlags

def index(request):
number_teams = Team.objects.count()
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion mittab/assign_judges.py → mittab/libs/assign_judges.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#THE SOFTWARE.

import tab_logic
from tab.models import *
from mittab.apps.tab.models import *
import mwmatching
import random
import errors
Expand Down
2 changes: 1 addition & 1 deletion mittab/backup.py → mittab/libs/backup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from tab.models import *
from mittab.apps.tab.models import *
from django.conf import settings
from django.core.servers.basehttp import FileWrapper

Expand Down
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 0 additions & 21 deletions mittab/errors.py → mittab/libs/errors.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
#Copyright (C) 2011 by Julia Boortz and Joseph Lynch

#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:

#The above copyright notice and this permission notice shall be included in
#all copies or substantial portions of the Software.

#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.


class Error(Exception):
pass

Expand Down
File renamed without changes.
97 changes: 1 addition & 96 deletions mittab/pairing_alg.py → mittab/libs/pairing_alg.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,97 +19,9 @@
#THE SOFTWARE.

import tab_logic
from tab.models import *
from mittab.apps.tab.models import *
import mwmatching
import random

#take in list of teams
#return pairing as list of [gov_team, opp_team]


#DOES NOT WORK
def approx_pairing(list_of_teams):

#print list_of_teams[bracket]
team_ideal = []
for i in range(len(list_of_teams[bracket])/2):
#print "i = " + str(i)
#print list_of_teams[bracket][len(list_of_teams[bracket])-1-i].seed
#print list_of_teams[bracket][i].seed

#teamIdeal is (rank, team, speak/seed of ideal team to hit)

team_ideal +=[(i, list_of_teams[bracket][i], tot_speaks(list_of_teams[bracket][len(list_of_teams[bracket])-1-i]))]
team_ideal +=[(len(list_of_teams[bracket])-1-i, list_of_teams[bracket][len(list_of_teams[bracket])-1-i], tot_speaks(list_of_teams[bracket][i]))]
#now_rounds[bracket] = list_of_teams[bracket]
now_rounds[bracket] = team_ideal

#Works for up to about ten teams
def exhaustive_pairing(list_of_teams):
#list of all possible pairings
all_pairs = pair_exhaustively(list_of_teams, [], [])
#print all_pairs
#now check weight and choose best
min_weight = None
opt_pairing = None
for pairing in all_pairs:
#print pairing
if len(pairing) == 2:
weight = 0
for pair in pairing:
indexA = list_of_teams.index(pair[0])
indexB = list_of_teams.index(pair[1])
pairA_opt = list_of_teams[len(list_of_teams)-indexA-1]
pairB_opt = list_of_teams[len(list_of_teams)-indexB-1]
weight += calc_weight(pair[0],pair[1],pairA_opt, pairB_opt)
if min_weight == None:
min_weight = weight
opt_pairing = pairing
else:
if weight < min_weight:
min_weight = weight
opt_pairing = pairing
else:
weight=0 #right now, don't calculate by in weight. Should change)
#print opt_pairing
return opt_pairing





#will return all possible pairings
def pair_exhaustively(list_of_teams, cur_pairing, all_pairs):
#print
#print "list_of_teams" + str(list_of_teams)
#print "cur_pairing" + str(cur_pairing)
if len(list_of_teams) == 0: #no more teams left to pair
all_pairs +=[cur_pairing]
cur_pairing = []
# print "all_pairs" + str(all_pairs)
else:
if len(list_of_teams)/2 != len(list_of_teams)/2.0 and cur_pairing == []:
for t in list_of_teams:
bye = t
temp_teams = []
for tmp in list_of_teams:
if tmp != bye:
temp_teams+=[tmp]
pair_exhaustively(temp_teams,cur_pairing+[[bye]],all_pairs)
for i in range(len(list_of_teams)):
# print i
if i!=0:
# print "cur_pairing" + str(cur_pairing)
teams = []
for t in list_of_teams:
teams +=[t]
teams.remove(list_of_teams[i])
teams.remove(list_of_teams[0])
# print "teams" + str(teams)
# print "cur_pair" + str(cur_pairing)
# print "all_pairs" + str(all_pairs)
pair_exhaustively(teams, cur_pairing+[[list_of_teams[0],list_of_teams[i]]], all_pairs)
return determine_gov_opp(all_pairs)

def perfect_pairing(list_of_teams):
#assign weights to edges:
Expand All @@ -123,9 +35,6 @@ def perfect_pairing(list_of_teams):
wt = calc_weight(list_of_teams[i], list_of_teams[j],i, j, list_of_teams[len(list_of_teams)-i-1], list_of_teams[len(list_of_teams)-j-1], len(list_of_teams)-i-1, len(list_of_teams)-j-1)
#now add edge to graph
graph_edges +=[(i,j,wt)]
#print "graph_edges"
#print graph_edges

pairings_num = mwmatching.maxWeightMatching(graph_edges, maxcardinality=True)
#print "Pairing numbers"
#print pairings_num
Expand All @@ -139,13 +48,9 @@ def perfect_pairing(list_of_teams):
#print all_pairs
return determine_gov_opp(all_pairs)




#Determine the weight of the pairing between teamA and teamB, i.e. how bad it is
#teamA_opt is the optimal team for teamA to be paired with
#teamB_opt is the optimal team for teamB to be paired with

def calc_weight(team_a,
team_b,
team_a_ind,
Expand Down
3 changes: 1 addition & 2 deletions mittab/tab_logic.py → mittab/libs/tab_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@

#Always sort so that top team is at the beginning of the list - use reverse!

from tab.models import *
from mittab.apps.tab.models import *
from django.db.models import *

import random
import pairing_alg
import assign_judges
import errors
from decimal import *
import send_texts
from datetime import datetime
import pprint
import itertools
Expand Down
11 changes: 0 additions & 11 deletions mittab/manage.py

This file was deleted.

5 changes: 0 additions & 5 deletions mittab/passwords

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 0 additions & 9 deletions mittab/runserver.sh

This file was deleted.

Loading

0 comments on commit 601dab6

Please sign in to comment.