Talis transactions.pl

From Mosaic Project

Jump to: navigation, search

n.b. before using this code, please check the 'history' tab for this page to ensure that the code has not been tampered with!

Notes

usage: transactions.pl [year]



#!/usr/local/bin/perl

# Extract loan data for a give academic year
# for subsequent processing by Mosaic processing script
# Filename: transactions.pl
# Authors: Tim Graves & Chris Keene, University of Sussex
# Date: 12/06/09

$Database=prod_talis;
$TALIS_HOME=$ENV{"TALIS_HOME"};
require "sybperl.pl";
require "$TALIS_HOME/perl_tools/std_utils.pl";

$startYear = "2007";

if ($ARGV[0]) {
        $startYear = $ARGV[0];
}
$endYear = $startYear + 1;
$academicYearStart = "1 aug";
$academicYearEnd = "31 jul";
$outfile = "transactions." . $startYear . ".txt";


&Std_open_db(sa);

(@transactions) = &sql($d,"
select DATEDIFF(second,'1970-01-01',CREATE_DATE), BORROWER_ID, ITEM_ID
from LOAN
where STATE = 0
and CREATE_DATE >= '$academicYearStart $startYear'
and CREATE_DATE <= '$academicYearEnd $endYear'
        ");


#open file for output
open(OUTPUT,">$outfile") or die "can not open output\n";

foreach $line(@transactions) {
        ($create_date, $borrower_id, $item_id) = split('~', $line);
#        print OUTPUT "$create_date\t$borrower_id\t$item_id\n";
        print OUTPUT "$create_date\t$item_id\t$borrower_id\n";   # fix for Dave's "readme" cock up!
}
exit;



Personal tools