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.

drh 2023-05-23 13:47 trunk
Commit 0b33be99a22d4fe031174972d0c345c8010e98209c119e3ee6baacd371d23bb4
1 file changed +15 -53
+15 -53
--- src/statrep.c
+++ src/statrep.c
@@ -143,48 +143,20 @@
143143
return "all types";
144144
}
145145
}
146146
147147
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
-
177148
/*
178149
** Implements the "byyear" and "bymonth" reports for /reports.
179150
** If includeMonth is true then it generates the "bymonth" report,
180151
** else the "byyear" report. If zUserName is not NULL then the report is
181152
** restricted to events created by the named user account.
182153
*/
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
+){
186158
Stmt query = empty_Stmt;
187159
int nRowNumber = 0; /* current TR number */
188160
int nEventTotal = 0; /* Total event count */
189161
int rowClass = 0; /* counter for alternating
190162
row colors */
@@ -241,11 +213,11 @@
241213
}
242214
db_reset(&query);
243215
while( SQLITE_ROW == db_step(&query) ){
244216
const char *zTimeframe = db_column_text(&query, 0);
245217
const int nCount = db_column_int(&query, 1);
246
- int nSize = nCount
218
+ int nSize = (nCount>0 && nMaxEvents>0)
247219
? (int)(100 * nCount / nMaxEvents)
248220
: 1;
249221
showYearTotal = 0;
250222
if(!nSize) nSize = 1;
251223
if(includeMonth){
@@ -297,21 +269,11 @@
297269
@ </td><td>%d(nCount)</td>
298270
@ <td>
299271
@ <div class='statistics-report-graph-line'
300272
@ style='width:%d(nSize)%%;'>&nbsp;</div>
301273
@ </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>
313275
314276
/*
315277
Potential improvement: calculate the min/max event counts and
316278
use percent-based graph bars.
317279
*/
@@ -629,12 +591,12 @@
629591
}
630592
631593
632594
/*
633595
** 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
636598
** created by the named user account.
637599
*/
638600
static void stats_report_year_weeks(const char *zUserName){
639601
const char *zYear = P("y"); /* Year for which report shown */
640602
Stmt q;
@@ -652,11 +614,11 @@
652614
" WHERE b>0+(SELECT substr(date(min(mtime)),1,4) FROM event)"
653615
") SELECT b, b FROM a ORDER BY b DESC");
654616
if( zYear==0 || strlen(zYear)!=4 ){
655617
zYear = db_text("1970","SELECT substr(date('now'),1,4);");
656618
}
657
- cgi_printf("<br>");
619
+ cgi_printf("<br>\n");
658620
db_prepare(&q,
659621
"SELECT DISTINCT strftime('%%W',mtime) AS wk, "
660622
" count(*) AS n "
661623
" FROM v_reports "
662624
" WHERE %Q=substr(date(mtime),1,4) "
@@ -670,17 +632,17 @@
670632
}
671633
@ </h1>
672634
style_table_sorter();
673635
cgi_printf("<table class='statistics-report-table-events sortable' "
674636
"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");
676638
cgi_printf("<thead><tr>"
677639
"<th>Week</th>"
678640
"<th>Events</th>"
679641
"<th width='90%%'><!-- relative commits graph --></th>"
680
- "</tr></thead>"
681
- "<tbody>");
642
+ "</tr></thead>\n"
643
+ "<tbody>\n");
682644
while( SQLITE_ROW == db_step(&q) ){
683645
const int nCount = db_column_int(&q, 1);
684646
if(nCount>nMaxEvents){
685647
nMaxEvents = nCount;
686648
}
@@ -709,11 +671,11 @@
709671
if(nCount){
710672
cgi_printf("<div class='statistics-report-graph-line'"
711673
"style='width:%d%%;'>&nbsp;</div>",
712674
nSize);
713675
}
714
- cgi_printf("</td></tr>");
676
+ cgi_printf("</td></tr>\n");
715677
}
716678
db_finalize(&q);
717679
cgi_printf("</tbody></table>");
718680
if(total){
719681
int nAvg = iterations ? (total/iterations) : 0;
@@ -867,14 +829,14 @@
867829
}
868830
style_submenu_element("Stats", "%R/stat");
869831
style_header("Activity Reports");
870832
switch( eType ){
871833
case RPT_BYYEAR:
872
- stats_report_by_month_year(0, 0, zUserName);
834
+ stats_report_by_month_year(0, zUserName);
873835
break;
874836
case RPT_BYMONTH:
875
- stats_report_by_month_year(1, 0, zUserName);
837
+ stats_report_by_month_year(1, zUserName);
876838
break;
877839
case RPT_BYWEEK:
878840
stats_report_year_weeks(zUserName);
879841
break;
880842
default:
881843
--- 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)%%;'>&nbsp;</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%%;'>&nbsp;</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)%%;'>&nbsp;</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%%;'>&nbsp;</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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button