From 6a361962cebc78e762e1259beb16c659a9654be3 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Mon, 12 Apr 2010 12:36:02 +0100 Subject: [PATCH] Refactor calc_reliability() down into Utils.pm, whence it is used by both full.mc and found.mc, and will in future be used by the record-commit rewriter --- lib/ZOOM/IRSpy/Utils.pm | 15 ++++++++++++++- web/htdocs/chrome/layout.mc | 2 +- web/htdocs/details/found.mc | 18 +----------------- web/htdocs/details/full.mc | 12 +++--------- 4 files changed, 19 insertions(+), 28 deletions(-) diff --git a/lib/ZOOM/IRSpy/Utils.pm b/lib/ZOOM/IRSpy/Utils.pm index 7853d20..9c5f951 100644 --- a/lib/ZOOM/IRSpy/Utils.pm +++ b/lib/ZOOM/IRSpy/Utils.pm @@ -18,7 +18,8 @@ our @EXPORT_OK = qw(utf8param irspy_identifier2target modify_xml_document bib1_access_point - render_record); + render_record + calc_reliability); use XML::LibXML; use XML::LibXML::XPathContext; @@ -770,4 +771,16 @@ sub render_record { } +sub calc_reliability { + my($xc) = @_; + + my @allpings = $xc->findnodes("i:status/i:probe"); + my $nall = @allpings; + return "[untested]" if $nall == 0; + my @okpings = $xc->findnodes('i:status/i:probe[@ok = "1"]'); + my $nok = @okpings; + return "$nok/$nall = " . int(100*$nok/$nall) . "%"; +} + + 1; diff --git a/web/htdocs/chrome/layout.mc b/web/htdocs/chrome/layout.mc index b99cb80..1471202 100644 --- a/web/htdocs/chrome/layout.mc +++ b/web/htdocs/chrome/layout.mc @@ -12,7 +12,7 @@ use ZOOM::IRSpy::Utils qw(utf8param isodate xml_encode cql_target cql_quote irspy_xpath_context irspy_make_identifier irspy_record2identifier irspy_identifier2target modify_xml_document - bib1_access_point); + bib1_access_point calc_reliability); % $r->content_type("text/html; charset=utf-8"); % my $text = $m->scomp($component, %ARGS); diff --git a/web/htdocs/details/found.mc b/web/htdocs/details/found.mc index 13143c6..8380171 100644 --- a/web/htdocs/details/found.mc +++ b/web/htdocs/details/found.mc @@ -19,22 +19,6 @@ sub navlink { return $url; } -# Identical to the same-named function in full.mc -# So maybe this should go into IRSpy::Utils.pm? -# Name changed (append 2) to prevent inadvertent clashes in Mason namespace -# -sub calc_reliability2 { - my($xc) = @_; - - my @allpings = $xc->findnodes("i:status/i:probe"); - my $nall = @allpings; - return "[untested]" if $nall == 0; - my @okpings = $xc->findnodes('i:status/i:probe[@ok = "1"]'); - my $nok = @okpings; - return "$nok/$nall = " . int(100*$nok/$nall) . "%"; -} - - # Just make this once; forge the connection on first use our $conn = undef; @@ -131,7 +115,7 @@ print_navlink(\%params, $last < $n, "Next", $skip+$count); <%perl> my $xc = irspy_xpath_context($rs->record($i-1)); my $title = $xc->find("e:databaseInfo/e:title") || "[UNTITLED]"; -my $reliability = calc_reliability2($xc); +my $reliability = calc_reliability($xc); my $host = $xc->find("e:serverInfo/e:host"); my $port = $xc->find("e:serverInfo/e:port"); my $db = $xc->find("e:serverInfo/e:database"); diff --git a/web/htdocs/details/full.mc b/web/htdocs/details/full.mc index abf5c01..4157b1f 100644 --- a/web/htdocs/details/full.mc +++ b/web/htdocs/details/full.mc @@ -41,7 +41,7 @@ if ($n == 0) { [ "Implementation ID" => "i:status/i:implementationId" ], [ "Implementation Name" => "i:status/i:implementationName" ], [ "Implementation Version" => "i:status/i:implementationVersion" ], - [ "Reliability/reliability" => \&calc_reliability, $xc ], + [ "Reliability/reliability" => \&calc_reliability_wrapper, $xc ], [ "Services" => \&calc_init_options, $xc ], [ "Bib-1 Use attributes" => \&calc_ap, $xc, "bib-1" ], [ "Dan-1 Use attributes" => \&calc_ap, $xc, "dan-1" ], @@ -95,15 +95,9 @@ if ($n == 0) { % } <%perl> -sub calc_reliability { +sub calc_reliability_wrapper { my($id, $xc) = @_; - - my @allpings = $xc->findnodes("i:status/i:probe"); - my $nall = @allpings; - return "[untested]" if $nall == 0; - my @okpings = $xc->findnodes('i:status/i:probe[@ok = "1"]'); - my $nok = @okpings; - return "$nok/$nall = " . int(100*$nok/$nall) . "%"; + return calc_reliability($xc); } sub calc_init_options { -- 1.7.10.4