]> git.donarmstrong.com Git - bin.git/blob - gb_munger.pl
add reset usb bus command
[bin.git] / gb_munger.pl
1 #! /usr/bin/perl
2 # , and is released
3 # under the terms of the GPL version 2, or any later version, at your
4 # option. See the file README and COPYING for more information.
5 # Copyright 2006 by Don Armstrong <don@donarmstrong.com>.
6 # $Id: perl_script 495 2006-08-10 08:02:01Z don $
7
8
9 use warnings;
10 use strict;
11
12 use Getopt::Long;
13 use Pod::Usage;
14
15 =head1 NAME
16
17  - 
18
19 =head1 SYNOPSIS
20
21  [options]
22
23  Options:
24   --debug, -d debugging level (Default 0)
25   --help, -h display this help
26   --man, -m display manual
27
28 =head1 OPTIONS
29
30 =over
31
32 =item B<--debug, -d>
33
34 Debug verbosity. (Default 0)
35
36 =item B<--help, -h>
37
38 Display brief useage information.
39
40 =item B<--man, -m>
41
42 Display this manual.
43
44 =back
45
46 =head1 EXAMPLES
47
48
49 =cut
50
51
52 use vars qw($DEBUG);
53 use IO::File;
54
55 my %options = (debug           => 0,
56                help            => 0,
57                man             => 0,
58                multiplier      => 1,
59                add             => 0,
60               );
61
62 GetOptions(\%options,'debug|d+','help|h|?','man|m',
63            'gradebook=s','ilearn_gradebook|ilearn-gradebook=s',
64            'gradebook_column|gb-col=s','ilearn_column|il-col=s','multiplier|mul=s',
65            'add|addition=s',
66           );
67
68 pod2usage() if $options{help};
69 pod2usage({verbose=>2}) if $options{man};
70
71 $DEBUG = $options{debug};
72
73 # read in the gradebook
74
75 my $gb = new IO::File $options{gradebook},'r' or
76      die "Unable to open $options{gradebook} for reading: $!";
77
78 my %gb_students;
79 while (<$gb>) {
80      chomp;
81      next unless /^\d+/;
82      my ($num,$name,$id,@columns) = split /\t/;
83      next unless defined $name;
84      $id =~ s/[^\d]+//g;
85      die "No student id for $name at line $." if not length $id;
86      $gb_students{$id} = {name => $name,
87                           score => (defined $columns[$options{gradebook_column}] and length $columns[$options{gradebook_column}])?
88                              $columns[$options{gradebook_column}]*$options{multiplier}+$options{add}:$columns[$options{gradebook_column}],
89                          };
90 }
91
92 my $il = new IO::File $options{ilearn_gradebook},'r' or
93      die "Unable to open $options{ilearn_gradebook} for reading: $!";
94
95 while (<$il>) {
96      chomp;
97      my ($name,@columns) = split /\t/;
98      my ($id) = $name =~ /\|\s+(\d+)/;
99      print $_,qq(\n) and next if not defined $id;
100      next if not exists $gb_students{$id};
101      $columns[$options{ilearn_column}] = $gb_students{$id}{score} if
102         defined $gb_students{$id}{score} and length $gb_students{$id}{score};
103      print join("\t",$name,@columns),qq(\n);
104 }
105
106
107
108
109 __END__