Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Perl script for printing stats for a given e-grammateia lesson
#!/usr/bin/env perl
# 22-10-2011 - Periklis Master_ex Ntanasis <pntanasis@gmail.com>
#
# Usage: grammateia-stats.pl <link-to-e-grammateia-page-with-lesson's-grades>
#
use Encode;
$egrmmateiapage = $ARGV[0];
$page = `curl '$egrmmateiapage' | sed -n 486p`;
$page = decode('Windows-1253',$page);
#<tr height="25"><td valign="top"><span class="tablecell">3990143</span></td><td valign="top"><span class="tablebold">5</span></td><td class="tablecell" valign="top">ΣΕΠΤ</td></tr>
for($i=0;$i<=10;$i=$i+0.5) {
$grades{$i}=0;
$grades_sep{$i}=0;
$grades_fj{$i}=0;
}
$total=0;
$total_sep=0;
$total_fj=0;
$passed=0;
$passed_sep=0;
$passed_fj=0;
while ( $page =~ m~(\d{7})</span></td><td valign="top"><span class="\w+">(\d+(,\d+)?)</span></td><td class="tablecell" valign="top">(\w{4})~g) {
$grade = $2;
$grade =~ s/,/./;
$semester = encode('UTF-8',$4);
$total++;
$grades{$grade}++;
if ($grade >= 5.0) {
$passed++;
}
if ($semester eq "ΣΕΠΤ") {
$grades_sep{$grade}++;
$total_sep++;
if ($grade >= 5.0) {
$passed_sep++;
}
} else {
$grades_fj{$grade}++;
$total_fj++;
if ($grade >= 5.0) {
$passed_fj++;
}
}
}
if ($total == 0) {
print "There were no results available";
} else {
print "Results Overall\n";
print "Grade \t Total \t % \t %passed\n";
for($i=0;$i<=10;$i=$i+0.5) {
$res = ($grades{$i}/$total)*100;
if ($i >= 5.0) {
$pass = ($grades{$i}/$passed)*100;
printf("%.1f \t %s \t %.2f \t %.2f\n",$i,$grades{$i},$res,$pass);
} else {
printf("%.1f \t %s \t %.2f \t ----\n",$i,$grades{$i},$res);
}
}
print "Total: $total\n";
if ($total_fj != 0) {
print "Results (February or June)\n";
print "Grade \t Total \t % \t %passed\n";
for($i=0;$i<=10;$i=$i+0.5) {
$res = ($grades_fj{$i}/$total_fj)*100;
if ($i >= 5.0 && $passed_fj!=0) {
$pass = ($grades_fj{$i}/$passed_fj)*100;
printf("%.1f \t %s \t %.2f \t %.2f\n",$i,$grades_fj{$i},$res,$pass);
} else {
printf("%.1f \t %s \t %.2f \t ----\n",$i,$grades_fj{$i},$res);
}
}
print "Total: $total_fj\n";
}
if ($total_sep != 0) {
print "Results September\n";
print "Grade \t Total \t % \t %passed\n";
for($i=0;$i<=10;$i=$i+0.5) {
$res = ($grades_sep{$i}/$total_sep)*100;
if ($i >= 5.0 && $passed_sep!=0) {
$pass = ($grades_sep{$i}/$passed_sep)*100;
printf("%.1f \t %s \t %.2f \t %.2f\n",$i,$grades_sep{$i},$res,$pass);
} else {
printf("%.1f \t %s \t %.2f \t ----\n",$i,$grades_sep{$i},$res);
}
}
print "Total: $total_sep\n";
}
}
Results Overall
Grade Total % %passed
0.0 6 1.57 ----
0.5 0 0.00 ----
1.0 29 7.59 ----
1.5 16 4.19 ----
2.0 24 6.28 ----
2.5 28 7.33 ----
3.0 22 5.76 ----
3.5 17 4.45 ----
4.0 0 0.00 ----
4.5 0 0.00 ----
5.0 95 24.87 39.58
5.5 19 4.97 7.92
6.0 59 15.45 24.58
6.5 26 6.81 10.83
7.0 10 2.62 4.17
7.5 11 2.88 4.58
8.0 6 1.57 2.50
8.5 5 1.31 2.08
9.0 1 0.26 0.42
9.5 6 1.57 2.50
10.0 2 0.52 0.83
Total: 382
Results (February or June)
Grade Total % %passed
0.0 5 1.31 ----
0.5 0 0.00 ----
1.0 15 3.93 ----
1.5 16 4.19 ----
2.0 7 1.83 ----
2.5 28 7.33 ----
3.0 7 1.83 ----
3.5 17 4.45 ----
4.0 0 0.00 ----
4.5 0 0.00 ----
5.0 61 15.97 30.96
5.5 19 4.97 9.64
6.0 55 14.40 27.92
6.5 26 6.81 13.20
7.0 7 1.83 3.55
7.5 11 2.88 5.58
8.0 5 1.31 2.54
8.5 5 1.31 2.54
9.0 1 0.26 0.51
9.5 6 1.57 3.05
10.0 1 0.26 0.51
Total: 292
Results September
Grade Total % %passed
0.0 1 0.26 ----
0.5 0 0.00 ----
1.0 14 3.66 ----
1.5 0 0.00 ----
2.0 17 4.45 ----
2.5 0 0.00 ----
3.0 15 3.93 ----
3.5 0 0.00 ----
4.0 0 0.00 ----
4.5 0 0.00 ----
5.0 34 8.90 79.07
5.5 0 0.00 0.00
6.0 4 1.05 9.30
6.5 0 0.00 0.00
7.0 3 0.79 6.98
7.5 0 0.00 0.00
8.0 1 0.26 2.33
8.5 0 0.00 0.00
9.0 0 0.00 0.00
9.5 0 0.00 0.00
10.0 1 0.26 2.33
Total: 90
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.