Nicely rendered BIB-1 table.
[irspy-moved-to-github.git] / web / htdocs / details / stats.mc
index fad2c11..0f26407 100644 (file)
@@ -1,4 +1,4 @@
-%# $Id: stats.mc,v 1.3 2006-12-15 14:37:03 mike Exp $
+%# $Id: stats.mc,v 1.4 2006-12-15 18:18:46 mike Exp $
 <%doc>
 Here are the headings in the Z-Spy version:
        The ten most commonly supported Bib-1 Use attributes
@@ -17,17 +17,73 @@ couched searchges, but it would still be necessary to trawl the
 records in order to find all the results, so we just take the path of
 least resistance and look at all the records by hand.
 </%doc>
+<%args>
+$query => undef
+</%args>
 <%perl>
-my $stats = $m->cache->get("stats");
+my $key = defined $query ? $query : "";
+my $from_cache = 1;
+my $stats = $m->cache->get($key);
 if (defined $stats) {
-    print "<h2>Reusing cached result</h2>\n";
-    print "stats=$stats\n";
 } else {
-    print "<h2>Recalculating stats</h2>\n";
-    $stats = new ZOOM::IRSpy::Stats("localhost:3313/IR-Explain---1");
-    $m->cache->set("stats", $stats, "1 minute");
+    $from_cache = 0;
+    $stats = new ZOOM::IRSpy::Stats("localhost:3313/IR-Explain---1", $query);
+    $m->cache->set($key, $stats, "1 minute");
 }
-print "<pre>";
-$stats->print();
-print "</pre>\n";
 </%perl>
+     <h2>Statistics for <% $stats->{conn}->option("host") %></h2>
+     <h3><% $stats->{n} %> targets analysed
+      <% defined $query ? "for '" . xml_encode($query) . "'" : "" %></h3>
+% if ($from_cache) {
+     <p>Reusing cached result</p>
+% } else {
+     <p>Recalculating stats</p>
+% }
+
+     <h3>Top 10 Bib-1 Attributes</h3>
+     <table border="1">
+      <tr>
+       <th>Attribute</th>
+       <th>Name</th>
+       <th># Db</th>
+      </tr>
+<%perl>
+my $hr;
+$hr = $stats->{bib1AccessPoints};
+foreach my $key ((sort { $hr->{$b} <=> $hr->{$a} 
+                        || $a <=> $b } keys %$hr)[0..9]) {
+</%perl>
+      <tr>
+       <td><% xml_encode($key) %></td>
+       <td><i>unknown</i></td>
+       <td><% xml_encode($hr->{$key}) . " (" .
+       100*$hr->{$key}/$stats->{n} . "%)" %></td>
+      </tr>
+% }
+</table>
+
+<%doc>
+    print "\nRECORD SYNTAXES\n";
+    $hr = $stats->{recordSyntaxes};
+    foreach my $key (sort { $hr->{$b} <=> $hr->{$a} 
+                           || $a cmp $b } keys %$hr) {
+       print sprintf("%-26s%5d (%d%%)\n",
+                     $key, $hr->{$key}, 100*$hr->{$key}/$stats->{n});
+    }
+
+    print "\nEXPLAIN SUPPORT\n";
+    $hr = $stats->{explain};
+    foreach my $key (sort { $hr->{$b} <=> $hr->{$a} 
+                           || $a cmp $b } keys %$hr) {
+       print sprintf("%-26s%5d (%d%%)\n",
+                     $key, $hr->{$key}, 100*$hr->{$key}/$stats->{n});
+    }
+
+    print "\nTOP-LEVEL DOMAINS\n";
+    $hr = $stats->{domains};
+    foreach my $key (sort { $hr->{$b} <=> $hr->{$a} 
+                           || $a cmp $b } keys %$hr) {
+       print sprintf("%-26s%5d (%d%%)\n",
+                     $key, $hr->{$key}, 100*$hr->{$key}/$stats->{n});
+    }
+</%doc>