Guest User

Untitled

a guest
Oct 21st, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1. # Create your models here.
  2. #Course taken by the student
  3. class Course(models.Model):
  4. name = models.CharField(unique="True", max_length=255)
  5. code = models.CharField(max_length=256)
  6. professor = models.ForeignKey('Professor',blank=True)
  7.  
  8. def __unicode__(self):
  9. return u'%d %s %s %s' % (self.id, self.name, self.code, self.professor)
  10.  
  11. #Professor teaches a list of classes, has details
  12. class Professor(models.Model):
  13. surname = models.CharField(max_length=256)
  14. firstname = models.CharField(max_length=256)
  15. othernames = models.CharField(max_length=256,blank=True)
  16. #course = models.ForeignKey('Course', to_field="name", blank=True)
  17. #course = models.ManyToManyField('Course', blank=True)
  18.  
  19. def __unicode__(self):
  20. return u'%s %s %s' % (self.surname, self.firstname, self.othernames)
  21.  
  22. #The StudentsGroup class has an ID and the name of the student group,
  23. # as well as the number of students (size of group).
  24. #It also contains a list of classes that the group attends.
  25. class StudentsGroup(models.Model):
  26. name = models.CharField(max_length=256)
  27. number_of_students = models.IntegerField()
  28. classes = models.ManyToManyField('Course')
  29. #course_class = models.ForeignKey('CourseClass', related_name='student_groups')
  30.  
  31. def __unicode__(self):
  32. return u'%s %d %s' % (self.name, self.number_of_students, self.classes)
  33.  
  34. class Classroom(models.Model):
  35. name = models.CharField(max_length=256)
  36. number_of_seats = models.IntegerField()
  37.  
  38. def __unicode__(self):
  39. return u'%s %s' % (self.name, self.number_of_seats)
  40.  
  41. #CourseClass holds a reference to the course to which the class belongs,
  42. # a reference to the professor who teaches,
  43. # and a list of student groups that attend the class.
  44. # It also stores how many seats (sum of student groups' sizes)
  45. # are needed in the classroom,
  46. # and the duration of the class (in hours).
  47. class CourseClass(models.Model):
  48. course = models.OneToOneField('Course')
  49. #professor = models.OneToOneField('Professor')
  50. duration = models.IntegerField()
  51. number_of_student_group_students = models.IntegerField(verbose_name="Number of students")
  52. list_of_student_groups = models.ManyToManyField('StudentsGroup')
  53.  
  54. def __unicode__(self):
  55. return u'%s %s %s %s' % (self.course, self.duration, self.number_of_student_group_students, self.list_of_student_groups)
  56.  
  57. from django.shortcuts import render
  58. # Create your views here.
  59. from django.shortcuts import get_object_or_404, render_to_response, HttpResponseRedirect
  60. from django.http import HttpResponse
  61. from django.contrib import admin
  62. from TimeTable.models import *
  63. from TimeTable.forms import *
  64. from django.contrib.auth.models import User
  65. from django.core.urlresolvers import reverse, reverse_lazy
  66. from django.template import RequestContext
  67. from django.template.defaultfilters import slugify
  68. from django.core.mail import EmailMessage
  69. from django.core import serializers
  70. from django.views.generic import TemplateView, ListView
  71. from django.views.generic.edit import CreateView, UpdateView, DeleteView
  72. import random
  73.  
  74. # Create your views here.
  75.  
  76. def index(request):
  77.  
  78. return render_to_response ('index.html', {})
  79.  
  80.  
  81. class ProfessorList(ListView):
  82. model = Professor
  83.  
  84.  
  85. class ProfessorCreate(CreateView):
  86. model = Professor
  87. #fields = ['course','duration','number_of_student_group_students']
  88. success_url = reverse_lazy('list_professor')
  89.  
  90.  
  91. class ProfessorUpdate(UpdateView):
  92. model = Professor
  93. success_url = reverse_lazy('list_professor')
  94.  
  95.  
  96. class ProfessorDelete(DeleteView):
  97. model = Professor
  98. success_url = reverse_lazy('list_professor')
  99.  
  100.  
  101. class StudentsGroupList(ListView):
  102. model = StudentsGroup
  103.  
  104.  
  105. class StudentsGroupCreate(CreateView):
  106. model = StudentsGroup
  107. #fields = ['course','duration','number_of_student_group_students']
  108. success_url = reverse_lazy('list_students_group')
  109.  
  110.  
  111. class StudentsGroupUpdate(UpdateView):
  112. model = StudentsGroup
  113. success_url = reverse_lazy('list_students_group')
  114.  
  115.  
  116. class StudentsGroupDelete(DeleteView):
  117. model = StudentsGroup
  118. success_url = reverse_lazy('list_students_group')
  119.  
  120.  
  121. class ClassroomList(ListView):
  122. model = Classroom
  123.  
  124.  
  125. class ClassroomCreate(CreateView):
  126. model = Classroom
  127. #fields = ['course','duration','number_of_student_group_students']
  128. success_url = reverse_lazy('list_classroom')
  129.  
  130.  
  131. class ClassroomUpdate(UpdateView):
  132. model = Classroom
  133. success_url = reverse_lazy('list_classroom')
  134.  
  135.  
  136. class ClassroomDelete(DeleteView):
  137. model = Classroom
  138. success_url = reverse_lazy('list_classroom')
  139.  
  140.  
  141. class CourseList(ListView):
  142. model = Course
  143.  
  144.  
  145. class CourseCreate(CreateView):
  146. model = Course
  147. #fields = ['course','duration','number_of_student_group_students']
  148. success_url = reverse_lazy('list_course')
  149.  
  150.  
  151. class CourseUpdate(UpdateView):
  152. model = Course
  153. success_url = reverse_lazy('list_course')
  154.  
  155.  
  156. class CourseDelete(DeleteView):
  157. model = Course
  158. success_url = reverse_lazy('list_course')
  159.  
  160.  
  161. class CourseClassList(ListView):
  162. model = CourseClass
  163.  
  164.  
  165. class CourseClassCreate(CreateView):
  166. model = CourseClass
  167. #fields = ['course','duration','number_of_student_group_students']
  168. success_url = reverse_lazy('list_course_class')
  169.  
  170.  
  171. class CourseClassUpdate(UpdateView):
  172. model = CourseClass
  173. success_url = reverse_lazy('list_course_class')
  174.  
  175.  
  176. class CourseClassDelete(DeleteView):
  177. model = CourseClass
  178. success_url = reverse_lazy('list_course_class')
  179.  
  180.  
  181. #Genetic mutation starts here, speed limit as per your processor, keep left unless overcompiling
  182. #Create a memeber of the population
  183. number_of_rooms = Classroom.objects.count()
  184. #Number of slots is number of hours multiply by number of days by number of rooms
  185. slots = 12*5*number_of_rooms
  186. classes = Classroom.objects.all()
  187. def individual(slots, first_position_in_slot, fitness, criteria, number_of_crossover_points,
  188. crossover_probability,mutation_probability):
  189. return [CourseClass.id(fitness=0, criteria=False, number_of_crossover_points=0, crossover_probability=0, mutation_probability=0 )
  190. for classes in xrange(slots)]
Add Comment
Please, Sign In to add comment