def generate(request):
    import json
    list_of_courses = {}
    try:
        if request.COOKIES.has_key('section_list'):
            list_of_courses = eval(request.COOKIES['section_list'])
        elif request.COOKIES.has_key('courses_string'):
            list_of_courses = getcourses.get_section_list(request.COOKIES['courses_string'])
    except:
        try:
            if request.COOKIES.has_key('courses_string'):
                list_of_courses = getcourses.get_section_list(request.COOKIES['courses_string'])
        except:
            return HttpResponseRedirect('/')


    startTime = int(request.POST.get('start_time'))
    if (startTime == -1): startTime = None
    endTime = int(request.POST.get('end_time'))
    if (endTime == -1): endTime = None
    preferences = {'startTime':startTime,'endTime':endTime,'minBreakDuration':None,'maximizeDaysOff':None,'clusterClasses':None,'easyDays':None}
    include_list = request.POST.getlist('include_list[]')
    disclude_list = request.POST.getlist('disclude_list[]')
    schedules = generator.generateRankedScheduleList(list_of_courses,preferences,[int(x) for x in include_list],[int(x) for x in disclude_list])

    if schedules is None:
        return HttpResponse(status=410)

    import json
    return HttpResponse(json.dumps({'schedules':[schedule for (schedule,score) in schedules]}))
Beispiel #2
0
def generate(request):
    import json

    list_of_courses = {}
    try:
        if request.COOKIES.has_key("section_list"):
            list_of_courses = eval(request.COOKIES["section_list"])
        elif request.COOKIES.has_key("courses_string"):
            list_of_courses = getcourses.get_section_list(request.COOKIES["courses_string"])
    except:
        try:
            if request.COOKIES.has_key("courses_string"):
                list_of_courses = getcourses.get_section_list(request.COOKIES["courses_string"])
        except:
            return HttpResponseRedirect("/")

    startTime = int(request.POST.get("start_time"))
    if startTime == -1:
        startTime = None
    endTime = int(request.POST.get("end_time"))
    if endTime == -1:
        endTime = None
    preferences = {
        "startTime": startTime,
        "endTime": endTime,
        "minBreakDuration": None,
        "maximizeDaysOff": None,
        "clusterClasses": None,
        "easyDays": None,
    }
    include_list = request.POST.getlist("include_list[]")
    disclude_list = request.POST.getlist("disclude_list[]")
    schedules = generator.generateRankedScheduleList(
        list_of_courses, preferences, [int(x) for x in include_list], [int(x) for x in disclude_list]
    )

    if schedules is None:
        return HttpResponse(status=410)

    import json

    return HttpResponse(json.dumps({"schedules": [schedule for (schedule, score) in schedules]}))
Beispiel #3
0
def index_submit(request):
    response = HttpResponsePermanentRedirect("/schedule/")

    if request.method == "POST":
        form = forms.CourseForm(request.POST)

        if form.is_valid():
            sessionCourseString = ""
            list_of_courses = getcourses.get_section_list(form.cleaned_data["courses"])
            for courseName in list_of_courses:
                sessionCourseString += courseName + ","
            # request.session['section_list'] = dict(list_of_courses)
            import json

            # response.set_cookie('section_list', str(list_of_courses))
            # request.session['courses_string'] = sessionCourseString
            response.set_cookie("courses_string", sessionCourseString)
            return response

    return HttpResponsePermanentRedirect("/")
def index_submit(request):
    response = HttpResponsePermanentRedirect('/schedule/')
        
    if request.method == 'POST':
        form = forms.CourseForm(request.POST)
        
        if form.is_valid():
            sessionCourseString = ''
            list_of_courses = getcourses.get_section_list(form.cleaned_data['courses'])
            if (list_of_courses != None):
                for courseName in list_of_courses:
                    sessionCourseString += courseName + ','    
            
            # request.session['section_list'] = dict(list_of_courses)
            import json
            # response.set_cookie('section_list', str(list_of_courses))
            # request.session['courses_string'] = sessionCourseString
            response.set_cookie('courses_string',sessionCourseString)
            return response
        
    return HttpResponsePermanentRedirect('/')
