-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.py
79 lines (74 loc) · 2.58 KB
/
calc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from datetime import datetime
def add_fare(filename):
d = {}
with open (filename) as text:
line_number = 0
for line in text:
line = line.strip()
line = line.split(",")
if line[7].isalpha() or line[8].isalpha():
line_number += 1
pass
else:
total_fare = float(line[7]) + float(line[8])
total_fare = round(total_fare, 2)
d[line_number] = total_fare
line_number += 1
return d
def split_dates(filename):
d = {}
with open (filename) as text:
line_number = 0
for line in text:
line = line.strip()
line = line.split(",")
if line[7].isalpha() or line[8].isalpha():
line_number += 1
pass
else:
sep_date_times = line[3].split(" ")
d[line_number] = sep_date_times
line_number += 1
return d
def make_datetime(filename):
d = {}
with open (filename) as text:
line_number = 0
for line in text:
line = line.strip()
line = line.split(",")
if line[7].isalpha() or line[8].isalpha():
line_number += 1
pass
else:
date = datetime.strptime(line[3], '%m/%d/%y %H:%M')
d[line_number] = date
line_number += 1
return d
def convert_user_datetime(user_date):
date = datetime.strptime(user_date, '%m/%d/%y')
return date
def convert_user_datetime(user_date):
date = datetime.strptime(user_date, '%m/%d/%y')
return date
def rel_fares(filename, budget, num_people, origin, date):
d = {}
with open (filename) as text:
line_number = 1
for line in text:
line = line.strip()
line = line.split(",")
if line[0] == "BatchId":
continue
total_price = float(add_fare(filename)[line_number]) * float(num_people)
new_date = convert_user_datetime(date)
if total_price <= budget and line[1] == origin and convert_user_datetime(split_dates(filename)[line_number][0]) >= new_date:
d[line_number] = line[1:3] + split_dates(filename)[line_number] + [line[4]] + [add_fare(filename)[line_number]]
line_number += 1
else:
line_number += 1
return d
#print(add_fare("Deals.csv"))
print(rel_fares("Deals.csv", 400, 1, "FLL", "12/6/17"))
#print(make_datetime("Deals.csv"))
#print split_dates("Deals.csv")