Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added more reports
  • Loading branch information
davorg committed Sep 9, 2014
1 parent 753b8c8 commit f3ddc6e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
42 changes: 40 additions & 2 deletions Kinza/lib/Kinza.pm
Expand Up @@ -165,8 +165,7 @@ get '/reports/form' => sub {
header 'Content-Disposition' => 'attachment; filename="form.csv"';

my $csv;
my $terms = join ',', map { $_->name }
schema->resultset('Term')->all;
my $terms = join ',', map { $_->name } $term_rs->all;

foreach my $y (schema->resultset('Year')->search({}, {
order_by => 'id',
Expand All @@ -191,6 +190,45 @@ get '/reports/form' => sub {
return $csv;
};

get '/reports/course' => sub {
content_type 'text/csv';
header 'Content-Disposition' => 'attachment; filename="course.csv"';

my $csv;

foreach my $p ($pres_rs->search({}, { order_by => 'id' })) {
$csv .= '"' . $p->course->title . '/' . $p->term->name . qq["\n];
foreach my $a ($p->attendances) {
$csv .= $a->student->name. "\n";
}
$csv .= "\n";
}

return $csv;
};

get '/reports/numbers' => sub {
content_type 'text/csv';
header 'Content-Disposition' => 'attachment; filename="numbers.csv"';

my $csv = "Course,T1,T2,T3,T4\n";
my @terms = $term_rs->all;

foreach my $c ($course_rs->search({}, { order_by => 'title' })) {
$csv .= '"' . $c->title . '"';
foreach my $t (@terms) {
if (my $p = $t->presentations->find({ course_id => $c->id })) {
$csv .= ',' . $p->attendances->count;
} else {
$csv .= ',';
}
}
$csv .= "\n";
}

return $csv;
};

get '/register' => sub {
if ($now le $live) {
return template 'comingsoon';
Expand Down
2 changes: 2 additions & 0 deletions Kinza/views/reports.tt
Expand Up @@ -2,4 +2,6 @@
<p>Select a report:</p>
<ul>
<li><a href="/reports/form">Student choices by form</a></li>
<li><a href="/reports/course">Lists of students by course and term</a></li>
<li><a href="/reports/numbers">Numbers of students per course and term</a></li>
</ul>

0 comments on commit f3ddc6e

Please sign in to comment.