def main():
	# Courses to take
	courseAbbrevs = 'CS2150,PSYC1010,PSYC2200,CS2102,CS2330,CHEM1410'
	# Preferences
	preferences = {'startTime':1100,'endTime':1600,'minBreakDuration':None,'easyDays':(1,0,0,0,0,1,1)}
	# Sections from the courses above that I want explicitly
	selected_section_ids = []
	# Sections from the courses above that I do not want
	discluded_section_ids = [11227,14077]

	# Call Nikhil's get_section_list method and supress output to console temporarily
	class DummyFile(object):
		def write(self, x): pass
	import sys
	save_stdout = sys.stdout
	sys.stdout = DummyFile()
	course_sections = getcourses.get_section_list(courseAbbrevs)
	sys.stdout = save_stdout

	schedules = generateRankedScheduleList(course_sections,preferences,selected_section_ids,discluded_section_ids)

	for section in schedules[0][0]:
		print(section['id'])
Beispiel #6
0
def schedule(request):
    import json

    list_of_courses = {}
    if request.COOKIES.has_key("section_list"):
        list_of_courses = eval(request.COOKIES["section_list"])
    elif request.COOKIES.has_key("courses_string"):
        list_of_courses = getcourses.get_section_list(request.COOKIES["courses_string"])
        # request.session['section_list'] = dict(list_of_courses)

    # Colors found at http://colors.findthedata.com/saved_search/Pastel-Colors
    # Pastel colors are best for showing text on top of them, and aren't too bright for the page
    # colors = ['#9400D3', '#00CED1','#FFA812', '#8B008B', '#666699', '#BDB76B', '#556B2F', '#8B0000', '#E75480', '#9B870C']
    # colors = ['#C23B22', '#FF6961', '#FDFD96', '#AEC6CF', '#FFB347', '#77DD77', '#B19CD9', '#779ECB', '#836953', '#DEA5A4']
    colors = ["#836953", "#DEA5A4", "#FF6961", "#966FD6", "#AEC6CF", "#FFB347", "#77DD77", "#F49AC2"]
    # PASTEL BROWN, PASTEL PINK, PASTEL RED, PASTEL PURPLE, PASTEL BLUE, PASTEL ORANGE, PASTEL GREEN

    has_lecture = {}
    has_lab = {}

    i = -1

    import random

    r = lambda: random.randint(0, 255)

    # color = colors[0]

    lecture_name = {}
    lecture_vowel = {}
    course_titles = {}
    if list_of_courses is not None and len(list_of_courses.keys()) > 0:
        for course in list_of_courses:  # Each course
            if i >= len(colors):
                color = colors[i % len(colors)]
            else:
                color = colors[i]

            for section in list_of_courses[course]:  # Each section for each course
                course_titles[course] = section["course_title"]

                section["color"] = color

                if section["type"] == "Lecture":
                    has_lecture[course] = True
                    lecture_name[course] = "Lecture"
                    lecture_vowel[course] = False
                elif course not in has_lecture:
                    has_lecture[course] = False

                section["instructortimes"] = zip(section["instructors"], section["times"])

            for section in list_of_courses[course]:  # Each section for each course
                if has_lecture[course]:
                    if section["type"] != lecture_name[course]:
                        has_lab[course] = True
                else:
                    if section["type"] == "Laboratory" or section["type"] == "Discussion":
                        has_lab[course] = True
                    else:
                        lecture_name[course] = section["type"]
                        has_lecture[course] = True

                if course in lecture_name and lecture_name[course][0] in [
                    "a",
                    "A",
                    "e",
                    "E",
                    "i",
                    "I",
                    "o",
                    "O",
                    "u",
                    "U",
                ]:
                    lecture_vowel[course] = True

            i += 1

    json_data = json.dumps(list_of_courses)
    # print(json_data);

    json_lecture_names = json.dumps(lecture_name)
    # courses = zip(list_of_courses, colors)

    update_form = forms.UpdateForm()

    response = render(
        request,
        "schedule.html",
        {
            "courses": list_of_courses,
            "lecture_vowel": lecture_vowel,
            "json_lecture_names": json_lecture_names,
            "lecture_names": lecture_name,
            "colors": colors,
            "json_data": json_data,
            "has_lecture": has_lecture,
            "has_lab": has_lab,
            "update_form": update_form,
            "course_titles": course_titles,
        },
        context_instance=RequestContext(request),
    )

    # response.set_cookie('section_list', str(list_of_courses))
    return response
