]> matita.cs.unibo.it Git - helm.git/commitdiff
* added a few calculations
authorLuca Padovani <luca.padovani@unito.it>
Mon, 8 Nov 2004 22:07:09 +0000 (22:07 +0000)
committerLuca Padovani <luca.padovani@unito.it>
Mon, 8 Nov 2004 22:07:09 +0000 (22:07 +0000)
helm/papers/use_case/stats/stats.cc

index 9892e12b67948113de7f7d61c833a7accf89e194..85ef8ba0675c1aae4a0aa435aabbda4f32a36c90 100644 (file)
@@ -1,4 +1,5 @@
 
+#include <vector>
 #include <cassert>
 #include <GdomeSmartDOM.hh>
 
@@ -12,6 +13,8 @@ unsigned n_attributes;
 unsigned max_attributes;
 unsigned max_depth;
 unsigned max_children;
+std::vector<unsigned> depths;
+std::vector<unsigned> widths;
 
 bool
 is_blank(const std::string& s)
@@ -54,13 +57,33 @@ visit(DOM::Node node, unsigned depth)
       n_children++;
     }
   max_children = std::max(max_children, n_children);
+
+  if (!node.get_firstChild())
+    depths.push_back(depth);
+  else
+    widths.push_back(n_children);
 }
 
 void
 print_results(const std::string& URI)
 {
+  unsigned tot_depth = 0;
+  for (std::vector<unsigned>::const_iterator p = depths.begin(); p != depths.end(); p++)
+         tot_depth += *p;
+  
+  unsigned tot_width = 0;
+  for (std::vector<unsigned>::const_iterator p = widths.begin(); p != widths.end(); p++)
+         tot_width += *p;
+
   std::cout << "<stats for=\"" << URI << "\">" << std::endl;
-  std::cout << "  <depth>" << max_depth << "</depth>" << std::endl;
+  std::cout << "  <depth>" << std::endl;
+  std::cout << "    <max>" << max_depth << "</max>" << std::endl;
+  std::cout << "    <leaf-avg>" << tot_depth / ((double) depths.size()) << "</leaf-avg>" << std::endl;
+  std::cout << "  </depth>" << std::endl;
+  std::cout << "  <width>" << std::endl;
+  std::cout << "    <max>" << max_children << "</max>" << std::endl;
+  std::cout << "    <inner-avg>" << tot_width / ((double) widths.size()) << "</inner-avg>" << std::endl;
+  std::cout << "  </width>" << std::endl;  
   std::cout << "  <elements>" << std::endl;
   std::cout << "    <total>" << n_elements << "</total>" << std::endl;
   std::cout << "    <leaf>" << n_leaf_elements << "</leaf>" << std::endl;
@@ -73,15 +96,17 @@ print_results(const std::string& URI)
   std::cout << "    <total>" << n_attributes << "</total>" << std::endl;
   std::cout << "    <max>" << max_attributes << "</max>" << std::endl;
   std::cout << "  </attributes>" << std::endl;
-  std::cout << "  <children>" << std::endl;
-  std::cout << "    <max>" << max_children << "</max>" << std::endl;
-  std::cout << "  </children>" << std::endl;  
   std::cout << "</stats>" << std::endl;
 }
 
 int
 main(int argc, char* argv[])
 {
+  if (argc != 2) {
+    std::cerr << "Usage: stats <URI>" << std::endl;
+    return -1;
+  }
+
   DOM::DOMImplementation di;
   DOM::Document doc = di.createDocumentFromURI(argv[1]);
   visit(doc, 0);