-
Notifications
You must be signed in to change notification settings - Fork 2
/
input_parser.py
75 lines (57 loc) · 2.16 KB
/
input_parser.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
# ----- CLASSES
class Video:
def __init__(self, number, size):
self.number = number
self.size = size
def __repr__(self):
return "number: %s, size: %s" % (self.number, self.size)
class Endpoint:
def __init__(self, number, datacenter_latency):
self.number = number
self.datacenter_latency = datacenter_latency
self.caches = []
def __repr__(self):
return "number: %s, datacenter_latency: %s, caches: %s" % (self.number, self.datacenter_latency, self.caches)
class CacheConnection:
def __init__(self, cache_number, latency):
self.cache_number = cache_number
self.latency = latency
def __repr__(self):
return "cache_number: %s, latency: %s" % (self.cache_number, self.latency)
class Request:
def __init__(self, amount, to_video, from_endpoint):
self.amount = amount
self.to_video = to_video
self.from_endpoint = from_endpoint
def __repr__(self):
return "amount: %s, to_video: %s, from_endpoint: %s" % (self.amount, self.to_video, self.from_endpoint)
# -------------
class InputParser():
def parse(self):
# Getting how many things there are of each
self.n_videos, self.n_endpoints, self.n_requests, self.n_caches, self.size_caches = input().split(" ")
# Getting videos
self.video_sizes = input().split(" ")
self.videos = []
for video_number, video_size in enumerate(self.video_sizes):
self.videos.append(Video(video_number, video_size))
# Getting endpoints and connections to cache
self.endpoints = []
for i in range(int(self.n_endpoints)):
datacenter_latency, n_connected_caches = input().split(" ")
endpoint = Endpoint(i, datacenter_latency)
for j in range(int(n_connected_caches)):
cache_number, latency = input().split(" ")
endpoint.caches.append(CacheConnection(cache_number, latency))
self.endpoints.append(endpoint)
# Getting all requests
self.requests = []
for i in range(int(self.n_requests)):
video_number, endpoint_number, latency = input().split(" ")
self.requests.append(Request(latency, self.videos[int(video_number)], self.endpoints[int(endpoint_number)]))
print(self.videos, self.endpoints, self.requests)
def main():
parser = InputParser()
parser.parse()
if __name__ == '__main__':
main()