summaryrefslogtreecommitdiff
path: root/db-pick-mirror
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-04-17 10:45:45 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-04-17 10:45:45 -0400
commita79d7c7251f4e6fd2f8b288b5c91a77a66ecff65 (patch)
treef44145d6cda8bb20070edf1ce464ad60b6bf3a04 /db-pick-mirror
parentf73a4a8844641b780644b8b96865372dc34936bd (diff)
parent752bd700e9da464006bfbd9877cc858dfad545ba (diff)
Merge branch 'lukeshu/xbs' into testmerge
# Conflicts: # test/lib/common.inc # test/test.d/create-filelists.sh # test/test.d/db-move.sh # test/test.d/db-remove.sh # test/test.d/db-repo-add.sh # test/test.d/db-repo-remove.sh # test/test.d/db-update.sh # test/test.d/ftpdir-cleanup.sh # test/test.d/sourceballs.sh
Diffstat (limited to 'db-pick-mirror')
-rwxr-xr-xdb-pick-mirror25
1 files changed, 25 insertions, 0 deletions
diff --git a/db-pick-mirror b/db-pick-mirror
new file mode 100755
index 0000000..4d01b95
--- /dev/null
+++ b/db-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"]