| ︙ | | |
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
case 'g':
return "tag changes";
default:
return "all types";
}
}
/*
** A helper for the /reports family of pages which prints out a menu
** of links for the various type=XXX flags. zCurrentViewName must be
** the name/value of the 'view' parameter which is in effect at the
** time this is called. e.g. if called from the 'byuser' view then
** zCurrentViewName must be "byuser". Any URL parameters which need to
** be added to the generated URLs should be passed in zParam. The
** caller is expected to have already encoded any zParam in the %T or
** %t encoding. */
static void stats_report_event_types_menu(const char *zCurrentViewName,
const char *zParam){
char *zTop;
if(zParam && !*zParam){
zParam = NULL;
}
zTop = mprintf("%s/reports?view=%s%s%s", g.zTop, zCurrentViewName,
zParam ? "&" : "", zParam);
cgi_printf("<div>");
cgi_printf("<span>Types:</span> ");
if('*' == statsReportType){
cgi_printf(" <strong>all</strong>", zTop);
}else{
cgi_printf(" <a href='%s'>all</a>", zTop);
}
if('c' == statsReportType){
cgi_printf(" <strong>check-ins</strong>", zTop);
}else{
cgi_printf(" <a href='%s&type=ci'>check-ins</a>", zTop);
}
if('e' == statsReportType){
cgi_printf(" <strong>technotes</strong>", zTop);
}else{
cgi_printf(" <a href='%s&type=e'>technotes</a>", zTop);
}
if( 't' == statsReportType ){
cgi_printf(" <strong>tickets</strong>", zTop);
}else{
cgi_printf(" <a href='%s&type=t'>tickets</a>", zTop);
}
if( 'g' == statsReportType ){
cgi_printf(" <strong>tags</strong>", zTop);
}else{
cgi_printf(" <a href='%s&type=g'>tags</a>", zTop);
}
if( 'w' == statsReportType ){
cgi_printf(" <strong>wiki</strong>", zTop);
}else{
cgi_printf(" <a href='%s&type=w'>wiki</a>", zTop);
}
fossil_free(zTop);
cgi_printf("</div>");
}
/*
** Helper for stats_report_by_month_year(), which generates a list of
** week numbers. zTimeframe should be either a timeframe in the form YYYY
** or YYYY-MM.
*/
static void stats_report_output_week_links(const char *zTimeframe){
|
| ︙ | | |
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
-
-
+
+
-
-
+
-
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
+
-
|
}
db_finalize(&stWeek);
}
/*
** Implements the "byyear" and "bymonth" reports for /reports.
** If includeMonth is true then it generates the "bymonth" report,
** else the "byyear" report. If zUserName is not NULL and not empty
** then the report is restricted to events created by the named user
** else the "byyear" report. If zUserName is not NULL then the report is
** restricted to events created by the named user account.
** account.
*/
static void stats_report_by_month_year(char includeMonth,
char includeWeeks,
const char *zUserName){
Stmt query = empty_Stmt;
int nRowNumber = 0; /* current TR number */
int nEventTotal = 0; /* Total event count */
int rowClass = 0; /* counter for alternating
row colors */
Blob sql = empty_blob; /* SQL */
const char *zTimeLabel = includeMonth ? "Year/Month" : "Year";
char zPrevYear[5] = {0}; /* For keeping track of when
we change years while looping */
int nEventsPerYear = 0; /* Total event count for the
current year */
char showYearTotal = 0; /* Flag telling us when to show
the per-year event totals */
Blob header = empty_blob; /* Page header text */
int nMaxEvents = 1; /* for calculating length of graph
bars. */
int iterations = 0; /* number of weeks/months we iterate
over */
Blob userFilter = empty_blob; /* Optional user=johndoe query string */
stats_report_init_view();
stats_report_event_types_menu( includeMonth ? "bymonth" : "byyear", NULL );
blob_appendf(&header, "Timeline Events (%s) by year%s",
if( zUserName ){
stats_report_label_for_type(),
(includeMonth ? "/month" : ""));
blob_append_sql(&sql,
"SELECT substr(date(mtime),1,%d) AS timeframe, "
"count(*) AS eventCount "
"FROM v_reports ",
includeMonth ? 7 : 4);
if(zUserName&&*zUserName){
blob_appendf(&userFilter, "user=%s", zUserName);
}
blob_reset(&userFilter);
db_prepare(&query,
"SELECT substr(date(mtime),1,%d) AS timeframe,"
" count(*) AS eventCount"
" FROM v_reports"
" WHERE ifnull(coalesce(euser,user,'')=%Q,1)"
" GROUP BY timeframe"
" ORDER BY timeframe DESC",
includeMonth ? 7 : 4, zUserName);
@ <h1>Timeline Events (%s(stats_report_label_for_type()))
@ by year%s(includeMonth ? "/month" : "")
if( zUserName ){
blob_append_sql(&sql, " WHERE user=%Q ", zUserName);
blob_appendf(&header," for user %q", zUserName);
@ for user %h(zUserName)
}
blob_append(&sql,
" GROUP BY timeframe"
" ORDER BY timeframe DESC",
-1);
db_prepare(&query, "%s", blob_sql_text(&sql));
blob_reset(&sql);
@ <h1>%b(&header)</h1>
@ </h1>
@ <table class='statistics-report-table-events' border='0' cellpadding='2'
@ cellspacing='0' id='statsTable'>
@ <thead>
@ <th>%s(zTimeLabel)</th>
@ <th>Events</th>
@ <th width='90%%'><!-- relative commits graph --></th>
@ </thead><tbody>
blob_reset(&header);
/*
Run the query twice. The first time we calculate the maximum
number of events for a given row. Maybe someone with better SQL
Fu can re-implement this with a single query.
*/
while( SQLITE_ROW == db_step(&query) ){
const int nCount = db_column_int(&query, 1);
|
| ︙ | | |
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
-
+
-
+
|
cgi_printf("<a href='%R/timeline?"
"ym=%t&n=%d&y=%s",
zTimeframe, nCount,
statsReportTimelineYFlag );
/* Reminder: n=nCount is not actually correct for bymonth unless
that was the only user who caused events.
*/
if( zUserName && *zUserName ){
if( zUserName ){
cgi_printf("&u=%t", zUserName);
}
cgi_printf("' target='_new'>%s</a>",zTimeframe);
}else {
cgi_printf("<a href='?view=byweek&y=%s&type=%c",
zTimeframe, (char)statsReportType);
if(zUserName && *zUserName){
if( zUserName ){
cgi_printf("&u=%t", zUserName);
}
cgi_printf("'>%s</a>", zTimeframe);
}
@ </td><td>%d(nCount)</td>
@ <td>
@ <div class='statistics-report-graph-line'
|
| ︙ | | |
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
|
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
|
-
-
-
+
+
-
+
-
+
+
-
+
-
+
-
+
+
-
+
-
+
+
+
-
+
-
+
+
+
+
+
|
int nRowNumber = 0; /* current TR number */
int nEventTotal = 0; /* Total event count */
int rowClass = 0; /* counter for alternating
row colors */
int nMaxEvents = 1; /* max number of events for
all rows. */
stats_report_init_view();
stats_report_event_types_menu("byuser", NULL);
@ <h1>Timeline Events
@ (%s(stats_report_label_for_type())) by User</h1>
db_multi_exec(
"CREATE TEMP TABLE piechart(amt,label);"
"INSERT INTO piechart SELECT count(*), user FROM v_reports"
" GROUP BY user ORDER BY count(*) DESC;"
"INSERT INTO piechart SELECT count(*), ifnull(euser,user) FROM v_reports"
" GROUP BY ifnull(euser,user) ORDER BY count(*) DESC;"
);
if( db_int(0, "SELECT count(*) FROM piechart")>=2 ){
@ <center><svg width=700 height=400>
piechart_render(700, 400, PIE_OTHER|PIE_PERCENT);
@ </svg></centre><hr/>
}
@ <table class='statistics-report-table-events' border='0'
@ cellpadding='2' cellspacing='0' id='statsTable'>
@ <thead><tr>
@ <th>User</th>
@ <th>Events</th>
@ <th width='90%%'><!-- relative commits graph --></th>
@ </tr></thead><tbody>
db_prepare(&query,
"SELECT user, "
"SELECT ifnull(euser,user), "
"COUNT(*) AS eventCount "
"FROM v_reports "
"GROUP BY user ORDER BY eventCount DESC");
"GROUP BY ifnull(euser,user) ORDER BY eventCount DESC");
while( SQLITE_ROW == db_step(&query) ){
const int nCount = db_column_int(&query, 1);
if(nCount>nMaxEvents){
nMaxEvents = nCount;
}
}
db_reset(&query);
while( SQLITE_ROW == db_step(&query) ){
const char *zUser = db_column_text(&query, 0);
const int nCount = db_column_int(&query, 1);
char y = (char)statsReportType;
int nSize = nCount
? (int)(100 * nCount / nMaxEvents)
: 0;
if(!nCount) continue /* arguable! Possible? */;
else if(!nSize) nSize = 1;
rowClass = ++nRowNumber % 2;
nEventTotal += nCount;
@<tr class='row%d(rowClass)'>
@ <tr class='row%d(rowClass)'>
@ <td>
@ <a href="?view=bymonth&user=%h(zUser)&type=%c((char)statsReportType)">%h(zUser)</a>
@ <a href="?view=bymonth&user=%h(zUser)&type=%c(y)">%h(zUser)</a>
@ </td><td data-sortkey='%08x(-nCount)'>%d(nCount)</td>
@ <td>
@ <div class='statistics-report-graph-line'
@ style='width:%d(nSize)%%;'> </div>
@ </td>
@</tr>
/*
Potential improvement: calculate the min/max event counts and
use percent-based graph bars.
*/
}
@ </tbody></table>
db_finalize(&query);
output_table_sorting_javascript("statsTable","tkx",2);
}
/*
** Implements the "byfile" view for /reports.
** Implements the "byfile" view for /reports. If zUserName is not NULL then the
** report is restricted to events created by the named user account.
*/
static void stats_report_by_file(){
static void stats_report_by_file(const char *zUserName){
Stmt query;
int mxEvent = 1; /* max number of events across all rows */
int nRowNumber = 0;
db_multi_exec(
"CREATE TEMP TABLE statrep(filename, cnt);"
"INSERT INTO statrep(filename, cnt)"
" SELECT filename.name, count(distinct mlink.mid)"
" FROM filename, mlink"
" FROM filename, mlink, event"
" WHERE filename.fnid=mlink.fnid"
" AND mlink.mid=event.objid"
" AND ifnull(coalesce(euser,user,'')=%Q,1)"
" GROUP BY 1;"
" GROUP BY 1", zUserName
);
db_prepare(&query,
"SELECT filename, cnt FROM statrep ORDER BY cnt DESC, filename /*sort*/"
);
mxEvent = db_int(1, "SELECT max(cnt) FROM statrep");
@ <h1>Check-ins Per File</h1>
@ <h1>Check-ins Per File
if( zUserName ){
@ for user %h(zUserName)
}
@ </h1>
@ <table class='statistics-report-table-events' border='0'
@ cellpadding='2' cellspacing='0' id='statsTable'>
@ <thead><tr>
@ <th>File</th>
@ <th>Check-ins</th>
@ <th width='90%%'><!-- relative commits graph --></th>
@ </tr></thead><tbody>
|
| ︙ | | |
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
|
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
|
-
+
+
-
+
+
-
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
|
}
@ </tbody></table>
db_finalize(&query);
output_table_sorting_javascript("statsTable","tNx",2);
}
/*
** Implements the "byweekday" view for /reports.
** Implements the "byweekday" view for /reports. If zUserName is not NULL then
** the report is restricted to events created by the named user account.
*/
static void stats_report_day_of_week(){
static void stats_report_day_of_week(const char *zUserName){
Stmt query = empty_Stmt;
int nRowNumber = 0; /* current TR number */
int nEventTotal = 0; /* Total event count */
int rowClass = 0; /* counter for alternating
row colors */
int nMaxEvents = 1; /* max number of events for
all rows. */
Blob userFilter = empty_blob; /* Optional user=johndoe query string */
static const char *const daysOfWeek[] = {
"Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday"
};
stats_report_init_view();
stats_report_event_types_menu("byweekday", NULL);
if( zUserName ){
blob_appendf(&userFilter, "user=%s", zUserName);
}
db_prepare(&query,
"SELECT cast(mtime %% 7 AS INTEGER) dow, "
"COUNT(*) AS eventCount "
"FROM v_reports "
"GROUP BY dow ORDER BY dow");
@ <h1>Timeline Events
@ (%s(stats_report_label_for_type())) by Day of the Week</h1>
"SELECT cast(mtime %% 7 AS INTEGER) dow,"
" COUNT(*) AS eventCount"
" FROM v_reports"
" WHERE ifnull(coalesce(euser,user,'')=%Q,1)"
" GROUP BY dow ORDER BY dow", zUserName);
@ <h1>Timeline Events (%h(stats_report_label_for_type())) by Day of the Week
if( zUserName ){
@ for user %h(zUserName)
}
@ </h1>
db_multi_exec(
"CREATE TEMP TABLE piechart(amt,label);"
"INSERT INTO piechart"
"INSERT INTO piechart SELECT count(*), cast(mtime %% 7 AS INT) FROM v_reports"
" GROUP BY 2 ORDER BY 2;"
"UPDATE piechart SET label = CASE label WHEN 0 THEN 'Monday' WHEN 1 THEN 'Tuesday'"
" WHEN 2 THEN 'Wednesday' WHEN 3 THEN 'Thursday' WHEN 4 THEN 'Friday'"
" WHEN 5 THEN 'Saturday' ELSE 'Sunday' END;"
" SELECT count(*), cast(mtime %% 7 AS INT) FROM v_reports"
" WHERE ifnull(coalesce(euser,user,'')=%Q,1)"
" GROUP BY 2 ORDER BY 2;"
"UPDATE piechart SET label = CASE label"
" WHEN 0 THEN 'Monday'"
" WHEN 1 THEN 'Tuesday'"
" WHEN 2 THEN 'Wednesday'"
" WHEN 3 THEN 'Thursday'"
" WHEN 4 THEN 'Friday'"
" WHEN 5 THEN 'Saturday'"
" ELSE 'Sunday' END;", zUserName
);
if( db_int(0, "SELECT count(*) FROM piechart")>=2 ){
@ <center><svg width=700 height=400>
piechart_render(700, 400, PIE_OTHER|PIE_PERCENT);
@ </svg></centre><hr/>
}
@ <table class='statistics-report-table-events' border='0'
|
| ︙ | | |
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
|
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
|
-
+
+
-
-
+
+
-
+
-
-
-
-
-
+
+
+
-
-
-
-
+
-
-
+
-
-
-
+
+
+
+
+
-
-
-
-
+
+
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
output_table_sorting_javascript("statsTable","ntnx",1);
}
/*
** Helper for stats_report_by_month_year(), which generates a list of
** week numbers. zTimeframe should be either a timeframe in the form YYYY
** or YYYY-MM.
** or YYYY-MM. If zUserName is not NULL then the report is restricted to events
** created by the named user account.
*/
static void stats_report_year_weeks(const char *zUserName){
const char *zYear = P("y");
int nYear = zYear ? strlen(zYear) : 0;
const char *zYear = P("y"); /* Year for which report shown */
int isValidYear = 0; /* True if a valid year */
int i = 0;
Stmt qYears = empty_Stmt;
Stmt q;
char *zDefaultYear = NULL;
Blob sql = empty_blob;
int nMaxEvents = 1; /* max number of events for
all rows. */
int iterations = 0; /* # of active time periods. */
stats_report_init_view();
if(4==nYear){
Blob urlParams = empty_blob;
int n = 0; /* Number of entries in azYear */
char **azYear = 0; /* Year dropdown menu */
int rowCount = 0;
blob_appendf(&urlParams, "y=%T", zYear);
stats_report_event_types_menu("byweek", blob_str(&urlParams));
blob_reset(&urlParams);
}else{
int total = 0;
stats_report_event_types_menu("byweek", NULL);
}
blob_append(&sql,
"SELECT DISTINCT substr(date(mtime),1,4) AS y "
"FROM v_reports WHERE 1 ", -1);
stats_report_init_view();
style_submenu_sql("y", "Year:",
"WITH RECURSIVE a(b) AS ("
" SELECT substr(date('now'),1,4) UNION ALL"
" SELECT b-1 FROM a"
if(zUserName&&*zUserName){
blob_append_sql(&sql,"AND user=%Q ", zUserName);
}
blob_append(&sql,"GROUP BY y ORDER BY y", -1);
" WHERE b>0+(SELECT substr(date(min(mtime)),1,4) FROM event)"
") SELECT b, b FROM a ORDER BY b DESC");
db_prepare(&qYears, "%s", blob_sql_text(&sql));
blob_reset(&sql);
cgi_printf("Select year: ");
while( SQLITE_ROW == db_step(&qYears) ){
const char *zT = db_column_text(&qYears, 0);
if( zYear==0 || strlen(zYear)!=4 ){
zYear = db_text("1970","SELECT substr(date('now'),1,4);");
if( i++ ){
cgi_printf(" ");
}
cgi_printf("<a href='?view=byweek&y=%s&type=%c", zT,
(char)statsReportType);
if(zUserName && *zUserName){
cgi_printf("&user=%t",zUserName);
}
cgi_printf("'>%s</a>",zT);
}
db_finalize(&qYears);
cgi_printf("<br/>");
if(!zYear || !*zYear){
zDefaultYear = db_text("????", "SELECT strftime('%%Y')");
zYear = zDefaultYear;
nYear = 4;
}
if(4 == nYear){
Stmt stWeek = empty_Stmt;
int rowCount = 0;
int total = 0;
Blob header = empty_blob;
blob_appendf(&header, "Timeline events (%s) for the calendar weeks "
"of %h", stats_report_label_for_type(),
zYear);
db_prepare(&q,
blob_append_sql(&sql,
"SELECT DISTINCT strftime('%%W',mtime) AS wk, "
"count(*) AS n "
"FROM v_reports "
"WHERE %Q=substr(date(mtime),1,4) "
"AND mtime < current_timestamp ",
zYear);
if(zUserName&&*zUserName){
"SELECT DISTINCT strftime('%%W',mtime) AS wk, "
" count(*) AS n "
" FROM v_reports "
" WHERE %Q=substr(date(mtime),1,4) "
" AND mtime < current_timestamp "
" AND ifnull(coalesce(euser,user,'')=%Q,1)"
" GROUP BY wk ORDER BY wk DESC", zYear, zUserName);
@ <h1>Timeline events (%h(stats_report_label_for_type()))
@ for the calendar weeks of %h(zYear)
if( zUserName ){
blob_append_sql(&sql, " AND user=%Q ", zUserName);
blob_appendf(&header," for user %h", zUserName);
}
@ for user %h(zUserName)
}
blob_append_sql(&sql, "GROUP BY wk ORDER BY wk DESC");
cgi_printf("<h1>%h</h1>", blob_str(&header));
@ </h1>
blob_reset(&header);
cgi_printf("<table class='statistics-report-table-events' "
"border='0' cellpadding='2' width='100%%' "
"cellspacing='0' id='statsTable'>");
cgi_printf("<thead><tr>"
"<th>Week</th>"
"<th>Events</th>"
"<th width='90%%'><!-- relative commits graph --></th>"
"</tr></thead>"
"<tbody>");
cgi_printf("<table class='statistics-report-table-events' "
"border='0' cellpadding='2' width='100%%' "
"cellspacing='0' id='statsTable'>");
cgi_printf("<thead><tr>"
"<th>Week</th>"
"<th>Events</th>"
"<th width='90%%'><!-- relative commits graph --></th>"
"</tr></thead>"
"<tbody>");
db_prepare(&stWeek, "%s", blob_sql_text(&sql));
blob_reset(&sql);
while( SQLITE_ROW == db_step(&stWeek) ){
const int nCount = db_column_int(&stWeek, 1);
if(nCount>nMaxEvents){
nMaxEvents = nCount;
}
++iterations;
}
db_reset(&stWeek);
while( SQLITE_ROW == db_step(&stWeek) ){
const char *zWeek = db_column_text(&stWeek,0);
const int nCount = db_column_int(&stWeek,1);
int nSize = nCount
? (int)(100 * nCount / nMaxEvents)
: 0;
if(!nSize) nSize = 1;
total += nCount;
cgi_printf("<tr class='row%d'>", ++rowCount % 2 );
cgi_printf("<td><a href='%R/timeline?yw=%t-%s&n=%d&y=%s",
zYear, zWeek, nCount,
statsReportTimelineYFlag);
if(zUserName && *zUserName){
cgi_printf("&u=%t",zUserName);
}
cgi_printf("'>%s</a></td>",zWeek);
while( SQLITE_ROW == db_step(&q) ){
const int nCount = db_column_int(&q, 1);
if(nCount>nMaxEvents){
nMaxEvents = nCount;
}
++iterations;
}
db_reset(&q);
while( SQLITE_ROW == db_step(&q) ){
const char *zWeek = db_column_text(&q,0);
const int nCount = db_column_int(&q,1);
int nSize = nCount
? (int)(100 * nCount / nMaxEvents)
: 0;
if(!nSize) nSize = 1;
total += nCount;
cgi_printf("<tr class='row%d'>", ++rowCount % 2 );
cgi_printf("<td><a href='%R/timeline?yw=%t-%s&n=%d&y=%s",
zYear, zWeek, nCount,
statsReportTimelineYFlag);
if( zUserName ){
cgi_printf("&u=%t",zUserName);
}
cgi_printf("'>%s</a></td>",zWeek);
cgi_printf("<td>%d</td>",nCount);
cgi_printf("<td>");
if(nCount){
cgi_printf("<div class='statistics-report-graph-line'"
"style='width:%d%%;'> </div>",
nSize);
}
cgi_printf("</td></tr>");
}
db_finalize(&stWeek);
cgi_printf("<td>%d</td>",nCount);
cgi_printf("<td>");
if(nCount){
cgi_printf("<div class='statistics-report-graph-line'"
"style='width:%d%%;'> </div>",
nSize);
}
cgi_printf("</td></tr>");
}
db_finalize(&q);
free(zDefaultYear);
cgi_printf("</tbody></table>");
if(total){
int nAvg = iterations ? (total/iterations) : 0;
cgi_printf("<br><div>Total events: %d<br>"
"Average per active week: %d</div>",
total, nAvg);
}
output_table_sorting_javascript("statsTable","tnx",-1);
}
}
cgi_printf("</tbody></table>");
if(total){
int nAvg = iterations ? (total/iterations) : 0;
cgi_printf("<br><div>Total events: %d<br>"
"Average per active week: %d</div>",
total, nAvg);
}
output_table_sorting_javascript("statsTable","tnx",-1);
}
/* Report types
*/
#define RPT_BYFILE 1
#define RPT_BYMONTH 2
#define RPT_BYUSER 3
#define RPT_BYWEEK 4
#define RPT_BYWEEKDAY 5
#define RPT_BYYEAR 6
#define RPT_NONE 0 /* None of the above */
/*
** WEBPAGE: reports
**
** Shows activity reports for the repository.
**
** Query Parameters:
|
| ︙ | | |
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
|
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
|
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
|
** view=byweek:
**
** y=YYYY The year to report (default is the server's
** current year).
*/
void stats_report_page(){
HQuery url; /* URL for various branch links */
const char *zView = P("view"); /* Which view/report to show. */
const char *zUserName = P("user");
const char *zView = P("view"); /* Which view/report to show. */
int eType = RPT_NONE; /* Numeric code for view/report to show */
int i; /* Loop counter */
const char *zUserName; /* Name of user */
const struct {
const char *zName; /* Name of view= screen type */
const char *zVal; /* Value of view= query parameter */
int eType; /* Corresponding RPT_* define */
} aViewType[] = {
{ "File Changes","byfile", RPT_BYFILE },
{ "By Month", "bymonth", RPT_BYMONTH },
{ "By User", "byuser", RPT_BYUSER },
{ "By Week", "byweek", RPT_BYWEEK },
{ "By Weekday", "byweekday", RPT_BYWEEKDAY },
{ "By Year", "byyear", RPT_BYYEAR },
};
const char *azType[] = {
"a", "All Changes",
"ci", "Check-ins",
"g", "Tags",
"e", "Tech Notes",
"t", "Tickets",
"w", "Wiki"
};
login_check_credentials();
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
zUserName = P("user");
if(!zUserName) zUserName = P("u");
if( zUserName==0 ) zUserName = P("u");
if( zUserName && zUserName[0]==0 ) zUserName = 0;
if( zView==0 ){
zView = "byuser";
cgi_replace_query_parameter("view","byuser");
}
for(i=0; i<ArraySize(aViewType); i++){
if( fossil_strcmp(zView, aViewType[i].zVal)==0 ){
eType = aViewType[i].eType;
break;
}
}
url_initialize(&url, "reports");
if(zUserName && *zUserName){
url_add_parameter(&url,"user", zUserName);
statrep_submenu(&url, "(Remove User Flag)", "view", zView, "user");
}
statrep_submenu(&url, "By Year", "view", "byyear", 0);
statrep_submenu(&url, "By Month", "view", "bymonth", 0);
statrep_submenu(&url, "By Week", "view", "byweek", 0);
cgi_query_parameters_to_url(&url);
if( eType!=RPT_NONE ){
int nView = 0; /* Slots used in azView[] */
const char *azView[16]; /* Drop-down menu of view types */
for(i=0; i<ArraySize(aViewType); i++){
azView[nView++] = aViewType[i].zVal;
azView[nView++] = aViewType[i].zName;
}
if( eType!=RPT_BYFILE ){
style_submenu_multichoice("type", ArraySize(azType)/2, azType, 0);
}
style_submenu_multichoice("view", nView/2, azView, 0);
if( eType!=RPT_BYUSER ){
style_submenu_sql("u","User:",
statrep_submenu(&url, "By Weekday", "view", "byweekday", 0);
statrep_submenu(&url, "By User", "view", "byuser", "user");
statrep_submenu(&url, "By File", "view", "byfile", "file");
"SELECT '', 'All Users' UNION ALL "
"SELECT x, x FROM ("
" SELECT DISTINCT trim(coalesce(euser,user)) AS x FROM event %s"
" ORDER BY 1 COLLATE nocase) WHERE x!=''",
eType==RPT_BYFILE ? "WHERE type='ci'" : ""
);
}
}
style_submenu_element("Stats", "Stats", "%R/stat");
url_reset(&url);
style_header("Activity Reports");
if(0==fossil_strcmp(zView,"byyear")){
stats_report_by_month_year(0, 0, zUserName);
}else if(0==fossil_strcmp(zView,"bymonth")){
stats_report_by_month_year(1, 0, zUserName);
}else if(0==fossil_strcmp(zView,"byweek")){
stats_report_year_weeks(zUserName);
}else if(0==fossil_strcmp(zView,"byuser")){
stats_report_by_user();
switch( eType ){
case RPT_BYYEAR:
stats_report_by_month_year(0, 0, zUserName);
break;
case RPT_BYMONTH:
stats_report_by_month_year(1, 0, zUserName);
break;
case RPT_BYWEEK:
stats_report_year_weeks(zUserName);
break;
default:
case RPT_BYUSER:
stats_report_by_user();
}else if(0==fossil_strcmp(zView,"byweekday")){
stats_report_day_of_week();
}else if(0==fossil_strcmp(zView,"byfile")){
stats_report_by_file();
}else{
break;
case RPT_BYWEEKDAY:
stats_report_day_of_week(zUserName);
break;
case RPT_BYFILE:
stats_report_by_file(zUserName);
break;
@ <h1>Activity Reports:</h1>
@ <ul>
@ <li>%z(href("?view=byyear"))Events by year</a></li>
@ <li>%z(href("?view=bymonth"))Events by month</a></li>
@ <li>%z(href("?view=byweek"))Events by calendar week</a></li>
@ <li>%z(href("?view=byweekday"))Events by day of the week</a></li>
@ <li>%z(href("?view=byuser"))Events by user</a></li>
@ <li>%z(href("?view=byfile"))Events by file</a></li>
@ </ul>
}
style_footer();
}
|