Fossil SCM
Added average event count per active time period to the /reports views.
Commit
16f033dda310214480a6e0778aba06ae0cd4367b
Parent
f8a2aa0ce7e372a…
1 file changed
+18
-6
+18
-6
| --- src/timeline.c | ||
| +++ src/timeline.c | ||
| @@ -1904,12 +1904,14 @@ | ||
| 1904 | 1904 | int nEventsPerYear = 0; /* Total event count for the |
| 1905 | 1905 | current year */ |
| 1906 | 1906 | char showYearTotal = 0; /* Flag telling us when to show |
| 1907 | 1907 | the per-year event totals */ |
| 1908 | 1908 | Blob header = empty_blob; /* Page header text */ |
| 1909 | - int nMaxEvents = 1; /* for calculating length of graph bars. */ | |
| 1910 | - | |
| 1909 | + int nMaxEvents = 1; /* for calculating length of graph | |
| 1910 | + bars. */ | |
| 1911 | + int iterations = 0; /* number of weeks/months we iterate | |
| 1912 | + over */ | |
| 1911 | 1913 | blob_appendf(&header, "Timeline Events by year%s", |
| 1912 | 1914 | (includeMonth ? "/month" : "")); |
| 1913 | 1915 | blob_appendf(&sql, |
| 1914 | 1916 | "SELECT substr(date(mtime),1,%d) AS timeframe, " |
| 1915 | 1917 | "count(*) AS eventCount " |
| @@ -1942,10 +1944,11 @@ | ||
| 1942 | 1944 | while( SQLITE_ROW == db_step(&query) ){ |
| 1943 | 1945 | const int nCount = db_column_int(&query, 1); |
| 1944 | 1946 | if(nCount>nMaxEvents){ |
| 1945 | 1947 | nMaxEvents = nCount; |
| 1946 | 1948 | } |
| 1949 | + ++iterations; | |
| 1947 | 1950 | } |
| 1948 | 1951 | db_reset(&query); |
| 1949 | 1952 | while( SQLITE_ROW == db_step(&query) ){ |
| 1950 | 1953 | const char * zTimeframe = db_column_text(&query, 0); |
| 1951 | 1954 | const int nCount = db_column_int(&query, 1); |
| @@ -2027,11 +2030,16 @@ | ||
| 2027 | 2030 | @ <td colspan='2'>Yearly total: %d(nEventsPerYear)</td> |
| 2028 | 2031 | @</tr> |
| 2029 | 2032 | } |
| 2030 | 2033 | @ </tbody></table> |
| 2031 | 2034 | if(nEventTotal){ |
| 2032 | - @ <br><div>Total events: %d(nEventTotal)</div> | |
| 2035 | + char const * zAvgLabel = includeMonth ? "month" : "year"; | |
| 2036 | + int nAvg = iterations ? (nEventTotal/iterations) : 0; | |
| 2037 | + int nWidth = (int)(100 * nAvg / nMaxEvents); | |
| 2038 | + @ <br><div>Total events: %d(nEventTotal) | |
| 2039 | + @ <br>Average per active %s(zAvgLabel): %d(nAvg) | |
| 2040 | + @ </div> | |
| 2033 | 2041 | } |
| 2034 | 2042 | if( !includeMonth ){ |
| 2035 | 2043 | output_table_sorting_javascript("statsTable","tnx"); |
| 2036 | 2044 | } |
| 2037 | 2045 | } |
| @@ -2112,11 +2120,12 @@ | ||
| 2112 | 2120 | Stmt qYears = empty_Stmt; |
| 2113 | 2121 | char * zDefaultYear = NULL; |
| 2114 | 2122 | Blob sql = empty_blob; |
| 2115 | 2123 | int nMaxEvents = 1; /* max number of events for |
| 2116 | 2124 | all rows. */ |
| 2117 | - | |
| 2125 | + int iterations; /* # of active time periods. */ | |
| 2126 | + | |
| 2118 | 2127 | cgi_printf("Select year: "); |
| 2119 | 2128 | blob_append(&sql, |
| 2120 | 2129 | "SELECT DISTINCT substr(date(mtime),1,4) AS y " |
| 2121 | 2130 | "FROM event WHERE 1 ", -1); |
| 2122 | 2131 | if(zUserName&&*zUserName){ |
| @@ -2178,10 +2187,11 @@ | ||
| 2178 | 2187 | while( SQLITE_ROW == db_step(&stWeek) ){ |
| 2179 | 2188 | const int nCount = db_column_int(&stWeek, 1); |
| 2180 | 2189 | if(nCount>nMaxEvents){ |
| 2181 | 2190 | nMaxEvents = nCount; |
| 2182 | 2191 | } |
| 2192 | + ++iterations; | |
| 2183 | 2193 | } |
| 2184 | 2194 | db_reset(&stWeek); |
| 2185 | 2195 | while( SQLITE_ROW == db_step(&stWeek) ){ |
| 2186 | 2196 | const char * zWeek = db_column_text(&stWeek,0); |
| 2187 | 2197 | const int nCount = db_column_int(&stWeek,1); |
| @@ -2208,12 +2218,14 @@ | ||
| 2208 | 2218 | } |
| 2209 | 2219 | db_finalize(&stWeek); |
| 2210 | 2220 | free(zDefaultYear); |
| 2211 | 2221 | cgi_printf("</tbody></table>"); |
| 2212 | 2222 | if(total){ |
| 2213 | - cgi_printf("<br><div>Total events: %d</div>", | |
| 2214 | - total); | |
| 2223 | + int nAvg = iterations ? (total/iterations) : 0; | |
| 2224 | + cgi_printf("<br><div>Total events: %d<br>" | |
| 2225 | + "Average per active week: %d</div>", | |
| 2226 | + total, nAvg); | |
| 2215 | 2227 | } |
| 2216 | 2228 | output_table_sorting_javascript("statsTable","tnx"); |
| 2217 | 2229 | } |
| 2218 | 2230 | } |
| 2219 | 2231 | |
| 2220 | 2232 |
| --- src/timeline.c | |
| +++ src/timeline.c | |
| @@ -1904,12 +1904,14 @@ | |
| 1904 | int nEventsPerYear = 0; /* Total event count for the |
| 1905 | current year */ |
| 1906 | char showYearTotal = 0; /* Flag telling us when to show |
| 1907 | the per-year event totals */ |
| 1908 | Blob header = empty_blob; /* Page header text */ |
| 1909 | int nMaxEvents = 1; /* for calculating length of graph bars. */ |
| 1910 | |
| 1911 | blob_appendf(&header, "Timeline Events by year%s", |
| 1912 | (includeMonth ? "/month" : "")); |
| 1913 | blob_appendf(&sql, |
| 1914 | "SELECT substr(date(mtime),1,%d) AS timeframe, " |
| 1915 | "count(*) AS eventCount " |
| @@ -1942,10 +1944,11 @@ | |
| 1942 | while( SQLITE_ROW == db_step(&query) ){ |
| 1943 | const int nCount = db_column_int(&query, 1); |
| 1944 | if(nCount>nMaxEvents){ |
| 1945 | nMaxEvents = nCount; |
| 1946 | } |
| 1947 | } |
| 1948 | db_reset(&query); |
| 1949 | while( SQLITE_ROW == db_step(&query) ){ |
| 1950 | const char * zTimeframe = db_column_text(&query, 0); |
| 1951 | const int nCount = db_column_int(&query, 1); |
| @@ -2027,11 +2030,16 @@ | |
| 2027 | @ <td colspan='2'>Yearly total: %d(nEventsPerYear)</td> |
| 2028 | @</tr> |
| 2029 | } |
| 2030 | @ </tbody></table> |
| 2031 | if(nEventTotal){ |
| 2032 | @ <br><div>Total events: %d(nEventTotal)</div> |
| 2033 | } |
| 2034 | if( !includeMonth ){ |
| 2035 | output_table_sorting_javascript("statsTable","tnx"); |
| 2036 | } |
| 2037 | } |
| @@ -2112,11 +2120,12 @@ | |
| 2112 | Stmt qYears = empty_Stmt; |
| 2113 | char * zDefaultYear = NULL; |
| 2114 | Blob sql = empty_blob; |
| 2115 | int nMaxEvents = 1; /* max number of events for |
| 2116 | all rows. */ |
| 2117 | |
| 2118 | cgi_printf("Select year: "); |
| 2119 | blob_append(&sql, |
| 2120 | "SELECT DISTINCT substr(date(mtime),1,4) AS y " |
| 2121 | "FROM event WHERE 1 ", -1); |
| 2122 | if(zUserName&&*zUserName){ |
| @@ -2178,10 +2187,11 @@ | |
| 2178 | while( SQLITE_ROW == db_step(&stWeek) ){ |
| 2179 | const int nCount = db_column_int(&stWeek, 1); |
| 2180 | if(nCount>nMaxEvents){ |
| 2181 | nMaxEvents = nCount; |
| 2182 | } |
| 2183 | } |
| 2184 | db_reset(&stWeek); |
| 2185 | while( SQLITE_ROW == db_step(&stWeek) ){ |
| 2186 | const char * zWeek = db_column_text(&stWeek,0); |
| 2187 | const int nCount = db_column_int(&stWeek,1); |
| @@ -2208,12 +2218,14 @@ | |
| 2208 | } |
| 2209 | db_finalize(&stWeek); |
| 2210 | free(zDefaultYear); |
| 2211 | cgi_printf("</tbody></table>"); |
| 2212 | if(total){ |
| 2213 | cgi_printf("<br><div>Total events: %d</div>", |
| 2214 | total); |
| 2215 | } |
| 2216 | output_table_sorting_javascript("statsTable","tnx"); |
| 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 |
| --- src/timeline.c | |
| +++ src/timeline.c | |
| @@ -1904,12 +1904,14 @@ | |
| 1904 | int nEventsPerYear = 0; /* Total event count for the |
| 1905 | current year */ |
| 1906 | char showYearTotal = 0; /* Flag telling us when to show |
| 1907 | the per-year event totals */ |
| 1908 | Blob header = empty_blob; /* Page header text */ |
| 1909 | int nMaxEvents = 1; /* for calculating length of graph |
| 1910 | bars. */ |
| 1911 | int iterations = 0; /* number of weeks/months we iterate |
| 1912 | over */ |
| 1913 | blob_appendf(&header, "Timeline Events by year%s", |
| 1914 | (includeMonth ? "/month" : "")); |
| 1915 | blob_appendf(&sql, |
| 1916 | "SELECT substr(date(mtime),1,%d) AS timeframe, " |
| 1917 | "count(*) AS eventCount " |
| @@ -1942,10 +1944,11 @@ | |
| 1944 | while( SQLITE_ROW == db_step(&query) ){ |
| 1945 | const int nCount = db_column_int(&query, 1); |
| 1946 | if(nCount>nMaxEvents){ |
| 1947 | nMaxEvents = nCount; |
| 1948 | } |
| 1949 | ++iterations; |
| 1950 | } |
| 1951 | db_reset(&query); |
| 1952 | while( SQLITE_ROW == db_step(&query) ){ |
| 1953 | const char * zTimeframe = db_column_text(&query, 0); |
| 1954 | const int nCount = db_column_int(&query, 1); |
| @@ -2027,11 +2030,16 @@ | |
| 2030 | @ <td colspan='2'>Yearly total: %d(nEventsPerYear)</td> |
| 2031 | @</tr> |
| 2032 | } |
| 2033 | @ </tbody></table> |
| 2034 | if(nEventTotal){ |
| 2035 | char const * zAvgLabel = includeMonth ? "month" : "year"; |
| 2036 | int nAvg = iterations ? (nEventTotal/iterations) : 0; |
| 2037 | int nWidth = (int)(100 * nAvg / nMaxEvents); |
| 2038 | @ <br><div>Total events: %d(nEventTotal) |
| 2039 | @ <br>Average per active %s(zAvgLabel): %d(nAvg) |
| 2040 | @ </div> |
| 2041 | } |
| 2042 | if( !includeMonth ){ |
| 2043 | output_table_sorting_javascript("statsTable","tnx"); |
| 2044 | } |
| 2045 | } |
| @@ -2112,11 +2120,12 @@ | |
| 2120 | Stmt qYears = empty_Stmt; |
| 2121 | char * zDefaultYear = NULL; |
| 2122 | Blob sql = empty_blob; |
| 2123 | int nMaxEvents = 1; /* max number of events for |
| 2124 | all rows. */ |
| 2125 | int iterations; /* # of active time periods. */ |
| 2126 | |
| 2127 | cgi_printf("Select year: "); |
| 2128 | blob_append(&sql, |
| 2129 | "SELECT DISTINCT substr(date(mtime),1,4) AS y " |
| 2130 | "FROM event WHERE 1 ", -1); |
| 2131 | if(zUserName&&*zUserName){ |
| @@ -2178,10 +2187,11 @@ | |
| 2187 | while( SQLITE_ROW == db_step(&stWeek) ){ |
| 2188 | const int nCount = db_column_int(&stWeek, 1); |
| 2189 | if(nCount>nMaxEvents){ |
| 2190 | nMaxEvents = nCount; |
| 2191 | } |
| 2192 | ++iterations; |
| 2193 | } |
| 2194 | db_reset(&stWeek); |
| 2195 | while( SQLITE_ROW == db_step(&stWeek) ){ |
| 2196 | const char * zWeek = db_column_text(&stWeek,0); |
| 2197 | const int nCount = db_column_int(&stWeek,1); |
| @@ -2208,12 +2218,14 @@ | |
| 2218 | } |
| 2219 | db_finalize(&stWeek); |
| 2220 | free(zDefaultYear); |
| 2221 | cgi_printf("</tbody></table>"); |
| 2222 | if(total){ |
| 2223 | int nAvg = iterations ? (total/iterations) : 0; |
| 2224 | cgi_printf("<br><div>Total events: %d<br>" |
| 2225 | "Average per active week: %d</div>", |
| 2226 | total, nAvg); |
| 2227 | } |
| 2228 | output_table_sorting_javascript("statsTable","tnx"); |
| 2229 | } |
| 2230 | } |
| 2231 | |
| 2232 |