]> git.ipfire.org Git - people/shoehn/ipfire.org.git/commitdiff
fireinfo: Add administration page.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 9 Jan 2011 12:58:03 +0000 (13:58 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 9 Jan 2011 12:58:03 +0000 (13:58 +0100)
www/templates/stasy-stats-admin.html [new file with mode: 0644]
www/webapp/backend/stasy.py
www/webapp/handlers_stasy.py

diff --git a/www/templates/stasy-stats-admin.html b/www/templates/stasy-stats-admin.html
new file mode 100644 (file)
index 0000000..ab0621c
--- /dev/null
@@ -0,0 +1,30 @@
+{% extends "stasy-base-2.html" %}
+
+{% block title %}{% end block %}
+
+{% block content %}
+       <h3>Need a headline</h3>
+
+       <table>
+               <tr>
+                       <td>
+                               {{ _("Sending profiles") }}
+                       </td>
+                       <td>
+                               {{ profiles_count }} / {{ profiles_count_all }}
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               {{ _("Archive size") }}
+                       </td>
+                       <td>
+                               {{ archives_count }}
+                       </td>
+               </tr>
+       </table>
+
+       <h3>{{ _("Updates in the last 24 hours") }}</h3>
+       {{ modules.StasyTable(updated_since_24h, percentage=False, sortby="percentage") }}
+{% end block %}
+
index c2f46bbd35cf2c0ee116501ce7419f4da18422c5..22346c2305d040ebd04700b30c9b544c50f97a50 100644 (file)
@@ -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()
index c1e152be26767d34ed3bde545bc72ee79c237e36..eb3b843dd1baf7e434c06b570a6839f294ce307d 100644 (file)
@@ -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)
+