Merge branch 'master' of git+ssh://maxious.lambdacomplex.org/git/ckanext-ga-report
--- a/ckanext/ga_report/controller.py
+++ b/ckanext/ga_report/controller.py
@@ -342,7 +342,8 @@
downloads += int(x.value)
else:
downloads = 'No data'
- top_packages.append((package, entry.pageviews, entry.visits, downloads))
+ if package.private == False:
+ top_packages.append((package, entry.pageviews, entry.visits, downloads))
else:
log.warning('Could not find package associated package')
--- a/ckanext/ga_report/download_analytics.py
+++ b/ckanext/ga_report/download_analytics.py
@@ -2,9 +2,11 @@
import logging
import datetime
import httplib
+import urllib
import collections
import requests
import json
+import re
from pylons import config
from ga_model import _normalize_url
import ga_model
@@ -424,7 +426,7 @@
args["end-date"] = end_date
args["ids"] = "ga:" + self.profile_id
- args["filters"] = 'ga:eventAction==download'
+ args["filters"] = 'ga:eventAction==Download'
args["dimensions"] = "ga:eventLabel"
args["metrics"] = "ga:totalEvents"
args["alt"] = "json"
@@ -450,7 +452,7 @@
if progress_count % 100 == 0:
log.debug('.. %d/%d done so far', progress_count, progress_total)
- url = result[0].strip()
+ url = urllib.unquote(result[0].strip())
# Get package id associated with the resource that has this URL.
q = model.Session.query(model.Resource)
@@ -458,8 +460,15 @@
r = q.filter(model.Resource.cache_url.like("%s%%" % url)).first()
else:
r = q.filter(model.Resource.url.like("%s%%" % url)).first()
+
+ # new style internal download links
+ if re.search('(?:/resource/)(.*)(?:/download/)',url):
+ resource_id = re.search('(?:/resource/)(.*)(?:/download/)',url)
+ r = q.filter(model.Resource.id.like("%s%%" % resource_id.group(1))).first()
package_name = r.resource_group.package.name if r else ""
+
+
if package_name:
data[package_name] = data.get(package_name, 0) + int(result[1])
else:
@@ -472,7 +481,7 @@
log.info('Associating downloads of resource URLs with their respective datasets')
process_result_data(results.get('rows'))
- try:
+ '''try:
# Because of issues of invalid responses, we are going to make these requests
# ourselves.
headers = {'authorization': 'Bearer ' + self.token}
@@ -492,7 +501,7 @@
results = dict(url=[])
log.info('Associating downloads of cache resource URLs with their respective datasets')
- process_result_data(results.get('rows'), cached=False)
+ process_result_data(results.get('rows'), cached=False)'''
self._filter_out_long_tail(data, MIN_DOWNLOADS)
ga_model.update_sitewide_stats(period_name, "Downloads", data, period_complete_day)
--- a/ckanext/ga_report/helpers.py
+++ b/ckanext/ga_report/helpers.py
@@ -116,6 +116,10 @@
_log.warning("Package {0} is not active, it is {1}".format(p.name, p.state))
continue
+ if not p.private == False:
+ _log.warning("Package {0} is private {1}".format(p.name, p.state))
+ continue
+
if not p in datasets:
datasets[p] = {'views':0, 'visits': 0}
--- a/ckanext/ga_report/plugin.py
+++ b/ckanext/ga_report/plugin.py
@@ -67,17 +67,17 @@
action='publisher_csv'
)
map.connect(
- '/site-usagesetsets_{id}_{month}.csv',
+ '/site-usage/dataset/datasets_{id}_{month}.csv',
controller='ckanext.ga_report.controller:GaDatasetReport',
action='dataset_csv'
)
map.connect(
- '/site-usageset',
+ '/site-usage/dataset',
controller='ckanext.ga_report.controller:GaDatasetReport',
action='read'
)
map.connect(
- '/site-usageset/{id}',
+ '/site-usage/dataset/{id}',
controller='ckanext.ga_report.controller:GaDatasetReport',
action='read_publisher'
)
--- a/ckanext/ga_report/templates/ga_report/publisher/read.html
+++ b/ckanext/ga_report/templates/ga_report/publisher/read.html
@@ -85,7 +85,7 @@
${h.link_to(package.title or package.name, h.url_for(controller='package', action='read', id=package.name))}
</td>
<td class="td-numeric">${views}</td>
- <td class="td-numeric">${downloads}</td>
+ <td class="td-numeric">${downloads}</td>
</tr>
</py:for>
</table>
--- a/ckanext/ga_report/templates/ga_report/site/index.html
+++ b/ckanext/ga_report/templates/ga_report/site/index.html
@@ -29,7 +29,7 @@
<div class="panel-body">
<ul>
<li><a href="/site-usage/publisher">Publisher Usage Statistics</a></li>
- <li><a href="/site-usageset">Dataset Usage Statistics</a></li>
+ <li><a href="/site-usage/dataset">Dataset Usage Statistics</a></li>
</ul>
</div>
</div>
--- a/ckanext/ga_report/templates/ga_report/site/layout_base.html
+++ b/ckanext/ga_report/templates/ga_report/site/layout_base.html
@@ -114,7 +114,7 @@
</span>
</div>
<a href="${h.url('home')}">
- <img width="64" src="${h.url_for_static(g.site_logo)}" alt="${g.site_title} Logo" title="${g.site_title} Logo" id="logo" />
+ <img width="196" src="${h.url_for_static(g.site_logo)}" alt="${g.site_title} Logo" title="${g.site_title} Logo" id="logo" />
</a>
<div id="site-name">
<!-- <a href="${h.url('home')}">${g.site_title} — ${g.site_description}</a>-->