-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest.rb
More file actions
27 lines (23 loc) · 741 Bytes
/
Copy pathrequest.rb
File metadata and controls
27 lines (23 loc) · 741 Bytes
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
class Request
attr_accessor :input, :size, :video, :endpoint, :cached, :processed
def initialize(input, line)
@input = input
@video, @endpoint, @size = line.split(' ').map(&:to_i)
@video = input.videos[@video]
@endpoint = input.endpoints[@endpoint]
@cached = false
@processed = false
end
def best_score
cache_latency = endpoint.get_best_cache_latency(video)
saving = cache_latency > 0 ? endpoint.latency - cache_latency : 0
size * saving
end
def get_latency_saving
#return 0 unless cached
endpoint.latency - endpoint.get_best_video_latency(video)
end
def self.sort_by_something(requests)
requests.select { |v| v.processed == false }.sort_by { |v| -v.best_score }
end
end