Permalink
Browse files

Added loans-by-published year graph.

  • Loading branch information...
1 parent 05768a1 commit f7d2f7adde1e260ad57d6e8c595595ae3f2044da Anand Chitipothu committed Dec 6, 2013
Showing with 53 additions and 2 deletions.
  1. +9 −1 openlibrary/core/loanstats.py
  2. +44 −1 openlibrary/templates/stats/lending.html
@@ -4,6 +4,7 @@
"""
import re
import time
+import datetime
import urllib
import logging
import simplejson
@@ -78,7 +79,7 @@ def _run_solr_facet_query(self, facet_fields, facet_limit=None):
params["facet.limit"] = facet_limit
response = self.solr_select(params)
- return dict((name, web.group(counts, 2)) for name, counts in response['facet_counts']['facet_fields'].items())
+ return dict((name, list(web.group(counts, 2))) for name, counts in response['facet_counts']['facet_fields'].items())
def _get_all_facet_counts(self):
if not self._facet_counts:
@@ -128,6 +129,13 @@ def get_facet_counts(self, name, limit=20):
facets = list(self.solr_select_facet(name))[:limit]
return [self.make_facet(name, key, count) for key, count in facets]
+ def get_loans_by_published_year(self):
+ d = self._run_solr_facet_query("publish_year")['publish_year']
+ # strip bad years
+ current_year = datetime.date.today().year
+ min_year = 1800
+ return [[int(y), count] for y, count in d if min_year < int(y) <= current_year]
+
def make_facet(self, name, key, count):
if name == "library_s":
title = self._get_library_title(key)
@@ -42,8 +42,15 @@ <h2>Loans Per Type</h2>
<noscript>$_("You need to have JavaScript turned on to see the nifty chart!")</noscript>
</div>
</div>
-
<div class="clearfix"></div>
+
+ <h2>Loans by Published Year</h2>
+ <div class="chart">
+ <div id="loans-by-published-year" class="graph">
+ <noscript>$_("You need to have JavaScript turned on to see the nifty chart!")</noscript>
+ </div>
+ </div>
+
<br/>
<br/>
@@ -143,6 +150,42 @@ <h2>Loans Per Type</h2>
show: false
}
});
+
+ \$.plot("#loans-by-published-year", [{data: $:json_encode(stats.get_loans_by_published_year())}], {
+ series: {
+ bars: {
+ show: true,
+ fill: 0.6,
+ color: "#ffa337",
+ align: "center"
+ },
+ points: {
+ show: true
+ },
+ color: "#ffa337"
+ },
+ grid: {
+ /*
+ hoverable: true,
+ clickable: true,
+ autoHighlight: true,
+ */
+ tickColor: "#d9d9d9",
+ borderWidth: 1,
+ borderColor: "#d9d9d9",
+ backgroundColor: "#fff"
+ },
+ xaxis: { tickDecimals: 0 },
+ yaxis: { tickDecimals: 0 }
+ /*
+ selection: { mode: "xy", color: "#00636a" },
+ crosshair: {
+ mode: "xy",
+ color: "rgba(000, 099, 106, 0.4)",
+ lineWidth: 1
+ }
+ */
+ });
});
</script>

0 comments on commit f7d2f7a

Please sign in to comment.