summaryrefslogtreecommitdiff
path: root/extra/xbs-lukeshu/db-pick-mirror
diff options
context:
space:
mode:
Diffstat (limited to 'extra/xbs-lukeshu/db-pick-mirror')
-rwxr-xr-xextra/xbs-lukeshu/db-pick-mirror24
1 files changed, 24 insertions, 0 deletions
diff --git a/extra/xbs-lukeshu/db-pick-mirror b/extra/xbs-lukeshu/db-pick-mirror
new file mode 100755
index 0000000..9474ed7
--- /dev/null
+++ b/extra/xbs-lukeshu/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"]