Refactor calc_reliability() down into Utils.pm, whence it is used by both full.mc...
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Utils.pm
index 7853d20..9c5f951 100644 (file)
@@ -18,7 +18,8 @@ our @EXPORT_OK = qw(utf8param
                    irspy_identifier2target
                    modify_xml_document
                    bib1_access_point
                    irspy_identifier2target
                    modify_xml_document
                    bib1_access_point
-                   render_record);
+                   render_record
+                   calc_reliability);
 
 use XML::LibXML;
 use XML::LibXML::XPathContext;
 
 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;
 1;