Skip to content
Snippets Groups Projects
Commit 9521aba6 authored by wclo2's avatar wclo2
Browse files

check data format before writing to database

parent ccb2fb57
Branches local
No related tags found
No related merge requests found
......@@ -13,6 +13,8 @@ def handleCSV(filename):
i=0
for line in f:
i += 1
if i != 1 and i % 200 != 0:
continue
lineList = line.split(',')
if i==1:
keyList = lineList.copy()
......@@ -57,9 +59,15 @@ def add_records(frid, year, month, day, origin, dest, depart_time_actual, depart
r.depart_time_scheduled = convertTime(depart_time_scheduled)
r.arrival_time_actual = convertTime(arrival_time_actual)
r.arrival_time_scheduled = convertTime(arrival_time_scheduled)
if dep_delay == "":
dep_delay = "0.0"
r.dep_delay = float(dep_delay)
if arr_delay == "":
arr_delay = "0.0"
r.arr_delay = float(arr_delay)
r.airline = airline
if number == "":
number = "0"
r.number = int(number)
r.save()
return r
......@@ -86,6 +94,7 @@ def populate():
r["CRSDepTime"], r["ArrTime"], r["CRSArrTime"], r["DepDelay"], r["ArrDelay"],
r["UniqueCarrier"], r["FlightNum"])
frid += 1
print(frid)
add_set()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment