Fix missing package definition
Fix missing package definition

file:b/.gitignore (new)
--- /dev/null
+++ b/.gitignore
@@ -1,1 +1,2 @@
+*.pyc
 

file:a/README.md -> file:b/README.md
--- a/README.md
+++ b/README.md
@@ -5,4 +5,5 @@
 * Remove private datasets from all statistics (except top users)
 * Add summary page
 * Add activity summary page
+* Add organisation public/private dataset count page
 

 Binary files a/ckanext/__init__.pyc and b/ckanext/__init__.pyc differ
 Binary files a/ckanext/dga_stats/__init__.pyc and b/ckanext/dga_stats/__init__.pyc differ
--- a/ckanext/dga_stats/controller.py
+++ b/ckanext/dga_stats/controller.py
@@ -16,6 +16,7 @@
         c.top_package_owners = stats.top_package_owners()
         c.summary_stats = stats.summary_stats()
         c.activity_counts = stats.activity_counts()
+        c.by_org = stats.by_org()
         c.new_packages_by_week = rev_stats.get_by_week('new_packages')
         c.deleted_packages_by_week = rev_stats.get_by_week('deleted_packages')
         c.num_packages_by_week = rev_stats.get_num_packages_by_week()

 Binary files a/ckanext/dga_stats/controller.pyc and b/ckanext/dga_stats/controller.pyc differ
 Binary files a/ckanext/dga_stats/plugin.pyc and b/ckanext/dga_stats/plugin.pyc differ
--- a/ckanext/dga_stats/stats.py
+++ b/ckanext/dga_stats/stats.py
@@ -42,7 +42,7 @@
         package_revision = table('package_revision')
         package = table('package')
         s = select([package_revision.c.id, func.count(package_revision.c.revision_id)], from_obj=[package_revision.join(package)]).\
-	      where(package.c.private == 'f').\
+	    where(package.c.private == 'f').\
             group_by(package_revision.c.id).\
             order_by(func.count(package_revision.c.revision_id).desc()).\
             limit(limit)
@@ -52,16 +52,28 @@
 
     @classmethod
     def largest_groups(cls, limit=10):
-        member = table('member')
-        package = table('package')
-        s = select([member.c.group_id, func.count(member.c.table_id)]).\
+         member = table('member')
+         s = select([member.c.group_id, func.count(member.c.table_id)]).\
             group_by(member.c.group_id).\
-            where(and_(member.c.group_id!=None, member.c.table_name=='package', package.c.private == 'f')).\
+            where(and_(member.c.group_id!=None, member.c.table_name=='package')).\
             order_by(func.count(member.c.table_id).desc()).\
             limit(limit)
 
+         res_ids = model.Session.execute(s).fetchall()
+         res_groups = [(model.Session.query(model.Group).get(unicode(group_id)), val) for group_id, val in res_ids]
+         return res_groups
+
+    @classmethod
+    def by_org(cls, limit=10):
+        group = table('group')
+        package = table('package')
+        s = select([group.c.id, package.c.private, func.count(package.c.private)]).\
+            group_by(group.c.id, package.c.private).\
+            order_by(group.c.id).\
+            limit(limit)
+
         res_ids = model.Session.execute(s).fetchall()
-        res_groups = [(model.Session.query(model.Group).get(unicode(group_id)), val) for group_id, val in res_ids]
+        res_groups = [(model.Session.query(model.Group).get(unicode(group_id)), private, val) for group_id, private, val in res_ids]
         return res_groups
 
     @classmethod
@@ -193,6 +205,7 @@
             # be 'for all time' else you get first revision in the time period.
             package_revision = table('package_revision')
             revision = table('revision')
+            package = table('package')
             s = select([package_revision.c.id, func.min(revision.c.timestamp)], from_obj=[package_revision.join(revision)]).\
 	      where(package.c.private == 'f').\
 	      group_by(package_revision.c.id).order_by(func.min(revision.c.timestamp))

 Binary files a/ckanext/dga_stats/stats.pyc and b/ckanext/dga_stats/stats.pyc differ
--- a/ckanext/dga_stats/templates/ckanext/stats/index.html
+++ b/ckanext/dga_stats/templates/ckanext/stats/index.html
@@ -163,7 +163,7 @@
               <th class="metric">{{ _('Number of datasets') }}</th>
             </tr>
           </thead>
-          <tbody>
+         <tbody>
             {% for group, num_packages in c.largest_groups %}
               <tr>
                 <td>{{ h.link_to(group.title or group.name, h.url_for(controller='group', action='read', id=group.name)) }}</td>
@@ -173,30 +173,7 @@
           </tbody>
         </table>
       {% else %}
-        <p class="empty">{{ _('No groups') }}</p>
-      {% endif %}
-    </section>
-    <section id="stats-largest-groups" class="module-content tab-content">
-      <h2>{{ _('Largest Groups') }}</h2>
-      {% if c.largest_groups %}
-        <table class="table table-chunky table-bordered table-striped">
-          <thead>
-            <tr>
-              <th>{{ _('Group') }}</th>
-              <th class="metric">{{ _('Number of datasets') }}</th>
-            </tr>
-          </thead>
-          <tbody>
-            {% for group, num_packages in c.largest_groups %}
-              <tr>
-                <td>{{ h.link_to(group.title or group.name, h.url_for(controller='group', action='read', id=group.name)) }}</td>
-                <td class="metric">{{ num_packages }}</td>
-              </tr>
-            {% endfor %}
-          </tbody>
-        </table>
-      {% else %}
-        <p class="empty">{{ _('No groups') }}</p>
+       <p class="empty">{{ _('No groups') }}</p>
       {% endif %}
     </section>
 
@@ -239,6 +216,36 @@
         </tbody>
       </table>
     </section>
+    <section id="stats-by-org" class="module-content tab-content">
+      <h2>{{ _('Datasets by Organization') }}</h2>
+      {% if c.by_org %}
+        <table class="table table-chunky table-bordered table-striped">
+          <thead>
+            <tr>
+              <th>{{ _('Group') }}</th>
+              <th>{{ _('Public/Archived') }}</th>
+              <th class="metric">{{ _('Number of datasets') }}</th>
+            </tr>
+          </thead>
+          <tbody>
+            {% for group,private, num_packages in c.by_org %}
+              <tr>
+                <td>{{ h.link_to(group.title or group.name, h.url_for(controller='organization', action='read', id=group.name)) }}</td>
+		{% if private == True %}
+	                <td>Archived</td>
+		{% else %}
+	                <td>Public</td>
+		{% endif %}
+                <td class="metric">{{ num_packages }}</td>
+              </tr>
+            {% endfor %}
+          </tbody>
+        </table>
+      {% else %}
+        <p class="empty">{{ _('No groups') }}</p>
+      {% endif %}
+    </section>
+
   </article>
 {% endblock %}
 
@@ -251,11 +258,11 @@
         <li class="nav-item"><a href="#activity-counts" data-toggle="tab">{{ _('Site Activity Log') }}</a></li>
         <li class="nav-item active"><a href="#stats-total-datasets" data-toggle="tab">{{ _('Total Number of Datasets') }}</a></li>
         <li class="nav-item"><a href="#stats-dataset-revisions" data-toggle="tab">{{ _('Dataset Revisions per Week') }}</a></li>
-        <li class="nav-item"><a href="#stats-top-rated" data-toggle="tab">{{ _('Top Rated Datasets') }}</a></li>
+<!--        <li class="nav-item"><a href="#stats-top-rated" data-toggle="tab">{{ _('Top Rated Datasets') }}</a></li> -->
         <li class="nav-item"><a href="#stats-most-edited" data-toggle="tab">{{ _('Most Edited Datasets') }}</a></li>
-        <li class="nav-item"><a href="#stats-largest-groups" data-toggle="tab">{{ _('Largest Groups') }}</a></li>
         <li class="nav-item"><a href="#stats-top-tags" data-toggle="tab">{{ _('Top Tags') }}</a></li>
         <li class="nav-item"><a href="#stats-most-owned" data-toggle="tab">{{ _('Users Owning Most Datasets') }}</a></li>
+        <li class="nav-item"><a href="#stats-by-org" data-toggle="tab">{{ _('Datasets by Organization') }}</a></li>
       </ul>
     </nav>
   </section>