diff options
Diffstat (limited to 'db-pick-mirror')
-rwxr-xr-x | db-pick-mirror | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/db-pick-mirror b/db-pick-mirror new file mode 100755 index 0000000..9474ed7 --- /dev/null +++ b/db-pick-mirror @@ -0,0 +1,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"] |