Beispiel #7
0
def update(request):
    if request.method == "POST":
        form = forms.UpdateForm(request.POST)

        if form.is_valid():
            import json

            list_of_courses = getcourses.get_section_list(form.cleaned_data["courses"])
            oldDict = {}
            if request.COOKIES.has_key("section_list"):
                oldDict = eval(request.COOKIES["section_list"])  # request.session['section_list']
            oldDict.update(list_of_courses)
            # request.session['section_list'] = dict(oldDict)

            sessionCourseString = ""
            if request.COOKIES.has_key("courses_string"):
                sessionCourseString = request.COOKIES["courses_string"]
            for courseString in list_of_courses:
                if courseString not in sessionCourseString:
                    sessionCourseString += courseString + ","
            sessionCourseString = sessionCourseString.replace(",,", ",")
            # request.session['courses_string'] = sessionCourseString.replace(',,',',')

            form.cleaned_data["courses"] = ""

            # Colors found at http://colors.findthedata.com/saved_search/Pastel-Colors
            # Pastel colors are best for showing text on top of them, and aren't too bright for the page
            # colors = ['#9400D3', '#00CED1','#FFA812', '#8B008B', '#666699', '#BDB76B', '#556B2F', '#8B0000', '#E75480', '#9B870C']
            # colors = colors.reverse()
            # colors = ['#C23B22', '#FF6961', '#FDFD96', '#AEC6CF', '#FFB347', '#77DD77', '#B19CD9', '#779ECB', '#836953', '#DEA5A4']

            has_lecture = {}
            has_lab = {}

            i = 0

            import random

            r = lambda: random.randint(50, 200)

            # color = colors[0]

            lecture_name = {}
            lecture_vowel = {}
            course_titles = {}

            for course in list_of_courses:  # Each course
                color = "#%02X%02X%02X" % (r(), r(), r())

                for section in list_of_courses[course]:  # Each section for each course
                    course_titles[course] = section["course_title"]

                    section["color"] = color

                    if section["type"] == "Lecture":
                        has_lecture[course] = True
                        lecture_name[course] = "Lecture"
                        lecture_vowel[course] = False
                    elif course not in has_lecture:
                        has_lecture[course] = False

                    section["instructortimes"] = zip(section["instructors"], section["times"])

                for section in list_of_courses[course]:  # Each section for each course
                    if has_lecture[course]:
                        if section["type"] != lecture_name[course]:
                            has_lab[course] = True
                    else:
                        if section["type"] == "Laboratory" or section["type"] == "Discussion":
                            has_lab[course] = True
                        else:
                            lecture_name[course] = section["type"]
                            has_lecture[course] = True

                    if course in lecture_name and lecture_name[course][0] in [
                        "a",
                        "A",
                        "e",
                        "E",
                        "i",
                        "I",
                        "o",
                        "O",
                        "u",
                        "U",
                    ]:
                        lecture_vowel[course] = True

                i += 1

            json_data = json.dumps(list_of_courses)
            # print(json_data);

            json_lecture_names = json.dumps(lecture_name)

            response = HttpResponse(
                json.dumps(
                    {
                        "courses": list_of_courses,
                        "lecture_vowel": lecture_vowel,
                        "json_lecture_names": json_lecture_names,
                        "lecture_names": lecture_name,
                        "json_data": json_data,
                        "has_lecture": has_lecture,
                        "has_lab": has_lab,
                        "course_titles": course_titles,
                    }
                )
            )

            # response.set_cookie('section_list', str(oldDict))
            response.set_cookie("courses_string", sessionCourseString)

            return response
        else:
            return HttpResponse("Invalid Form")
    else:
        return HttpResponse("Failure")
