Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Move the "Activity Report" controls into drop-down menus. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | andygoth-user-reports |
Files: | files | file ages | folders |
SHA1: |
4d60469f15833c6d2962a90762a55622 |
User & Date: | drh 2015-05-18 19:19:25.803 |
Context
2015-05-18
| ||
20:00 | Fix the display of /reports?view=byweek with an invalid user. ... (check-in: 5fa4d012 user: drh tags: andygoth-user-reports) | |
19:19 | Move the "Activity Report" controls into drop-down menus. ... (check-in: 4d60469f user: drh tags: andygoth-user-reports) | |
17:53 | Catch up with recent changes on trunk. ... (check-in: 991f4b98 user: drh tags: andygoth-user-reports) | |
Changes
Changes to src/statrep.c.
︙ | ︙ | |||
139 140 141 142 143 144 145 | case 'g': return "tag changes"; default: return "all types"; } } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | case 'g': return "tag changes"; default: return "all types"; } } /* ** 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){ |
︙ | ︙ | |||
253 254 255 256 257 258 259 | int iterations = 0; /* number of weeks/months we iterate over */ Blob userFilter = empty_blob; /* Optional user=johndoe query string */ stats_report_init_view(); if( zUserName ){ blob_appendf(&userFilter, "user=%s", zUserName); } | < < | 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | int iterations = 0; /* number of weeks/months we iterate over */ Blob userFilter = empty_blob; /* Optional user=johndoe query string */ stats_report_init_view(); if( 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" |
︙ | ︙ | |||
399 400 401 402 403 404 405 | 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(); | < | 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | 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(); @ <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(*), ifnull(euser,user) FROM v_reports" " GROUP BY ifnull(euser,user) ORDER BY count(*) DESC;" ); |
︙ | ︙ | |||
434 435 436 437 438 439 440 441 442 443 444 445 446 447 | 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); int nSize = nCount ? (int)(100 * nCount / nMaxEvents) : 0; if(!nCount) continue /* arguable! Possible? */; else if(!nSize) nSize = 1; rowClass = ++nRowNumber % 2; nEventTotal += nCount; | > | | | 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 | 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)'> @ <td> @ <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> /* |
︙ | ︙ | |||
538 539 540 541 542 543 544 | "Friday", "Saturday", "Sunday" }; stats_report_init_view(); if( zUserName ){ blob_appendf(&userFilter, "user=%s", zUserName); } | < > | | | | > > | > > | > | 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 | "Friday", "Saturday", "Sunday" }; stats_report_init_view(); if( zUserName ){ blob_appendf(&userFilter, "user=%s", zUserName); } db_prepare(&query, "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" " 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' |
︙ | ︙ | |||
612 613 614 615 616 617 618 | /* ** 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. 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){ | | | | < > > | | < < | < < < < | < | | < | > | > > | < | < < < < < < < | > > < < < < < < < < < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | | | | | | | | | | > > > > > > > > > | 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 676 677 678 679 680 681 | /* ** 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. 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"); /* Year for which report shown */ int isValidYear = 0; /* True if a valid year */ int i = 0; Stmt q; int nMaxEvents = 1; /* max number of events for all rows. */ int iterations = 0; /* # of active time periods. */ int n = 0; /* Number of entries in azYear */ char **azYear = 0; /* Year dropdown menu */ int rowCount = 0; int total = 0; stats_report_init_view(); db_prepare(&q, "SELECT DISTINCT substr(date(mtime),1,4) AS y" " FROM v_reports" " WHERE ifnull(coalesce(euser,user,'')=%Q,1)" " GROUP BY y ORDER BY y DESC", zUserName); while( SQLITE_ROW == db_step(&q) ){ azYear = fossil_realloc(azYear, sizeof(char*)*(n+2)); azYear[n] = fossil_strdup(db_column_text(&q,0)); azYear[n+1] = azYear[n]; if( !isValidYear && fossil_strcmp(zYear,azYear[n])==0 ) isValidYear = 1; n += 2; } db_finalize(&q); if( !isValidYear ) zYear = azYear[0]; style_submenu_multichoice("y", n/2, (const char**)azYear, 0); cgi_printf("<br/>"); db_prepare(&q, "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 ){ @ for user %h(zUserName) } @ </h1> 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>"); 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(&q); 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: |
︙ | ︙ | |||
752 753 754 755 756 757 758 | ** 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 */ | | > > | > > > > | > > > > > > > > > > > > > > > | | | | > > > < > > | > | > > > > > > | > > | | < | > > | < < < < < < | > | > | | > | | > > | | < > > | > | | | < < < < < < < < < < | 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. */ 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[] = { { "By File", "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", "Any Type", "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==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"); 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; } style_submenu_multichoice("view", nView/2, azView, 0); if( eType!=RPT_BYFILE ){ style_submenu_multichoice("type", ArraySize(azType)/2, azType, 0); } if( eType!=RPT_BYUSER ){ style_submenu_entry("u", "User:", 12, 0); } } style_submenu_element("Stats", "Stats", "%R/stat"); url_reset(&url); style_header("Activity Reports"); 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(); break; case RPT_BYWEEKDAY: stats_report_day_of_week(zUserName); break; case RPT_BYFILE: stats_report_by_file(zUserName); break; } style_footer(); } |