def event_data(): print("Please enter the following informations!") date_of_event = Switch.general_data_inputer(["Date of the event", "Date of the event (YYYY.MM.DD)"]) start_time = Switch.general_data_inputer(["Start time", "Start time (hh:mm)"]) end_time = Switch.general_data_inputer(["End time", "End time (hh:mm)", start_time]) zip_code = Switch.general_data_inputer(["Zip code", "Zip code"]) city = Switch.general_data_inputer(["City", "City"]) address = Switch.general_data_inputer(["Address", "Address"]) available_beds = Switch.general_data_inputer(["Available beds", "Available beds"]) planned_donor_number = Switch.general_data_inputer(["Planned donor number", "Planned donor number"]) event_duration_time = EventCalculations.duration_in_time(start_time, end_time) colon_in_duration_time = str(event_duration_time).find(":") final_donor_number = EventCalculations.maximum_donor_number(available_beds, start_time, end_time) success_rate = EventCalculations.success_rate(planned_donor_number, final_donor_number) success_text = EventCalculations.success_text(success_rate) os.system('cls') print("\n" + "-" * 32 + "\n") print("Details of the planned event:\n") print("Date of the event:", date_of_event) print("Start time:", start_time) print("End time:", end_time) print("Event duration time: %s hour(s) %s minute(s)" % (str(event_duration_time)[:colon_in_duration_time], str(event_duration_time)[colon_in_duration_time+1:colon_in_duration_time+3])) print("Zip code:", zip_code) print("City:", city) print("Address:", address) print("Available beds:", available_beds) print("Planned donor number:", planned_donor_number) print("Maximum donor number:", final_donor_number) print("Percent of success:", success_rate, "%") print("Efficiency:", success_text) print("\n" + "-" * 32) if os.path.isfile("C:/Users/" + user_name + "/AppData/Local/Programs/Python/Python35-32/Lib/site-packages/colorama-0.3.3-py3.5.egg"): save = SaveMenu.save_menu(2, 21) else: save = SaveMenuOldFashioned.save_menu(2, "Do you want to save?") print() if save: every_file_data = [str(date_of_event).replace("-", "."), str(start_time)[:len(str(start_time))-3],\ str(end_time)[:len(str(end_time))-3], zip_code, city, address, available_beds, \ planned_donor_number, final_donor_number] header = "id,date_of_event,start_time,end_time,zip_code,city,address,number_of_available_beds," + \ "planned_donor_number,final_donor_number\n" FileOperator.save_new_data(every_file_data, header, 'Data/donations.csv') print("Save was successful!") time.sleep(2)
def test_time_to_datetime(self): test_start_time = datetime.strptime("10:00", "%H:%M").time() test_end_time = datetime.strptime("15:40", "%H:%M").time() self.assertEqual( 300, EventCalculations.maximum_donor_number(30, test_start_time, test_end_time))
def change_process_event(original, changed, file_line_number): header = ["Date of the event","Start time","End time","Zip code","City","Address","Available beds", "Planned donor number","Final donor number"] which_result = 0 result_number = len(original) os.system('cls') if result_number > 1: print("There are " + str(result_number) + " results:") else: print("The result:") print("-" * 52) for i in range(result_number): ChangeClass.print_preprocessor_event(original, 0, header, i, -1) if result_number > 1: print("Which result would you like to change?") which_result = int(input("Please give the result serial number (or 0 if none):")) if which_result == 0: return False else: os.system('cls') print("-" * 52) which_result -= 1 ChangeClass.print_preprocessor_event(original, 0, header, which_result, -1) menu_number = 3 while True: print("Would you like to change any of the data of this event?") select = ChangeOptionsMenu.change_options(2, " ", menu_number) print() if select == 1: changed[which_result].date_of_event = Switch.general_data_inputer([header[0], "Date of the event (YYYY.MM.DD)", changed[which_result].date_of_event, "Change"]) changed[which_result].start_time = Switch.general_data_inputer([header[1],"Start time (hh:mm)", changed[which_result].start_time,"Change"]) changed[which_result].end_time = Switch.general_data_inputer([header[2],"End time (hh:mm)", changed[which_result].start_time,changed[which_result].end_time, "Change"]) changed[which_result].zip_code = Switch.general_data_inputer([header[3], header[3],changed[which_result].zip_code,"Change"]) changed[which_result].city = Switch.general_data_inputer([header[4], header[4],changed[which_result].city,"Change"]) changed[which_result].address = Switch.general_data_inputer([header[5], header[5],changed[which_result].address,"Change"]) changed[which_result].available_beds = Switch.general_data_inputer([header[6], header[6],changed[which_result].available_beds,"Change"]) changed[which_result].planned_donor_number = Switch.general_data_inputer([header[7], header[7],changed[which_result].planned_donor_number,"Change"]) changed[which_result].final_donor_number = str(EventCalculations.maximum_donor_number( changed[which_result].available_beds,changed[which_result].start_time, changed[which_result].end_time)) ChangeClass.print_preprocessor_event(original, changed, header, which_result, -1) elif select == 2: os.system('cls') ChangeClass.print_preprocessor_event(original, changed, header, which_result, [0,7]) if ChangeClass.change_select_arrow == 0: changed[which_result].date_of_event = Switch.general_data_inputer([header[0], "Date of the event (YYYY.MM.DD)",changed[which_result].date_of_event,"Change"]) elif ChangeClass.change_select_arrow == 1: changed[which_result].start_time = Switch.general_data_inputer([header[1],"Start time (hh:mm)", changed[which_result].start_time,"Change"]) elif ChangeClass.change_select_arrow == 2: changed[which_result].end_time = Switch.general_data_inputer([header[2],"End time (hh:mm)", changed[which_result].start_time,changed[which_result].end_time,"Change"]) elif ChangeClass.change_select_arrow == 3: changed[which_result].zip_code = Switch.general_data_inputer([header[3], header[3],changed[which_result].zip_code,"Change"]) elif ChangeClass.change_select_arrow == 4: changed[which_result].city = Switch.general_data_inputer([header[4], header[4],changed[which_result].city,"Change"]) elif ChangeClass.change_select_arrow == 5: changed[which_result].address = Switch.general_data_inputer([header[5], header[5],changed[which_result].address,"Change"]) elif ChangeClass.change_select_arrow == 6: changed[which_result].available_beds = Switch.general_data_inputer([header[6], header[6],changed[which_result].available_beds,"Change"]) elif ChangeClass.change_select_arrow == 7: changed[which_result].planned_donor_number = Switch.general_data_inputer([header[7], header[7],changed[which_result].planned_donor_number,"Change"]) changed[which_result].final_donor_number = str(EventCalculations.maximum_donor_number( changed[which_result].available_beds,changed[which_result].start_time,changed[which_result].end_time)) ChangeClass.print_preprocessor_event(original,changed,header,which_result,-1) elif select == 3: if os.path.isfile("C:/Users/" + user_name + "/AppData/Local/Programs/Python/Python35-32/Lib/site-packages/colorama-0.3.3-py3.5.egg"): save = SaveMenu.yes_no_menu_relative_position(2, "Do you really want to save?") else: save = SaveMenuOldFashioned.save_menu(2, "Do you really want to save?") print() if save: try: FileOperator.save_changes("Data/donations.csv", file_line_number, changed[which_result]) if os.path.isfile("C:/Users/" + user_name + "/AppData/Local/Programs/Python/Python35-32/Lib/site-packages/colorama-0.3.3-py3.5.egg"): print(Fore.GREEN + "Save was successful!" + Style.RESET_ALL) else: print("Save was successful!") time.sleep(2) break except ValueError as var: print(var) if os.path.isfile("C:/Users/" + user_name + "/AppData/Local/Programs/Python/Python35-32/Lib/site-packages/colorama-0.3.3-py3.5.egg"): print(Fore.RED + "Unfortunately, save was unsuccessful!" + Style.RESET_ALL) else: print("Unfortunately, save was unsuccessful!") time.sleep(2) os.system('cls') ChangeClass.print_preprocessor_event(original,changed,header,which_result,-1) elif select == 4: break menu_number = ChangeClass.is_there_any_changes(original, changed, header, which_result, "Event")
def test_too_early(self): test_start_time = datetime.strptime("10:00", "%H:%M").time() test_end_time = datetime.strptime("10:59", "%H:%M").time() self.assertFalse( EventCalculations.end_time_after_start_time( test_end_time, test_start_time))
def test_success_text_four(self): self.assertEqual("Outstanding!", EventCalculations.success_text(110.1))
def test_success_text_three(self): self.assertEqual("Successful!", EventCalculations.success_text(75))
def test_success_text_two(self): self.assertEqual("Normal event.", EventCalculations.success_text(20))
def test_success_text_one(self): self.assertEqual("Unsuccessful, not worths to organise there again...", EventCalculations.success_text(19))
def test_success_rate_two(self): self.assertEqual(210, EventCalculations.success_rate("20", "42"))
def test_success_rate(self): self.assertEqual(40, EventCalculations.success_rate("100", "40"))
def test_time_to_datetime(self): test_time = datetime.strptime("10:00", "%H:%M").time() self.assertIsInstance(EventCalculations.time_to_datetime(test_time), datetime)
def test_duration_is_one_hour(self): test_start_time = datetime.strptime("10:00", "%H:%M").time() test_end_time = datetime.strptime("11:00", "%H:%M").time() self.assertEqual( timedelta(seconds=3600), EventCalculations.duration_in_time(test_start_time, test_end_time))
def test_duration_is_thirtyminutes(self): test_start_time = datetime.strptime("10:00", "%H:%M").time() test_end_time = datetime.strptime("10:30", "%H:%M").time() self.assertEqual( timedelta(seconds=1800), EventCalculations.duration_in_time(test_start_time, test_end_time))
def test_correct(self): test_start_time = datetime.strptime("10:00", "%H:%M").time() test_end_time = datetime.strptime("11:00", "%H:%M").time() self.assertTrue( EventCalculations.end_time_after_start_time( test_end_time, test_start_time))
def switcher(input_data, get_data): if get_data[0] == "Donor's name": if Validations.check_name(input_data): return NameFormat.name_corr_format(input_data) else: return False elif get_data[0] == "Birth date": if CheckDateFormat.check_date_format(input_data): input_data = donor_dates.get_date(input_data) input_data = Validations.validate_birthdate(input_data) return input_data else: return False elif get_data[0] == "Weight": return Validations.check_weight(input_data) elif get_data[0] == "Gender": return Validations.validate_gender(input_data) elif get_data[0] == "Unique ID": if Validations.check_uniqeid_exist(input_data): return Validations.validate_uniqeid(input_data) else: return False elif get_data[0] == "Expiration of ID": if CheckDateFormat.check_date_format(input_data): input_data = donor_dates.get_date(input_data) input_data = Validations.exp_uniqueid(input_data) return input_data else: return False elif get_data[0] == "Blood type": return Validations.blood_type_validation(input_data) elif get_data[0] == "Hemoglobin": return Validations.validate_hmg_from_keypad(input_data) elif get_data[0] == "Last donation date": if "never" in input_data.lower() or input_data.lower() == "n": return ["Never"] elif CheckDateFormat.check_date_format(input_data): input_data = donor_dates.get_date(input_data) input_data = Validations.last_donation_more_than_three_month_ago( input_data) return input_data else: return False elif get_data[0] == "Sickness": return Validations.check_arusicklastmonth(input_data) elif get_data[0] == "Mobile number": return Validations.validate_mobil_number(input_data) elif get_data[0] == "Email": return Validations.validate_email(input_data) elif get_data[0] == "Date of the event": if CheckDateFormat.check_date_format(input_data): input_data = donor_dates.get_date(input_data) if DateIsWeekday.is_date_weekday( input_data ) and DateTenDayBeforeEvent.is_date_ten_day_before_event( input_data): return input_data else: return False else: return False elif get_data[0] == "Start time": if CheckTimeFormat.check_time_form(input_data): return donor_dates.get_time(input_data) else: return False elif get_data[0] == "End time": if CheckTimeFormat.check_time_form(input_data): input_data = donor_dates.get_time(input_data) if EventCalculations.end_time_after_start_time( input_data, get_data[2]): return input_data else: return False else: return False elif get_data[0] == "City": if Address.validate_city(input_data): return NameFormat.name_corr_format(input_data) else: return False elif get_data[0] == "Zip code": return Address.check_zip_code(input_data) elif get_data[0] == "Available beds" or get_data[ 0] == "Planned donor number": return CheckIfPositiveInteger.check_if_positive_integer(input_data) elif get_data[0] == "Address": if Address.validate_address(input_data): return NameFormat.address_name_correct_form(input_data) else: return False