def class_info(request, class_name): # Display textbox for user to enter a class form = GetSubjectForm() if request.method == 'POST': form = GetSubjectForm(request.POST) if form.is_valid(): class_name = form.cleaned_data['class_'] info = subject_info.get_online_info(class_name) # The user searched with a keyword if info == None: # TODO: only do this for English words. Invalid classes should throw error recs = keyword_similarity.keyword_similarity(class_name) return render(request, 'recommender/recommendations-keywords.html', {'form':form, 'recs': recs}) # The user searched with a class number term_stats = subject_info.get_term_stats(class_name) # Create bar graph data = create_graphs.create_bar_graph(term_stats, class_name, info) data['form'] = form # TODO # return redirect(reverse('recommender:class_info'), args=(response,), urllib.urlencode(data)) return render(request, 'recommender/stats_by_class.html', data)
def generate_recommendations(major, cur_semester, student_classes): new_classes = get_new_classes.get_classes_to_take(major, student_classes) all_classes = student_classes + new_classes if major == '18_applied' or major == '18_general': major = '18' else: major = major.replace('_', ' ') class_table = {k:v for k, v in zip(all_classes, xrange(len(all_classes)))} shared_classes_table = create_shared_classes_table(major, all_classes, class_table) # consider caching # Calculate time (semester) relevance cur_term = "term%s" % cur_semester term_data, class_titles = get_term_relevance_data(cur_term, new_classes) # Calculate "importance" of each class that hasn't been taken by the student importance_ratings = {} for new_class in new_classes: rating = calculate_rating(new_class, student_classes, class_table, shared_classes_table) # try: # rating *= term_data[new_class] # time relevance # except: # pass importance_ratings[new_class] = rating # Create list of classes in order of popularity sorted_classes = sorted(importance_ratings, key=importance_ratings.get, reverse=True) recs = [] for c in sorted_classes[:20]: try: title = class_titles[c] except: try: title = subject_info.get_online_info(c)['title'] except: title = "" recs.append((c, title)) return recs