diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-04-17 10:58:22 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-04-17 11:10:57 -0400 |
commit | bf2cb9784fe726b163667aaeab541cf7ae7f21a9 (patch) | |
tree | db3706dad0ccfc5ac4fbd43aa6241a689e8e3e96 /db-import-pick-mirror | |
parent | 03c3068761682bb1af9c615c91bc30da67fddf06 (diff) |
Give things more consistent names.
Diffstat (limited to 'db-import-pick-mirror')
-rwxr-xr-x | db-import-pick-mirror | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/db-import-pick-mirror b/db-import-pick-mirror new file mode 100755 index 0000000..4d01b95 --- /dev/null +++ b/db-import-pick-mirror @@ -0,0 +1,25 @@ +#!/usr/bin/env ruby + +require 'json' +require 'net/http' + +protocol = ARGV[0] +jsonurl = ARGV[1] + +data = JSON::parse(Net::HTTP.get(URI(jsonurl))) + +if data["version"] != 3 + print "Data format version != 3" + exit 1 +end + +# Filter out URLs with incomplete information +urls = data["urls"].select{|a| a.none?{|k,v|v.nil?}} +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"] |