Grades
view release on metacpan or search on metacpan
lib/Grades/Groupwork.pm view on Meta::CPAN
has 'classMax' => (is => 'ro', isa => 'Int', lazy => 1, required => 1,
default => sub { shift->league->yaml->{classMax} } );
=head3 beancanseries
The different beancans for each of the sessions in the series. In the directory for each session of the series, there is a file called beancans.yaml, containing mappings of a beancan name to a sequence of PlayerNames, the members of the beancan. If b...
=cut
has 'beancanseries' => ( is => 'ro', lazy_build => 1 );
method _build_beancanseries {
my $dir = $self->groupworkdirs;
my $series = $self->series;
my $league = $self->league->id;
my %beancans;
for my $round ( @$series ) {
my $beancanfile = "$dir/$round/beancans.yaml";
my $file = -e $beancanfile? $beancanfile: "$dir/$round/groups.yaml";
try { $beancans{$round} = $self->inspect( $file ) }
catch { local $" = ', ';
warn "Missing beancans in $league $dir round $round," };
}
return \%beancans;
}
=head3 beancans
A hashref of all the beancans in a given session with the names keying the ids of the members of each beancan. The number, composition and names of the beancans may change from one session of the series to the next.
Players in one beancan all get the same Groupwork grade for that session. The beancan members may be the same as the members of the class group, who work together in class, or may be individuals. Usually in a big class, the beancans will be the same ...
Players in the 'Absent' beancan all get a grade of 0 for the session.
Rather than refactor the class to work with individuals rather than groups, and expand some methods (?) to fall back to league members if it finds them in the weekly files instead of groups, I decided to introduce another file, beancans.yaml, and cha...
=cut
method beancans (Str $session) {
my $beancans = $self->beancanseries->{$session};
my $league = $self->league;
my %beancans = map { my $can = $_;
$can => { map { $_ => $league->ided( $_ ) }
@{$beancans->{$can}} } } keys %$beancans;
return \%beancans;
}
=head3 beancan_names
A hashref of all the beancans in a given session with the names of the members of each beancan.
=cut
method beancan_names (Str $session) { $self->beancanseries->{$session}; }
=head3 allfiles
The files (unsorted) containing classwork points (beans) awarded to beancans, of form, groupworkdir/\d+\.yaml$
=cut
has 'allfiles' => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1 );
method _build_allfiles {
my $dir = $self->groupworkdirs;
my $series = $self->series;
my $league = $self->league->id;
my $files = [ grep m|/(\d+)\.yaml$|, glob "$dir/*.yaml"];
croak "${league}'s @$series session files: @$files?" unless @$files;
return $files;
}
=head3 all_ided_files
The files containing classwork points (beans) awarded to beancans, of form, groupworkdir/\d+\.yaml$ keyed on the \d+.
=cut
has 'all_ided_files' => ( is => 'ro', isa => 'HashRef', lazy_build => 1 );
method _build_all_ided_files {
my $files = $self->allfiles;
my %files = map { m|/(\d+)\.yaml$|; $1 => $_ } @$files;
croak "No classwork files: $files?" unless %files;
return \%files;
}
=head3 all_events
The events (an array ref of integers) in which beans were awarded.
=cut
has 'all_events' => ( is => 'ro', isa => 'ArrayRef', lazy_build => 1 );
method _build_all_events {
my $files = $self->all_ided_files;
my @events = sort { $a <=> $b } keys %$files;
croak "No classwork weeks: @events" unless @events;
return \@events;
}
=head3 lastweek
The last week in which beans were awarded. TODO lexicographic order, not numerical order.
=cut
has 'lastweek' => ( is => 'ro', isa => 'Int', lazy_build => 1 );
method _build_lastweek {
my $weeks = $self->all_events;
max @$weeks;
}
=head3 data
The beans awarded to the beancans in the individual cards over the weeks of the series (semester.)
=cut
has 'data' => (is => 'ro', isa => 'HashRef', lazy_build => 1);
method _build_data {
my $files = $self->all_ided_files;
+{ map { $_ => $self->inspect( $files->{$_} ) } keys %$files };
}
=head3 card
Classwork beans for each beancan for the given week
=cut
method card (Num $week) {
my $card = $self->data->{$week};
croak "Week $week card probably has undefined or non-numeric Merit, Absence, Tardy scores, or possibly illegal beancan."
unless is_Card( $card );
return $card;
}
=head3 active
Given a session, returns the active beancans, ie all but the 'Absent' beancan.
=cut
method active (Str $session) {
my $beancans = $self->beancan_names($session);
my %active = %$beancans;
delete $active{Absent};
return \%active;
}
=head3 files
Given a session, returns the files containing beans awarded during the session according to the league.yaml session key. The files are of form, \d+\.yaml$
=cut
method files (Str $session) {
my $sessions = $self->league->session;
croak "No session $session.\n" unless defined $sessions->{$session};
my $firstweek = $sessions->{$session};
my $allfiles = $self->allfiles;
my @files;
if ( defined $sessions->{$session+1} ) {
my $nextfirstweek = $sessions->{$session+1};
my $lastweek = $nextfirstweek - 1;
if ( $lastweek >= $firstweek ) {
my $range = ( $firstweek .. $lastweek );
@files = grep { m/\/(\d+)*\.yaml/;
$1 >= $firstweek && $1 <= $lastweek } @$allfiles;
}
else {
croak "Following session starts in week $nextfirstweek, the same week as or earlier than the start of session $session, in week $firstweek\n"
}
}
else {
@files = grep { m/(\d+)*\.yaml/; $1 >= $firstweek } @$allfiles;
}
return \@files;
}
( run in 2.194 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )