[ckan-changes] [okfn/ckan] 591f87: tracking_summary added to package_dictize
GitHub
noreply at github.com
Fri Apr 20 09:39:29 UTC 2012
Branch: refs/heads/enhancement-2251-tracking
Home: https://github.com/okfn/ckan
Commit: 591f878b90000f5d293525d811127e3e9bb55d9c
https://github.com/okfn/ckan/commit/591f878b90000f5d293525d811127e3e9bb55d9c
Author: Toby <toby.junk at gmail.com>
Date: 2012-04-20 (Fri, 20 Apr 2012)
Changed paths:
M ckan/lib/dictization/model_dictize.py
Log Message:
-----------
tracking_summary added to package_dictize
diff --git a/ckan/lib/dictization/model_dictize.py b/ckan/lib/dictization/model_dictize.py
index d0e7d6c..fbe6890 100644
--- a/ckan/lib/dictization/model_dictize.py
+++ b/ckan/lib/dictization/model_dictize.py
@@ -43,6 +43,11 @@ def resource_list_dictize(res_list, context):
resource_dict = resource_dictize(res, context)
if active and res.state not in ('active', 'pending'):
continue
+ #tracking
+ model = context['model']
+ tracking = model.TrackingSummary.get_for_resource(res.url)
+ resource_dict['tracking_summary'] = tracking
+
result_list.append(resource_dict)
return sorted(result_list, key=lambda x: x["position"])
@@ -166,6 +171,9 @@ def package_dictize(pkg, context):
q = select([extra_rev]).where(extra_rev.c.package_id == pkg.id)
result = _execute_with_revision(q, extra_rev, context)
result_dict["extras"] = extras_list_dictize(result, context)
+ #tracking
+ tracking = model.TrackingSummary.get_for_package(pkg.id)
+ result_dict['tracking_summary'] = tracking
#groups
member_rev = model.member_revision_table
group = model.group_table
================================================================
Commit: 36dec32b4f75f9b910bb7c1eb527118dbe8cb487
https://github.com/okfn/ckan/commit/36dec32b4f75f9b910bb7c1eb527118dbe8cb487
Author: Toby <toby.junk at gmail.com>
Date: 2012-04-20 (Fri, 20 Apr 2012)
Changed paths:
A ckan/migration/versions/054_tracking.py
M ckan/model/__init__.py
A ckan/model/tracking.py
Log Message:
-----------
add tracking tables
diff --git a/ckan/migration/versions/054_tracking.py b/ckan/migration/versions/054_tracking.py
new file mode 100644
index 0000000..edb60cd
--- /dev/null
+++ b/ckan/migration/versions/054_tracking.py
@@ -0,0 +1,29 @@
+from sqlalchemy import *
+from migrate import *
+
+def upgrade(migrate_engine):
+ migrate_engine.execute('''
+ BEGIN;
+ CREATE TABLE tracking_raw (
+ user_key character varying(100) NOT NULL,
+ url text NOT NULL,
+ tracking_type character varying(10) NOT NULL,
+ access_timestamp timestamp without time zone DEFAULT current_timestamp
+ );
+
+ CREATE TABLE tracking_summary(
+ url text NOT NULL,
+ package_id text,
+ tracking_type character varying(10) NOT NULL,
+ count int NOT NULL,
+ running_total int NOT NULL DEFAULT 0,
+ date date
+ );
+
+ CREATE INDEX tracking_summary_url ON tracking_summary(url);
+ CREATE INDEX tracking_summary_package_id ON tracking_summary(package_id);
+ CREATE INDEX tracking_summary_date ON tracking_summary(date);
+
+ COMMIT;
+ '''
+ )
diff --git a/ckan/model/__init__.py b/ckan/model/__init__.py
index df0d2f5..1a59fe5 100644
--- a/ckan/model/__init__.py
+++ b/ckan/model/__init__.py
@@ -22,6 +22,7 @@
from authz import *
from package_extra import *
from resource import *
+from tracking import *
from rating import *
from package_relationship import *
from task_status import *
diff --git a/ckan/model/tracking.py b/ckan/model/tracking.py
new file mode 100644
index 0000000..c138271
--- /dev/null
+++ b/ckan/model/tracking.py
@@ -0,0 +1,36 @@
+from meta import *
+from domain_object import DomainObject
+
+tracking_summary_table = Table('tracking_summary', metadata,
+ Column('url', UnicodeText, primary_key=True, nullable=False),
+ Column('package_id', UnicodeText),
+ Column('tracking_type', Unicode(10), nullable=False),
+ Column('count', Integer, nullable=False),
+ Column('running_total', Integer, nullable=False),
+ Column('date', DateTime),
+ )
+
+class TrackingSummary(DomainObject):
+
+ @classmethod
+ def get_for_package(cls, package_id):
+ obj = Session.query(cls).autoflush(False)
+ data = obj.filter_by(package_id=package_id).first()
+ if data:
+ return {'total' : data.running_total,
+ 'recent': 7,}#data.recent}
+
+ return {'total' : 0, 'recent' : 0}
+
+
+ @classmethod
+ def get_for_resource(cls, url):
+ obj = Session.query(cls).autoflush(False)
+ data = obj.filter_by(url=url).first()
+ if data:
+ return {'total' : data.running_total,
+ 'recent': 7,}#data.recent}
+
+ return {'total' : 0, 'recent' : 0}
+
+mapper(TrackingSummary, tracking_summary_table)
================================================================
Commit: c4d03312c8771886ad98541bdad3adb6186b6a22
https://github.com/okfn/ckan/commit/c4d03312c8771886ad98541bdad3adb6186b6a22
Author: Toby <toby.junk at gmail.com>
Date: 2012-04-20 (Fri, 20 Apr 2012)
Changed paths:
M ckan/lib/search/index.py
Log Message:
-----------
better indexing of tracking stats
diff --git a/ckan/lib/search/index.py b/ckan/lib/search/index.py
index 4768dcd..600901c 100644
--- a/ckan/lib/search/index.py
+++ b/ckan/lib/search/index.py
@@ -132,17 +132,10 @@ def index_package(self, pkg_dict):
pkg_dict['groups'] = [group['name'] for group in groups]
- # views
- import ckan.model as model
- sql = '''SELECT running_total
- FROM tracking_summary
- WHERE package_id='%s'
- ORDER BY date DESC LIMIT 1''' % pkg_dict['id']
- result = model.Session.execute(sql).fetchall()
- if result:
- pkg_dict['views'] = result[0]['running_total']
- else:
- pkg_dict['views'] = 0
+ # tracking
+ tracking_summary = pkg_dict.pop('tracking_summary', None)
+ if tracking_summary:
+ pkg_dict['views'] = tracking_summary['total']
# flatten the structure for indexing:
for resource in pkg_dict.get('resources', []):
================================================================
Commit: a411e22fff19def7ab10417fa35d34986f27d185
https://github.com/okfn/ckan/commit/a411e22fff19def7ab10417fa35d34986f27d185
Author: Toby <toby.junk at gmail.com>
Date: 2012-04-20 (Fri, 20 Apr 2012)
Changed paths:
M ckan/templates/package/layout.html
M ckan/templates/package/read.html
Log Message:
-----------
clean testing from templates
diff --git a/ckan/templates/package/layout.html b/ckan/templates/package/layout.html
index e3c2e30..736f6d7 100644
--- a/ckan/templates/package/layout.html
+++ b/ckan/templates/package/layout.html
@@ -27,7 +27,7 @@
<hr py:if="len(c.pkg_dict.get('resources',[]))>0"/>
</li>
<li py:for="res in c.pkg_dict.get('resources', [])">
- <a href="${h.url_for(controller='package', action='resource_read', id=c.pkg_dict['name'], resource_id=res['id'])}">${h.resource_icon(res) + h.resource_display_name(res)} ${h.rank_resource(res.url)}</a>
+ <a href="${h.url_for(controller='package', action='resource_read', id=c.pkg_dict['name'], resource_id=res['id'])}">${h.resource_icon(res) + h.resource_display_name(res)}</a>
</li>
</ul>
</div>
diff --git a/ckan/templates/package/read.html b/ckan/templates/package/read.html
index f2ae43c..a9da991 100644
--- a/ckan/templates/package/read.html
+++ b/ckan/templates/package/read.html
@@ -20,7 +20,6 @@
<py:match path="primarysidebar">
- <p>${h.tracking_count_package(c.pkg.id)}</p>
<li py:if="c.pkg.license_id" id="dataset-license" class="sidebar-section">
<strong>License:</strong>
<py:choose test="">
================================================================
Compare: https://github.com/okfn/ckan/compare/3ab532f...a411e22
More information about the ckan-changes
mailing list