-
Notifications
You must be signed in to change notification settings - Fork 3
/
getnumberofenrollmentsforcourse.rb
52 lines (45 loc) · 1.24 KB
/
getnumberofenrollmentsforcourse.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
require 'canvas-api'
require_relative 'connection'
require_relative 'siktfunctions'
if(ARGV.size < 2)
dbg("Usage: ruby #{$0} prod/beta courseid]")
dbg("prod/beta angir om kommandoene skal kjøres mot henholdsvis #{$prod} eller #{$beta}")
dbg("Lister ut enrollments statistikk per dag for kurs med id courseid.")
dbg("Brukere med samme navn teller som en bruker.")
exit
end
dst = ARGV[0]
courseId = ARGV[1]
$canvas = getCanvasConnection(dst)
$uniqueNames = Hash.new
def processEnrollments(list)
list.each { |e|
name = e["user"]["name"];
if(!$uniqueNames.key?(name))
$uniqueNames[name] = 1
else
$uniqueNames[name] += 1
puts "Skip duplicate name: #{name}"
end
}
end
page = 1
puts "page #{page}"
list = getEnrollmentsForCourse(courseId)
processEnrollments(list)
page += 1
while list.more? do
puts "page #{page}"
list = list.next_page!
processEnrollments(list)
page += 1
end
uniqueNames = $uniqueNames.sort.to_h
uniqueNames.each {|k, v|
if(v > 1)
puts "Duplicate names\tNumber"
puts "#{k}\t#{v}"
end
}
noOfUniqueNames = $uniqueNames.count
puts "\nNo of unique names: #{noOfUniqueNames}"