-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparseInput.py
More file actions
59 lines (38 loc) · 1.67 KB
/
parseInput.py
File metadata and controls
59 lines (38 loc) · 1.67 KB
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
# Takes in a string and returns the data represented by that string
def parseInput(file):
# Read header
video_count, endpoint_count, requests, cache_count, cache_size = split_line(file.readline())
# Dictionary to return
data = {'videos': [], 'endpoints': [], 'cache_size': int(cache_size), 'cache_count': int(cache_count)}
# Read the video sizes
video_sizes = split_line(file.readline())
# Sanity check size
if len(video_sizes) != int(video_count):
print("Header video count does not match read videos.")
data['videos'] = list(map(int, video_sizes))
for x in range(0, int(endpoint_count)):
data['endpoints'].append(read_endpoint(file))
for x in range(0, int(requests)):
read_request(file, data)
return data
def read_endpoint(file):
latency_to_dc, cache_count = split_line(file.readline())
data = {'latency_to_dc': int(latency_to_dc), 'latency_to_caches': {}, 'requests': {}}
for x in range(0, int(cache_count)):
cache_number, cache_latency = split_line(file.readline())
data['latency_to_caches'][int(cache_number)] = int(cache_latency)
return data
def read_request(file, data):
video, endpoint, count = split_line(file.readline())
endpoint_as_int = int(endpoint)
data['endpoints'][endpoint_as_int]['requests'][int(video)] = int(count)
def split_line(line):
return line.split(" ")
def getParsedInputs(files):
# Contains the input data as { fileName: data }
parsedInputs = {}
for fileName in files:
print("Parsing " + fileName)
file = open(fileName, "r")
parsedInputs[fileName.split(".")[0]] = parseInput(file)
return parsedInputs