Refactor
This commit is contained in:
parent
27a97b65b8
commit
260cd9a69a
46
input.py
46
input.py
|
@ -1,46 +0,0 @@
|
||||||
#!/usr/bin/python3
|
|
||||||
|
|
||||||
import sys
|
|
||||||
|
|
||||||
filename = sys.argv[1]
|
|
||||||
|
|
||||||
with open(filename) as file:
|
|
||||||
text = file.readlines()
|
|
||||||
|
|
||||||
tokenised = [line.strip().split() for line in text]
|
|
||||||
|
|
||||||
videoCount = int(tokenised[0][0])
|
|
||||||
endpointCount = int(tokenised[0][1])
|
|
||||||
requestDescriptionCount = int(tokenised[0][2])
|
|
||||||
cacheCount = int(tokenised[0][3])
|
|
||||||
cacheSize = int(tokenised[0][4])
|
|
||||||
|
|
||||||
videoSizes = [int(video) for video in tokenised[1]]
|
|
||||||
|
|
||||||
endpointDatacenterLatencies = []
|
|
||||||
endpointCacheLatencies = []
|
|
||||||
i = 2
|
|
||||||
for endpoint in range(0, endpointCount):
|
|
||||||
datacenterLatency = int(tokenised[endpoint + i][0])
|
|
||||||
endpointDatacenterLatencies.append(datacenterLatency)
|
|
||||||
|
|
||||||
endpointCacheLatencies.append({})
|
|
||||||
endpointCacheCount = int(tokenised[endpoint + i][1])
|
|
||||||
for cache in range(0, endpointCacheCount):
|
|
||||||
cacheId = int(tokenised[endpoint + 1 + cache + i][0])
|
|
||||||
cacheLatency = int(tokenised[endpoint + 1 + cache + i][1])
|
|
||||||
endpointCacheLatencies[endpoint][cacheId] = cacheLatency
|
|
||||||
i += endpointCacheCount
|
|
||||||
|
|
||||||
|
|
||||||
i += endpointCount
|
|
||||||
|
|
||||||
requestDescriptions = []
|
|
||||||
for video in range(0, videoCount):
|
|
||||||
requestDescriptions.append({})
|
|
||||||
|
|
||||||
for requestDescription in range(0, requestDescriptionCount):
|
|
||||||
video = int(tokenised[i + requestDescription][0])
|
|
||||||
endpoint = int(tokenised[i + requestDescription][1])
|
|
||||||
requestCount = int(tokenised[i + requestDescription][2])
|
|
||||||
requestDescriptions[video][endpoint] = requestCount
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def parseInput():
|
||||||
|
filename = sys.argv[1]
|
||||||
|
|
||||||
|
with open(filename) as file:
|
||||||
|
text = file.readlines()
|
||||||
|
|
||||||
|
tokenised = [line.strip().split() for line in text]
|
||||||
|
|
||||||
|
videoCount = int(tokenised[0][0])
|
||||||
|
endpointCount = int(tokenised[0][1])
|
||||||
|
requestDescriptionCount = int(tokenised[0][2])
|
||||||
|
cacheCount = int(tokenised[0][3])
|
||||||
|
cacheSize = int(tokenised[0][4])
|
||||||
|
|
||||||
|
videoSizes = [int(video) for video in tokenised[1]]
|
||||||
|
|
||||||
|
endpointDatacenterLatencies = []
|
||||||
|
endpointCacheLatencies = []
|
||||||
|
i = 2
|
||||||
|
for endpoint in range(0, endpointCount):
|
||||||
|
datacenterLatency = int(tokenised[endpoint + i][0])
|
||||||
|
endpointDatacenterLatencies.append(datacenterLatency)
|
||||||
|
|
||||||
|
endpointCacheLatencies.append({})
|
||||||
|
endpointCacheCount = int(tokenised[endpoint + i][1])
|
||||||
|
for cache in range(0, endpointCacheCount):
|
||||||
|
cacheId = int(tokenised[endpoint + 1 + cache + i][0])
|
||||||
|
cacheLatency = int(tokenised[endpoint + 1 + cache + i][1])
|
||||||
|
endpointCacheLatencies[endpoint][cacheId] = cacheLatency
|
||||||
|
i += endpointCacheCount
|
||||||
|
|
||||||
|
i += endpointCount
|
||||||
|
|
||||||
|
requestDescriptions = []
|
||||||
|
for video in range(0, videoCount):
|
||||||
|
requestDescriptions.append({})
|
||||||
|
|
||||||
|
for requestDescription in range(0, requestDescriptionCount):
|
||||||
|
video = int(tokenised[i + requestDescription][0])
|
||||||
|
endpoint = int(tokenised[i + requestDescription][1])
|
||||||
|
requestCount = int(tokenised[i + requestDescription][2])
|
||||||
|
requestDescriptions[video][endpoint] = requestCount
|
||||||
|
|
||||||
|
return videoCount, endpointCount, cacheCount, videoSizes, endpointDatacenterLatencies, endpointCacheLatencies, requestDescriptions
|
||||||
|
|
||||||
|
def main():
|
||||||
|
videoCount, endpointCount, cacheCount, videoSizes, endpointDatacenterLatencies, endpointCacheLatencies, requestDescriptions = parseInput()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
Reference in New Issue