read database name from config
[irspy-moved-to-github.git] / web / htdocs / details / stats.mc
1 %# $Id: stats.mc,v 1.9 2007-11-02 12:49:28 mike Exp $
2 <%doc>
3 Here are the headings in the Z-Spy version:
4         The ten most commonly supported Bib-1 Use attributes
5         Record syntax support by database
6         Explain support
7         Z39.50 Protocol Services Support
8         Z39.50 Server Atlas
9         Top Domains
10         Implementation
11 You can see his version live at
12         http://targettest.indexdata.com/stat.php
13 Or a static local copy at ../../../archive/stats.html
14
15 There may be way to generate some of this information by cleverly
16 couched searchges, but it would still be necessary to trawl the
17 records in order to find all the results, so we just take the path of
18 least resistance and look at all the records by hand.
19 </%doc>
20 <%args>
21 $query => undef
22 $reload => 0
23 </%args>
24 <%perl>
25 my $key = defined $query ? $query : "";
26 my $from_cache = 1;
27 my $stats = $m->cache->get($key);
28 if (!defined $stats || $reload) {
29     $from_cache = 0;
30     my $db = ZOOM::IRSpy::connect_to_registry();
31     $stats = new ZOOM::IRSpy::Stats($db, $query);
32     $m->cache->set($key, $stats, "1 day");
33 }
34 </%perl>
35      <h2>Statistics for <% xml_encode($stats->{host}) %></h2>
36      <h3><% $stats->{n} %> targets analysed
37       <% defined $query ? "for '" . xml_encode($query) . "'" : "" %></h3>
38 % if ($from_cache) {
39      <p>Reusing cached result</p>
40 % } else {
41      <p>Recalculating stats</p>
42 % }
43 <& table, stats => $stats, data => "bib1AccessPoints",
44         title => "The ten most commonly supported Bib-1 Use attributes",
45         headings => [ "Attribute", "Name"],
46         col3 => sub { bib1_access_point(@_) } &>
47 <& table, stats => $stats, data => "recordSyntaxes",
48         title => "Record syntax support by database",
49         headings => [ "Record Syntax"] &>
50 <& table, stats => $stats, data => "explain",
51         title => "Explain Support",
52         headings => [ "Explain Category"] &>
53 <& table, stats => $stats, data => "z3950_init_opt",
54         title => "Z39.50 Protocol Services Support",
55         headings => [ "Service"] &>
56 <& table, stats => $stats, data => "domains",
57         title => "Top Domains",
58         headings => [ "Top Domain"] &>
59 <& table, stats => $stats, data => "implementation",
60         title => "Implementation",
61         headings => [ "Name" ], maxrows => 20 &>
62 %#
63 %#
64 <%def table>
65 <%args>
66 $stats
67 $data
68 $title
69 $maxrows => 10
70 @headings
71 $col3 => undef
72 </%args>
73      <h3><% $title %></h3>
74      <table border="1">
75       <thead>
76        <tr>
77 % foreach my $heading ("#", @headings, "# Targets") {
78         <th><% xml_encode($heading) %></th>
79 % }
80        </tr>
81       </thead>
82       <tbody>
83 <%perl>
84 my $hr;
85 $hr = $stats->{$data};
86 my @sorted = sort { $hr->{$b} <=> $hr->{$a} || $a <=> $b } keys %$hr;
87 my $n = @sorted; $n = $maxrows if @sorted > 10;
88 foreach my $i (1..$n) {
89     my $key = $sorted[$i-1];
90 </%perl>
91       <tr>
92        <td><% $i %></td>
93        <td><% xml_encode(substr($key, 0, 54), "HUH?") %></td>
94 % if (defined $col3) {
95        <td><% xml_encode(&$col3($key), "HUH2?") %></td>
96 % }
97        <td><% xml_encode($hr->{$key}, "HUH3?") . " (" .
98         int(10000*$hr->{$key}/$stats->{n})/100 . "%)" %></td>
99       </tr>
100 % }
101       </tbody>
102      </table>
103 </%def>