def run(self, dispatcher, tracker, domain): # elastic_cat = course category e.g. short course / admissions courses # elastic_score = course relevancy score elastic_title, elastic_cat, elastic_score = elastic.get_course_title( tracker.get_slot("course")) if elastic_cat == "SC": elastic_output, elastic_score = elastic.get_sc_field( elastic_title, "Cost") response = str(elastic_title).title() + " costs £" + str( elastic_output) + "." elif elastic_cat == "AD": # fee_variables # 0 1 2 # course, home_fee, int_fee fee_variables = elastic.get_ad_fees(elastic_title) response = "" if fee_variables[1]: response = "%s costs £%s if you are from Scotland or the EU. " % ( fee_variables[0], fee_variables[1]) if fee_variables[2]: response = response + "%s costs £%s if you are from elsewhere in the UK or abroad." % ( fee_variables[0], fee_variables[2]) if response == "": response = "Sorry, I could not find any fees for that course" dispatcher.utter_message(response) return
def run(self, dispatcher, tracker, domain): # elastic_cat = course category e.g. short course / admissions courses # elastic_score = course relevancy score elastic_title, elastic_cat, elastic_score = elastic.get_course_title( tracker.get_slot("course")) # we don't have teaching information about PGT if elastic_cat == "SC": tutor_number, tutor_list = elastic.getMultiTutors( tracker.get_slot("course")) if tutor_number == 1: response = "The tutor for {} is: {}.".format( elastic_title, str(tutor_list)) elif tutor_number > 1: response = "There are " + str( tutor_number) + " different tutors for " + str( elastic_title).title() + ":" response += str(tutor_list) else: response = "Sorry, I could not find any tutors for " + str( elastic_title) elif elastic_output == "AD": response = "Sorry, I do not know who teaches {}".format( elastic_title) else: response = "Sorry, I could not find the tutor for {}".format( elastic_title) dispatcher.utter_message(response) return
def run(self, dispatcher, tracker, domain): # elastic_cat = course category e.g. short course / admissions courses # elastic_score = course relevancy score elastic_title, elastic_cat, elastic_score = elastic.get_course_title( tracker.get_slot("course")) if elastic_cat == "SC": # instances_variables # 0 1 2 3 4 5 # title, sdate, edate, stime, etime, duration instance_variables = elastic.get_sc_times(elastic_title) # If the course begins in January, then it will specify, response = "I have found {} instance(s) of that course: \n".format( str(len(instance_variables))) i = 1 for time_variables in instance_variables: if time_variables[5] is not 1: response += "Instance " + str( i ) + " of %s starts on %s and ends on %s, and runs from %s to %s \n" % ( time_variables[0], time_variables[1], time_variables[2], time_variables[3], time_variables[4]) else: response += "Instance " + str( i) + " of %s runs from %s to %s on %s \n" % ( time_variables[0], time_variables[3], time_variables[4], time_variables[1]) i += 1 elif elastic_cat == "AD": # time_variables # 0 1 2 # title, term, january_start time_variables = elastic.get_ad_times(elastic_title) # If the course begins in January, then it will specify, # Otherwise it will not mention the start month as we do not have more information if time_variables[2]: answer = "%s starts in %s and begins in January." % ( time_variables[0], time_variables[1]) else: answer = "%s starts in %s" % (time_variables[0], time_variables[1]) response = str(answer) else: response = "Sorry, I could not find information on times for this course" dispatcher.utter_message(response) return
def run(self, dispatcher, tracker, domain): elastic_title, elastic_cat, elastic_score = elastic.get_course_title( tracker.get_slot("course")) response = "Did you want the course: {}?".format(elastic_title) buttons = [{ "title": "Yes", "payload": "/confirmation" }, { "title": "No", "payload": "/denial" }] dispatcher.utter_button_message(response, buttons) return
def run(self, dispatcher, tracker, domain): # CheckCourse should have ran & confirmed beforehand # so this would be what the user confirmed elastic_title, elastic_cat, elastic_score = elastic.get_course_title( tracker.get_slot("course")) link = elastic.get_sc_course_link(elastic_title) if link: response = "Here's a link to the webpage for {}: {}".format( elastic_title, link) else: response = "Sorry, this short course does not seem to have a web page. This might be because it only runs for one day." dispatcher.utter_message(response) return [SlotSet("course_type", "short")]
def test_get_course_title(self): self.assertEqual(elastic.get_course_title("Brain Sciences"), ('Brain Sciences', 'AD', 9.722658)) self.assertEqual( elastic.get_course_title("ANIMAL WELFARE SCIENCE"), ('Animal Welfare Science, Ethics And Law', 'AD', 8.870279)) self.assertEqual(elastic.get_course_title("Orkney"), ('Orkney In Scotland', 'SC', 4.4347043)) self.assertEqual(elastic.get_course_title("Film"), ('Film Curation', 'AD', 5.484622)) self.assertEqual(elastic.get_course_title("Film Studies"), ('Film Studies 1', 'SC', 9.140733)) self.assertEqual(elastic.get_course_title("szdfedg"), (None, None, None))
def run(self, dispatcher, tracker, domain): course = tracker.get_slot("course") title, category, score = elastic.get_course_title(course) if category == "AD": response = "Standard PGT university courses are usually worth 120 credits, but I don't have any more specific information." elif category == "SC": elastic_title, elastic_result = elastic.get_sc_credits(course) if elastic_result: response = "{} is worth {} credits".format( elastic_title, elastic_result) else: response = "There doesn't seem to be any credits attached to the course {}".format( elastic_title) else: response = "I'm sorry, I don't think I understood the course right." dispatcher.utter_message(response) return
def run(self, dispatcher, tracker, domain): elastic_title, elastic_cat, elastic_score = elastic.get_course_title( tracker.get_slot("course")) if elastic_cat == "AD": pt_ft_answer, pt_ft_variables = elastic.check_pt_ft_course( elastic_title) else: response = "Sorry, I can only check for part-time/full-time for PGT courses." dispatcher.utter_message(response) return if pt_ft_answer == "not_running": response = "Sorry, it does not seem this course is running this year" elif pt_ft_answer == "running": response = "{} runs {}".format(pt_ft_variables[0], ', '.join(pt_ft_variables[1])) # this is for good practice -- normally the function only ever returns running or not running else: response = "Sorry, it seems I wasn't able to follow through with your query." dispatcher.utter_message(response) return
acro, desc, score = elastic.get_acronym_desc("mario decision") assert ( desc == "MaRio decision means admissions have the decision-making capacity, not the school" ), desc print("Found right answer for MaRio decision with get_acronym_desc") # tests that were ran while cleaning up code -- test driven development # sc, sc_len = elastic.get_sc_type_courses("art") # new_sc, new_sc_len = elastic.get_type_courses("art", "short") # new_ad, new_ad_len = elastic.get_type_courses("science", "admissions") # assert sorted(sc) == sorted(new_sc), "New functionality doesn't match for short courses" # assert type(new_ad) is list, new_ad # check functionality works # print("New function functionality works") title, credits = elastic.get_sc_credits("songwriting workshop") assert not credits, "Songwriting workshop should return 0 credits, returned " + str( credits) title, credits = elastic.get_sc_credits("spanish stage 3") assert credits == 10, "Spanish stage 3 should return 0 credits, returned " + str( credits) print("Credits function works") run, vars = elastic.check_pt_ft_course("international law") assert "part-time" and "full-time" in vars[1], vars print("PT/FT function debugged") title, category, score = elastic.get_course_title("you the juror") assert category == "SC", [title, category, score] print("Course title function debugged")