Skip to content

Commit

Permalink
Format undefined means with dash rather than zero
Browse files Browse the repository at this point in the history
This was a bug caught by `use warnings`.  If an answer was not selected
by anyone in the sample, the mean is undefined.  A line in the LaTeX
exporter was formatting this undef as a float (0.00).  A better choice
for that formatting is '---'.
  • Loading branch information
leingang committed Jan 7, 2019
1 parent ffe7ff8 commit 5676c2a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ Changed
Fixed
~~~~~

* Fixed a bug in LaTeX formatting that caused undefined averages to
be formatted as 0.00.

* Fixed a bug that caused free response problems with two-digit point
values to elude detection.

Expand Down
26 changes: 17 additions & 9 deletions lib/AMC/Export/ItemAnalysis_LaTeX.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ use strict;
use warnings;
use parent q(AMC::Export::ItemAnalysis);

use Data::Dumper;

=head1 METHOD
=head2 export
Expand Down Expand Up @@ -234,22 +236,28 @@ sub export {
my @answers = sort keys( %{ $q->{'responses'} } );

for my $k (@answers) {
$a = $q->{'responses'}->{$k};
my $answer = $q->{'responses'}->{$k};
if ( $row++ ) {
print $fh '\\\\', "\n", q(\\multicolumn{7}{c}{} & );
}
my $label = ( defined( $a->{'label'} ) ? $a->{'label'} : $k );
# print Dumper($answer);
my $label = ( defined( $answer->{'label'} ) ? $answer->{'label'} : $k );
print $fh $label, " & ";
print $fh sprintf( "%.2f", $a->{'weight'} ), " & ";
print $fh sprintf( "%.2f", $a->{'mean'} ), " & ";
print $fh $a->{'count'}, " & ";
print $fh sprintf( "%.2f", $answer->{'weight'} ), " & ";
my $answer_mean = (
defined($answer->{'mean'}) ?
sprintf( "%.2f", $answer->{'mean'} ) :
"{---}"
);
print $fh $answer_mean, " & ";
print $fh $answer->{'count'}, " & ";
print $fh
sprintf( "\\SI{%.2f}{\\percent}", $a->{'frequency'} * 100 ),
sprintf( "%.2f\\%%", $answer->{'frequency'} * 100 ),
" & ";
my $bar_key = $a->{'correct'} ? "correct" : "incorrect";
my $bar_key = $answer->{'correct'} ? "correct" : "incorrect";
print $fh
sprintf( "\\tikz{\\draw[bar,$bar_key] (0,0) rectangle (%.2f,1);}",
$a->{'frequency'} );
$answer->{'frequency'} );
}
print $fh '\\\\[\itemsep]', "\n";
}
Expand Down Expand Up @@ -316,7 +324,7 @@ sub export {

# print the scatterplot
print $fh q(
\section{Scatterplot}
\subsection{Scatterplot}
\begin{center}
\begin{tikzpicture}
Expand Down

0 comments on commit 5676c2a

Please sign in to comment.