forked from git/git-scm.com
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsort-gui
executable file
·64 lines (52 loc) · 2.28 KB
/
sort-gui
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env ruby
# frozen_string_literal: true
# This script helps to sort the git GUI clients listed on the website.
# We have been using Google Trends to help sorting the clients by popularity,
# unfortunatelly, at this moment, Google Trends doesn't provide an API.
# The solution is to generate Google Trends links to help sorting manually.
# For each generated Google Trends link, check if the clients are
# ordered by popularity. Rearrange the order if needed and iterate
# on this process until the order is fixed.
# The script also validates no duplicated clients exist in the listing.
require "yaml"
require "open-uri"
yaml = YAML.load_file("resources/guis.yml")
guis_info = yaml["guis"]
# Just checking duplicates because during manual sorting one may commit mistakes
if guis_info.map { |e| e["name"] }.uniq.length != guis_info.length
puts "\n======= WARNING: THERE ARE DUPLICATED GUIS ======="
end
# Just checking if there are repeated 'order' values
orders = guis_info.map { |e| e["order"] }
duplicated_order = orders.detect { |e| orders.count(e) > 1 }
if duplicated_order
puts "\n======= WARNING: THERE ARE DUPLICATED ORDERS (value: #{duplicated_order}) ======="
end
puts "\n=== GUIs (#{guis_info.size}) ==="
puts guis_info
encoded = guis_info.sort_by { |g| g["order"] }.map do |g|
key = g.key?("trend_name") ? g["trend_name"] : g["name"]
URI::encode(key)
end
# Google trends currently one allows up to 5 terms in the comparison
# For comparison we are using 'windows' of 5 elements, where the first element
# of a window, is the last element of the previous window, so that new elements
# can be compared with the previous window
minIndex = 0
maxIndex = 4
# trend_groups is an array of pairs (abstracted as an array of size 2),
# containing the min and max GUI index for the current iteration
trend_groups = []
last_idx = encoded.size - 1
while minIndex < last_idx do
trend_groups.push([minIndex, [maxIndex, last_idx].min])
minIndex += 4
maxIndex += 4
end
# For each pair of indexes we fetch the GUI window and create the Google Trend URL
trend_urls = trend_groups.map do |min_max|
terms = (min_max[0]..min_max[1]).map { |idx| encoded[idx] }
"https://trends.google.pt/trends/explore?cat=31&q=#{terms.join(",")}&hl=en_us"
end
puts "\n=== Trends URLs (#{trend_urls.size}) ==="
puts trend_urls