[LON-CAPA-cvs] cvs: loncom /homework grades.pm /interface domainprefs.pm /lonnet/perl lonnet.pm
raeburn
raeburn at source.lon-capa.org
Mon Jan 28 16:37:04 EST 2019
raeburn Mon Jan 28 21:37:04 2019 EDT
Modified files:
/loncom/interface domainprefs.pm
/loncom/homework grades.pm
/loncom/lonnet/perl lonnet.pm
Log:
- Uploaded bubblesheet data can consist of comma separated values.
- Domain configuration for conversion of csv file to txt file:
(a) Delete first line (column titles) Y/N
(b) Remove leading white space except question responses Y/N
(c) Pad PaperID with leading zeroes, up to PaperIDlength Y/N
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.346 loncom/interface/domainprefs.pm:1.347
--- loncom/interface/domainprefs.pm:1.346 Sun Jan 27 14:39:48 2019
+++ loncom/interface/domainprefs.pm Mon Jan 28 21:36:45 2019
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.346 2019/01/27 14:39:48 raeburn Exp $
+# $Id: domainprefs.pm,v 1.347 2019/01/28 21:36:45 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -7996,14 +7996,24 @@
// <![CDATA[
function toggleScantron(form) {
+ var csvfieldset = new Array();
if (document.getElementById('scantroncsv_cols')) {
- var csvfieldset = document.getElementById('scantroncsv_cols');
+ csvfieldset.push(document.getElementById('scantroncsv_cols'));
+ }
+ if (document.getElementById('scantroncsv_options')) {
+ csvfieldset.push(document.getElementById('scantroncsv_options'));
+ }
+ if (csvfieldset.length) {
if (document.getElementById('scantronconfcsv')) {
- var scantroncsv = document.getElementById('scantronconfcsv');
+ var scantroncsv = document.getElementById('scantronconfcsv');
if (scantroncsv.checked) {
- csvfieldset.style.display = 'inline-block';
+ for (var i=0; i<csvfieldset.length; i++) {
+ csvfieldset[i].style.display = 'block';
+ }
} else {
- csvfieldset.style.display = 'none';
+ for (var i=0; i<csvfieldset.length; i++) {
+ csvfieldset[i].style.display = 'none';
+ }
var csvselects = document.getElementsByClassName('scantronconfig_csv');
if (csvselects.length) {
for (var j=0; j<csvselects.length; j++) {
@@ -8199,8 +8209,18 @@
my ($dom,$settings,$rowtotal) = @_;
my $itemcount = 2;
my $is_checked = ' checked="checked"';
+ my %optionson = (
+ hdr => ' checked="checked"',
+ pad => ' checked="checked"',
+ rem => ' checked="checked"',
+ );
+ my %optionsoff = (
+ hdr => '',
+ pad => '',
+ rem => '',
+ );
my $currcsvsty = 'none';
- my ($datatable,%csvfields,%checked,%onclick);
+ my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
my @fields = &scantroncsv_fields();
my %titles = &scantronconfig_titles();
if (ref($settings) eq 'HASH') {
@@ -8209,10 +8229,21 @@
$checked{'dat'} = $is_checked;
}
if (ref($settings->{config}->{csv}) eq 'HASH') {
- %csvfields = %{$settings->{config}->{csv}};
- if (keys(%csvfields) > 0) {
- $checked{'csv'} = $is_checked;
- $currcsvsty = 'inline-block';
+ if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
+ %csvfields = %{$settings->{config}->{csv}->{fields}};
+ if (keys(%csvfields) > 0) {
+ $checked{'csv'} = $is_checked;
+ $currcsvsty = 'block';
+ }
+ }
+ if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
+ %csvoptions = %{$settings->{config}->{csv}->{options}};
+ foreach my $option (keys(%optionson)) {
+ unless ($csvoptions{$option}) {
+ $optionsoff{$option} = $optionson{$option};
+ $optionson{$option} = '';
+ }
+ }
}
}
} else {
@@ -8229,7 +8260,7 @@
my $id;
if ($item eq 'csv') {
$id = 'id="scantronconfcsv" ';
- }
+ }
$datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
$titles{$item}.'</label>'.(' 'x3);
if ($item eq 'csv') {
@@ -8258,7 +8289,16 @@
}
$datatable .= '</select></td></tr>';
}
- $datatable .= '</table></fieldset>';
+ $datatable .= '</table></fieldset>'.
+ '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
+ '<legend>'.&mt('CSV Options').'</legend>';
+ foreach my $option ('hdr','pad','rem') {
+ $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
+ '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
+ &mt('Yes').'</label>'.(' 'x2)."\n".
+ '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
+ }
+ $datatable .= '</fieldset>';
$itemcount ++;
}
}
@@ -8271,6 +8311,9 @@
return &Apache::lonlocal::texthash(
dat => 'Standard format (.dat)',
csv => 'Comma separated values (.csv)',
+ hdr => 'Remove first line in file (contains column titles)',
+ pad => 'Prepend 0s to PaperID',
+ rem => 'Remove leading spaces (except Q columns)',
CODE => 'CODE',
ID => 'Student ID',
PaperID => 'Paper ID',
@@ -15137,18 +15180,20 @@
if ($env{'form.scantronformat_del'}) {
$confhash{'scantron'}{'scantronformat'} = '';
$changes{'scantronformat'} = 1;
+ } else {
+ $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
}
}
}
+ my @options = ('hdr','pad','rem');
my @fields = &scantroncsv_fields();
my %titles = &scantronconfig_titles();
- my @formats = &Apache::loncommon::get_env_multiple('form.scantronformat');
+ my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
my ($newdat,$currdat,%newcol,%currcol);
if (grep(/^dat$/, at formats)) {
$confhash{'scantron'}{config}{dat} = 1;
$newdat = 1;
} else {
- $confhash{'scantron'}{config}{dat} = 0;
$newdat = 0;
}
if (grep(/^csv$/, at formats)) {
@@ -15157,21 +15202,30 @@
if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
my $posscol = $1;
if (($posscol < 20) && (!$bynum{$posscol})) {
- $confhash{'scantron'}{config}{csv}{$field} = $posscol;
+ $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
$bynum{$posscol} = $field;
$newcol{$field} = $posscol;
}
}
}
+ if (keys(%newcol)) {
+ foreach my $option (@options) {
+ if ($env{'form.scantroncsv_'.$option}) {
+ $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
+ }
+ }
+ }
}
$currdat = 1;
if (ref($domconfig{'scantron'}) eq 'HASH') {
if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
- if (!$domconfig{'scantron'}{'config'}{'dat'}) {
+ unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
$currdat = 0;
}
if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
- %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}};
+ if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
+ %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
+ }
}
}
}
@@ -15183,7 +15237,7 @@
if ($currcol{$field} ne $newcol{$field}) {
$changes{'config'} = 1;
last;
- }
+ }
} elsif ($newcol{$field} ne '') {
$changes{'config'} = 1;
last;
@@ -15204,21 +15258,34 @@
$resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
}
}
- if ($changes{'config'}) {
+ if ($changes{'config'}) {
if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
if ($confhash{'scantron'}{'config'}{'dat'}) {
$resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
}
if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
- if (keys(%{$confhash{'scantron'}{'config'}{'csv'}})) {
- '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
- foreach my $field (@fields) {
- if ($confhash{'scantron'}{'config'}{'csv'}{$field} ne '') {
- my $showcol = $confhash{'scantron'}{'config'}{'csv'}{$field} + 1;
- $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
+ if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
+ if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
+ $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
+ foreach my $field (@fields) {
+ if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
+ my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
+ $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
+ }
+ }
+ $resulttext .= '</ul></li>';
+ if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
+ if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
+ $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
+ foreach my $option (@options) {
+ if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
+ $resulttext .= '<li>'.$titles{$option}.'</li>';
+ }
+ }
+ $resulttext .= '</ul></li>';
+ }
}
}
- $resulttext .= '</ul></li>';
}
}
} else {
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.755 loncom/homework/grades.pm:1.756
--- loncom/homework/grades.pm:1.755 Sun Jan 27 23:16:25 2019
+++ loncom/homework/grades.pm Mon Jan 28 21:36:53 2019
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.755 2019/01/27 23:16:25 raeburn Exp $
+# $Id: grades.pm,v 1.756 2019/01/28 21:36:53 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -5915,7 +5915,7 @@
return false;
}
formname.submit();
- }'.$formatjs));
+ }'."\n".$formatjs));
$r->print('
<form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
'.$default_form_data.'
@@ -9099,20 +9099,21 @@
if (keys(%{$domconfig{'scantron'}{'config'}}) > 1) {
if (($domconfig{'scantron'}{'config'}{'dat'}) &&
(ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH')) {
- if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}})) {
- my ($onclick,$formatextra,$singleline);
- my @lines = &Apache::lonnet::get_scantronformat_file();
- my $count = 0;
- foreach my $line (@lines) {
- next if ($line =~ /^#/);
- $singleline = $line;
- $count ++;
- }
- if ($count > 1) {
- $formatextra = '<div style="display:none" id="bubbletype">'.
- &scantron_scantab().'</div>';
- $onclick = ' onclick="toggleScantab(this.form);"';
- $formatjs = <<"END";
+ if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
+ if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}})) {
+ my ($onclick,$formatextra,$singleline);
+ my @lines = &Apache::lonnet::get_scantronformat_file();
+ my $count = 0;
+ foreach my $line (@lines) {
+ next if ($line =~ /^#/);
+ $singleline = $line;
+ $count ++;
+ }
+ if ($count > 1) {
+ $formatextra = '<div style="display:none" id="bubbletype">'.
+ &scantron_scantab().'</div>';
+ $onclick = ' onclick="toggleScantab(this.form);"';
+ $formatjs = <<"END";
function toggleScantab(form) {
var divid = 'bubbletype';
if (document.getElementById(divid)) {
@@ -9135,22 +9136,25 @@
}
END
- } elsif ($count == 1) {
- my $formatname = (split(/:/,$singleline,2))[0];
- $formatextra = '<input type="hidden" name="scantron_format" value="'.$formatname.'" />';
+ } elsif ($count == 1) {
+ my $formatname = (split(/:/,$singleline,2))[0];
+ $formatextra = '<input type="hidden" name="scantron_format" value="'.$formatname.'" />';
+ }
+ $formattitle = &mt('File format');
+ $formatoptions = '<label><input name="fileformat" type="radio" value="dat" checked="checked"'.$onclick.' />'.
+ &mt('Plain Text (no delimiters)').
+ '</label>'.(' 'x2).
+ '<label><input name="fileformat" type="radio" value="csv"'.$onclick.' />'.
+ &mt('Comma separated values').'</label>'.$formatextra;
}
- $formattitle = &mt('File format');
- $formatoptions = '<label><input name="fileformat" type="radio" value="dat" checked="checked"'.$onclick.' />'.
- &mt('Plain Text (no delimiters)').
- '</label>'.(' 'x2).
- '<label><input name="fileformat" type="radio" value="csv"'.$onclick.' />'.
- &mt('Comma separated values').'</label>'.$formatextra;
}
}
} elsif (keys(%{$domconfig{'scantron'}{'config'}}) == 1) {
- if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}})) {
- $formattitle = &mt('Format of bubblesheet data file:');
- $formatoptions = &scantron_scantab();
+ if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
+ if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}})) {
+ $formattitle = &mt('Format of bubblesheet data file:');
+ $formatoptions = &scantron_scantab();
+ }
}
}
}
@@ -9192,15 +9196,19 @@
if (@possibles > 1) {
if ($env{'form.fileformat'} eq 'csv') {
if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
- if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}}) > 1) {
- $is_csv = 1;
+ if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
+ if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}}) > 1) {
+ $is_csv = 1;
+ }
}
}
}
} elsif (@possibles == 1) {
if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
- if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}}) > 1) {
- $is_csv = 1;
+ if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
+ if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}}) > 1) {
+ $is_csv = 1;
+ }
}
}
}
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1403 loncom/lonnet/perl/lonnet.pm:1.1404
--- loncom/lonnet/perl/lonnet.pm:1.1403 Sun Jan 27 23:16:36 2019
+++ loncom/lonnet/perl/lonnet.pm Mon Jan 28 21:37:03 2019
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.1403 2019/01/27 23:16:36 raeburn Exp $
+# $Id: lonnet.pm,v 1.1404 2019/01/28 21:37:03 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -4361,7 +4361,13 @@
if ((&domain($cdom) ne '') &&
($fullpath =~ m{^\Q$perlvar{'lonDocRoot'}/userfiles/$cdom/\E$match_courseid/scantron_orig}) &&
(-e $fullpath) && (ref($config) eq 'HASH') && ($format ne '')) {
- my %csvcols = %{$config};
+ my (%csvcols,%csvoptions);
+ if (ref($config->{'fields'}) eq 'HASH') {
+ %csvcols = %{$config->{'fields'}};
+ }
+ if (ref($config->{'options'}) eq 'HASH') {
+ %csvoptions = %{$config->{'options'}};
+ }
my %csvbynum = reverse(%csvcols);
my %scantronconf = &get_scantron_config($format,$cdom);
if (keys(%scantronconf)) {
@@ -4397,7 +4403,10 @@
my %lettdig = &letter_to_digits();
my %diglett = reverse(%lettdig);
my $numletts = scalar(keys(%lettdig));
+ my $num = 0;
while (my $line=<$fh>) {
+ $num ++;
+ next if (($num == 1) && ($csvoptions{'hdr'} == 1));
$line =~ s{[\r\n]+$}{};
my %found;
my @values = split(/,/,$line);
@@ -4454,8 +4463,10 @@
$found{'FirstQuestion'} .= $values[$i];
}
} elsif (exists($csvbynum{$i})) {
- $values[$i] =~ s/^\s+//;
- if ($csvbynum{$i} eq 'PaperID') {
+ if ($csvoptions{'rem'}) {
+ $values[$i] =~ s/^\s+//;
+ }
+ if (($csvbynum{$i} eq 'PaperID') && ($csvoptions{'pad'})) {
while (length($values[$i]) < $scantronconf{$maplength{$csvbynum{$i}}}) {
$values[$i] = '0'.$values[$i];
}
More information about the LON-CAPA-cvs
mailing list