Fossil SCM
Remove unused and unreachable code from the activity report generators. Also add extra newlines in the generated HTML so that it is easier to read.
Commit
0b33be99a22d4fe031174972d0c345c8010e98209c119e3ee6baacd371d23bb4
Parent
e053682a4eb2233…
1 file changed
+15
-53
+15
-53
| --- src/statrep.c | ||
| +++ src/statrep.c | ||
| @@ -143,48 +143,20 @@ | ||
| 143 | 143 | return "all types"; |
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | |
| 148 | -/* | |
| 149 | -** Helper for stats_report_by_month_year(), which generates a list of | |
| 150 | -** week numbers. zTimeframe should be either a timeframe in the form YYYY | |
| 151 | -** or YYYY-MM. | |
| 152 | -*/ | |
| 153 | -static void stats_report_output_week_links(const char *zTimeframe){ | |
| 154 | - Stmt stWeek = empty_Stmt; | |
| 155 | - char yearPart[5] = {0,0,0,0,0}; | |
| 156 | - memcpy(yearPart, zTimeframe, 4); | |
| 157 | - db_prepare(&stWeek, | |
| 158 | - "SELECT DISTINCT strftime('%%W',mtime) AS wk, " | |
| 159 | - "count(*) AS n, " | |
| 160 | - "substr(date(mtime),1,%d) AS ym " | |
| 161 | - "FROM v_reports " | |
| 162 | - "WHERE ym=%Q AND mtime < current_timestamp " | |
| 163 | - "GROUP BY wk ORDER BY wk", | |
| 164 | - strlen(zTimeframe), | |
| 165 | - zTimeframe); | |
| 166 | - while( SQLITE_ROW == db_step(&stWeek) ){ | |
| 167 | - const char *zWeek = db_column_text(&stWeek,0); | |
| 168 | - const int nCount = db_column_int(&stWeek,1); | |
| 169 | - cgi_printf("<a href='%R/timeline?" | |
| 170 | - "yw=%t-%t&n=%d&y=%s'>%s</a>", | |
| 171 | - yearPart, zWeek, | |
| 172 | - nCount, statsReportTimelineYFlag, zWeek); | |
| 173 | - } | |
| 174 | - db_finalize(&stWeek); | |
| 175 | -} | |
| 176 | - | |
| 177 | 148 | /* |
| 178 | 149 | ** Implements the "byyear" and "bymonth" reports for /reports. |
| 179 | 150 | ** If includeMonth is true then it generates the "bymonth" report, |
| 180 | 151 | ** else the "byyear" report. If zUserName is not NULL then the report is |
| 181 | 152 | ** restricted to events created by the named user account. |
| 182 | 153 | */ |
| 183 | -static void stats_report_by_month_year(char includeMonth, | |
| 184 | - char includeWeeks, | |
| 185 | - const char *zUserName){ | |
| 154 | +static void stats_report_by_month_year( | |
| 155 | + char includeMonth, /* 0 for stats-by-year. 1 for stats-by-month */ | |
| 156 | + const char *zUserName /* Only report events by this user */ | |
| 157 | +){ | |
| 186 | 158 | Stmt query = empty_Stmt; |
| 187 | 159 | int nRowNumber = 0; /* current TR number */ |
| 188 | 160 | int nEventTotal = 0; /* Total event count */ |
| 189 | 161 | int rowClass = 0; /* counter for alternating |
| 190 | 162 | row colors */ |
| @@ -241,11 +213,11 @@ | ||
| 241 | 213 | } |
| 242 | 214 | db_reset(&query); |
| 243 | 215 | while( SQLITE_ROW == db_step(&query) ){ |
| 244 | 216 | const char *zTimeframe = db_column_text(&query, 0); |
| 245 | 217 | const int nCount = db_column_int(&query, 1); |
| 246 | - int nSize = nCount | |
| 218 | + int nSize = (nCount>0 && nMaxEvents>0) | |
| 247 | 219 | ? (int)(100 * nCount / nMaxEvents) |
| 248 | 220 | : 1; |
| 249 | 221 | showYearTotal = 0; |
| 250 | 222 | if(!nSize) nSize = 1; |
| 251 | 223 | if(includeMonth){ |
| @@ -297,21 +269,11 @@ | ||
| 297 | 269 | @ </td><td>%d(nCount)</td> |
| 298 | 270 | @ <td> |
| 299 | 271 | @ <div class='statistics-report-graph-line' |
| 300 | 272 | @ style='width:%d(nSize)%%;'> </div> |
| 301 | 273 | @ </td> |
| 302 | - @</tr> | |
| 303 | - if(includeWeeks){ | |
| 304 | - /* This part works fine for months but it terribly slow (4.5s on my PC), | |
| 305 | - so it's only shown for by-year for now. Suggestions/patches for | |
| 306 | - a better/faster layout are welcomed. */ | |
| 307 | - @ <tr class='row%d(rowClass)'> | |
| 308 | - @ <td colspan='2' class='statistics-report-week-number-label'>Week #:</td> | |
| 309 | - @ <td class='statistics-report-week-of-year-list'> | |
| 310 | - stats_report_output_week_links(zTimeframe); | |
| 311 | - @ </td></tr> | |
| 312 | - } | |
| 274 | + @ </tr> | |
| 313 | 275 | |
| 314 | 276 | /* |
| 315 | 277 | Potential improvement: calculate the min/max event counts and |
| 316 | 278 | use percent-based graph bars. |
| 317 | 279 | */ |
| @@ -629,12 +591,12 @@ | ||
| 629 | 591 | } |
| 630 | 592 | |
| 631 | 593 | |
| 632 | 594 | /* |
| 633 | 595 | ** Helper for stats_report_by_month_year(), which generates a list of |
| 634 | -** week numbers. zTimeframe should be either a timeframe in the form YYYY | |
| 635 | -** or YYYY-MM. If zUserName is not NULL then the report is restricted to events | |
| 596 | +** week numbers. The "y" query parameter is the year in format YYYY. | |
| 597 | +** If zUserName is not NULL then the report is restricted to events | |
| 636 | 598 | ** created by the named user account. |
| 637 | 599 | */ |
| 638 | 600 | static void stats_report_year_weeks(const char *zUserName){ |
| 639 | 601 | const char *zYear = P("y"); /* Year for which report shown */ |
| 640 | 602 | Stmt q; |
| @@ -652,11 +614,11 @@ | ||
| 652 | 614 | " WHERE b>0+(SELECT substr(date(min(mtime)),1,4) FROM event)" |
| 653 | 615 | ") SELECT b, b FROM a ORDER BY b DESC"); |
| 654 | 616 | if( zYear==0 || strlen(zYear)!=4 ){ |
| 655 | 617 | zYear = db_text("1970","SELECT substr(date('now'),1,4);"); |
| 656 | 618 | } |
| 657 | - cgi_printf("<br>"); | |
| 619 | + cgi_printf("<br>\n"); | |
| 658 | 620 | db_prepare(&q, |
| 659 | 621 | "SELECT DISTINCT strftime('%%W',mtime) AS wk, " |
| 660 | 622 | " count(*) AS n " |
| 661 | 623 | " FROM v_reports " |
| 662 | 624 | " WHERE %Q=substr(date(mtime),1,4) " |
| @@ -670,17 +632,17 @@ | ||
| 670 | 632 | } |
| 671 | 633 | @ </h1> |
| 672 | 634 | style_table_sorter(); |
| 673 | 635 | cgi_printf("<table class='statistics-report-table-events sortable' " |
| 674 | 636 | "border='0' cellpadding='2' width='100%%' " |
| 675 | - "cellspacing='0' data-column-types='tnx' data-init-sort='0'>"); | |
| 637 | + "cellspacing='0' data-column-types='tnx' data-init-sort='0'>\n"); | |
| 676 | 638 | cgi_printf("<thead><tr>" |
| 677 | 639 | "<th>Week</th>" |
| 678 | 640 | "<th>Events</th>" |
| 679 | 641 | "<th width='90%%'><!-- relative commits graph --></th>" |
| 680 | - "</tr></thead>" | |
| 681 | - "<tbody>"); | |
| 642 | + "</tr></thead>\n" | |
| 643 | + "<tbody>\n"); | |
| 682 | 644 | while( SQLITE_ROW == db_step(&q) ){ |
| 683 | 645 | const int nCount = db_column_int(&q, 1); |
| 684 | 646 | if(nCount>nMaxEvents){ |
| 685 | 647 | nMaxEvents = nCount; |
| 686 | 648 | } |
| @@ -709,11 +671,11 @@ | ||
| 709 | 671 | if(nCount){ |
| 710 | 672 | cgi_printf("<div class='statistics-report-graph-line'" |
| 711 | 673 | "style='width:%d%%;'> </div>", |
| 712 | 674 | nSize); |
| 713 | 675 | } |
| 714 | - cgi_printf("</td></tr>"); | |
| 676 | + cgi_printf("</td></tr>\n"); | |
| 715 | 677 | } |
| 716 | 678 | db_finalize(&q); |
| 717 | 679 | cgi_printf("</tbody></table>"); |
| 718 | 680 | if(total){ |
| 719 | 681 | int nAvg = iterations ? (total/iterations) : 0; |
| @@ -867,14 +829,14 @@ | ||
| 867 | 829 | } |
| 868 | 830 | style_submenu_element("Stats", "%R/stat"); |
| 869 | 831 | style_header("Activity Reports"); |
| 870 | 832 | switch( eType ){ |
| 871 | 833 | case RPT_BYYEAR: |
| 872 | - stats_report_by_month_year(0, 0, zUserName); | |
| 834 | + stats_report_by_month_year(0, zUserName); | |
| 873 | 835 | break; |
| 874 | 836 | case RPT_BYMONTH: |
| 875 | - stats_report_by_month_year(1, 0, zUserName); | |
| 837 | + stats_report_by_month_year(1, zUserName); | |
| 876 | 838 | break; |
| 877 | 839 | case RPT_BYWEEK: |
| 878 | 840 | stats_report_year_weeks(zUserName); |
| 879 | 841 | break; |
| 880 | 842 | default: |
| 881 | 843 |
| --- src/statrep.c | |
| +++ src/statrep.c | |
| @@ -143,48 +143,20 @@ | |
| 143 | return "all types"; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | |
| 148 | /* |
| 149 | ** Helper for stats_report_by_month_year(), which generates a list of |
| 150 | ** week numbers. zTimeframe should be either a timeframe in the form YYYY |
| 151 | ** or YYYY-MM. |
| 152 | */ |
| 153 | static void stats_report_output_week_links(const char *zTimeframe){ |
| 154 | Stmt stWeek = empty_Stmt; |
| 155 | char yearPart[5] = {0,0,0,0,0}; |
| 156 | memcpy(yearPart, zTimeframe, 4); |
| 157 | db_prepare(&stWeek, |
| 158 | "SELECT DISTINCT strftime('%%W',mtime) AS wk, " |
| 159 | "count(*) AS n, " |
| 160 | "substr(date(mtime),1,%d) AS ym " |
| 161 | "FROM v_reports " |
| 162 | "WHERE ym=%Q AND mtime < current_timestamp " |
| 163 | "GROUP BY wk ORDER BY wk", |
| 164 | strlen(zTimeframe), |
| 165 | zTimeframe); |
| 166 | while( SQLITE_ROW == db_step(&stWeek) ){ |
| 167 | const char *zWeek = db_column_text(&stWeek,0); |
| 168 | const int nCount = db_column_int(&stWeek,1); |
| 169 | cgi_printf("<a href='%R/timeline?" |
| 170 | "yw=%t-%t&n=%d&y=%s'>%s</a>", |
| 171 | yearPart, zWeek, |
| 172 | nCount, statsReportTimelineYFlag, zWeek); |
| 173 | } |
| 174 | db_finalize(&stWeek); |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | ** Implements the "byyear" and "bymonth" reports for /reports. |
| 179 | ** If includeMonth is true then it generates the "bymonth" report, |
| 180 | ** else the "byyear" report. If zUserName is not NULL then the report is |
| 181 | ** restricted to events created by the named user account. |
| 182 | */ |
| 183 | static void stats_report_by_month_year(char includeMonth, |
| 184 | char includeWeeks, |
| 185 | const char *zUserName){ |
| 186 | Stmt query = empty_Stmt; |
| 187 | int nRowNumber = 0; /* current TR number */ |
| 188 | int nEventTotal = 0; /* Total event count */ |
| 189 | int rowClass = 0; /* counter for alternating |
| 190 | row colors */ |
| @@ -241,11 +213,11 @@ | |
| 241 | } |
| 242 | db_reset(&query); |
| 243 | while( SQLITE_ROW == db_step(&query) ){ |
| 244 | const char *zTimeframe = db_column_text(&query, 0); |
| 245 | const int nCount = db_column_int(&query, 1); |
| 246 | int nSize = nCount |
| 247 | ? (int)(100 * nCount / nMaxEvents) |
| 248 | : 1; |
| 249 | showYearTotal = 0; |
| 250 | if(!nSize) nSize = 1; |
| 251 | if(includeMonth){ |
| @@ -297,21 +269,11 @@ | |
| 297 | @ </td><td>%d(nCount)</td> |
| 298 | @ <td> |
| 299 | @ <div class='statistics-report-graph-line' |
| 300 | @ style='width:%d(nSize)%%;'> </div> |
| 301 | @ </td> |
| 302 | @</tr> |
| 303 | if(includeWeeks){ |
| 304 | /* This part works fine for months but it terribly slow (4.5s on my PC), |
| 305 | so it's only shown for by-year for now. Suggestions/patches for |
| 306 | a better/faster layout are welcomed. */ |
| 307 | @ <tr class='row%d(rowClass)'> |
| 308 | @ <td colspan='2' class='statistics-report-week-number-label'>Week #:</td> |
| 309 | @ <td class='statistics-report-week-of-year-list'> |
| 310 | stats_report_output_week_links(zTimeframe); |
| 311 | @ </td></tr> |
| 312 | } |
| 313 | |
| 314 | /* |
| 315 | Potential improvement: calculate the min/max event counts and |
| 316 | use percent-based graph bars. |
| 317 | */ |
| @@ -629,12 +591,12 @@ | |
| 629 | } |
| 630 | |
| 631 | |
| 632 | /* |
| 633 | ** Helper for stats_report_by_month_year(), which generates a list of |
| 634 | ** week numbers. zTimeframe should be either a timeframe in the form YYYY |
| 635 | ** or YYYY-MM. If zUserName is not NULL then the report is restricted to events |
| 636 | ** created by the named user account. |
| 637 | */ |
| 638 | static void stats_report_year_weeks(const char *zUserName){ |
| 639 | const char *zYear = P("y"); /* Year for which report shown */ |
| 640 | Stmt q; |
| @@ -652,11 +614,11 @@ | |
| 652 | " WHERE b>0+(SELECT substr(date(min(mtime)),1,4) FROM event)" |
| 653 | ") SELECT b, b FROM a ORDER BY b DESC"); |
| 654 | if( zYear==0 || strlen(zYear)!=4 ){ |
| 655 | zYear = db_text("1970","SELECT substr(date('now'),1,4);"); |
| 656 | } |
| 657 | cgi_printf("<br>"); |
| 658 | db_prepare(&q, |
| 659 | "SELECT DISTINCT strftime('%%W',mtime) AS wk, " |
| 660 | " count(*) AS n " |
| 661 | " FROM v_reports " |
| 662 | " WHERE %Q=substr(date(mtime),1,4) " |
| @@ -670,17 +632,17 @@ | |
| 670 | } |
| 671 | @ </h1> |
| 672 | style_table_sorter(); |
| 673 | cgi_printf("<table class='statistics-report-table-events sortable' " |
| 674 | "border='0' cellpadding='2' width='100%%' " |
| 675 | "cellspacing='0' data-column-types='tnx' data-init-sort='0'>"); |
| 676 | cgi_printf("<thead><tr>" |
| 677 | "<th>Week</th>" |
| 678 | "<th>Events</th>" |
| 679 | "<th width='90%%'><!-- relative commits graph --></th>" |
| 680 | "</tr></thead>" |
| 681 | "<tbody>"); |
| 682 | while( SQLITE_ROW == db_step(&q) ){ |
| 683 | const int nCount = db_column_int(&q, 1); |
| 684 | if(nCount>nMaxEvents){ |
| 685 | nMaxEvents = nCount; |
| 686 | } |
| @@ -709,11 +671,11 @@ | |
| 709 | if(nCount){ |
| 710 | cgi_printf("<div class='statistics-report-graph-line'" |
| 711 | "style='width:%d%%;'> </div>", |
| 712 | nSize); |
| 713 | } |
| 714 | cgi_printf("</td></tr>"); |
| 715 | } |
| 716 | db_finalize(&q); |
| 717 | cgi_printf("</tbody></table>"); |
| 718 | if(total){ |
| 719 | int nAvg = iterations ? (total/iterations) : 0; |
| @@ -867,14 +829,14 @@ | |
| 867 | } |
| 868 | style_submenu_element("Stats", "%R/stat"); |
| 869 | style_header("Activity Reports"); |
| 870 | switch( eType ){ |
| 871 | case RPT_BYYEAR: |
| 872 | stats_report_by_month_year(0, 0, zUserName); |
| 873 | break; |
| 874 | case RPT_BYMONTH: |
| 875 | stats_report_by_month_year(1, 0, zUserName); |
| 876 | break; |
| 877 | case RPT_BYWEEK: |
| 878 | stats_report_year_weeks(zUserName); |
| 879 | break; |
| 880 | default: |
| 881 |
| --- src/statrep.c | |
| +++ src/statrep.c | |
| @@ -143,48 +143,20 @@ | |
| 143 | return "all types"; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | |
| 148 | /* |
| 149 | ** Implements the "byyear" and "bymonth" reports for /reports. |
| 150 | ** If includeMonth is true then it generates the "bymonth" report, |
| 151 | ** else the "byyear" report. If zUserName is not NULL then the report is |
| 152 | ** restricted to events created by the named user account. |
| 153 | */ |
| 154 | static void stats_report_by_month_year( |
| 155 | char includeMonth, /* 0 for stats-by-year. 1 for stats-by-month */ |
| 156 | const char *zUserName /* Only report events by this user */ |
| 157 | ){ |
| 158 | Stmt query = empty_Stmt; |
| 159 | int nRowNumber = 0; /* current TR number */ |
| 160 | int nEventTotal = 0; /* Total event count */ |
| 161 | int rowClass = 0; /* counter for alternating |
| 162 | row colors */ |
| @@ -241,11 +213,11 @@ | |
| 213 | } |
| 214 | db_reset(&query); |
| 215 | while( SQLITE_ROW == db_step(&query) ){ |
| 216 | const char *zTimeframe = db_column_text(&query, 0); |
| 217 | const int nCount = db_column_int(&query, 1); |
| 218 | int nSize = (nCount>0 && nMaxEvents>0) |
| 219 | ? (int)(100 * nCount / nMaxEvents) |
| 220 | : 1; |
| 221 | showYearTotal = 0; |
| 222 | if(!nSize) nSize = 1; |
| 223 | if(includeMonth){ |
| @@ -297,21 +269,11 @@ | |
| 269 | @ </td><td>%d(nCount)</td> |
| 270 | @ <td> |
| 271 | @ <div class='statistics-report-graph-line' |
| 272 | @ style='width:%d(nSize)%%;'> </div> |
| 273 | @ </td> |
| 274 | @ </tr> |
| 275 | |
| 276 | /* |
| 277 | Potential improvement: calculate the min/max event counts and |
| 278 | use percent-based graph bars. |
| 279 | */ |
| @@ -629,12 +591,12 @@ | |
| 591 | } |
| 592 | |
| 593 | |
| 594 | /* |
| 595 | ** Helper for stats_report_by_month_year(), which generates a list of |
| 596 | ** week numbers. The "y" query parameter is the year in format YYYY. |
| 597 | ** If zUserName is not NULL then the report is restricted to events |
| 598 | ** created by the named user account. |
| 599 | */ |
| 600 | static void stats_report_year_weeks(const char *zUserName){ |
| 601 | const char *zYear = P("y"); /* Year for which report shown */ |
| 602 | Stmt q; |
| @@ -652,11 +614,11 @@ | |
| 614 | " WHERE b>0+(SELECT substr(date(min(mtime)),1,4) FROM event)" |
| 615 | ") SELECT b, b FROM a ORDER BY b DESC"); |
| 616 | if( zYear==0 || strlen(zYear)!=4 ){ |
| 617 | zYear = db_text("1970","SELECT substr(date('now'),1,4);"); |
| 618 | } |
| 619 | cgi_printf("<br>\n"); |
| 620 | db_prepare(&q, |
| 621 | "SELECT DISTINCT strftime('%%W',mtime) AS wk, " |
| 622 | " count(*) AS n " |
| 623 | " FROM v_reports " |
| 624 | " WHERE %Q=substr(date(mtime),1,4) " |
| @@ -670,17 +632,17 @@ | |
| 632 | } |
| 633 | @ </h1> |
| 634 | style_table_sorter(); |
| 635 | cgi_printf("<table class='statistics-report-table-events sortable' " |
| 636 | "border='0' cellpadding='2' width='100%%' " |
| 637 | "cellspacing='0' data-column-types='tnx' data-init-sort='0'>\n"); |
| 638 | cgi_printf("<thead><tr>" |
| 639 | "<th>Week</th>" |
| 640 | "<th>Events</th>" |
| 641 | "<th width='90%%'><!-- relative commits graph --></th>" |
| 642 | "</tr></thead>\n" |
| 643 | "<tbody>\n"); |
| 644 | while( SQLITE_ROW == db_step(&q) ){ |
| 645 | const int nCount = db_column_int(&q, 1); |
| 646 | if(nCount>nMaxEvents){ |
| 647 | nMaxEvents = nCount; |
| 648 | } |
| @@ -709,11 +671,11 @@ | |
| 671 | if(nCount){ |
| 672 | cgi_printf("<div class='statistics-report-graph-line'" |
| 673 | "style='width:%d%%;'> </div>", |
| 674 | nSize); |
| 675 | } |
| 676 | cgi_printf("</td></tr>\n"); |
| 677 | } |
| 678 | db_finalize(&q); |
| 679 | cgi_printf("</tbody></table>"); |
| 680 | if(total){ |
| 681 | int nAvg = iterations ? (total/iterations) : 0; |
| @@ -867,14 +829,14 @@ | |
| 829 | } |
| 830 | style_submenu_element("Stats", "%R/stat"); |
| 831 | style_header("Activity Reports"); |
| 832 | switch( eType ){ |
| 833 | case RPT_BYYEAR: |
| 834 | stats_report_by_month_year(0, zUserName); |
| 835 | break; |
| 836 | case RPT_BYMONTH: |
| 837 | stats_report_by_month_year(1, zUserName); |
| 838 | break; |
| 839 | case RPT_BYWEEK: |
| 840 | stats_report_year_weeks(zUserName); |
| 841 | break; |
| 842 | default: |
| 843 |