forked from coreinfrastructure/best-practices-badge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compute-criteria-stats
executable file
·56 lines (50 loc) · 2.11 KB
/
compute-criteria-stats
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
#!/bin/sh
# Report the criteria that the most projects are missing
rails console <<CONSOLE_END
Rails.logger.level = :warn # Reduce log noise
def database_stats()
p = Project.order(:created_at).last
puts "Last project created: #{p.created_at} (project #{p.id})"
p = Project.order(:updated_at).last
puts "Last project update: #{p.updated_at} (project #{p.id})"
puts "Total number of projects = #{Project.count}"
puts "Total number of passing projects = #{Project.where('badge_percentage_0 >= 100').count}"
puts "Total number of 90%+ projects (INCLUDING 100%) = #{Project.where('badge_percentage_0 >= 100').count}"
end
# Print analysis for projects at least "min_percentage"
def analyze(min_percentage)
puts
puts "Reporting on projects #{min_percentage}% or better but NOT 100%."
results = []
# Show only "MUST" since those aren't easily justified. To show all, use:
# my_criteria = Project::ALL_CRITERIA_STATUS
my_criteria = Criteria['0'].select { |k,v| v.must? }
# puts my_criteria
my_criteria = my_criteria.map { |k,v| v.name.to_s + '_status' }
# puts my_criteria
project_count=Project.where("badge_percentage_0 >= #{min_percentage} AND badge_percentage_0 < 100").count
puts "Number of projects with minimum percentage = #{project_count}"
my_criteria.each do |criterion|
data=Project.where("badge_percentage_0 >= #{min_percentage} AND badge_percentage_0 < 100").select(criterion.to_s).group(criterion.to_s).unscope(:order).count
results.append([criterion.to_s, data.fetch('Met',0),
data.fetch('Unmet',0), data.fetch('?',0), data.fetch('N/A',0)])
end
# Sort by total "unmet+?", because "Met" and "N/A" are okay.
# Negate to reverse search ("largest first") - start with most unmet+?
results.sort! { |x,y| -(x[2]+x[3]) <=> -(y[2]+y[3]) }
puts 'criterion,Met,Unmet,?,N/A,Unmet+?'
results.each do |row|
totaluq=row[2].to_i+row[3].to_i # Unmet + ?
percentuq=(totaluq*100.0/project_count).round
print row.join(',')
print ",#{totaluq}"
print ",#{percentuq}%"
puts
end
nil # Don't return the results
end
database_stats()
analyze(90)
analyze(75)
puts 'Done.'
CONSOLE_END