def collector_parser(self, collector, input): temp_input = input.split() keyword = temp_input[0] print keyword if keyword == "EDQ": collector.end_survey() return "Survey completion finished." elif keyword == "EDC": collector.end_choice() return "Enter new question or send EDQ to end survery creation." elif keyword == "CREATE": if len(temp_input) > 1: collector.create_Survey(' '.join(temp_input[1:])) return "Survey creation started. Enter first question:\n" elif keyword == "CTL": if len(temp_input) > 1: numbers = temp_input[1:] for number in numbers: if number not in self.volunteers: volunteer = Volunteer(number) self.volunteers[number] = volunteer collector.add_contact_list(' '.join(numbers)) return "Contact group generated." elif keyword == "CHECK": if len(temp_input) > 1: data = ''.join(temp_input).split(',') if len(data) > 1: survey_function = data[1] survey_name = data[2] response_list = [] for v in self.volunteers: response_list += [v.get_survey(survey_name).get_question_list()] dictionary = {} for response in response_list: for question in response: if str(question.ans) in dictionary: if question.get_type() is "str": dictionary[str(question.ans)] += [1] elif question.get_type() is "num": dictionary[str(question.ans)] += [question.ans] for k in dictionary: if survey_function is "AVG": dictionary[k] = sum(dictionary[k])/len(dictionary[k]) else: dictionary[k] = sum(dictionary[k]) return str(dictionary) elif keyword == "SEND": if len(temp_input) > 2: for number in collector.send(temp_input[3:]): if number in self.volunteers: self.volunteers[number].add_survey(collector.get_survey(temp_input[1])) return "Survery sent" else: if collector.process_response(input) == 1: return "Enter answer type: " else: return "Enter answer choice text: "
def createVolunteer(last, first, phone="", email=""): v = Volunteer(last, first, phone, email) conn, c = open() insert = [str(v.id), str(v.last), str(v.first), str(v.phone), str(v.email)] c.execute("""INSERT INTO Volunteers VALUES(?,?,?,?,?)""", insert) close(conn)
def test_availability(self): sample_availability = { 'week1': 1, 'week2': 0, 'week3': 1, 'week4': 0, 'week5': 0 } vol = Volunteer(volunteer_id='v001') vol.set_availability('tuesday', sample_availability) self.assertEqual(vol.get_availability('tuesday'), sample_availability, "availability is set and retrieved correctly")
def test_scheduling_unalvailable_volunteer(self): vol = Volunteer(volunteer_id='v001') vol.availability['tuesday']['week2'] = 0 # set as not available # create a session group = StudentGroup('A') sess = Session(week='week2', day='tuesday', session_id='s001') sess.assign_student_group(group) #schedule volunteer sess.schedule_volunteer(vol) self.assertEqual(vol.schedule['tuesday']['week2'], [], "volunteer is not scheduled for the session") self.assertEqual( sess.get_scheduled_volunteers(), [], "volunteer is not added to list of scheduled volunteers")
def test_over_scheduling_session(self): vols = [] # create five volunteers for i in range(1, 6): vols.append(Volunteer(volunteer_id='v00' + str(i))) # create a session group = StudentGroup('A') sess = Session(week='week2', day='thursday', session_id='s001') sess.assign_student_group(group) # assign all volunteers to the session for vol in vols: sess.schedule_volunteer(vol) self.assertEqual(len(sess.get_scheduled_volunteers()), 4, "only four volunteers scheduled")
def test_simple_scheduling(self): vol = Volunteer(volunteer_id='v001') group = StudentGroup('A') sess = Session(week='week2', day='thursday', session_id='s001') sess.assign_student_group(group) sess.schedule_volunteer(vol) self.assertEqual( vol.get_groups_seen(), ['A'], 'volunteer has correctly updated list of groups seen') self.assertEqual(vol.get_schedule()['thursday']['week2'], ['s001'], 'volunteer schedule updated correctly') self.assertEqual(vol.get_times_scheduled(), 1, 'correctly counted times scheduled') self.assertEqual(vol.get_schedule()['tuesday']['week2'], [], 'Tuesday not updated')
def test_shceduling_previously_seen_volunteer(self): vol = Volunteer(volunteer_id='v001') group = StudentGroup('A') sess1 = Session(week='week2', day='thursday', session_id='s001') sess1.assign_student_group(group) sess2 = Session(week='week3', day='tuesday', session_id='s002') sess2.assign_student_group(group) sess1.schedule_volunteer(vol) sess2.schedule_volunteer(vol) self.assertEqual( vol.get_groups_seen(), ['A'], 'volunteer has correctly updated list of groups seen') self.assertEqual(vol.get_schedule()['thursday']['week2'], ['s001'], 'first schedule update successful') self.assertEqual(vol.get_schedule()['tuesday']['week3'], [], 'second schedule update not successful')
def test_over_scheduling_volunteer(self): vol = Volunteer(volunteer_id='v001') # create 5 sessions on the same day, each session with a different student group sessions = [] for i in range(1, 6): group = StudentGroup('A' + str(i)) sess = Session(week='week2', day='thursday', session_id='s00' + str(i)) sess.assign_student_group(group) sessions.append(sess) # schedule the volunteer for all sessions for session in sessions: session.schedule_volunteer(vol) self.assertEqual(len(vol.get_schedule()['thursday']['week2']), 4, "only four of the five sessions are scheduled")
def make_volunteer(volunteer_info): volunteer = Volunteer(volunteer_info[0]) tues_av = { "week1": volunteer_info[1], "week2": volunteer_info[3], "week3": volunteer_info[5], "week4": volunteer_info[7], "week5": volunteer_info[9] } thur_av = { "week1": volunteer_info[2], "week2": volunteer_info[4], "week3": volunteer_info[6], "week4": volunteer_info[8], "week5": volunteer_info[10] } volunteer.set_availability('tuesday', tues_av) volunteer.set_availability('thursday', thur_av) return volunteer
def test_volunteer_id(self): vol = Volunteer(volunteer_id='v001') self.assertEqual(vol.get_id(), 'v001', "Correct volunteer id is assigned and retrieved")