def schedule(request):
    import json
    list_of_courses = {}
    if request.COOKIES.has_key('section_list'):
        list_of_courses = eval(request.COOKIES['section_list'])
    elif request.COOKIES.has_key('courses_string'):
        list_of_courses = getcourses.get_section_list(request.COOKIES['courses_string'])
        # request.session['section_list'] = dict(list_of_courses)
        
    # Colors found at http://colors.findthedata.com/saved_search/Pastel-Colors
    # Pastel colors are best for showing text on top of them, and aren't too bright for the page
    #colors = ['#9400D3', '#00CED1','#FFA812', '#8B008B', '#666699', '#BDB76B', '#556B2F', '#8B0000', '#E75480', '#9B870C']
    #colors = ['#C23B22', '#FF6961', '#FDFD96', '#AEC6CF', '#FFB347', '#77DD77', '#B19CD9', '#779ECB', '#836953', '#DEA5A4']
    colors = ['#836953', '#DEA5A4', '#FF6961', '#966FD6', '#AEC6CF', '#FFB347', '#77DD77', '#F49AC2']
    #PASTEL BROWN, PASTEL PINK, PASTEL RED, PASTEL PURPLE, PASTEL BLUE, PASTEL ORANGE, PASTEL GREEN
    
    has_lecture = {}
    has_lab = {}
    
    i = -1
    
    import random
    r = lambda: random.randint(0,255)
    
    #color = colors[0]
    
    
    lecture_name = {}
    lecture_vowel = {}
    course_titles = {}
    if list_of_courses is not None and len(list_of_courses.keys()) > 0:
        for course in list_of_courses: # Each course
            if i >= len(colors):
                color = colors[i % len(colors)]
            else:
                color = colors[i]
            
            for section in list_of_courses[course]: # Each section for each course
                course_titles[course] = section['course_title']
                
                section['color'] = color
            
                if section['type'] == 'Lecture':
                    has_lecture[course] = True
                    lecture_name[course] = 'Lecture'
                    lecture_vowel[course] = False
                elif course not in has_lecture:
                    has_lecture[course] = False
                    
                section['instructortimes'] = zip(section['instructors'], section['times'])
                
            for section in list_of_courses[course]: # Each section for each course
                if has_lecture[course]:
                    if section['type'] != lecture_name[course]:
                        has_lab[course] = True
                else:
                    if section['type'] == 'Laboratory' or section['type'] == 'Discussion':
                        has_lab[course] = True
                    else:
                        lecture_name[course] = section['type']
                        has_lecture[course] = True
                
                if course in lecture_name and lecture_name[course][0] in ['a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U']:
                    lecture_vowel[course] = True
            
            i += 1
        
    
    json_data = json.dumps(list_of_courses)
    #print(json_data);
    
    json_lecture_names = json.dumps(lecture_name)
    #courses = zip(list_of_courses, colors)
    
    update_form = forms.UpdateForm()
    
    response = render(request, 'schedule.html', {'courses': list_of_courses, 'lecture_vowel': lecture_vowel, 
        'json_lecture_names': json_lecture_names, 'lecture_names': lecture_name,'colors': colors, 
        'json_data': json_data, 'has_lecture': has_lecture, 'has_lab': has_lab, 'update_form': update_form, 'course_titles':course_titles}, context_instance=RequestContext(request))
    
    # response.set_cookie('section_list', str(list_of_courses))
    return response
def update(request):
    if request.method == 'POST':
        form = forms.UpdateForm(request.POST)

        if form.is_valid():
            import json
            list_of_courses = getcourses.get_section_list(form.cleaned_data['courses'])
            if (list_of_courses != None):
                oldDict = {}
                if request.COOKIES.has_key('section_list'):
                    oldDict = eval(request.COOKIES['section_list']) #request.session['section_list']
                oldDict.update(list_of_courses)
                # request.session['section_list'] = dict(oldDict)
    
                sessionCourseString = ''
                if request.COOKIES.has_key('courses_string'):
                    sessionCourseString = request.COOKIES['courses_string']
                for courseString in list_of_courses:
                    if courseString not in  sessionCourseString:
                        sessionCourseString += courseString + ','
                        
                sessionCourseString = sessionCourseString.replace(',,',',')
                # request.session['courses_string'] = sessionCourseString.replace(',,',',')
                
                form.cleaned_data['courses'] = ''

                # Colors found at http://colors.findthedata.com/saved_search/Pastel-Colors
                # Pastel colors are best for showing text on top of them, and aren't too bright for the page
                # colors = ['#9400D3', '#00CED1','#FFA812', '#8B008B', '#666699', '#BDB76B', '#556B2F', '#8B0000', '#E75480', '#9B870C']
                # colors = colors.reverse()
                # colors = ['#C23B22', '#FF6961', '#FDFD96', '#AEC6CF', '#FFB347', '#77DD77', '#B19CD9', '#779ECB', '#836953', '#DEA5A4']
            
            
                has_lecture = {}
                has_lab = {}
                
                i = 0
            
                import random
                r = lambda: random.randint(50,200)
                
                #color = colors[0]
                
            
                lecture_name = {}
                lecture_vowel = {}
                course_titles = {}
                
                for course in list_of_courses: # Each course
                    color = '#%02X%02X%02X' % (r(),r(),r())
                    
                    for section in list_of_courses[course]: # Each section for each course
                        course_titles[course] = section['course_title']
                        
                        section['color'] = color
                
                        if section['type'] == 'Lecture':
                            has_lecture[course] = True
                            lecture_name[course] = 'Lecture'
                            lecture_vowel[course] = False
                        elif course not in has_lecture:
                            has_lecture[course] = False
                        
                        section['instructortimes'] = zip(section['instructors'], section['times'])
                    
                    for section in list_of_courses[course]: # Each section for each course
                        if has_lecture[course]:
                            if section['type'] != lecture_name[course]:
                                has_lab[course] = True
                        else:
                            if section['type'] == 'Laboratory' or section['type'] == 'Discussion':
                                has_lab[course] = True
                            else:
                                lecture_name[course] = section['type']
                                has_lecture[course] = True
                        
                        if course in lecture_name and lecture_name[course][0] in ['a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U']:
                            lecture_vowel[course] = True
                    
                    i += 1
                
                json_data = json.dumps(list_of_courses)
                #print(json_data);
            
                json_lecture_names = json.dumps(lecture_name)
            
                response = HttpResponse(json.dumps({'courses': list_of_courses, 'lecture_vowel': lecture_vowel, 'json_lecture_names': json_lecture_names, 'lecture_names': lecture_name, 
                'json_data': json_data, 'has_lecture': has_lecture, 'has_lab': has_lab, 'course_titles': course_titles}))
            
                # response.set_cookie('section_list', str(oldDict))
                response.set_cookie('courses_string',sessionCourseString)
            
                return response
            else:
                return HttpResponse("Invalid Form")
        else:
            return HttpResponse("Failure")
