-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathupdated-authors.rb
executable file
·94 lines (80 loc) · 2.53 KB
/
updated-authors.rb
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env ruby
require 'yaml'
require 'cgi'
LANGUAGES = {
"cs" => "C#",
"fsharp" => "F#",
"javascript" => "JavaScript",
"rescript" => "ReScript",
"sqlite" => "SQLite",
"ts" => "TypeScript",
"php" => "PHP",
"ms-sql" => "MS SQL",
"r" => "R",
"asm_80x86" => "Assembler (x86)"
}.freeze
def language_label(key)
LANGUAGES.fetch(key, key.capitalize)
end
def authors
@authors ||= begin
YAML.load(IO.read('./authors.yml'), symbolize_names: true)
.fetch(:authors).sort_by { |a| a[:name] }
end
end
def profile(author)
"[%{name}](%{profile})" % author
end
def solutions(author)
groups = author.fetch(:solutions, [])
.group_by { |path| path.split('/')[1] }
.map { |k,v| [k, v.map {|p| {name: p.split("/").last, path: p} }]}
.sort_by { |k,_| k }
.freeze
render_groups(groups)
end
def render_groups(groups)
groups.map do |language, paths|
if paths.size == 1
"[%{language}](%{path})" % paths.first.merge!(language: language_label(language))
else
"%s:" % language_label(language) + " " + paths.map do |solution|
"[%{name}](%{path})" % solution
end.join(", ")
end
end.join(", ")
end
def render_chart(authors)
stats = authors.map {|a| a[:solutions].map {|s| s.split('/')[1] } }.flatten.tally
.map {|k,v| [language_label(k),v]}
.sort_by { |k,v| -v + k.to_i }
languages = stats.map(&:first).map {|l| CGI.escape(l) }.join("|")
sizes = stats.map(&:last).join(",")
"![Language / Solutions Breakdown](https://image-charts.com/chart?chs=500x500&chd=t:#{sizes}&cht=p3&chl=#{languages})"
end
def render(authors)
out = "## Authors\n\n"
out += "| Author | Solutions |\n"
out += "| --- | --- |\n"
authors.each do |author|
out += "|" + profile(author) + " | " + solutions(author) + "|\n"
end
out += "\n"
out += "## The Stats 📈\n"
out += "- The number of authors: #{authors.size}\n"
out += "- The number of solutions: #{authors.map { |a| a[:solutions] }.flatten.size}\n"
out += "- The number of programming languages: #{authors.map {|a| a[:solutions]}.flatten.map {|s| s.split('/')[1] }.uniq.size}\n"
out += "- The language / solutions breakdown: "
out += authors.map {|a| a[:solutions].map {|s| s.split('/')[1] } }.flatten.tally
.map {|k,v| [language_label(k),v]}
.sort_by { |k,v| -v + k.to_i }
.map { |k,v| "#{k}: #{v}"}
.join(", ")
out += "\n\n" + render_chart(authors)
out + "\n\n"
end
def replace_authors
readme_file = 'README.md'.freeze
File.read(readme_file).gsub!(/## Authors.*\z/m, render(authors))
end
puts replace_authors()