Created
February 7, 2019 22:10
-
-
Save atandy/fb2ab705831245c7975d9c5a3eb9b088 to your computer and use it in GitHub Desktop.
Example of an estimation calculator for Transferwise transfers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calculate_delivery_estimate(todays_date, current_weekday): | |
'''Calculates a delivery estimate based on today's date and day of week''' | |
# average time in minutes that it took for a transfer complete | |
# when it was created on that day of the week | |
# this data only represents Payment Type A in a single currency_corridor. | |
# it also already has total transfer time delivery outliers removed. | |
weekday_delivery_avg_minutes = { | |
'Fri': 5677.73, | |
'Mon': 2918.34, | |
'Sat': 4619.68, | |
'Sun': 2963.84, | |
'Thu': 5355.96, | |
'Tue': 3050.19, | |
'Wed': 3401.28} | |
# convert a minute timestamp to number-of-days (use to produce estimate on front-end for user) | |
def minutes_to_day_converter(minutes): | |
return round(minutes/24/60, 1) | |
# hardcode some holidays as strings for demonstration | |
holidays = ['12/25/18', '01/21/18'] | |
# get the expected average from today's data | |
todays_average = weekday_averages[current_weekday] | |
# get the value in hours that would be displayed in UI | |
ui_hour_value = minutes_to_day_converter(todays_average) | |
# mostly for demonstrative purposes | |
def generate_ui_message(ui_hour_value, is_holiday=False): | |
'''Generates message for UI. If it is a holiday, use a custom note.''' | |
if is_holiday: | |
return "NOTE: It is currently a holiday and your transfer may take longer than usual.{}On non holidays, this transfer usually takes less than {} days" .format("\n", ui_hour_value) | |
return "Your transfer should arrive in less than {} days".format(ui_hour_value) | |
if not todays_date in holidays: | |
# can return basic message | |
print(generate_ui_message(ui_hour_value)) | |
else: | |
# today's date is in a holiday range. therefore return some message like "unable to give accurate estimate due to holidays" | |
print(generate_ui_message(ui_hour_value, is_holiday=True)) | |
# test output of function with some values: | |
calculate_delivery_estimate('12/25/18', 'Tue') | |
calculate_delivery_estimate('12/08/18', 'Sat') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment