trac-hacks / tracstats

Project and source code statistics plugin for Trac.
http://trac-hacks.org/wiki/TracStatsPlugin
Other
20 stars 13 forks source link

Change Tickets graphs? #17

Open icco opened 13 years ago

icco commented 13 years ago

http://cl.ly/2Zxq and http://cl.ly/2aXh

Our developers accept tickets when they are working on them, but this graph seems not as useful as it could be.

My suggestion would be show the difference of closed tickets versus open tickets.

icco commented 13 years ago

I would also suggest adding graphs like there is for code, with tickets filed by hour and day.

knarrff commented 12 years ago

I quickly hacked what this ticket asks for (not recommended directly for upstream - you might want to have that configurable), but I could not figure out how to add attachments here, so I just paste the patch here:

diff --git a/tracstats/templates/tickets.html b/tracstats/templates/tickets.html
index dbe1f13..a250917 100644
--- a/tracstats/templates/tickets.html
+++ b/tracstats/templates/tickets.html
@@ -40,7 +40,7 @@
 <py:if test="history">
 <br />

-<h2>Open Tickets</h2>
+<h2>Closed/Open Tickets</h2>

 <div id="opentickets" style="width:600px;height:300px;"></div>

@@ -55,14 +55,14 @@ $(function () {
     };

-    var d1 = [<py:for each="i in range(len(history))">[${history[i].x}, ${history[i].opened}]<py:if
-                      test="i != len(history)-1">,[${history[i+1].x}, ${history[i].opened}],</py:if
+    var d1 = [<py:for each="i in range(len(history))">[${history[i].x}, ${history[i].closed}]<py:if
+                      test="i != len(history)-1">,[${history[i+1].x}, ${history[i].closed}],</py:if

-    var d2 = [<py:for each="i in range(len(history))">[${history[i].x}, ${history[i].accepted}]<py:
-                      test="i != len(history)-1">,[${history[i+1].x}, ${history[i].accepted}],</py:
+    var d2 = [<py:for each="i in range(len(history))">[${history[i].x}, ${history[i].opened}]<py:if
+                      test="i != len(history)-1">,[${history[i+1].x}, ${history[i].opened}],</py:if

-    $.plot($("#opentickets"), [ { data: d1, label: 'Open' },
-                                { data: d2, label: 'Accepted' } ], options);
+    $.plot($("#opentickets"), [ { data: d1, label: 'Closed' },
+                                { data: d2, label: 'Opened' } ], options);
 });
 </script>
 </py:if>
diff --git a/tracstats/web_ui.py b/tracstats/web_ui.py
index fe976b6..3129ba9 100644
--- a/tracstats/web_ui.py
+++ b/tracstats/web_ui.py
@@ -1071,6 +1071,7 @@ class TracStatsPlugin(Component):
             d = {}
             opened = 0
             accepted = 0
+            closed = 0
             for ticket, t, oldvalue, newvalue in sorted(rows, key=itemgetter(1)):
                 if newvalue == 'accepted' and oldvalue != 'accepted':
                     accepted += 1
@@ -1080,13 +1081,18 @@ class TracStatsPlugin(Component):
                     opened += 1
                 elif newvalue == "closed" and oldvalue != "closed":
                     opened -= 1
-                d[int(t)] = (opened, accepted)
+                if newvalue == 'closed' and oldvalue != 'closed':
+                    closed += 1
+                elif newvalue != 'closed' and oldvalue == 'closed':
+                    closed -= 1
+                d[int(t)] = (opened, accepted, closed)
             steps = max(len(d) / 250, 1)
             for k, v in sorted(d.iteritems(), key=itemgetter(0))[::steps]:
                 if k > since:
                     stats.append({'x': k * 1000,
                                   'opened': v[0],
-                                  'accepted': v[1],})
+                                  'accepted': v[1],
+                                  'closed': v[2],})
         data['history'] = stats

         cursor.execute("""\