summaryrefslogtreecommitdiffabout
path: root/ui-stats.c
Unidiff
Diffstat (limited to 'ui-stats.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-stats.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/ui-stats.c b/ui-stats.c
index 50c2540..2a0c174 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -1,31 +1,35 @@
1#include <string-list.h>
2
3#include "cgit.h" 1#include "cgit.h"
4#include "html.h" 2#include "html.h"
5#include "ui-shared.h" 3#include "ui-shared.h"
6#include "ui-stats.h" 4#include "ui-stats.h"
7 5
6#ifdef NO_C99_FORMAT
7#define SZ_FMT "%u"
8#else
9#define SZ_FMT "%zu"
10#endif
11
8#define MONTHS 6 12#define MONTHS 6
9 13
10struct authorstat { 14struct authorstat {
11 long total; 15 long total;
12 struct string_list list; 16 struct string_list list;
13}; 17};
14 18
15#define DAY_SECS (60 * 60 * 24) 19#define DAY_SECS (60 * 60 * 24)
16#define WEEK_SECS (DAY_SECS * 7) 20#define WEEK_SECS (DAY_SECS * 7)
17 21
18static void trunc_week(struct tm *tm) 22static void trunc_week(struct tm *tm)
19{ 23{
20 time_t t = timegm(tm); 24 time_t t = timegm(tm);
21 t -= ((tm->tm_wday + 6) % 7) * DAY_SECS; 25 t -= ((tm->tm_wday + 6) % 7) * DAY_SECS;
22 gmtime_r(&t, tm); 26 gmtime_r(&t, tm);
23} 27}
24 28
25static void dec_week(struct tm *tm) 29static void dec_week(struct tm *tm)
26{ 30{
27 time_t t = timegm(tm); 31 time_t t = timegm(tm);
28 t -= WEEK_SECS; 32 t -= WEEK_SECS;
29 gmtime_r(&t, tm); 33 gmtime_r(&t, tm);
30} 34}
31 35
@@ -262,133 +266,133 @@ void print_combined_authorrow(struct string_list *authors, int from, int to,
262 struct tm *tm; 266 struct tm *tm;
263 char *tmp; 267 char *tmp;
264 268
265 time(&now); 269 time(&now);
266 tm = gmtime(&now); 270 tm = gmtime(&now);
267 period->trunc(tm); 271 period->trunc(tm);
268 for (i = 1; i < period->count; i++) 272 for (i = 1; i < period->count; i++)
269 period->dec(tm); 273 period->dec(tm);
270 274
271 total = 0; 275 total = 0;
272 htmlf("<tr><td class='%s'>%s</td>", leftclass, 276 htmlf("<tr><td class='%s'>%s</td>", leftclass,
273 fmt(name, to - from + 1)); 277 fmt(name, to - from + 1));
274 for (j = 0; j < period->count; j++) { 278 for (j = 0; j < period->count; j++) {
275 tmp = period->pretty(tm); 279 tmp = period->pretty(tm);
276 period->inc(tm); 280 period->inc(tm);
277 subtotal = 0; 281 subtotal = 0;
278 for (i = from; i <= to; i++) { 282 for (i = from; i <= to; i++) {
279 author = &authors->items[i]; 283 author = &authors->items[i];
280 authorstat = author->util; 284 authorstat = author->util;
281 items = &authorstat->list; 285 items = &authorstat->list;
282 date = string_list_lookup(items, tmp); 286 date = string_list_lookup(items, tmp);
283 if (date) 287 if (date)
284 subtotal += (size_t)date->util; 288 subtotal += (size_t)date->util;
285 } 289 }
286 htmlf("<td class='%s'>%d</td>", centerclass, subtotal); 290 htmlf("<td class='%s'>%ld</td>", centerclass, subtotal);
287 total += subtotal; 291 total += subtotal;
288 } 292 }
289 htmlf("<td class='%s'>%d</td></tr>", rightclass, total); 293 htmlf("<td class='%s'>%ld</td></tr>", rightclass, total);
290} 294}
291 295
292void print_authors(struct string_list *authors, int top, 296void print_authors(struct string_list *authors, int top,
293 struct cgit_period *period) 297 struct cgit_period *period)
294{ 298{
295 struct string_list_item *author; 299 struct string_list_item *author;
296 struct authorstat *authorstat; 300 struct authorstat *authorstat;
297 struct string_list *items; 301 struct string_list *items;
298 struct string_list_item *date; 302 struct string_list_item *date;
299 time_t now; 303 time_t now;
300 long i, j, total; 304 long i, j, total;
301 struct tm *tm; 305 struct tm *tm;
302 char *tmp; 306 char *tmp;
303 307
304 time(&now); 308 time(&now);
305 tm = gmtime(&now); 309 tm = gmtime(&now);
306 period->trunc(tm); 310 period->trunc(tm);
307 for (i = 1; i < period->count; i++) 311 for (i = 1; i < period->count; i++)
308 period->dec(tm); 312 period->dec(tm);
309 313
310 html("<table class='stats'><tr><th>Author</th>"); 314 html("<table class='stats'><tr><th>Author</th>");
311 for (j = 0; j < period->count; j++) { 315 for (j = 0; j < period->count; j++) {
312 tmp = period->pretty(tm); 316 tmp = period->pretty(tm);
313 htmlf("<th>%s</th>", tmp); 317 htmlf("<th>%s</th>", tmp);
314 period->inc(tm); 318 period->inc(tm);
315 } 319 }
316 html("<th>Total</th></tr>\n"); 320 html("<th>Total</th></tr>\n");
317 321
318 if (top <= 0 || top > authors->nr) 322 if (top <= 0 || top > authors->nr)
319 top = authors->nr; 323 top = authors->nr;
320 324
321 for (i = 0; i < top; i++) { 325 for (i = 0; i < top; i++) {
322 author = &authors->items[i]; 326 author = &authors->items[i];
323 html("<tr><td class='left'>"); 327 html("<tr><td class='left'>");
324 html_txt(author->string); 328 html_txt(author->string);
325 html("</td>"); 329 html("</td>");
326 authorstat = author->util; 330 authorstat = author->util;
327 items = &authorstat->list; 331 items = &authorstat->list;
328 total = 0; 332 total = 0;
329 for (j = 0; j < period->count; j++) 333 for (j = 0; j < period->count; j++)
330 period->dec(tm); 334 period->dec(tm);
331 for (j = 0; j < period->count; j++) { 335 for (j = 0; j < period->count; j++) {
332 tmp = period->pretty(tm); 336 tmp = period->pretty(tm);
333 period->inc(tm); 337 period->inc(tm);
334 date = string_list_lookup(items, tmp); 338 date = string_list_lookup(items, tmp);
335 if (!date) 339 if (!date)
336 html("<td>0</td>"); 340 html("<td>0</td>");
337 else { 341 else {
338 htmlf("<td>%d</td>", date->util); 342 htmlf("<td>"SZ_FMT"</td>", (size_t)date->util);
339 total += (size_t)date->util; 343 total += (size_t)date->util;
340 } 344 }
341 } 345 }
342 htmlf("<td class='sum'>%d</td></tr>", total); 346 htmlf("<td class='sum'>%ld</td></tr>", total);
343 } 347 }
344 348
345 if (top < authors->nr) 349 if (top < authors->nr)
346 print_combined_authorrow(authors, top, authors->nr - 1, 350 print_combined_authorrow(authors, top, authors->nr - 1,
347 "Others (%d)", "left", "", "sum", period); 351 "Others (%ld)", "left", "", "sum", period);
348 352
349 print_combined_authorrow(authors, 0, authors->nr - 1, "Total", 353 print_combined_authorrow(authors, 0, authors->nr - 1, "Total",
350 "total", "sum", "sum", period); 354 "total", "sum", "sum", period);
351 html("</table>"); 355 html("</table>");
352} 356}
353 357
354/* Create a sorted string_list with one entry per author. The util-field 358/* Create a sorted string_list with one entry per author. The util-field
355 * for each author is another string_list which is used to calculate the 359 * for each author is another string_list which is used to calculate the
356 * number of commits per time-interval. 360 * number of commits per time-interval.
357 */ 361 */
358void cgit_show_stats(struct cgit_context *ctx) 362void cgit_show_stats(struct cgit_context *ctx)
359{ 363{
360 struct string_list authors; 364 struct string_list authors;
361 struct cgit_period *period; 365 struct cgit_period *period;
362 int top, i; 366 int top, i;
363 const char *code = "w"; 367 const char *code = "w";
364 368
365 if (ctx->qry.period) 369 if (ctx->qry.period)
366 code = ctx->qry.period; 370 code = ctx->qry.period;
367 371
368 i = cgit_find_stats_period(code, &period); 372 i = cgit_find_stats_period(code, &period);
369 if (!i) { 373 if (!i) {
370 cgit_print_error(fmt("Unknown statistics type: %c", code)); 374 cgit_print_error(fmt("Unknown statistics type: %c", code[0]));
371 return; 375 return;
372 } 376 }
373 if (i > ctx->repo->max_stats) { 377 if (i > ctx->repo->max_stats) {
374 cgit_print_error(fmt("Statistics type disabled: %s", 378 cgit_print_error(fmt("Statistics type disabled: %s",
375 period->name)); 379 period->name));
376 return; 380 return;
377 } 381 }
378 authors = collect_stats(ctx, period); 382 authors = collect_stats(ctx, period);
379 qsort(authors.items, authors.nr, sizeof(struct string_list_item), 383 qsort(authors.items, authors.nr, sizeof(struct string_list_item),
380 cmp_total_commits); 384 cmp_total_commits);
381 385
382 top = ctx->qry.ofs; 386 top = ctx->qry.ofs;
383 if (!top) 387 if (!top)
384 top = 10; 388 top = 10;
385 htmlf("<h2>Commits per author per %s", period->name); 389 htmlf("<h2>Commits per author per %s", period->name);
386 if (ctx->qry.path) { 390 if (ctx->qry.path) {
387 html(" (path '"); 391 html(" (path '");
388 html_txt(ctx->qry.path); 392 html_txt(ctx->qry.path);
389 html("')"); 393 html("')");
390 } 394 }
391 html("</h2>"); 395 html("</h2>");
392 396
393 html("<form method='get' action='' style='float: right; text-align: right;'>"); 397 html("<form method='get' action='' style='float: right; text-align: right;'>");
394 cgit_add_hidden_formfields(1, 0, "stats"); 398 cgit_add_hidden_formfields(1, 0, "stats");