Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Create your models here.
- #Course taken by the student
- class Course(models.Model):
- name = models.CharField(unique="True", max_length=255)
- code = models.CharField(max_length=256)
- professor = models.ForeignKey('Professor',blank=True)
- def __unicode__(self):
- return u'%d %s %s %s' % (self.id, self.name, self.code, self.professor)
- #Professor teaches a list of classes, has details
- class Professor(models.Model):
- surname = models.CharField(max_length=256)
- firstname = models.CharField(max_length=256)
- othernames = models.CharField(max_length=256,blank=True)
- #course = models.ForeignKey('Course', to_field="name", blank=True)
- #course = models.ManyToManyField('Course', blank=True)
- def __unicode__(self):
- return u'%s %s %s' % (self.surname, self.firstname, self.othernames)
- #The StudentsGroup class has an ID and the name of the student group,
- # as well as the number of students (size of group).
- #It also contains a list of classes that the group attends.
- class StudentsGroup(models.Model):
- name = models.CharField(max_length=256)
- number_of_students = models.IntegerField()
- classes = models.ManyToManyField('Course')
- #course_class = models.ForeignKey('CourseClass', related_name='student_groups')
- def __unicode__(self):
- return u'%s %d %s' % (self.name, self.number_of_students, self.classes)
- class Classroom(models.Model):
- name = models.CharField(max_length=256)
- number_of_seats = models.IntegerField()
- def __unicode__(self):
- return u'%s %s' % (self.name, self.number_of_seats)
- #CourseClass holds a reference to the course to which the class belongs,
- # a reference to the professor who teaches,
- # and a list of student groups that attend the class.
- # It also stores how many seats (sum of student groups' sizes)
- # are needed in the classroom,
- # and the duration of the class (in hours).
- class CourseClass(models.Model):
- course = models.OneToOneField('Course')
- #professor = models.OneToOneField('Professor')
- duration = models.IntegerField()
- number_of_student_group_students = models.IntegerField(verbose_name="Number of students")
- list_of_student_groups = models.ManyToManyField('StudentsGroup')
- def __unicode__(self):
- return u'%s %s %s %s' % (self.course, self.duration, self.number_of_student_group_students, self.list_of_student_groups)
- from django.shortcuts import render
- # Create your views here.
- from django.shortcuts import get_object_or_404, render_to_response, HttpResponseRedirect
- from django.http import HttpResponse
- from django.contrib import admin
- from TimeTable.models import *
- from TimeTable.forms import *
- from django.contrib.auth.models import User
- from django.core.urlresolvers import reverse, reverse_lazy
- from django.template import RequestContext
- from django.template.defaultfilters import slugify
- from django.core.mail import EmailMessage
- from django.core import serializers
- from django.views.generic import TemplateView, ListView
- from django.views.generic.edit import CreateView, UpdateView, DeleteView
- import random
- # Create your views here.
- def index(request):
- return render_to_response ('index.html', {})
- class ProfessorList(ListView):
- model = Professor
- class ProfessorCreate(CreateView):
- model = Professor
- #fields = ['course','duration','number_of_student_group_students']
- success_url = reverse_lazy('list_professor')
- class ProfessorUpdate(UpdateView):
- model = Professor
- success_url = reverse_lazy('list_professor')
- class ProfessorDelete(DeleteView):
- model = Professor
- success_url = reverse_lazy('list_professor')
- class StudentsGroupList(ListView):
- model = StudentsGroup
- class StudentsGroupCreate(CreateView):
- model = StudentsGroup
- #fields = ['course','duration','number_of_student_group_students']
- success_url = reverse_lazy('list_students_group')
- class StudentsGroupUpdate(UpdateView):
- model = StudentsGroup
- success_url = reverse_lazy('list_students_group')
- class StudentsGroupDelete(DeleteView):
- model = StudentsGroup
- success_url = reverse_lazy('list_students_group')
- class ClassroomList(ListView):
- model = Classroom
- class ClassroomCreate(CreateView):
- model = Classroom
- #fields = ['course','duration','number_of_student_group_students']
- success_url = reverse_lazy('list_classroom')
- class ClassroomUpdate(UpdateView):
- model = Classroom
- success_url = reverse_lazy('list_classroom')
- class ClassroomDelete(DeleteView):
- model = Classroom
- success_url = reverse_lazy('list_classroom')
- class CourseList(ListView):
- model = Course
- class CourseCreate(CreateView):
- model = Course
- #fields = ['course','duration','number_of_student_group_students']
- success_url = reverse_lazy('list_course')
- class CourseUpdate(UpdateView):
- model = Course
- success_url = reverse_lazy('list_course')
- class CourseDelete(DeleteView):
- model = Course
- success_url = reverse_lazy('list_course')
- class CourseClassList(ListView):
- model = CourseClass
- class CourseClassCreate(CreateView):
- model = CourseClass
- #fields = ['course','duration','number_of_student_group_students']
- success_url = reverse_lazy('list_course_class')
- class CourseClassUpdate(UpdateView):
- model = CourseClass
- success_url = reverse_lazy('list_course_class')
- class CourseClassDelete(DeleteView):
- model = CourseClass
- success_url = reverse_lazy('list_course_class')
- #Genetic mutation starts here, speed limit as per your processor, keep left unless overcompiling
- #Create a memeber of the population
- number_of_rooms = Classroom.objects.count()
- #Number of slots is number of hours multiply by number of days by number of rooms
- slots = 12*5*number_of_rooms
- classes = Classroom.objects.all()
- def individual(slots, first_position_in_slot, fitness, criteria, number_of_crossover_points,
- crossover_probability,mutation_probability):
- return [CourseClass.id(fitness=0, criteria=False, number_of_crossover_points=0, crossover_probability=0, mutation_probability=0 )
- for classes in xrange(slots)]
Add Comment
Please, Sign In to add comment