Beispiel #10
0
def schedule(request):
    if request.method == 'POST':
        form = forms.CourseForm(request.POST)
        
        if form.is_valid():
            list_of_courses = get_section_list(form.cleaned_data['courses'])
            
            if list_of_courses == 'ConnectionError':
                return render(request, 'error.html', {error: "Lou's List seems to be down at the moment."});
                
            # Colors found at http://colors.findthedata.com/saved_search/Pastel-Colors
            # Pastel colors are best for showing text on top of them, and aren't too bright for the page
            #colors = ['#9400D3', '#00CED1','#FFA812', '#8B008B', '#666699', '#BDB76B', '#556B2F', '#8B0000', '#E75480', '#9B870C']
            #colors = ['#C23B22', '#FF6961', '#FDFD96', '#AEC6CF', '#FFB347', '#77DD77', '#B19CD9', '#779ECB', '#836953', '#DEA5A4']
            colors = ['#836953', '#DEA5A4', '#FF6961', '#966FD6', '#AEC6CF', '#FFB347', '#77DD77', '#F49AC2']
            #PASTEL BROWN, PASTEL PINK, PASTEL RED, PASTEL PURPLE, PASTEL BLUE, PASTEL ORANGE, PASTEL GREEN
            
            has_lecture = {}
            has_lab = {}
            
            i = 0
            
            import random
            r = lambda: random.randint(0,255)
            
            #color = colors[0]
            
            
            lecture_name = {}
            lecture_vowel = {}
            course_titles = {}
            
            for course in list_of_courses: # Each course
                if i >= len(colors):
                    color = colors[i % len(colors)]
                else:
                    color = colors[i]
                
                for section in list_of_courses[course]: # Each section for each course
                    course_titles[course] = section['course_title']
                    
                    section['color'] = color
                
                    if section['type'] == 'Lecture':
                        has_lecture[course] = True
                        lecture_name[course] = 'Lecture'
                        lecture_vowel[course] = False
                    elif course not in has_lecture:
                        has_lecture[course] = False
                        
                    section['instructortimes'] = zip(section['instructors'], section['times'])
                    
                for section in list_of_courses[course]: # Each section for each course
                    if has_lecture[course]:
                        if section['type'] != lecture_name[course]:
                            has_lab[course] = True
                    else:
                        if section['type'] == 'Laboratory' or section['type'] == 'Discussion':
                            has_lab[course] = True
                        else:
                            lecture_name[course] = section['type']
                            has_lecture[course] = True
                    
                    if course in lecture_name and lecture_name[course][0] in ['a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U']:
                        lecture_vowel[course] = True
                
                i += 1
                
                
            import json
            json_data = json.dumps(list_of_courses)
            #print(json_data);
            
            json_lecture_names = json.dumps(lecture_name)
            #courses = zip(list_of_courses, colors)
            
            update_form = forms.UpdateForm()
            
            return render(request, 'schedule.html', {'courses': list_of_courses, 'lecture_vowel': lecture_vowel, 
                'json_lecture_names': json_lecture_names, 'lecture_names': lecture_name,'colors': colors, 
                'json_data': json_data, 'has_lecture': has_lecture, 'has_lab': has_lab, 'update_form': update_form, 'course_titles':course_titles}, context_instance=RequestContext(request))
        else:
            print form.errors
            print("Error found")
    else:
        return HttpResponseRedirect('/')