Add feature to recalculate visitor counts
This commit is contained in:
parent
83d878a6b6
commit
ca241f2bcf
|
@ -113,6 +113,28 @@ def log_referrer(request, link):
|
|||
return None
|
||||
|
||||
|
||||
def rebuild_visitor_stats():
|
||||
"""Recalculate the total unique/hits based on daily info."""
|
||||
total_unique = {}
|
||||
total_hits = 0
|
||||
|
||||
# Tally them all up!
|
||||
for date in JsonDB.list_docs("traffic/unique"):
|
||||
if date == "total":
|
||||
continue
|
||||
db = JsonDB.get("traffic/unique/{}".format(date), cache=False)
|
||||
total_unique.update(db)
|
||||
for date in JsonDB.list_docs("traffic/hits"):
|
||||
if date == "total":
|
||||
continue
|
||||
db = JsonDB.get("traffic/hits/{}".format(date), cache=False)
|
||||
total_hits += db.get("hits", 0)
|
||||
|
||||
# Write the outputs.
|
||||
JsonDB.commit("traffic/unique/total", total_unique)
|
||||
JsonDB.commit("traffic/hits/total", dict(hits=total_hits))
|
||||
|
||||
|
||||
def get_visitor_details():
|
||||
"""Retrieve detailed visitor information for the frontend."""
|
||||
result = {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
from flask import g, Blueprint, request, redirect, url_for, session, flash
|
||||
|
||||
import rophako.model.user as User
|
||||
import rophako.model.tracking as Tracking
|
||||
from rophako.modules.account import validate_create_form
|
||||
from rophako.utils import template, admin_required
|
||||
|
||||
|
@ -180,3 +181,11 @@ def unimpersonate():
|
|||
|
||||
flash("No longer impersonating.")
|
||||
return redirect(url_for("index"))
|
||||
|
||||
@mod.route("/maint/rebuild_visitor_counts")
|
||||
@admin_required
|
||||
def rebuild_visitor_counts():
|
||||
"""Rebuild visitor counts."""
|
||||
Tracking.rebuild_visitor_stats()
|
||||
flash("Visitor counts recalculated.")
|
||||
return redirect(url_for(".index"))
|
||||
|
|
|
@ -9,4 +9,10 @@
|
|||
<li><a href="{{ url_for('admin.users') }}">View and Manage Users</a></li>
|
||||
</ul>
|
||||
|
||||
{% endblock %}
|
||||
<h1>Maintenance Tasks</h1>
|
||||
|
||||
<ul>
|
||||
<li><a href="{{ url_for('admin.rebuild_visitor_counts') }}">Rebuild Visitor Counts</a></li>
|
||||
</ul>
|
||||
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in New Issue
Block a user