summaryrefslogtreecommitdiff
path: root/extra/xbs-lukeshu/db-pick-mirror
blob: 9474ed7300cb823aa93565ec87039a56fa4ee80a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env ruby

require 'json'
require 'rest_client'

protocol = ARGV[0]
jsonurl = ARGV[1]

data = JSON::parse(RestClient.get(jsonurl))

if data["version"] != 3
	print "Data format version != 3"
	exit 1
end

urls = data["urls"]
rsync_urls = urls.select{|a| a["protocol"]==protocol}

# By score ( (delay+speed)/completion )
#best = rsync_urls.sort{|a,b| (a["score"] || Float::INFINITY) <=> (b["score"] || Float::INFINITY) }.first
# By delay/completion
best = rsync_urls.sort{|a,b| a["delay"]/a["completion_pct"] <=> b["delay"]/b["completion_pct"] }.first

puts best["url"]