-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage_table.py
61 lines (52 loc) · 2.59 KB
/
package_table.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
# Author: Matthew Shelbourn | Student ID: 001059665 | mshelbo@wgu.edu | December, 2020
# package_table.py ingests the data from the 'WGUPS Package File' csv and
# enters data for each package into package hash table
import csv
from hash_table import HashTable
from distances import get_addresses
# Getter for package_table
# Space-time complexity O(N^2)
def get_package_table():
# Ingest package data from 'WGUPS Package File.csv'
with open('./data/wgups-package-data.csv') as csvfile:
package_csv = csv.reader(csvfile, delimiter=',')
package_table = HashTable() # Creates an instance of the hash table for packages to be entered into
addresses = get_addresses() # Assigning addresses to local variable
# Ingest package data from csv file and insert them into hash table as key/value pairs
# Key == package ID / Value == array containing package details
# Space complexity O(N), Time complexity O(N^2)
for row in package_csv:
package_id = row[0]
street = row[1]
city = row[2]
state = row[3]
zip = row[4]
deadline = row[5]
weight = row[6]
notes = row[7]
left_hub = ''
current_location = "Western Governors University"
delivery_time = ''
status = 'At the Hub'
assigned = False
package_key = int(package_id)
package_value = [package_id, street, city, state, zip, deadline, weight, notes, left_hub,
current_location, delivery_time, status, assigned]
# Adds each key/value pair to the package hash table
# Space-time complexity O(N) -- Since some rows in the table may contain nested lists that need to be
# iterated through, the space-time complexity for this operation is O(N), otherwise it would be O(1)
package_table.create(package_key, package_value)
# Iterates over packages and assigns a package address index based on the
# distance_addresses variable in distances.py
# This index will help to simplify distance calculations necessary in the program
# Space complexity O(N), Time complexity O(N^2)
for el in range(1, 41):
pkg = package_table.read(el)
address_index = ''
address = pkg[1]
for key, value in addresses.items():
if address in value['address']:
address_index = key
pkg.append(address_index)
package_table.update(el, pkg)
return package_table