-
-
Save bkleinen/d65078de2916c8e11a5b to your computer and use it in GitHub Desktop.
LSF Participant Extraction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# this scripts collects participant data from the "special info" list | |
# - mainly, it eliminates doublettes (students who have been rejected and applied again) | |
# and keeps only the most successful application | |
inputfile = ARGV[0] | |
outputfile = ARGV[1] | |
unless inputfile # && outputfile | |
puts "usage: tn.rb inputfile [outputfile]" | |
exit 1 | |
end | |
# some helper methods etc | |
Anmeldung = Struct.new(:matrikel, :studiengang, :nachname, :vorname, :status) | |
# 123456 - IMI (M) ( 920 ) Kleinen, Barbara AB | |
#1. 123456 | |
#2. IMI | |
#3. Kleinen | |
#4. Barbara | |
#5. AB | |
REGEX = /\s*(\d{3,6}) - (\w+)\s+\(M\)\s+\(.*\)\s+([\w,ä,ü,ö,é, ]+),\s+([\w,ä,ü,ö,é,-]+)\s+(\w+)/ | |
def split_line(line) | |
m = REGEX.match(line) | |
unless m | |
puts "could not match line #{line}" | |
exit 1 | |
end | |
Anmeldung.new(*m[1,5]) | |
end | |
# keep only the Listing with the highest precedence: | |
# ZU - Zugelassen (admitted) | |
# AN - Angemeldet (applied) | |
# AB - Abgelehnt - rejected | |
BIGGER = ['ZU','AN','AB'] | |
def bigger(s1,s2) | |
BIGGER.index(s1) < BIGGER.index(s2) | |
end | |
def add_anmeldung(h,anmeldung) | |
key = anmeldung.nachname | |
prev = h[key] | |
if (prev == nil) || bigger(anmeldung.status,prev.status) | |
h[key] = anmeldung | |
end | |
end | |
# actual script begins here | |
File.open(inputfile,'r') do | file| | |
h = {} | |
file.each_line do | line | | |
anmeldung = split_line(line) | |
add_anmeldung(h,anmeldung) | |
end | |
counts = Hash.new(0) | |
begin | |
if (outputfile) | |
out = File.open(outputfile,'w') | |
else | |
out = $stdout | |
end | |
h.keys.sort.each do | nachname | | |
a = h[nachname] | |
out.puts "#{a.status}, #{a.nachname}, #{a.vorname}, #{a.studiengang}, #{a.matrikel}" | |
counts[a.status] += 1 | |
counts['total'] += 1 | |
end | |
out.puts | |
out.puts counts.inspect | |
rescue | |
raise | |
ensure | |
out.close if outputfile | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment