Permalink
Browse files

Added loans-per-type pie chart.

  • Loading branch information...
1 parent 2630210 commit 6041a6ec7d513fbeaa78b4c66bdaeb0494acc00f Anand Chitipothu committed Dec 5, 2013
Showing with 34 additions and 1 deletion.
  1. +5 −1 openlibrary/core/loanstats.py
  2. +29 −0 openlibrary/templates/stats/lending.html
@@ -85,7 +85,7 @@ def _get_all_facet_counts(self):
facets = [
"library_s","region_s",
"ia_collections_id", "sponsor_s", "contributor_s",
- "book_key_s",
+ "book_key_s", "resource_type_s",
"subject_facet", "place_facet", "person_facet", "time_facet"]
params = {
@@ -120,6 +120,10 @@ def get_loans_per_day(self, resource_type="total"):
day_facet = web.group(counts0, 2)
return [[self.date2timestamp(*self.parse_date(day))*1000, count] for day, count in day_facet]
+ def get_loans_per_type(self):
+ rows = self.get_facet_counts("resource_type_s")
+ return [{"label": row.title, "data": row.count} for row in rows]
+
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]
@@ -36,6 +36,17 @@ <h6 class="black collapse uppercase">$label</h6>
</div>
</div>
+ <h2>Loans Per Type</h2>
+ <div class="left">
+ <div id="loans-types-pie-chart" class="pie">
+ <noscript>$_("You need to have JavaScript turned on to see the nifty chart!")</noscript>
+ </div>
+ </div>
+
+ <div class="clearfix"></div>
+ <br/>
+ <br/>
+
$if not stats.library and not stats.region:
<div>
$:render_counts("Libraries", stats.get_facet_counts("library_s"), klass="contentHalf")
@@ -117,6 +128,20 @@ <h6 class="black collapse uppercase">$label</h6>
position: "nw"
}
});
+
+ \$.plot("#loans-types-pie-chart", $:json_encode(stats.get_loans_per_type()), {
+ series: {
+ pie: {
+ show: true,
+ label: {
+ show: true,
+ }
+ }
+ },
+ legend: {
+ show: false
+ }
+ });
});
</script>
@@ -127,6 +152,10 @@ <h6 class="black collapse uppercase">$label</h6>
float:none;
background-image:none;
}
+div.pie {
+ width: 350px;
+ height: 250px;
+}
.chartYaxis{
width:180px;
top:85px;

0 comments on commit 6041a6e

Please sign in to comment.