Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added loans by country to loan stats.

  • Loading branch information...
commit 524904ee65a5032c05e7a5d1a625f91a62541918 1 parent c8e0012
@anandology anandology authored
View
11 openlibrary/core/loanstats.py
@@ -11,16 +11,18 @@
import web
from infogami import config
from . import inlibrary
+from .. import i18n
logger = logging.getLogger(__name__)
re_solrescape = re.compile(r'([&|+\-!(){}\[\]^"~*?:])')
class LoanStats:
- def __init__(self, region=None, library=None, collection=None, subject=None):
+ def __init__(self, region=None, library=None, country=None, collection=None, subject=None):
self.base_url = "http://%s/solr" % config.get("stats_solr")
self.region = region
self.library = library
+ self.country = country
self.collection = collection
self.subject = subject
self.time_period = None
@@ -44,6 +46,8 @@ def solr_select(self, params):
params['fq'].append("region_s:" + self.solrescape(self.region))
if self.library:
params['fq'].append("library_s:" + self.solrescape(self.library))
+ if self.country:
+ params['fq'].append("country_s:" + self.solrescape(self.country))
if self.collection:
params['fq'].append("ia_collections_id:" + self.solrescape(self.collection))
@@ -104,7 +108,7 @@ def _run_solr_facet_query(self, facet_fields, facet_limit=None):
def _get_all_facet_counts(self):
if not self._facet_counts:
facets = [
- "library_s","region_s",
+ "library_s","region_s", "country_s",
"ia_collections_id", "sponsor_s", "contributor_s",
"book_key_s", "author_keys_id", "resource_type_s",
"subject_facet", "place_facet", "person_facet", "time_facet"]
@@ -203,6 +207,9 @@ def make_facet(self, name, key, count):
elif name == "region_s":
title = key.upper()
slug = key
+ elif name == "country_s":
+ title = i18n.gettext_territory(key)
+ slug = key
elif name == "book_key_s":
# XXX-Anand: Optimize this by pre loading all books
book = web.ctx.site.get(key)
View
8 openlibrary/templates/stats/lending.html
@@ -18,7 +18,7 @@
</div>
-$ facet_urls = {"libraries": "/stats/lending/libraries/%(slug)s", "regions": "/stats/lending/regions/%(slug)s", "collections": "/stats/lending/collections/%(slug)s", "subjects": "/stats/lending/subjects/%(slug)s", "places": "/stats/lending/subjects/place:%(slug)s", "people": "/stats/lending/subjects/person:%(slug)s", "time": "/stats/lending/subjects/time:%(slug)s", "popular books": "%(slug)s", "popular authors": "%(slug)s"}
+$ facet_urls = {"libraries": "/stats/lending/libraries/%(slug)s", "regions": "/stats/lending/regions/%(slug)s", "countries": "/stats/lending/countries/%(slug)s", "collections": "/stats/lending/collections/%(slug)s", "subjects": "/stats/lending/subjects/%(slug)s", "places": "/stats/lending/subjects/place:%(slug)s", "people": "/stats/lending/subjects/person:%(slug)s", "time": "/stats/lending/subjects/time:%(slug)s", "popular books": "%(slug)s", "popular authors": "%(slug)s"}
$def render_counts(label, counts, klass="contentQuarter"):
<div class="$klass">
@@ -71,6 +71,12 @@ <h6 class="black collapse uppercase">$label</h6>
<br/>
<br/>
+ $if not stats.country:
+ <div>
+ $:render_counts("Countries", stats.get_facet_counts("country_s"))
+ </div>
+ <div class="clearfix"></div>
+
$if not stats.library and not stats.region:
<div>
View
4 openlibrary/views/loanstats.py
@@ -16,7 +16,7 @@ def GET(self):
re_time_period2 = re.compile("(\d\d\d\d)(\d\d)(\d\d)-(\d\d\d\d)(\d\d)(\d\d)")
class lending_stats(app.view):
- path = "/stats/lending(?:/(libraries|regions|collections|subjects|format)/(.+))?"
+ path = "/stats/lending(?:/(libraries|regions|countries|collections|subjects|format)/(.+))?"
def is_enabled(self):
return "loanstats" in web.ctx.features
@@ -27,6 +27,8 @@ def GET(self, key, value):
stats.library = value
elif key == 'regions':
stats.region = value
+ elif key == 'countries':
+ stats.country = value
elif key == 'collections':
stats.collection = value
elif key == 'subjects':
Please sign in to comment.
Something went wrong with that request. Please try again.