Calculate BIB-1 use attributes.
[irspy-moved-to-github.git] / web / htdocs / details / full.mc
1 %# $Id: full.mc,v 1.8 2006-11-06 17:01:03 mike Exp $
2 <%args>
3 $id
4 </%args>
5 <%once>
6 use ZOOM;
7 </%once>
8 <%perl>
9 my $conn = new ZOOM::Connection("localhost:3313/IR-Explain---1");
10 $conn->option(elementSetName => "zeerex");
11 my $qid = $id;
12 $qid =~ s/"/\\"/g;
13 my $query = qq[rec.id="$qid"];
14 my $rs = $conn->search(new ZOOM::Query::CQL($query));
15 my $n = $rs->size();
16 if ($n == 0) {
17     $m->comp("/details/error.mc",
18              title => "Error", message => "No such ID '$id'");
19 } else {
20     my $rec = $rs->record(0);
21     my $xc = irspy_xpath_context($rec);
22     my @fields = (
23                   [ "Last Checked" => "i:status/i:probe[last()]" ],
24                   [ Protocol => "e:serverInfo/\@protocol" ],
25                   [ Host => "e:serverInfo/e:host" ],
26                   [ Port => "e:serverInfo/e:port" ],
27                   [ "Database Name" => "e:serverInfo/e:database" ],
28                   [ "Username (if needed)" =>
29                     "e:serverInfo/e:authentication/e:user" ],
30                   [ "Password (if needed)" =>
31                     "e:serverInfo/e:authentication/e:password" ],
32                   [ Title => "e:databaseInfo/e:title",
33                     lang => "en", primary => "true" ],
34                   [ Description => "e:databaseInfo/e:description",
35                     lang => "en", primary => "true" ],
36                   [ Author => "e:databaseInfo/e:author" ],
37                   [ Contact => "e:databaseInfo/e:contact" ],
38                   [ Extent => "e:databaseInfo/e:extent" ],
39                   [ History => "e:databaseInfo/e:history" ],
40                   [ "Language of Records" => "e:databaseInfo/e:langUsage" ],
41                   [ Restrictions => "e:databaseInfo/e:restrictions" ],
42                   [ Subjects => "e:databaseInfo/e:subjects" ],
43                   [ "Implementation ID" => "i:status/i:implementationId" ],
44                   [ "Implementation Name" => "i:status/i:implementationName" ],
45                   [ "Implementation Version" => "i:status/i:implementationVersion" ],
46                   [ "Reliability" => \&calc_reliability, $xc ],
47                   [ "Services" => sub { "### IRSpy does not yet check for search, present, delSet, concurrentOperations, namedResultSets, etc. and store the information is a usable form." } ],
48                   [ "Bib-1 Use attributes" => \&calc_bib1, $xc ],
49                   [ "Operators" => sub { "### and, or, not" } ],
50                   [ "Record syntaxes" => sub { "### SUTRS, USmarc, Danmarc" } ],
51                   [ "Explain" => sub { "### CategoryList, TargetInfo, DatabaseInfo, RecordSyntaxInfo, AttributeSetInfo, AttributeDetails" } ],
52                   );
53 </%perl>
54      <h2><% xml_encode($xc->find("e:databaseInfo/e:title")) %></h2>
55      <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
56 <%perl>
57     foreach my $ref (@fields) {
58         my($caption, $xpath, @args) = @$ref;
59         my $data;
60         if (ref $xpath && ref($xpath) eq "CODE") {
61             $data = &$xpath(@args);
62         } else {
63             $data = $xc->find($xpath);
64         }
65         if ($data) {
66 </%perl>
67       <tr>
68        <th><% xml_encode($caption) %></th>
69        <td><% xml_encode($data) %></td>
70       </tr>
71 %       }
72 %   }
73      </table>
74 % }
75 <%perl>
76
77 sub calc_reliability {
78     my($xc) = @_;
79
80     my @allpings = $xc->findnodes("i:status/i:probe");
81     my $nall = @allpings;
82     return "[untested]" if $nall == 0;
83     my @okpings = $xc->findnodes('i:status/i:probe[@ok = "1"]');
84     my $nok = @okpings;
85     return "$nok/$nall = " . int(100*$nok/$nall) . "%";
86 }
87
88 sub calc_bib1 {
89     my($xc) = @_;
90
91     my @bib1nodes = $xc->findnodes('e:indexInfo/e:index/e:map/e:attr[
92         @set = "bib-1" and @type = "1"]');
93     my $nbib1 = @bib1nodes;
94     return "[none]" if $nbib1 == 0;
95
96     my $res = "";
97     my($first, $last);
98     @bib1nodes = sort { $a->findvalue(".") <=> $b->findvalue(".") } @bib1nodes;
99     foreach my $node (@bib1nodes) {
100         my $ap .= $node->findvalue(".");
101         if (!defined $first) {
102             $first = $ap;
103         } elsif (!defined $last || $last == $ap-1) {
104             $last = $ap;
105         } else {
106             # Got a complete range
107             $res .= ", " if $res ne "";
108             $res .= "$first";
109             $res .= "-$last" if defined $last;
110             $first = $ap;
111             $last = undef;
112         }
113     }
114
115     # Leftovers
116     if (defined $first) {
117         $res .= ", " if $res ne "";
118         $res .= "$first";
119         $res .= "-$last" if defined $last;
120     }
121
122     return "$nbib1 access points: $res";
123 }
124
125 </%perl>