|
|
|
@@ -1,424 +1,422 @@ |
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 | |
8 | #ifdef NO_C99_FORMAT |
6 | #ifdef NO_C99_FORMAT |
9 | #define SZ_FMT "%u" |
7 | #define SZ_FMT "%u" |
10 | #else |
8 | #else |
11 | #define SZ_FMT "%zu" |
9 | #define SZ_FMT "%zu" |
12 | #endif |
10 | #endif |
13 | |
11 | |
14 | #define MONTHS 6 |
12 | #define MONTHS 6 |
15 | |
13 | |
16 | struct authorstat { |
14 | struct authorstat { |
17 | long total; |
15 | long total; |
18 | struct string_list list; |
16 | struct string_list list; |
19 | }; |
17 | }; |
20 | |
18 | |
21 | #define DAY_SECS (60 * 60 * 24) |
19 | #define DAY_SECS (60 * 60 * 24) |
22 | #define WEEK_SECS (DAY_SECS * 7) |
20 | #define WEEK_SECS (DAY_SECS * 7) |
23 | |
21 | |
24 | static void trunc_week(struct tm *tm) |
22 | static void trunc_week(struct tm *tm) |
25 | { |
23 | { |
26 | time_t t = timegm(tm); |
24 | time_t t = timegm(tm); |
27 | t -= ((tm->tm_wday + 6) % 7) * DAY_SECS; |
25 | t -= ((tm->tm_wday + 6) % 7) * DAY_SECS; |
28 | gmtime_r(&t, tm); |
26 | gmtime_r(&t, tm); |
29 | } |
27 | } |
30 | |
28 | |
31 | static void dec_week(struct tm *tm) |
29 | static void dec_week(struct tm *tm) |
32 | { |
30 | { |
33 | time_t t = timegm(tm); |
31 | time_t t = timegm(tm); |
34 | t -= WEEK_SECS; |
32 | t -= WEEK_SECS; |
35 | gmtime_r(&t, tm); |
33 | gmtime_r(&t, tm); |
36 | } |
34 | } |
37 | |
35 | |
38 | static void inc_week(struct tm *tm) |
36 | static void inc_week(struct tm *tm) |
39 | { |
37 | { |
40 | time_t t = timegm(tm); |
38 | time_t t = timegm(tm); |
41 | t += WEEK_SECS; |
39 | t += WEEK_SECS; |
42 | gmtime_r(&t, tm); |
40 | gmtime_r(&t, tm); |
43 | } |
41 | } |
44 | |
42 | |
45 | static char *pretty_week(struct tm *tm) |
43 | static char *pretty_week(struct tm *tm) |
46 | { |
44 | { |
47 | static char buf[10]; |
45 | static char buf[10]; |
48 | |
46 | |
49 | strftime(buf, sizeof(buf), "W%V %G", tm); |
47 | strftime(buf, sizeof(buf), "W%V %G", tm); |
50 | return buf; |
48 | return buf; |
51 | } |
49 | } |
52 | |
50 | |
53 | static void trunc_month(struct tm *tm) |
51 | static void trunc_month(struct tm *tm) |
54 | { |
52 | { |
55 | tm->tm_mday = 1; |
53 | tm->tm_mday = 1; |
56 | } |
54 | } |
57 | |
55 | |
58 | static void dec_month(struct tm *tm) |
56 | static void dec_month(struct tm *tm) |
59 | { |
57 | { |
60 | tm->tm_mon--; |
58 | tm->tm_mon--; |
61 | if (tm->tm_mon < 0) { |
59 | if (tm->tm_mon < 0) { |
62 | tm->tm_year--; |
60 | tm->tm_year--; |
63 | tm->tm_mon = 11; |
61 | tm->tm_mon = 11; |
64 | } |
62 | } |
65 | } |
63 | } |
66 | |
64 | |
67 | static void inc_month(struct tm *tm) |
65 | static void inc_month(struct tm *tm) |
68 | { |
66 | { |
69 | tm->tm_mon++; |
67 | tm->tm_mon++; |
70 | if (tm->tm_mon > 11) { |
68 | if (tm->tm_mon > 11) { |
71 | tm->tm_year++; |
69 | tm->tm_year++; |
72 | tm->tm_mon = 0; |
70 | tm->tm_mon = 0; |
73 | } |
71 | } |
74 | } |
72 | } |
75 | |
73 | |
76 | static char *pretty_month(struct tm *tm) |
74 | static char *pretty_month(struct tm *tm) |
77 | { |
75 | { |
78 | static const char *months[] = { |
76 | static const char *months[] = { |
79 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
77 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
80 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
78 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
81 | }; |
79 | }; |
82 | return fmt("%s %d", months[tm->tm_mon], tm->tm_year + 1900); |
80 | return fmt("%s %d", months[tm->tm_mon], tm->tm_year + 1900); |
83 | } |
81 | } |
84 | |
82 | |
85 | static void trunc_quarter(struct tm *tm) |
83 | static void trunc_quarter(struct tm *tm) |
86 | { |
84 | { |
87 | trunc_month(tm); |
85 | trunc_month(tm); |
88 | while(tm->tm_mon % 3 != 0) |
86 | while(tm->tm_mon % 3 != 0) |
89 | dec_month(tm); |
87 | dec_month(tm); |
90 | } |
88 | } |
91 | |
89 | |
92 | static void dec_quarter(struct tm *tm) |
90 | static void dec_quarter(struct tm *tm) |
93 | { |
91 | { |
94 | dec_month(tm); |
92 | dec_month(tm); |
95 | dec_month(tm); |
93 | dec_month(tm); |
96 | dec_month(tm); |
94 | dec_month(tm); |
97 | } |
95 | } |
98 | |
96 | |
99 | static void inc_quarter(struct tm *tm) |
97 | static void inc_quarter(struct tm *tm) |
100 | { |
98 | { |
101 | inc_month(tm); |
99 | inc_month(tm); |
102 | inc_month(tm); |
100 | inc_month(tm); |
103 | inc_month(tm); |
101 | inc_month(tm); |
104 | } |
102 | } |
105 | |
103 | |
106 | static char *pretty_quarter(struct tm *tm) |
104 | static char *pretty_quarter(struct tm *tm) |
107 | { |
105 | { |
108 | return fmt("Q%d %d", tm->tm_mon / 3 + 1, tm->tm_year + 1900); |
106 | return fmt("Q%d %d", tm->tm_mon / 3 + 1, tm->tm_year + 1900); |
109 | } |
107 | } |
110 | |
108 | |
111 | static void trunc_year(struct tm *tm) |
109 | static void trunc_year(struct tm *tm) |
112 | { |
110 | { |
113 | trunc_month(tm); |
111 | trunc_month(tm); |
114 | tm->tm_mon = 0; |
112 | tm->tm_mon = 0; |
115 | } |
113 | } |
116 | |
114 | |
117 | static void dec_year(struct tm *tm) |
115 | static void dec_year(struct tm *tm) |
118 | { |
116 | { |
119 | tm->tm_year--; |
117 | tm->tm_year--; |
120 | } |
118 | } |
121 | |
119 | |
122 | static void inc_year(struct tm *tm) |
120 | static void inc_year(struct tm *tm) |
123 | { |
121 | { |
124 | tm->tm_year++; |
122 | tm->tm_year++; |
125 | } |
123 | } |
126 | |
124 | |
127 | static char *pretty_year(struct tm *tm) |
125 | static char *pretty_year(struct tm *tm) |
128 | { |
126 | { |
129 | return fmt("%d", tm->tm_year + 1900); |
127 | return fmt("%d", tm->tm_year + 1900); |
130 | } |
128 | } |
131 | |
129 | |
132 | struct cgit_period periods[] = { |
130 | struct cgit_period periods[] = { |
133 | {'w', "week", 12, 4, trunc_week, dec_week, inc_week, pretty_week}, |
131 | {'w', "week", 12, 4, trunc_week, dec_week, inc_week, pretty_week}, |
134 | {'m', "month", 12, 4, trunc_month, dec_month, inc_month, pretty_month}, |
132 | {'m', "month", 12, 4, trunc_month, dec_month, inc_month, pretty_month}, |
135 | {'q', "quarter", 12, 4, trunc_quarter, dec_quarter, inc_quarter, pretty_quarter}, |
133 | {'q', "quarter", 12, 4, trunc_quarter, dec_quarter, inc_quarter, pretty_quarter}, |
136 | {'y', "year", 12, 4, trunc_year, dec_year, inc_year, pretty_year}, |
134 | {'y', "year", 12, 4, trunc_year, dec_year, inc_year, pretty_year}, |
137 | }; |
135 | }; |
138 | |
136 | |
139 | /* Given a period code or name, return a period index (1, 2, 3 or 4) |
137 | /* Given a period code or name, return a period index (1, 2, 3 or 4) |
140 | * and update the period pointer to the correcsponding struct. |
138 | * and update the period pointer to the correcsponding struct. |
141 | * If no matching code is found, return 0. |
139 | * If no matching code is found, return 0. |
142 | */ |
140 | */ |
143 | int cgit_find_stats_period(const char *expr, struct cgit_period **period) |
141 | int cgit_find_stats_period(const char *expr, struct cgit_period **period) |
144 | { |
142 | { |
145 | int i; |
143 | int i; |
146 | char code = '\0'; |
144 | char code = '\0'; |
147 | |
145 | |
148 | if (!expr) |
146 | if (!expr) |
149 | return 0; |
147 | return 0; |
150 | |
148 | |
151 | if (strlen(expr) == 1) |
149 | if (strlen(expr) == 1) |
152 | code = expr[0]; |
150 | code = expr[0]; |
153 | |
151 | |
154 | for (i = 0; i < sizeof(periods) / sizeof(periods[0]); i++) |
152 | for (i = 0; i < sizeof(periods) / sizeof(periods[0]); i++) |
155 | if (periods[i].code == code || !strcmp(periods[i].name, expr)) { |
153 | if (periods[i].code == code || !strcmp(periods[i].name, expr)) { |
156 | if (period) |
154 | if (period) |
157 | *period = &periods[i]; |
155 | *period = &periods[i]; |
158 | return i+1; |
156 | return i+1; |
159 | } |
157 | } |
160 | return 0; |
158 | return 0; |
161 | } |
159 | } |
162 | |
160 | |
163 | const char *cgit_find_stats_periodname(int idx) |
161 | const char *cgit_find_stats_periodname(int idx) |
164 | { |
162 | { |
165 | if (idx > 0 && idx < 4) |
163 | if (idx > 0 && idx < 4) |
166 | return periods[idx - 1].name; |
164 | return periods[idx - 1].name; |
167 | else |
165 | else |
168 | return ""; |
166 | return ""; |
169 | } |
167 | } |
170 | |
168 | |
171 | static void add_commit(struct string_list *authors, struct commit *commit, |
169 | static void add_commit(struct string_list *authors, struct commit *commit, |
172 | struct cgit_period *period) |
170 | struct cgit_period *period) |
173 | { |
171 | { |
174 | struct commitinfo *info; |
172 | struct commitinfo *info; |
175 | struct string_list_item *author, *item; |
173 | struct string_list_item *author, *item; |
176 | struct authorstat *authorstat; |
174 | struct authorstat *authorstat; |
177 | struct string_list *items; |
175 | struct string_list *items; |
178 | char *tmp; |
176 | char *tmp; |
179 | struct tm *date; |
177 | struct tm *date; |
180 | time_t t; |
178 | time_t t; |
181 | |
179 | |
182 | info = cgit_parse_commit(commit); |
180 | info = cgit_parse_commit(commit); |
183 | tmp = xstrdup(info->author); |
181 | tmp = xstrdup(info->author); |
184 | author = string_list_insert(authors, tmp); |
182 | author = string_list_insert(authors, tmp); |
185 | if (!author->util) |
183 | if (!author->util) |
186 | author->util = xcalloc(1, sizeof(struct authorstat)); |
184 | author->util = xcalloc(1, sizeof(struct authorstat)); |
187 | else |
185 | else |
188 | free(tmp); |
186 | free(tmp); |
189 | authorstat = author->util; |
187 | authorstat = author->util; |
190 | items = &authorstat->list; |
188 | items = &authorstat->list; |
191 | t = info->committer_date; |
189 | t = info->committer_date; |
192 | date = gmtime(&t); |
190 | date = gmtime(&t); |
193 | period->trunc(date); |
191 | period->trunc(date); |
194 | tmp = xstrdup(period->pretty(date)); |
192 | tmp = xstrdup(period->pretty(date)); |
195 | item = string_list_insert(items, tmp); |
193 | item = string_list_insert(items, tmp); |
196 | if (item->util) |
194 | if (item->util) |
197 | free(tmp); |
195 | free(tmp); |
198 | item->util++; |
196 | item->util++; |
199 | authorstat->total++; |
197 | authorstat->total++; |
200 | cgit_free_commitinfo(info); |
198 | cgit_free_commitinfo(info); |
201 | } |
199 | } |
202 | |
200 | |
203 | static int cmp_total_commits(const void *a1, const void *a2) |
201 | static int cmp_total_commits(const void *a1, const void *a2) |
204 | { |
202 | { |
205 | const struct string_list_item *i1 = a1; |
203 | const struct string_list_item *i1 = a1; |
206 | const struct string_list_item *i2 = a2; |
204 | const struct string_list_item *i2 = a2; |
207 | const struct authorstat *auth1 = i1->util; |
205 | const struct authorstat *auth1 = i1->util; |
208 | const struct authorstat *auth2 = i2->util; |
206 | const struct authorstat *auth2 = i2->util; |
209 | |
207 | |
210 | return auth2->total - auth1->total; |
208 | return auth2->total - auth1->total; |
211 | } |
209 | } |
212 | |
210 | |
213 | /* Walk the commit DAG and collect number of commits per author per |
211 | /* Walk the commit DAG and collect number of commits per author per |
214 | * timeperiod into a nested string_list collection. |
212 | * timeperiod into a nested string_list collection. |
215 | */ |
213 | */ |
216 | struct string_list collect_stats(struct cgit_context *ctx, |
214 | struct string_list collect_stats(struct cgit_context *ctx, |
217 | struct cgit_period *period) |
215 | struct cgit_period *period) |
218 | { |
216 | { |
219 | struct string_list authors; |
217 | struct string_list authors; |
220 | struct rev_info rev; |
218 | struct rev_info rev; |
221 | struct commit *commit; |
219 | struct commit *commit; |
222 | const char *argv[] = {NULL, ctx->qry.head, NULL, NULL, NULL, NULL}; |
220 | const char *argv[] = {NULL, ctx->qry.head, NULL, NULL, NULL, NULL}; |
223 | int argc = 3; |
221 | int argc = 3; |
224 | time_t now; |
222 | time_t now; |
225 | long i; |
223 | long i; |
226 | struct tm *tm; |
224 | struct tm *tm; |
227 | char tmp[11]; |
225 | char tmp[11]; |
228 | |
226 | |
229 | time(&now); |
227 | time(&now); |
230 | tm = gmtime(&now); |
228 | tm = gmtime(&now); |
231 | period->trunc(tm); |
229 | period->trunc(tm); |
232 | for (i = 1; i < period->count; i++) |
230 | for (i = 1; i < period->count; i++) |
233 | period->dec(tm); |
231 | period->dec(tm); |
234 | strftime(tmp, sizeof(tmp), "%Y-%m-%d", tm); |
232 | strftime(tmp, sizeof(tmp), "%Y-%m-%d", tm); |
235 | argv[2] = xstrdup(fmt("--since=%s", tmp)); |
233 | argv[2] = xstrdup(fmt("--since=%s", tmp)); |
236 | if (ctx->qry.path) { |
234 | if (ctx->qry.path) { |
237 | argv[3] = "--"; |
235 | argv[3] = "--"; |
238 | argv[4] = ctx->qry.path; |
236 | argv[4] = ctx->qry.path; |
239 | argc += 2; |
237 | argc += 2; |
240 | } |
238 | } |
241 | init_revisions(&rev, NULL); |
239 | init_revisions(&rev, NULL); |
242 | rev.abbrev = DEFAULT_ABBREV; |
240 | rev.abbrev = DEFAULT_ABBREV; |
243 | rev.commit_format = CMIT_FMT_DEFAULT; |
241 | rev.commit_format = CMIT_FMT_DEFAULT; |
244 | rev.no_merges = 1; |
242 | rev.no_merges = 1; |
245 | rev.verbose_header = 1; |
243 | rev.verbose_header = 1; |
246 | rev.show_root_diff = 0; |
244 | rev.show_root_diff = 0; |
247 | setup_revisions(argc, argv, &rev, NULL); |
245 | setup_revisions(argc, argv, &rev, NULL); |
248 | prepare_revision_walk(&rev); |
246 | prepare_revision_walk(&rev); |
249 | memset(&authors, 0, sizeof(authors)); |
247 | memset(&authors, 0, sizeof(authors)); |
250 | while ((commit = get_revision(&rev)) != NULL) { |
248 | while ((commit = get_revision(&rev)) != NULL) { |
251 | add_commit(&authors, commit, period); |
249 | add_commit(&authors, commit, period); |
252 | free(commit->buffer); |
250 | free(commit->buffer); |
253 | free_commit_list(commit->parents); |
251 | free_commit_list(commit->parents); |
254 | } |
252 | } |
255 | return authors; |
253 | return authors; |
256 | } |
254 | } |
257 | |
255 | |
258 | void print_combined_authorrow(struct string_list *authors, int from, int to, |
256 | void print_combined_authorrow(struct string_list *authors, int from, int to, |
259 | const char *name, const char *leftclass, const char *centerclass, |
257 | const char *name, const char *leftclass, const char *centerclass, |
260 | const char *rightclass, struct cgit_period *period) |
258 | const char *rightclass, struct cgit_period *period) |
261 | { |
259 | { |
262 | struct string_list_item *author; |
260 | struct string_list_item *author; |
263 | struct authorstat *authorstat; |
261 | struct authorstat *authorstat; |
264 | struct string_list *items; |
262 | struct string_list *items; |
265 | struct string_list_item *date; |
263 | struct string_list_item *date; |
266 | time_t now; |
264 | time_t now; |
267 | long i, j, total, subtotal; |
265 | long i, j, total, subtotal; |
268 | struct tm *tm; |
266 | struct tm *tm; |
269 | char *tmp; |
267 | char *tmp; |
270 | |
268 | |
271 | time(&now); |
269 | time(&now); |
272 | tm = gmtime(&now); |
270 | tm = gmtime(&now); |
273 | period->trunc(tm); |
271 | period->trunc(tm); |
274 | for (i = 1; i < period->count; i++) |
272 | for (i = 1; i < period->count; i++) |
275 | period->dec(tm); |
273 | period->dec(tm); |
276 | |
274 | |
277 | total = 0; |
275 | total = 0; |
278 | htmlf("<tr><td class='%s'>%s</td>", leftclass, |
276 | htmlf("<tr><td class='%s'>%s</td>", leftclass, |
279 | fmt(name, to - from + 1)); |
277 | fmt(name, to - from + 1)); |
280 | for (j = 0; j < period->count; j++) { |
278 | for (j = 0; j < period->count; j++) { |
281 | tmp = period->pretty(tm); |
279 | tmp = period->pretty(tm); |
282 | period->inc(tm); |
280 | period->inc(tm); |
283 | subtotal = 0; |
281 | subtotal = 0; |
284 | for (i = from; i <= to; i++) { |
282 | for (i = from; i <= to; i++) { |
285 | author = &authors->items[i]; |
283 | author = &authors->items[i]; |
286 | authorstat = author->util; |
284 | authorstat = author->util; |
287 | items = &authorstat->list; |
285 | items = &authorstat->list; |
288 | date = string_list_lookup(items, tmp); |
286 | date = string_list_lookup(items, tmp); |
289 | if (date) |
287 | if (date) |
290 | subtotal += (size_t)date->util; |
288 | subtotal += (size_t)date->util; |
291 | } |
289 | } |
292 | htmlf("<td class='%s'>%ld</td>", centerclass, subtotal); |
290 | htmlf("<td class='%s'>%ld</td>", centerclass, subtotal); |
293 | total += subtotal; |
291 | total += subtotal; |
294 | } |
292 | } |
295 | htmlf("<td class='%s'>%ld</td></tr>", rightclass, total); |
293 | htmlf("<td class='%s'>%ld</td></tr>", rightclass, total); |
296 | } |
294 | } |
297 | |
295 | |
298 | void print_authors(struct string_list *authors, int top, |
296 | void print_authors(struct string_list *authors, int top, |
299 | struct cgit_period *period) |
297 | struct cgit_period *period) |
300 | { |
298 | { |
301 | struct string_list_item *author; |
299 | struct string_list_item *author; |
302 | struct authorstat *authorstat; |
300 | struct authorstat *authorstat; |
303 | struct string_list *items; |
301 | struct string_list *items; |
304 | struct string_list_item *date; |
302 | struct string_list_item *date; |
305 | time_t now; |
303 | time_t now; |
306 | long i, j, total; |
304 | long i, j, total; |
307 | struct tm *tm; |
305 | struct tm *tm; |
308 | char *tmp; |
306 | char *tmp; |
309 | |
307 | |
310 | time(&now); |
308 | time(&now); |
311 | tm = gmtime(&now); |
309 | tm = gmtime(&now); |
312 | period->trunc(tm); |
310 | period->trunc(tm); |
313 | for (i = 1; i < period->count; i++) |
311 | for (i = 1; i < period->count; i++) |
314 | period->dec(tm); |
312 | period->dec(tm); |
315 | |
313 | |
316 | html("<table class='stats'><tr><th>Author</th>"); |
314 | html("<table class='stats'><tr><th>Author</th>"); |
317 | for (j = 0; j < period->count; j++) { |
315 | for (j = 0; j < period->count; j++) { |
318 | tmp = period->pretty(tm); |
316 | tmp = period->pretty(tm); |
319 | htmlf("<th>%s</th>", tmp); |
317 | htmlf("<th>%s</th>", tmp); |
320 | period->inc(tm); |
318 | period->inc(tm); |
321 | } |
319 | } |
322 | html("<th>Total</th></tr>\n"); |
320 | html("<th>Total</th></tr>\n"); |
323 | |
321 | |
324 | if (top <= 0 || top > authors->nr) |
322 | if (top <= 0 || top > authors->nr) |
325 | top = authors->nr; |
323 | top = authors->nr; |
326 | |
324 | |
327 | for (i = 0; i < top; i++) { |
325 | for (i = 0; i < top; i++) { |
328 | author = &authors->items[i]; |
326 | author = &authors->items[i]; |
329 | html("<tr><td class='left'>"); |
327 | html("<tr><td class='left'>"); |
330 | html_txt(author->string); |
328 | html_txt(author->string); |
331 | html("</td>"); |
329 | html("</td>"); |
332 | authorstat = author->util; |
330 | authorstat = author->util; |
333 | items = &authorstat->list; |
331 | items = &authorstat->list; |
334 | total = 0; |
332 | total = 0; |
335 | for (j = 0; j < period->count; j++) |
333 | for (j = 0; j < period->count; j++) |
336 | period->dec(tm); |
334 | period->dec(tm); |
337 | for (j = 0; j < period->count; j++) { |
335 | for (j = 0; j < period->count; j++) { |
338 | tmp = period->pretty(tm); |
336 | tmp = period->pretty(tm); |
339 | period->inc(tm); |
337 | period->inc(tm); |
340 | date = string_list_lookup(items, tmp); |
338 | date = string_list_lookup(items, tmp); |
341 | if (!date) |
339 | if (!date) |
342 | html("<td>0</td>"); |
340 | html("<td>0</td>"); |
343 | else { |
341 | else { |
344 | htmlf("<td>"SZ_FMT"</td>", (size_t)date->util); |
342 | htmlf("<td>"SZ_FMT"</td>", (size_t)date->util); |
345 | total += (size_t)date->util; |
343 | total += (size_t)date->util; |
346 | } |
344 | } |
347 | } |
345 | } |
348 | htmlf("<td class='sum'>%ld</td></tr>", total); |
346 | htmlf("<td class='sum'>%ld</td></tr>", total); |
349 | } |
347 | } |
350 | |
348 | |
351 | if (top < authors->nr) |
349 | if (top < authors->nr) |
352 | print_combined_authorrow(authors, top, authors->nr - 1, |
350 | print_combined_authorrow(authors, top, authors->nr - 1, |
353 | "Others (%ld)", "left", "", "sum", period); |
351 | "Others (%ld)", "left", "", "sum", period); |
354 | |
352 | |
355 | print_combined_authorrow(authors, 0, authors->nr - 1, "Total", |
353 | print_combined_authorrow(authors, 0, authors->nr - 1, "Total", |
356 | "total", "sum", "sum", period); |
354 | "total", "sum", "sum", period); |
357 | html("</table>"); |
355 | html("</table>"); |
358 | } |
356 | } |
359 | |
357 | |
360 | /* 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 |
361 | * 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 |
362 | * number of commits per time-interval. |
360 | * number of commits per time-interval. |
363 | */ |
361 | */ |
364 | void cgit_show_stats(struct cgit_context *ctx) |
362 | void cgit_show_stats(struct cgit_context *ctx) |
365 | { |
363 | { |
366 | struct string_list authors; |
364 | struct string_list authors; |
367 | struct cgit_period *period; |
365 | struct cgit_period *period; |
368 | int top, i; |
366 | int top, i; |
369 | const char *code = "w"; |
367 | const char *code = "w"; |
370 | |
368 | |
371 | if (ctx->qry.period) |
369 | if (ctx->qry.period) |
372 | code = ctx->qry.period; |
370 | code = ctx->qry.period; |
373 | |
371 | |
374 | i = cgit_find_stats_period(code, &period); |
372 | i = cgit_find_stats_period(code, &period); |
375 | if (!i) { |
373 | if (!i) { |
376 | cgit_print_error(fmt("Unknown statistics type: %c", code[0])); |
374 | cgit_print_error(fmt("Unknown statistics type: %c", code[0])); |
377 | return; |
375 | return; |
378 | } |
376 | } |
379 | if (i > ctx->repo->max_stats) { |
377 | if (i > ctx->repo->max_stats) { |
380 | cgit_print_error(fmt("Statistics type disabled: %s", |
378 | cgit_print_error(fmt("Statistics type disabled: %s", |
381 | period->name)); |
379 | period->name)); |
382 | return; |
380 | return; |
383 | } |
381 | } |
384 | authors = collect_stats(ctx, period); |
382 | authors = collect_stats(ctx, period); |
385 | qsort(authors.items, authors.nr, sizeof(struct string_list_item), |
383 | qsort(authors.items, authors.nr, sizeof(struct string_list_item), |
386 | cmp_total_commits); |
384 | cmp_total_commits); |
387 | |
385 | |
388 | top = ctx->qry.ofs; |
386 | top = ctx->qry.ofs; |
389 | if (!top) |
387 | if (!top) |
390 | top = 10; |
388 | top = 10; |
391 | htmlf("<h2>Commits per author per %s", period->name); |
389 | htmlf("<h2>Commits per author per %s", period->name); |
392 | if (ctx->qry.path) { |
390 | if (ctx->qry.path) { |
393 | html(" (path '"); |
391 | html(" (path '"); |
394 | html_txt(ctx->qry.path); |
392 | html_txt(ctx->qry.path); |
395 | html("')"); |
393 | html("')"); |
396 | } |
394 | } |
397 | html("</h2>"); |
395 | html("</h2>"); |
398 | |
396 | |
399 | html("<form method='get' action='' style='float: right; text-align: right;'>"); |
397 | html("<form method='get' action='' style='float: right; text-align: right;'>"); |
400 | cgit_add_hidden_formfields(1, 0, "stats"); |
398 | cgit_add_hidden_formfields(1, 0, "stats"); |
401 | if (ctx->repo->max_stats > 1) { |
399 | if (ctx->repo->max_stats > 1) { |
402 | html("Period: "); |
400 | html("Period: "); |
403 | html("<select name='period' onchange='this.form.submit();'>"); |
401 | html("<select name='period' onchange='this.form.submit();'>"); |
404 | for (i = 0; i < ctx->repo->max_stats; i++) |
402 | for (i = 0; i < ctx->repo->max_stats; i++) |
405 | htmlf("<option value='%c'%s>%s</option>", |
403 | htmlf("<option value='%c'%s>%s</option>", |
406 | periods[i].code, |
404 | periods[i].code, |
407 | period == &periods[i] ? " selected" : "", |
405 | period == &periods[i] ? " selected" : "", |
408 | periods[i].name); |
406 | periods[i].name); |
409 | html("</select><br/><br/>"); |
407 | html("</select><br/><br/>"); |
410 | } |
408 | } |
411 | html("Authors: "); |
409 | html("Authors: "); |
412 | html(""); |
410 | html(""); |
413 | html("<select name='ofs' onchange='this.form.submit();'>"); |
411 | html("<select name='ofs' onchange='this.form.submit();'>"); |
414 | htmlf("<option value='10'%s>10</option>", top == 10 ? " selected" : ""); |
412 | htmlf("<option value='10'%s>10</option>", top == 10 ? " selected" : ""); |
415 | htmlf("<option value='25'%s>25</option>", top == 25 ? " selected" : ""); |
413 | htmlf("<option value='25'%s>25</option>", top == 25 ? " selected" : ""); |
416 | htmlf("<option value='50'%s>50</option>", top == 50 ? " selected" : ""); |
414 | htmlf("<option value='50'%s>50</option>", top == 50 ? " selected" : ""); |
417 | htmlf("<option value='100'%s>100</option>", top == 100 ? " selected" : ""); |
415 | htmlf("<option value='100'%s>100</option>", top == 100 ? " selected" : ""); |
418 | htmlf("<option value='-1'%s>All</option>", top == -1 ? " selected" : ""); |
416 | htmlf("<option value='-1'%s>All</option>", top == -1 ? " selected" : ""); |
419 | html("</select>"); |
417 | html("</select>"); |
420 | html("<noscript> <input type='submit' value='Reload'/></noscript>"); |
418 | html("<noscript> <input type='submit' value='Reload'/></noscript>"); |
421 | html("</form>"); |
419 | html("</form>"); |
422 | print_authors(&authors, top, period); |
420 | print_authors(&authors, top, period); |
423 | } |
421 | } |
424 | |
422 | |
|