def recommend(self, howMany): userKnownLanguages = {} for button in self.buttons: if(button.clicked == True): if button.t not in userKnownLanguages: userKnownLanguages[button.t] = 1 topicOfChoice = "" # Grab the topic the user selected try: index = self.listbox.curselection()[0] topicOfChoice = self.listbox.get(index) except IndexError: pass nearestCluster = classifier.nearest(userKnownLanguages, self.indexByTopic) for frame in self.frames: frame.pack_forget() self.displayRecommendations(topicOfChoice, userKnownLanguages) data = classifier.difference(self.indexByTopic[nearestCluster]['languages'], userKnownLanguages) labels,d1 =zip(*data) d = Drawing(300,200) chart = VerticalBarChart() chart.width = 260 chart.height = 160 chart.x = 20 chart.y = 10 chart.data = [d1] chart.categoryAxis.categoryNames = labels d.add(chart) d.save(formats=['pdf'],outDir='.',fnRoot='graph') os.system('open graph.pdf')
def displayRecommendations(self, topicOfChoice, userKnownLanguages): unknownLanguages = [] self.frames[0].destroy() mainFrame = Tkinter.Frame(self.window) f = tkFont.Font(size=18) if topicOfChoice == "": topLanguages = "" for x in dict(sorted(self.indexByLanguage.iteritems(), key=itemgetter(1),reverse=True)[:3]): topLanguages = topLanguages + " " + x text = Tkinter.Text(mainFrame, width = 135, font = f) text.insert(INSERT,"Since no topic was selected, it is recommended that you learn one of the top languages across all given topics which are the following:") text.grid(row = 0, column = 0) text.insert(INSERT,topLanguages) text.grid(row = 1, column = 0) else: for key in self.indexByTopic[topicOfChoice]['languages']: if key not in userKnownLanguages: unknownLanguages.append({'language':key, 'count':self.indexByTopic[topicOfChoice]['languages'][key]}) sortedList = (sorted(unknownLanguages, key=itemgetter('count'))) if len(sortedList) == 0: text = Tkinter.Text(mainFrame, font=f) text.insert(INSERT, "You already know all the languages that you need to get a job in ") text.insert(INSERT, topicOfChoice) text.insert(INSERT, ". You are too smart!") text.grid(row = 0, column = 0) mainFrame.pack(side = TOP) return '' topicToLearn = sortedList[len(sortedList)-1]['language'] if topicToLearn == "office": topicToLearn = "microsoft office" text2 = Tkinter.Text(mainFrame, height = 2, font=f) text2.insert(INSERT, "It is recommended that you learn ") text2.insert(INSERT, topicToLearn) text2.insert(INSERT, " to increase your job options when searching for a job in ") text2.insert(INSERT, topicOfChoice + ".") text2.grid(row=3, column=0) length = len(userKnownLanguages) # Determine how close the user is to each topic currently nearestCluster = classifier.nearest(userKnownLanguages, self.indexByTopic) text3 = Tkinter.Text(mainFrame, height = 3, font=f) if len(userKnownLanguages) == 0: text3.insert(INSERT, "You don't know any languages already, so go into Liberal Arts") else: text3.insert(INSERT, "Based on the languages you already know: ") for x in dict(sorted(userKnownLanguages.iteritems(), key=itemgetter(1),reverse=True)[:length]): text3.insert(INSERT, x + ", ") text3.insert(INSERT, "you are most capable of working in the field of " + nearestCluster + ".") text3.grid(row = 4, column = 0) restart = Tkinter.Button(mainFrame, text="Choose another selection") restart.grid(row=5) restart.bind("<Button-1>", lambda e: self.restartFunc()) self.windowVisible = False mainFrame.pack(side = TOP) self.frames.append(mainFrame) pass