220 likes | 349 Views
Reports in a complex enviroment. IGELU 2012. Zurich - 12 September 2012. Zeno Tajoli – z.tajoli @ cineca.it. Main points. More Modules ? To use cron Retrieve from BIB Retrieve from ADM Display with Excel Util e and GUI. More Modules ?. The language used: perl 5.8.x
E N D
Reports in a complex enviroment IGELU 2012 Zurich - 12 September 2012 Zeno Tajoli – z.tajoli@ cineca.it 12.Sep.2012
Main points • More Modules ? • To use cron • Retrieve from BIB • Retrieve from ADM • Display with Excel • Util e and GUI 12.Sep.2012
More Modules ? • The language used: perl 5.8.x • Two perl on Aleph500: • OS perl • Perl installed with Aleph500 • You can use both • Perl installed with Aleph500 has more modules that SUN or RHEL perl 12.Sep.2012
More Modules ? • Useful extra modules: • Unicode::Lite • Convert::Translit • Sun solution: • Install a third perl (like /usr/local/bin/perl) • RHEL solution: • Add modules to OS perl with CPAN 12.Sep.2012
To use cron • Better to not repeat tasks • Cron is not the command line • Cron is a different enviroment • So you need to configure it to have the same results • Our solution [ crontab –l ] 12.Sep.2012
To use cron #List serials 34 10 31 12 * csh -c "/exlibris/aleph/list.csh" > /tmp/log18 -c [script] reads commands from the specified script file 12.Sep.2012
#!/bin/csh source /exlibris/aleph/.cshrc source /exlibris/aleph/a20_1/alephm/.cshrc source /exlibris/aleph/u20_1/alephe/aleph_start source $aleph_proc/def_local_env set user = aleph setenv LOGNAME aleph cd /exlibris/aleph/serials /exlibris/aleph/serials/list_serials.pl <params> 12.Sep.2012
Retrieve from BIB • Cataloguers have insert data in bib records instead of ADM records • Elaborate a bibliography • Extract with p-ret-01 and p-print-03 • Tuning tab expand • As format: “MARC with alphanumeric tags” • Do you need a fix routine ? • Or a character conversion ? 12.Sep.2012
use MARC::Batch; #Work one record at time my $batch = MARC::Batch->new( 'USMARC', $input_file ); $batch->warnings_off(); $batch->strict_off(); RECORD: while () { my $record; eval { $record = $batch->next() }; if ($@) { print ERRFILE "Bad MARC record " . $records_read . ": skipped.\n"; next; } last unless ($record); $records_read++; list_serials($record); } 12.Sep.2012
sub list_serials{ my $record = shift; my $tipo =''; my $ldr = $record->leader(); my $id = $record->field('001')->data(); eval{$tipo = $record->field('200')->subfield("b")->data()}; if ($@) {$tipo = ''}; my @arr958 = $record->field('958'); 12.Sep.2012
if ((substr($ldr,5,3) eq 'nas') and (length($tipo)< 1)){ my $presenza_subs = 0; foreach my $campo (@arr958){ my $dato = $campo->subfield('a'); if (length($dato)>1){ $dato = substr($dato,0,3); if (length($dato)>1){ $presenza_subs++; $dato =~ s/\://g; $dato =~ s/\s//g; my $i = $subs_presenti{$dato}; if ($i<1){ $subs_presenti{$dato} = 1; }else{ $i++; $subs_presenti{$dato}= $i; }; } } } if ($presenza_subs > 0){$contatore_serials_globale++} 12.Sep.2012
sub send_avviso{ use MIME::Lite; my $val_subject = $_[0]; my $val_body=$_[1]; my $msg=MIME::Lite->new( From=>'list_ser@opac.myuser.it', To=>‘mymail@cilea.it', Subject=>$val_subject, Type=>'multipart/mixed'); $msg->attach(Type=>'TEXT',Data=>$val_body); $msg->attach(Type=>'text/plain', Path=>"/exlibris/aleph/lista.dat", Filename=>"lista.dat", Disposition=>'attachment'); MIME::Lite->send('smtp', 'localhost', Timeout=>60); $msg->send; }; 12.Sep.2012
Retrieve from ADM • You retrieve data from Oracle • DBI, Unicode::Lite • Read the Oracle documentation from Doc Portal • Explore data with Oracle SQL Developer • Setup the oracle environment in the scripts 12.Sep.2012
Retrieve from ADM • A selection: $ENV{ORACLE_OWNER} = "oracle"; $ENV{ORACLE_VERSION} = "11"; $ENV{ORACLE_SID} = "aleph20"; $ENV{ORACLE_BASE} = "/exlibris/app/oracle"; $ENV{ORACLE_HOME} = "/exlibris/app/oracle/product/11"; $ENV{ORACLE_CONF} = "/exlibris/aleph/ora_aleph"; • Use printenv to see 12.Sep.2012
Retrieve from ADM • Order and group data with ORDER BY and GROUP BY $piano_sql = qq{ select z305_rec_key from xxx.z305}; $sel_ids = $lda->prepare($piano_sql); $main::sel_ids->execute(); my $ref_arr_ids = $sel_ids->fetchall_arrayref(); foreach my $row(@$ref_arr_ids){ my ($idz305) = @$row; 12.Sep.2012
select count(z35_rec_key), z35_sub_library from z35 where Z35_event_date like '2011%' and (z35_event_type = '71' OR z35_event_type = '71' OR z35_event_type = '72' OR z35_event_type = '73' OR z35_event_type = '74') group by z35_sub_library; 12.Sep.2012
select z36h_sub_library, count(z36h_rec_key) from z36h where z36h_item_status = '20' AND Z36h_LOAN_DATE between '20120101' and '20121231' group by z36h_sub_library select z36_status, count(z36_rec_key) from z36 where z36_sub_library = 'BF ' AND Z36_LOAN_DATE between '20120101' and '20121231' group by z36_status 12.Sep.2012
select z305_bor_status, count(z305_rec_key) from z305 where z305_rec_key like '%FIL ' group by z305_bor_status; • In a for cicle with all sublibraries • With a translation for bor status 12.Sep.2012
Display with Excel • SYmbolic LinK (SYLK) format • http://en.wikipedia.org/wiki/SYmbolic_LinK_(SYLK) • http://wiki.tcl.tk/9800 • http://netghost.narod.ru/gff/graphics/summary/micsylk.htm • It’s plain text • Quick and dirty 12.Sep.2012
Display with Excel • Column name with bold • Formatting values • Format dates • Excel and Calc (LibreOffice) • Selected ten years ago • Now better Open Document Format (XML) • http://standards.iso.org/ittf/PubliclyAvailableStandards/c043485_ISO_IEC_26300_2006(E).zip 12.Sep.2012
Util e and GUI • Util e 15 and 16 are like cron • Setup time and parameters • Open when Aleph is open # From p_custom_01 source $aleph_proc/def_local_env start_p_generic_proc /exlibris/aleph/repotes.pl echo "Fine lavori" exit: bl_end rm_f_symbol exit 12.Sep.2012
Util e and GUI • From Doc Portal: • How to make a home made custom service (19+) • How_to_add_additional_privileges_to_user_function_lng • You can use GUI to: • Send parameters • Send time • Use task Manager • Setup permission 12.Sep.2012