Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion openlibrary/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def get_counts(self, ndays=28, times=False):


@cache.memoize(engine="memcache", key="admin._get_visitor_counts_from_graphite", expires=5 * 60)
def _get_visitor_counts_from_graphite(self, ndays: int = 28) -> list[list[int]]:
def _get_visitor_counts_from_graphite(ndays: int = 28) -> list[list[int]]:
"""
Read the unique visitors (IP addresses) per day for the last ndays from graphite.
:param ndays: number of days to read
Expand All @@ -114,6 +114,7 @@ def _get_visitor_counts_from_graphite(self, ndays: int = 28) -> list[list[int]]:
"tz": "UTC",
"format": "json",
},
timeout=5,
)
response.raise_for_status()
visitors = response.json()[0]["datapoints"]
Expand Down
6 changes: 4 additions & 2 deletions openlibrary/templates/admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,10 @@ <h2>$_("Members")</h2>

<div class="clearfix"></div>

<h2>$_("Unique Visitors")</h2>
<img alt="$_('Unique visitors IPs per day graph')" src="https://graphite.us.archive.org/render/?min=0&template=plain&lineMode=staircase&areaMode=stacked&areaAlpha=0.5&yAxisSide=right&title=openlibrary+++Unique+IPs+per+day+++(uip_openlibrary)&hideLegend=true&target=cactiStyle(alias(summarize(sumSeries(group(stats.uniqueips.openlibrary)),%221day%22),%22openlibrary+++Unique+IPs+per+day+++(uip_openlibrary)%22))&colorList=00ff00&height=200&width=900&from=-60days"/>
$# Conditional check since the graphite source is currently unreliable, hiding the stat when it returns nothing
$if counts.get("visitors") and counts["visitors"].get_summary(28):
<h2>$_("Unique Visitors")</h2>
<img alt="$_('Unique visitors IPs per day graph')" src="https://graphite.us.archive.org/render/?min=0&template=plain&lineMode=staircase&areaMode=stacked&areaAlpha=0.5&yAxisSide=right&title=openlibrary+++Unique+IPs+per+day+++(uip_openlibrary)&hideLegend=true&target=cactiStyle(alias(summarize(sumSeries(group(stats.uniqueips.openlibrary)),%221day%22),%22openlibrary+++Unique+IPs+per+day+++(uip_openlibrary)%22))&colorList=00ff00&height=200&width=900&from=-60days"/>

<h2>$_("Borrows")</h2>
<img alt="$_('Borrows, last 3 months graph')" src="https://graphite.us.archive.org/render?target=hitcount(stats.ol.loans.bookreader,%221d%22)&from=-3months&tz=UTC&width=900"/>
Expand Down
44 changes: 20 additions & 24 deletions openlibrary/templates/home/stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,39 @@ <h2 class="inline">$_('Around the Library')</h2>
</div>

<div id="home-stats-charts">
<div class="statschart">
<div class="chartShow" onclick="window.location.href='//archive.org/stats';" title="$_('See all visitors to OpenLibrary.org')">
$# Conditional check since the graphite source is currently unreliable, hiding the stat when it returns nothing
$if stats["visitors"].get_summary(28):
<div class="statschart" onclick="window.location.href='//archive.org/stats';" title="$_('See all visitors to OpenLibrary.org')">
<div id="visitors-graph" style="width:150px;height:60px;" title="$_('Area graph of recent unique visitors')"></div>
<a href="//archive.org/stats" title="$_('See all visitors to OpenLibrary.org')"><span class="ticks">$:commify(stats["visitors"].get_summary(28))</span><span class="label">$_('Unique Visitors')</span></a>
</div>
</div>

<div class="statschart">
<div class="chartShow" onclick="window.location.href='/stats';" title="$_('How many new Open Library members have we welcomed?')">
<div id="members-graph" style="width:150px;height:60px;" title="$_('Area graph of new members')"></div>
<a href="/stats" title="$_('How many new Open Library members have we welcomed?')"><span class="ticks">$:commify(stats["members"].get_summary(28))</span><span class="label">$_('New Members')</span></a>
</div>
<div class="statschart" onclick="window.location.href='/stats';" title="$_('How many new Open Library members have we welcomed?')">
<div id="members-graph" style="width:150px;height:60px;" title="$_('Area graph of new members')"></div>
<a href="/stats" title="$_('How many new Open Library members have we welcomed?')"><span class="ticks">$:commify(stats["members"].get_summary(28))</span><span class="label">$_('New Members')</span></a>
</div>
<div class="statschart">
<div class="chartShow" onclick="window.location.href='/recentchanges';" title="$_('People are constantly updating the catalog')">
<div id="edits-graph" style="width:150px;height:60px;" title="$_('Area graph of recent catalog edits')"></div>
<a href="/recentchanges" title="$_('People are constantly updating the catalog')"><span class="ticks">$:commify(stats["human_edits"].get_summary(28))</span><span class="label">$_('Catalog Edits')</span></a>
</div>

<div class="statschart" onclick="window.location.href='/recentchanges';" title="$_('People are constantly updating the catalog')">
<div id="edits-graph" style="width:150px;height:60px;" title="$_('Area graph of recent catalog edits')"></div>
<a href="/recentchanges" title="$_('People are constantly updating the catalog')"><span class="ticks">$:commify(stats["human_edits"].get_summary(28))</span><span class="label">$_('Catalog Edits')</span></a>
</div>

<div class="statschart">
<div class="chartShow" onclick="window.location.href='/lists';" title="$_('Members can create Lists')">
<div id="lists-graph" style="width:150px;height:60px;" title="$_('Area graph of lists created recently')"></div>
<a href="/lists" title="$_('Members can create Lists')"><span class="ticks">$:commify(stats["lists"].get_summary(28))</span><span class="label">$_('Lists Created')</span></a>
</div>
<div class="statschart" onclick="window.location.href='/lists';" title="$_('Members can create Lists')">
<div id="lists-graph" style="width:150px;height:60px;" title="$_('Area graph of lists created recently')"></div>
<a href="/lists" title="$_('Members can create Lists')"><span class="ticks">$:commify(stats["lists"].get_summary(28))</span><span class="label">$_('Lists Created')</span></a>
</div>

<div class="statschart">
<div class="chartShow" onclick="window.location.href='/stats';" title="$_('We\'re a library, so we lend books, too')">
<div id="ebooks-graph" style="width:150px;height:60px;" title="$_('Area graph of ebooks borrowed recently')"></div>
<a href="/subjects/in_library#ebooks=true" title="$_('We\'re a library, so we lend books, too')"><span class="ticks">$:commify(stats["loans"].get_summary(28))</span><span class="label">$_('eBooks Borrowed')</span></a>
</div>
<div class="statschart" onclick="window.location.href='/stats';" title="$_('We\'re a library, so we lend books, too')">
<div id="ebooks-graph" style="width:150px;height:60px;" title="$_('Area graph of ebooks borrowed recently')"></div>
<a href="/subjects/in_library#ebooks=true" title="$_('We\'re a library, so we lend books, too')"><span class="ticks">$:commify(stats["loans"].get_summary(28))</span><span class="label">$_('eBooks Borrowed')</span></a>
</div>

</div>
</div>

<script type="text/json+graph" id="graph-json-visitors-graph">$:json_encode(stats["visitors"].get_counts(28, True))</script>
$# Conditional check since the graphite source is currently unreliable, hiding the stat when it returns nothing
$if stats["visitors"].get_summary(28):
<script type="text/json+graph" id="graph-json-visitors-graph">$:json_encode(stats["visitors"].get_counts(28, True))</script>
<script type="text/json+graph" id="graph-json-members-graph">$:json_encode(stats["members"].get_counts(28, True))</script>
<script type="text/json+graph" id="graph-json-edits-graph">$:json_encode(stats["human_edits"].get_counts(28, True))</script>
<script type="text/json+graph" id="graph-json-lists-graph">$:json_encode(stats["lists"].get_counts(28, True))</script>
Expand Down
16 changes: 4 additions & 12 deletions static/css/components/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,20 @@ div.chartHome a:hover,
#home-stats-charts {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}

#home-stats-charts .statschart {
flex: 1;
height: 110px;
text-align: center;
padding: 1px;
margin: 0 var(--spacing-inline-sm);
cursor: pointer;
}

/* stylelint-disable-next-line max-nesting-depth */
#home-stats-charts .statschart .chartShow {
width: 145px;
height: 60px;
margin: 0 var(--spacing-inline-sm);
#home-stats-charts .statschart div {
border-bottom: 1px solid var(--grey);
cursor: pointer;
}

/* stylelint-disable no-descending-specificity */
/* stylelint-disable max-nesting-depth */
#home-stats-charts .statschart a {
color: var(--black);
text-decoration: none;
Expand All @@ -97,8 +91,6 @@ div.chartHome a:hover,
font-size: 0.625em;
text-transform: uppercase;
}
/* stylelint-enable no-descending-specificity */
/* stylelint-enable max-nesting-depth */

#home-resource {
font-size: 13px;
Expand Down
Loading