From cbb9726a54f42d9c3694f054a47d4aaf35ce73cb Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 9 Jan 2011 13:58:03 +0100 Subject: [PATCH] fireinfo: Add administration page. --- www/templates/stasy-stats-admin.html | 30 ++++++++++++++++++++++++++++ www/webapp/backend/stasy.py | 27 ++++++++++++++++++++++++- www/webapp/handlers_stasy.py | 21 +++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 www/templates/stasy-stats-admin.html diff --git a/www/templates/stasy-stats-admin.html b/www/templates/stasy-stats-admin.html new file mode 100644 index 00000000..ab0621c5 --- /dev/null +++ b/www/templates/stasy-stats-admin.html @@ -0,0 +1,30 @@ +{% extends "stasy-base-2.html" %} + +{% block title %}{% end block %} + +{% block content %} +

Need a headline

+ + + + + + + + + + +
+ {{ _("Sending profiles") }} + + {{ profiles_count }} / {{ profiles_count_all }} +
+ {{ _("Archive size") }} + + {{ archives_count }} +
+ +

{{ _("Updates in the last 24 hours") }}

+ {{ modules.StasyTable(updated_since_24h, percentage=False, sortby="percentage") }} +{% end block %} + diff --git a/www/webapp/backend/stasy.py b/www/webapp/backend/stasy.py index c2f46bbd..22346c23 100644 --- a/www/webapp/backend/stasy.py +++ b/www/webapp/backend/stasy.py @@ -2,6 +2,7 @@ from __future__ import division +import datetime import hwdata import logging import pymongo @@ -371,7 +372,11 @@ class Stasy(object): # a given date # All distinct profiles (based on public_id) - return self._db.profiles.distinct("public_id").count() + # XXX possibly bad performance + return len(self._db.profiles.distinct("public_id")) + + def get_archives_count(self): + return self._db.archives.count() #def _get_profile_cursor(self, public_id): # c = self._db.profiles.find({ "public_id" : public_id }) @@ -717,6 +722,26 @@ class Stasy(object): return zones + def get_profile_ratio(self): + return (self.query({}).count(), self.get_profile_count()) + + def get_updated_since(self, since, _query={}): + since = datetime.datetime.utcnow() - datetime.timedelta(**since) + + query = { "updated" : { "$gte" : since }} + query.update(_query) + + return self.query(query) + + def get_updates_by_release_since(self, since): + updates = {} + + for release in self.releases: + updates[release] = self.get_updated_since(since, + { "profile.system.release" : release }).count() + + return updates + if __name__ == "__main__": s = Stasy() diff --git a/www/webapp/handlers_stasy.py b/www/webapp/handlers_stasy.py index c1e152be..eb3b843d 100644 --- a/www/webapp/handlers_stasy.py +++ b/www/webapp/handlers_stasy.py @@ -165,3 +165,24 @@ class StasyStatsModelDetail(StasyBaseHandler): model_id=model_id, model_name=model_name, percentage=percentage) + + +class StasyStatsAdminHandler(StasyBaseHandler): + def get(self): + _ = self.locale.translate + + data = {} + + data["profiles_count"], data["profiles_count_all"] = \ + self.stasy.get_profile_ratio() + + data["archives_count"] = self.stasy.get_archives_count() + + # updated since 24h + since = { "hours" : 24 } + updates = self.stasy.get_updates_by_release_since(since) + #updates[_("All versions")] = self.stasy.get_updated_since(since).count() + data["updated_since_24h"] = updates + + self.render("stasy-stats-admin.html", **data) + -- 2.47.3