incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [12/12] git commit: [#5655] Refactored site_stats and added ticket and post 24hr stats
Date Fri, 26 Apr 2013 14:53:16 GMT
[#5655] Refactored site_stats and added ticket and post 24hr stats

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/ab2236dc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/ab2236dc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/ab2236dc

Branch: refs/heads/cj/5655
Commit: ab2236dc1ae67124a0c8d3ea2b9bd7de037d7c8d
Parents: 2740a68
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Wed Apr 24 22:30:06 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Fri Apr 26 14:52:54 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/rest.py             |   11 +++++++----
 ForgeDiscussion/forgediscussion/site_stats.py |    8 ++++++++
 ForgeDiscussion/setup.py                      |    3 +++
 ForgeTracker/forgetracker/site_stats.py       |   10 ++++++++++
 ForgeTracker/setup.py                         |    3 +++
 5 files changed, 31 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ab2236dc/Allura/allura/controllers/rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/rest.py b/Allura/allura/controllers/rest.py
index 0d519cc..70e3ac7 100644
--- a/Allura/allura/controllers/rest.py
+++ b/Allura/allura/controllers/rest.py
@@ -62,10 +62,13 @@ class RestController(object):
 
     @expose('json:')
     def index(self, **kw):
-        provider = g.entry_points['site_stats'].get('provider')
-        if provider:
-            return provider()
-        return dict()
+        summary = dict()
+        stats = dict()
+        for stat, provider in g.entry_points['site_stats'].iteritems():
+            stats[stat] = provider()
+        if stats:
+            summary['site_stats'] = stats
+        return summary
 
     @expose()
     def _lookup(self, name, *remainder):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ab2236dc/ForgeDiscussion/forgediscussion/site_stats.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/site_stats.py b/ForgeDiscussion/forgediscussion/site_stats.py
new file mode 100644
index 0000000..e76201d
--- /dev/null
+++ b/ForgeDiscussion/forgediscussion/site_stats.py
@@ -0,0 +1,8 @@
+from datetime import datetime, timedelta
+
+from . import model as DM
+
+
+def posts_24hr():
+    window = datetime.utcnow() - timedelta(hours=24)
+    return DM.ForumPost.query.find({'timestamp': {'$gte': window}}).count()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ab2236dc/ForgeDiscussion/setup.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/setup.py b/ForgeDiscussion/setup.py
index 5c58b7a..812c8a0 100644
--- a/ForgeDiscussion/setup.py
+++ b/ForgeDiscussion/setup.py
@@ -44,5 +44,8 @@ setup(name='ForgeDiscussion',
       # -*- Entry points: -*-
       [allura]
       Discussion=forgediscussion.forum_main:ForgeDiscussionApp
+
+      [allura.site_stats]
+      posts_24hr=forgediscussion.site_stats:posts_24hr
       """,
       )

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ab2236dc/ForgeTracker/forgetracker/site_stats.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/site_stats.py b/ForgeTracker/forgetracker/site_stats.py
new file mode 100644
index 0000000..e0baa63
--- /dev/null
+++ b/ForgeTracker/forgetracker/site_stats.py
@@ -0,0 +1,10 @@
+from datetime import datetime, timedelta
+
+from bson import ObjectId
+
+from . import model as TM
+
+
+def tickets_stats_24hr():
+    window = datetime.utcnow() - timedelta(hours=24)
+    return TM.Ticket.query.find({'_id': {'$gte': ObjectId.from_datetime(window)}}).count()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ab2236dc/ForgeTracker/setup.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/setup.py b/ForgeTracker/setup.py
index 57e5d45..1934cc2 100644
--- a/ForgeTracker/setup.py
+++ b/ForgeTracker/setup.py
@@ -43,6 +43,9 @@ setup(name='ForgeTracker',
       [allura]
       Tickets=forgetracker.tracker_main:ForgeTrackerApp
 
+      [allura.site_stats]
+      tickets_24hr=forgetracker.site_stats:tickets_stats_24hr
+
       [easy_widgets.resources]
       ew_resources=forgetracker.config.resources:register_ew_resources
 


Mime
View raw message