Created
February 21, 2018 00:06
-
-
Save KaroAntonio/34a0da1a54c31ba30bb857c6f4d9a95e to your computer and use it in GitHub Desktop.
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
# script to extract foodora payment info from a string | |
# assumes columns are organized as: | |
# Order Code / Date / Time / KMs / Tips / Zone / Corp Tips | |
# for testing | |
info = '''s5wd-i3oh 31/01/2018 18:32:00 1.84 2.91 Toronto - Center | |
s3dj-e0fm 31/01/2018 18:41:00 0.25 3.75 Toronto - Center | |
s4rh-j6dp 31/01/2018 19:03:00 1.54 3.80 Toronto - Center | |
s4hf-f7ar 31/01/2018 19:20:00 0.23 4.35 Toronto - Center | |
s4bo-z2sn 31/01/2018 19:30:00 1.42 2.70 Toronto - Center | |
s5dr-g4oc 31/01/2018 19:52:00 1.71 | |
- Toronto - Center | |
s5dr-g4oc 31/01/2018 19:52:00 1.71 Toronto - Center 2.09 | |
s7gv-s7rw 31/01/2018 20:06:00 2.04 | |
- Toronto - Center | |
s7gv-s7rw 31/01/2018 20:06:00 2.04 Toronto - Center 3.89''' | |
#info = raw_input('paste info: ') | |
def parse_info( info ): | |
area_delim = 'Toronto - Center' | |
info = info.replace ('Toronto - Center', '<AREA>') | |
area_info = info | |
info = info.replace('\n', ' ') | |
info = info.replace(' ', ' ') | |
info = info.split(' ') | |
for i,e in enumerate(info): | |
if '-' in e and len(e) == 9: info[i] = '<START>' | |
info = ' '.join(info) | |
start_info = info | |
info = info.split('<START>') | |
n_orders = 0 | |
tips = 0 | |
distance = 0 | |
order_mult = 4.5 | |
distance_mult = 1 | |
seen_datetimes = {} | |
for line in info: | |
if len(line) < 4: continue | |
#if '-' in items: continue | |
items = line.split(' ') | |
print(line) | |
print(items) | |
item_date = items[1] | |
item_time = items[2] | |
datetime = item_date + item_time | |
# n_orders | |
if datetime not in seen_datetimes: | |
seen_datetimes[datetime] = '' | |
n_orders += 1 | |
# tips | |
if 't' not in seen_datetimes[datetime] and items[4] not in ['-','<AREA>']: | |
seen_datetimes[datetime] += 't' | |
tips += float(items[4]) | |
# corp tips | |
area_idx = items.index('<AREA>') | |
if 'c' not in seen_datetimes[datetime] and len(items) > area_idx+1 and items[area_idx + 1] != '': | |
seen_datetimes[datetime] += 'c' | |
tips += float(items[area_idx + 1]) | |
# distance | |
distance += float(items[3] ) | |
print(' ') | |
print('n orders: {}'.format(n_orders)) | |
print('tips: {}'.format(tips)) | |
print('distance: {}'.format(distance)) | |
total = n_orders * order_mult + distance * distance_mult + tips | |
print('Total Income: {}'.format(total)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment