statistics helper functions
statistics helper functions

--- a/ckanext/datagovau/plugin.py
+++ b/ckanext/datagovau/plugin.py
@@ -6,6 +6,9 @@
 import ckan.plugins.toolkit as tk
 import ckan.model as model
 from pylons import config
+
+from sqlalchemy import orm
+import ckan.model
 
 #parse the activity feed for last active non-system user
 def get_last_active_user(id):
@@ -25,6 +28,18 @@
     active_datasets_list = [x['data']['package'] for x in 
 				lib.helpers.get_action('user_activity_list',{'id':user_dict['id']}) if x['data'].get('package')]
     return created_datasets_list + active_datasets_list
+
+def get_dga_stats():
+	connection = model.Session.connection()
+        res = connection.execute("SELECT 'organization', count(*) from \"group\" where type = 'organization' and state = 'active' 		union select 'package', count(*) from package where state='active' or state='draft' or state='draft-complete' 		union select 'resource', count(*) from resource where state='active' 		union select name||role, 0 from user_object_role inner join \"user\" on user_object_role.user_id = \"user\".id where name not in ('logged_in','visitor') group by name,role;")
+        return res
+
+
+def get_activity_counts():
+	connection = model.Session.connection()
+        res = connection.execute("select to_char(timestamp, 'YYYY-MM') as month,activity_type, count(*) from activity group by month, activity_type order by month;").fetchall();
+        return res
+
 
 class DataGovAuPlugin(plugins.SingletonPlugin,
                                 tk.DefaultDatasetForm):
@@ -49,7 +64,7 @@
         # config['licenses_group_url'] = 'http://%(ckan.site_url)/licenses.json'
 
     def get_helpers(self):
-        return {'get_last_active_user': get_last_active_user, 'get_user_datasets': get_user_datasets}
+        return {'get_last_active_user': get_last_active_user, 'get_user_datasets': get_user_datasets, 'get_dga_stats': get_dga_stats, 'get_activity_counts': get_activity_counts}
 
     def is_fallback(self):
         # Return True to register this plugin as the default handler for

--- a/ckanext/datagovau/templates/package/read.rdf
+++ b/ckanext/datagovau/templates/package/read.rdf
@@ -23,28 +23,20 @@
         <dct:description>${c.pkg_dict['notes']}</dct:description>
         <dct:issued>${c.pkg_dict['metadata_created']}</dct:issued>
         <dct:modified>${c.pkg_dict['metadata_modified']}</dct:modified>
-        <dct:language>en</dct:language>
 
 <py:choose>
   <py:when test="c.pkg_dict.get('license_url',None)">
-        <dct:license>${c.pkg_dict['license_url']}</dct:license>
+        <dct:license rdf:resource="${c.pkg_dict['license_url']}"/>
         <dct:rights rdf:resource="${c.pkg_dict['license_url']}"/>
   </py:when>
   <py:otherwise>
         <dct:license>${c.pkg_dict['license_id']}</dct:license>
-        <dct:rights rdf:resource="${c.pkg_dict['license_id']}"/>
+        <dct:rights>"${c.pkg_dict['license_id']}"</dct:rights>
   </py:otherwise>
 </py:choose>
         <py:for each="tag_dict in c.pkg_dict.get('tags',[])">
             <dcat:keyword>${ tag_dict["name"] }</dcat:keyword>
         </py:for>
-        <py:for each="group_dict in c.pkg_dict.get('groups',[])">
-            <dcat:theme>${ group_dict["title"] }</dcat:theme>
-        </py:for>
-
-        <foaf:homepage
-                rdf:resource="${ h.url_for(controller='package',action='read',id=c.pkg_dict['name'], qualified=True)}"/>
-        <rdfs:label>${c.pkg_dict['name']}</rdfs:label>
 
 
         <py:for each="rsc_dict in c.pkg_dict['resources']">
@@ -69,6 +61,9 @@
                 </dcat:Distribution>
             </dcat:distribution>
         </py:for>
+
+
+<!-- data.gov.au specific stuff below this line -->
         <dct:publisher py:if="c.pkg_dict.get('organization', None)">
             <rdf:Description>
                 <foaf:name>${ c.pkg_dict['organization']['title'] }</foaf:name>
@@ -87,10 +82,26 @@
             </rdf:Description>
         </dct:contributor>
 
-
-        <foaf:homepage py:if="c.pkg_dict.get('url')">${c.pkg_dict.get('url')}</foaf:homepage>
+        <py:for each="extra_dict in c.pkg_dict.get('extras',[])">
+            <dct:relation>
+                <rdf:Description>
+                    <rdfs:label>${extra_dict.get('key','')}</rdfs:label>
+                    <rdf:value>${extra_dict.get('value','')}</rdf:value>
+                </rdf:Description>
+            </dct:relation>
+        </py:for>
+        <dct:language>en</dct:language>
+        <foaf:homepage
+                rdf:resource="${ h.url_for(controller='package',action='read',id=c.pkg_dict['name'], qualified=True)}"/>
         <dcat:contactPoint py:if="c.pkg_dict.get('contact_point')">${c.pkg_dict.contact_point }</dcat:contactPoint>
+<py:choose>
+  <py:when test="c.pkg_dict.get('spatial',None)">
+        <dct:spatial py:if="c.pkg_dict.get('spatial')">${ c.pkg_dict.spatial }</dct:spatial>
+  </py:when>
+  <py:otherwise>
         <dct:spatial py:if="c.pkg_dict.get('spatial_coverage')">${ c.pkg_dict.spatial_coverage }</dct:spatial>
+  </py:otherwise>
+</py:choose>
         <aglsterms:AglsJuri py:if="c.pkg_dict.get('jurisdiction')">${ c.pkg_dict.jurisdiction }</aglsterms:AglsJuri>
         <dct:temporal py:if="c.pkg_dict.get('temporal_coverage')">${ c.pkg_dict.get('temporal_coverage') }</dct:temporal>
         <dct:relation py:if="c.pkg_dict.get('data_state')">
@@ -117,14 +128,6 @@
                 <rdf:value>${ c.pkg_dict.get('granularity') }</rdf:value>
             </rdf:Description>
         </dct:relation>
-        <py:for each="extra_dict in c.pkg_dict.get('extras',[])">
-            <dct:relation>
-                <rdf:Description>
-                    <rdfs:label>${extra_dict.get('key','')}</rdfs:label>
-                    <rdf:value>${extra_dict.get('value','')}</rdf:value>
-                </rdf:Description>
-            </dct:relation>
-        </py:for>
     </dcat:Dataset>
 </rdf:RDF>