##// END OF EJS Templates
Some fixes to summary, and total rewrite of summary graphs implemented more interactive graph....
marcink -
r487:b12ea84f celery
parent child Browse files
Show More
@@ -19,8 +19,12 b' def run_task(task,*args,**kwargs):'
19 t = task.delay(*args,**kwargs)
19 t = task.delay(*args, **kwargs)
20 log.info('running task %s',t.task_id)
20 log.info('running task %s', t.task_id)
21 return t
21 return t
22 except:
22 except Exception, e:
23 if e.errno == 111:
24 log.debug('Unnable to connect. Sync execution')
25 else:
23 log.error(traceback.format_exc())
26 log.error(traceback.format_exc())
24 #pure sync version
27 #pure sync version
25 return ResultWrapper(task(*args,**kwargs))
28 return ResultWrapper(task(*args, **kwargs))
29
26 No newline at end of file
30
@@ -7,8 +7,9 b' from pylons_app.lib.celerylib import run'
7 from pylons_app.lib.helpers import person
7 from pylons_app.lib.helpers import person
8 from pylons_app.lib.smtp_mailer import SmtpMailer
8 from pylons_app.lib.smtp_mailer import SmtpMailer
9 from pylons_app.lib.utils import OrderedDict
9 from pylons_app.lib.utils import OrderedDict
10 from operator import itemgetter
11 from vcs.backends.hg import MercurialRepository
10 from time import mktime
12 from time import mktime
11 from vcs.backends.hg import MercurialRepository
12 import calendar
13 import calendar
13 import traceback
14 import traceback
14 import json
15 import json
@@ -98,13 +99,14 b' def get_commits_stats(repo):'
98 d, 0, 0, 0, 0, 0, 0,))
99 d, 0, 0, 0, 0, 0, 0,))
99
100
100 ts_max_y = mktime((y, m, d, 0, 0, 0, 0, 0, 0,))
101 ts_max_y = mktime((y, m, d, 0, 0, 0, 0, 0, 0,))
102 skip_date_limit = True
101
103
102 def author_key_cleaner(k):
104 def author_key_cleaner(k):
103 k = person(k)
105 k = person(k)
104 k = k.replace('"', "") #for js data compatibilty
106 k = k.replace('"', "") #for js data compatibilty
105 return k
107 return k
106
108
107 for cs in repo[:1000]:#added limit 200 until fix #29 is made
109 for cs in repo[:200]:#added limit 200 until fix #29 is made
108 k = '%s-%s-%s' % (cs.date.timetuple()[0], cs.date.timetuple()[1],
110 k = '%s-%s-%s' % (cs.date.timetuple()[0], cs.date.timetuple()[1],
109 cs.date.timetuple()[2])
111 cs.date.timetuple()[2])
110 timetupple = [int(x) for x in k.split('-')]
112 timetupple = [int(x) for x in k.split('-')]
@@ -119,7 +121,7 b' def get_commits_stats(repo):'
119
121
120 else:
122 else:
121 #aggregate[author_key_cleaner(cs.author)].update(dates_range)
123 #aggregate[author_key_cleaner(cs.author)].update(dates_range)
122 if k >= ts_min_y and k <= ts_max_y:
124 if k >= ts_min_y and k <= ts_max_y or skip_date_limit:
123 aggregate[author_key_cleaner(cs.author)][k] = {}
125 aggregate[author_key_cleaner(cs.author)][k] = {}
124 aggregate[author_key_cleaner(cs.author)][k]["commits"] = 1
126 aggregate[author_key_cleaner(cs.author)][k]["commits"] = 1
125 aggregate[author_key_cleaner(cs.author)][k]["added"] = len(cs.added)
127 aggregate[author_key_cleaner(cs.author)][k]["added"] = len(cs.added)
@@ -127,7 +129,7 b' def get_commits_stats(repo):'
127 aggregate[author_key_cleaner(cs.author)][k]["removed"] = len(cs.removed)
129 aggregate[author_key_cleaner(cs.author)][k]["removed"] = len(cs.removed)
128
130
129 else:
131 else:
130 if k >= ts_min_y and k <= ts_max_y:
132 if k >= ts_min_y and k <= ts_max_y or skip_date_limit:
131 aggregate[author_key_cleaner(cs.author)] = OrderedDict()
133 aggregate[author_key_cleaner(cs.author)] = OrderedDict()
132 #aggregate[author_key_cleaner(cs.author)].update(dates_range)
134 #aggregate[author_key_cleaner(cs.author)].update(dates_range)
133 aggregate[author_key_cleaner(cs.author)][k] = {}
135 aggregate[author_key_cleaner(cs.author)][k] = {}
@@ -145,15 +147,19 b' def get_commits_stats(repo):'
145 overview_data = []
147 overview_data = []
146 for k, v in overview_aggregate.items():
148 for k, v in overview_aggregate.items():
147 overview_data.append([k, v])
149 overview_data.append([k, v])
150 overview_data = sorted(overview_data, key=itemgetter(0))
148 data = {}
151 data = {}
149 for author in aggregate:
152 for author in aggregate:
150 data[author] = {"label":author,
153 commit_data = sorted([{"time":x,
151 "data":[{"time":x,
152 "commits":aggregate[author][x]['commits'],
154 "commits":aggregate[author][x]['commits'],
153 "added":aggregate[author][x]['added'],
155 "added":aggregate[author][x]['added'],
154 "changed":aggregate[author][x]['changed'],
156 "changed":aggregate[author][x]['changed'],
155 "removed":aggregate[author][x]['removed'],
157 "removed":aggregate[author][x]['removed'],
156 } for x in aggregate[author]],
158 } for x in aggregate[author]],
159 key=itemgetter('time'))
160
161 data[author] = {"label":author,
162 "data":commit_data,
157 "schema":["commits"]
163 "schema":["commits"]
158 }
164 }
159
165
@@ -77,6 +77,8 b' E.onDOMReady(function(e){'
77 </div>
77 </div>
78 <div class="input-short">
78 <div class="input-short">
79 ${h.age(c.repo_info.last_change)} - ${h.rfc822date(c.repo_info.last_change)}
79 ${h.age(c.repo_info.last_change)} - ${h.rfc822date(c.repo_info.last_change)}
80 ${_('by')} ${c.repo_info.get_changeset('tip').author}
81
80 </div>
82 </div>
81 </div>
83 </div>
82
84
@@ -121,7 +123,7 b' E.onDOMReady(function(e){'
121 <div class="box box-right" style="min-height:455px">
123 <div class="box box-right" style="min-height:455px">
122 <!-- box / title -->
124 <!-- box / title -->
123 <div class="title">
125 <div class="title">
124 <h5>${_('Last month commit activity')}</h5>
126 <h5>${_('Commit activity')}</h5>
125 </div>
127 </div>
126
128
127 <div class="table">
129 <div class="table">
@@ -136,80 +138,99 b' E.onDOMReady(function(e){'
136 </div>
138 </div>
137 </div>
139 </div>
138 <script type="text/javascript">
140 <script type="text/javascript">
139
141 /**
140 (function () {
142 * Plots summary graph
141 var datasets = ${c.commit_data|n};
143 *
142 var overview_data = ${c.overview_data|n};
144 * @class SummaryPlot
143
145 * @param {from} initial from for detailed graph
144 var i = 0;
146 * @param {to} initial to for detailed graph
147 * @param {dataset}
148 * @param {overview_dataset}
149 */
150 function SummaryPlot(from,to,dataset,overview_dataset) {
151 var initial_ranges = {
152 "xaxis":{
153 "from":from,
154 "to":to,
155 },
156 };
157 var dataset = dataset;
158 var overview_dataset = [overview_dataset];
145 var choiceContainer = YAHOO.util.Dom.get("legend_choices");
159 var choiceContainer = YAHOO.util.Dom.get("legend_choices");
146 var choiceContainerTable = YAHOO.util.Dom.get("legend_choices_tables");
160 var choiceContainerTable = YAHOO.util.Dom.get("legend_choices_tables");
147 for(var key in datasets) {
161 var plotContainer = YAHOO.util.Dom.get('commit_history');
148 datasets[key].color = i;
162 var overviewContainer = YAHOO.util.Dom.get('overview');
149 i++;
150 choiceContainerTable.innerHTML += '<tr><td>'+
151 '<input type="checkbox" name="' + key +'" checked="checked" />'
152 +datasets[key].label+
153 '</td></tr>';
154 };
155
156 function plotAccordingToChoices() {
157 var data = [];
158
163
159 var inputs = choiceContainer.getElementsByTagName("input");
164 var plot_options = {
160 for(var i=0; i<inputs.length; i++) {
161 var key = inputs[i].name;
162 if (key && datasets[key]){
163 if(!inputs[i].checked){
164 data.push({label:key,data:[[0,1],]});
165 }
166 else{
167 data.push(datasets[key]);
168 }
169 }
170 };
171
172 if (data.length > 0){
173 var options = {
174 bars: {show:true,align:'center',lineWidth:4},
165 bars: {show:true,align:'center',lineWidth:4},
175 legend: {show:true, container:"legend_container"},
166 legend: {show:true, container:"legend_container"},
176 points: {show:true,radius:0,fill:false},
167 points: {show:true,radius:0,fill:false},
177 yaxis: {tickDecimals:0,},
168 yaxis: {tickDecimals:0,},
178 xaxis: {mode: "time",
169 xaxis: {
170 mode: "time",
179 timeformat: "%d/%m",
171 timeformat: "%d/%m",
180 min:${c.ts_min},
172 min:from,
181 max:${c.ts_max},
173 max:to,
182
183 },
174 },
184 grid: {hoverable: true,
175 grid: {
176 hoverable: true,
185 clickable: true,
177 clickable: true,
186 autoHighlight:true,
178 autoHighlight:true,
187 color: "#999"},
179 color: "#999"
180 },
181 //selection: {mode: "x"}
182 };
183 var overview_options = {
184 legend:{show:false},
185 bars: {show:true,barWidth: 2,},
186 shadowSize: 0,
187 xaxis: {mode: "time", timeformat: "%d/%m/%y",},
188 yaxis: {ticks: 3, min: 0,},
189 grid: {color: "#999",},
188 selection: {mode: "x"}
190 selection: {mode: "x"}
189 };
191 };
190
192
191 //main plot
193 /**
192 var plot = YAHOO.widget.Flot("commit_history",data,options);
194 *get dummy data needed in few places
195 */
196 function getDummyData(label){
197 return {"label":label,
198 "data":[{"time":0,
199 "commits":0,
200 "added":0,
201 "changed":0,
202 "removed":0,
203 }],
204 "schema":["commits"],
205 "color":'#ffffff',
206 }
207 }
193
208
194 //overview
209 /**
195 var overview = YAHOO.widget.Flot("overview", [overview_data], {
210 * generate checkboxes accordindly to data
196 legend:{show:false},
211 * @param keys
197 bars: {show:true,
212 * @returns
198 barWidth: 2,
213 */
199 },
214 function generateCheckboxes(data) {
200 shadowSize: 0,
215 //append checkboxes
201 xaxis: {mode: "time",
216 var i = 0;
202 timeformat: "%d/%m/%y",
217 choiceContainerTable.innerHTML = '';
203 },
218 for(var pos in data) {
204 yaxis: {ticks: 3, min: 0,},
205 grid: {color: "#999",},
206 selection: {mode: "x"}
207 });
208
219
209 var ranges = {"xaxis":{"from":${c.ts_min},
220 data[pos].color = i;
210 "to":${c.ts_max},},}
221 i++;
211 overview.setSelection(ranges);
222 if(data[pos].label != ''){
223 choiceContainerTable.innerHTML += '<tr><td>'+
224 '<input type="checkbox" name="' + data[pos].label +'" checked="checked" />'
225 +data[pos].label+
226 '</td></tr>';
227 }
228 }
229 }
212
230
231 /**
232 * ToolTip show
233 */
213 function showTooltip(x, y, contents) {
234 function showTooltip(x, y, contents) {
214 var div=document.getElementById('tooltip');
235 var div=document.getElementById('tooltip');
215 if(!div) {
236 if(!div) {
@@ -230,6 +251,140 b' E.onDOMReady(function(e){'
230 anim.animate();
251 anim.animate();
231 }
252 }
232
253
254 /**
255 * This function will detect if selected period has some changesets for this user
256 if it does this data is then pushed for displaying
257 Additionally it will only display users that are selected by the checkbox
258 */
259 function getDataAccordingToRanges(ranges) {
260
261 var data = [];
262 var keys = [];
263 for(var key in dataset){
264 var push = false;
265 //method1 slow !!
266 ///*
267 for(var ds in dataset[key].data){
268 commit_data = dataset[key].data[ds];
269 //console.log(key);
270 //console.log(new Date(commit_data.time*1000));
271 //console.log(new Date(ranges.xaxis.from*1000));
272 //console.log(new Date(ranges.xaxis.to*1000));
273 if (commit_data.time >= ranges.xaxis.from && commit_data.time <= ranges.xaxis.to){
274 push = true;
275 break;
276 }
277 }
278 //*/
279 /*//method2 sorted commit data !!!
280 var first_commit = dataset[key].data[0].time;
281 var last_commit = dataset[key].data[dataset[key].data.length-1].time;
282
283 console.log(first_commit);
284 console.log(last_commit);
285
286 if (first_commit >= ranges.xaxis.from && last_commit <= ranges.xaxis.to){
287 push = true;
288 }
289 */
290 if(push){
291 data.push(dataset[key]);
292 }
293 }
294 if(data.length >= 1){
295 return data;
296 }
297 else{
298 //just return dummy data for graph to plot itself
299 return [getDummyData('')];
300 }
301
302 }
303
304 /**
305 * redraw using new checkbox data
306 */
307 function plotchoiced(e,args){
308 var cur_data = args[0];
309 var cur_ranges = args[1];
310
311 var new_data = [];
312 var inputs = choiceContainer.getElementsByTagName("input");
313
314 //show only checked labels
315 for(var i=0; i<inputs.length; i++) {
316 var checkbox_key = inputs[i].name;
317
318 if(inputs[i].checked){
319 for(var d in cur_data){
320 if(cur_data[d].label == checkbox_key){
321 new_data.push(cur_data[d]);
322 }
323 }
324 }
325 else{
326 //push dummy data to not hide the label
327 new_data.push(getDummyData(checkbox_key));
328 }
329 }
330
331 var new_options = YAHOO.lang.merge(plot_options, {
332 xaxis: {
333 min: cur_ranges.xaxis.from,
334 max: cur_ranges.xaxis.to,
335 mode:"time",
336 timeformat: "%d/%m",
337 }
338 });
339 if (!new_data){
340 new_data = [[0,1]];
341 }
342 // do the zooming
343 plot = YAHOO.widget.Flot(plotContainer, new_data, new_options);
344
345 plot.subscribe("plotselected", plotselected);
346
347 //resubscribe plothover
348 plot.subscribe("plothover", plothover);
349
350 // don't fire event on the overview to prevent eternal loop
351 overview.setSelection(cur_ranges, true);
352
353 }
354
355 /**
356 * plot only selected items from overview
357 * @param ranges
358 * @returns
359 */
360 function plotselected(ranges,cur_data) {
361 //updates the data for new plot
362 data = getDataAccordingToRanges(ranges);
363 generateCheckboxes(data);
364
365 var new_options = YAHOO.lang.merge(plot_options, {
366 xaxis: {
367 min: ranges.xaxis.from,
368 max: ranges.xaxis.to,
369 mode:"time",
370 timeformat: "%d/%m",
371 }
372 });
373 // do the zooming
374 plot = YAHOO.widget.Flot(plotContainer, data, new_options);
375
376 plot.subscribe("plotselected", plotselected);
377
378 //resubscribe plothover
379 plot.subscribe("plothover", plothover);
380
381 // don't fire event on the overview to prevent eternal loop
382 overview.setSelection(ranges, true);
383
384 //resubscribe choiced
385 YAHOO.util.Event.on(choiceContainer.getElementsByTagName("input"), "click", plotchoiced, [data, ranges]);
386 }
387
233 var previousPoint = null;
388 var previousPoint = null;
234
389
235 function plothover(o) {
390 function plothover(o) {
@@ -256,7 +411,7 b' E.onDOMReady(function(e){'
256 var fd = d.toDateString()
411 var fd = d.toDateString()
257 var nr_commits = parseInt(y);
412 var nr_commits = parseInt(y);
258
413
259 var cur_data = datasets[item.series.label].data[item.dataIndex];
414 var cur_data = dataset[item.series.label].data[item.dataIndex];
260 var added = cur_data.added;
415 var added = cur_data.added;
261 var changed = cur_data.changed;
416 var changed = cur_data.changed;
262 var removed = cur_data.removed;
417 var removed = cur_data.removed;
@@ -290,36 +445,33 b' E.onDOMReady(function(e){'
290 }
445 }
291 }
446 }
292
447
293 plot.subscribe("plothover", plothover);
448 /**
449 * MAIN EXECUTION
450 */
451
452 var data = getDataAccordingToRanges(initial_ranges);
453 generateCheckboxes(data);
294
454
295 function plotselected(ranges) {
455 //main plot
296 // do the zooming
456 var plot = YAHOO.widget.Flot(plotContainer,data,plot_options);
297 plot = YAHOO.widget.Flot("commit_history", data,
298 YAHOO.lang.merge(options, {
299 xaxis: { min: ranges.xaxis.from,
300 max: ranges.xaxis.to,
301 mode:"time",
302 timeformat: "%d/%m",
303 }
304 }));
305 plot.subscribe("plotselected", plotselected);
306 plot.subscribe("plothover", plothover);
307
457
308 // don't fire event on the overview to prevent eternal loop
458 //overview
309 overview.setSelection(ranges, true);
459 var overview = YAHOO.widget.Flot(overviewContainer, overview_dataset, overview_options);
310 }
460
461 //show initial selection on overview
462 overview.setSelection(initial_ranges);
463
311 plot.subscribe("plotselected", plotselected);
464 plot.subscribe("plotselected", plotselected);
312
465
313 overview.subscribe("plotselected", function (ranges) {
466 overview.subscribe("plotselected", function (ranges) {
314 plot.setSelection(ranges);
467 plot.setSelection(ranges);
315 });
468 });
316 }
469
317 }
470 plot.subscribe("plothover", plothover);
318
471
319 YAHOO.util.Event.on(choiceContainer.getElementsByTagName("input"), "click", plotAccordingToChoices);
472 YAHOO.util.Event.on(choiceContainer.getElementsByTagName("input"), "click", plotchoiced, [data, initial_ranges]);
320
473 }
321 plotAccordingToChoices();
474 SummaryPlot(${c.ts_min},${c.ts_max},${c.commit_data|n},${c.overview_data|n});
322 })();
323 </script>
475 </script>
324
476
325 </div>
477 </div>
General Comments 0
You need to be logged in to leave comments. Login now