-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathreport_projects_ranks.rb
90 lines (82 loc) · 2.36 KB
/
report_projects_ranks.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
require 'csv'
require 'pry'
require 'to_regexp'
require './comment'
def report_ranks(fin, fpstats, frep)
# Read list of projects to generate statistics for
# project
pstats = {}
CSV.foreach(fpstats, headers: true) do |row|
next if is_comment row
h = row.to_h
proj = h['project']
if pstats.key? proj
puts "Project #{proj} already present in projects statistics file"
return
end
pstats[proj] = true
end
# org,repo,activity,comments,prs,commits,issues,authors,project,url
res = {}
CSV.foreach(fin, headers: true) do |row|
next if is_comment row
h = row.to_h
proj = h['project']
if res.key? proj
puts "Project #{proj} already present in projects file"
return
end
res[proj] = h
end
# Generate list of projects
pstats = pstats.keys.sort
out = []
all_projs = res.keys.sort
pstats.each do |proj|
if proj[0] == '/'
puts "Matching regexp: #{proj.to_regexp}"
projs = all_projs.select { |p| p.match(proj.to_regexp) }
projs.each { |p| out << p }
next
end
unless res[proj]
puts "Project #{proj} not found, skipping stats"
next
end
out << proj
end
pstats = out.sort
puts "Generating statistics for projects: #{pstats.join(', ')}"
# Generate project rank statistics
props = nil
stats = {}
pstats.each do |proj|
obj = res[proj]
unless obj
puts "Project #{proj} not found, aborting stats"
return
end
props = obj.keys.select { |key| obj[key].to_i.to_s == obj[key].to_s } - %w(authors_alt1 authors_alt2) unless props
props.each do |prop|
stats[proj] = {} unless stats.key? proj
stats[proj][prop] = res.map { |k, v| [v[prop].to_i, v] }.sort_by { |r| -r[0] }.map.with_index { |r, i| [i + 1, r[1]['project'], r[1][prop]] }.select { |r| r[1] == proj }.first
# binding.pry if proj == 'Chromium' && prop == 'commits'
end
end
File.open(frep, 'w') do |rep|
stats.keys.sort.each do |proj|
rep.write("#{proj}:\n")
stats[proj].keys.sort.each do |prop|
v = stats[proj][prop]
rep.write("\t\##{v[0]} by #{prop} (#{v[2]})\n")
end
rep.write("\n")
end
end
puts "Statistics done."
end
if ARGV.size < 3
puts "Missing arguments: projects/unlimited_both.csv map/projects_statistics.csv projects/projects_ranks.txt"
exit(1)
end
report_ranks(ARGV[0], ARGV[1], ARGV[2])