update semantic markup, add publicbodies.org csv export
[disclosr.git] / admin / refreshDesignDoc.php
blob:a/admin/refreshDesignDoc.php -> blob:b/admin/refreshDesignDoc.php
--- a/admin/refreshDesignDoc.php
+++ b/admin/refreshDesignDoc.php
@@ -112,15 +112,25 @@
   }
 }";
 $obj->views->getStatistics->map = 
-"function(doc) {
-  if (doc.statistics) {
-	for (var statisticSet in doc.statistics)  {
-for (var statisticPeriod in doc.statistics[statisticSet])  {
-    emit([statisticSet,statisticPeriod], doc.statistics[statisticSet][statisticPeriod]['value']);
+"
+function (doc) {
+    if (doc.statistics) {
+        for (var statisticSet in doc.statistics) {
+            for (var statisticPeriod in doc.statistics[statisticSet]) {
+                if (doc.statistics[statisticSet][statisticPeriod]['value']) {
+                    emit([statisticSet, statisticPeriod], doc.statistics[statisticSet][statisticPeriod]['value']);
+                } else {
+                    for (var statisticSubSet in doc.statistics[statisticSet][statisticPeriod]) {
+                        if (statisticSubSet != 'source' && statisticSubSet != 'value') {
+                            emit([statisticSubSet, statisticPeriod], doc.statistics[statisticSet][statisticPeriod][statisticSubSet]);
+                        }
+                    }
+                }
+            }
+        }
+    }
 }
-}
-  }
-}";
+";
 $obj->views->getStatistics->reduce = '_sum';
 // http://stackoverflow.com/questions/646628/javascript-startswith
 $obj->views->score->map = 'if(!String.prototype.startsWith){