Fossil SCM
Added /stats_report?view=byweek.
Commit
747bca14c02a9fb49a577e58c5737c488f62f793
Parent
887150679ce615a…
1 file changed
+80
-1
+80
-1
| --- src/timeline.c | ||
| +++ src/timeline.c | ||
| @@ -2055,10 +2055,87 @@ | ||
| 2055 | 2055 | @ </tbody></table> |
| 2056 | 2056 | db_finalize(&query); |
| 2057 | 2057 | output_table_sorting_javascript("statsTable","tnx"); |
| 2058 | 2058 | } |
| 2059 | 2059 | |
| 2060 | + | |
| 2061 | +/* | |
| 2062 | +** Helper for stats_report_by_month_year(), which generates a list of | |
| 2063 | +** week numbers. zTimeframe should be either a timeframe in the form YYYY | |
| 2064 | +** or YYYY-MM. | |
| 2065 | +*/ | |
| 2066 | +static void stats_report_year_weeks(){ | |
| 2067 | + char const * zYear = P("y"); | |
| 2068 | + int nYear = zYear ? strlen(zYear) : 0; | |
| 2069 | + int i = 0; | |
| 2070 | + Stmt qYears = empty_Stmt; | |
| 2071 | + char * zDefaultYear = NULL; | |
| 2072 | + cgi_printf("Select a year: "); | |
| 2073 | + db_prepare(&qYears, | |
| 2074 | + "SELECT DISTINCT substr(date(mtime),1,4) AS y " | |
| 2075 | + "FROM event GROUP BY y ORDER BY y"); | |
| 2076 | + while( SQLITE_ROW == db_step(&qYears) ){ | |
| 2077 | + char const * zT = db_column_text(&qYears, 0); | |
| 2078 | + if( i++ ){ | |
| 2079 | + cgi_printf(" "); | |
| 2080 | + } | |
| 2081 | + cgi_printf("<a href='?view=byweek&y=%s'>%s</a>", | |
| 2082 | + zT, zT); | |
| 2083 | + } | |
| 2084 | + db_finalize(&qYears); | |
| 2085 | + cgi_printf("<br/>"); | |
| 2086 | + if(!zYear || !*zYear){ | |
| 2087 | + zDefaultYear = db_text("????", "SELECT strftime('%%Y')"); | |
| 2088 | + zYear = zDefaultYear; | |
| 2089 | + nYear = 4; | |
| 2090 | + } | |
| 2091 | + if(4 == nYear){ | |
| 2092 | + int const nPixelsPerEvent = 3; /* for sizing the "graph" part */ | |
| 2093 | + Stmt stWeek = empty_Stmt; | |
| 2094 | + int rowCount = 0; | |
| 2095 | + cgi_printf("<h1>Timeline events for the calendar weeks of %h.</h1>", | |
| 2096 | + zYear); | |
| 2097 | + cgi_printf("<table class='statistics-report-table-events' " | |
| 2098 | + "border='0' cellpadding='2' " | |
| 2099 | + "cellspacing='0' id='statsTable'>"); | |
| 2100 | + cgi_printf("<thead><tr>" | |
| 2101 | + "<th>Week #</th>" | |
| 2102 | + "<th>Events</th>" | |
| 2103 | + "<th><!-- relative commits graph --></th>" | |
| 2104 | + "</tr></thead>" | |
| 2105 | + "<tbody>"); | |
| 2106 | + db_prepare(&stWeek, | |
| 2107 | + "SELECT DISTINCT strftime('%%W',mtime) AS wk, " | |
| 2108 | + "count(*) AS n " | |
| 2109 | + "FROM event " | |
| 2110 | + "WHERE %Q=substr(date(mtime),1,4) " | |
| 2111 | + "AND mtime < current_timestamp " | |
| 2112 | + "GROUP BY wk ORDER BY wk DESC", | |
| 2113 | + zYear); | |
| 2114 | + while( SQLITE_ROW == db_step(&stWeek) ){ | |
| 2115 | + char const * zWeek = db_column_text(&stWeek,0); | |
| 2116 | + int nCount = db_column_int(&stWeek,1); | |
| 2117 | + int const graphSize = nPixelsPerEvent * nCount; | |
| 2118 | + cgi_printf("<tr class='row%d'>", ++rowCount % 2 ); | |
| 2119 | + cgi_printf("<td><a href='%s/timeline?yw=%t-%s'>%s</a></td>", | |
| 2120 | + g.zTop, zYear, zWeek, zWeek); | |
| 2121 | + cgi_printf("<td>%d</td>",nCount); | |
| 2122 | + cgi_printf("<td>"); | |
| 2123 | + if(nCount){ | |
| 2124 | + cgi_printf("<div class='statistics-report-graph-line'" | |
| 2125 | + "style='height:16px;width:%dpx;'></div>", | |
| 2126 | + graphSize); | |
| 2127 | + } | |
| 2128 | + cgi_printf("</td></tr>"); | |
| 2129 | + } | |
| 2130 | + db_finalize(&stWeek); | |
| 2131 | + cgi_printf("</tbody></table>"); | |
| 2132 | + output_table_sorting_javascript("statsTable","tnx"); | |
| 2133 | + free(zDefaultYear); | |
| 2134 | + } | |
| 2135 | +} | |
| 2136 | + | |
| 2060 | 2137 | /* |
| 2061 | 2138 | ** WEBPAGE: stats_report |
| 2062 | 2139 | ** |
| 2063 | 2140 | ** Shows activity reports for the repository. |
| 2064 | 2141 | ** |
| @@ -2077,27 +2154,29 @@ | ||
| 2077 | 2154 | url_add_parameter(&url,"user", zUserName); |
| 2078 | 2155 | timeline_submenu(&url, "(Remove User Flag)", "view", zView, "user"); |
| 2079 | 2156 | } |
| 2080 | 2157 | timeline_submenu(&url, "By Year", "view", "byyear", 0); |
| 2081 | 2158 | timeline_submenu(&url, "By Month", "view", "bymonth", 0); |
| 2159 | + timeline_submenu(&url, "By Week", "view", "byweek", 0); | |
| 2082 | 2160 | timeline_submenu(&url, "By User", "view", "byuser", "user"); |
| 2083 | 2161 | url_reset(&url); |
| 2084 | 2162 | style_header("Activity Reports"); |
| 2085 | 2163 | if(0==fossil_strcmp(zView,"byyear")){ |
| 2086 | 2164 | stats_report_by_month_year(0, zUserName); |
| 2087 | 2165 | }else if(0==fossil_strcmp(zView,"bymonth")){ |
| 2088 | 2166 | stats_report_by_month_year(1, zUserName); |
| 2089 | 2167 | }else if(0==fossil_strcmp(zView,"byweek")){ |
| 2090 | - @ TODO: by-week report. | |
| 2168 | + stats_report_year_weeks(); | |
| 2091 | 2169 | }else if(0==fossil_strcmp(zView,"byuser")){ |
| 2092 | 2170 | stats_report_by_user(); |
| 2093 | 2171 | }else{ |
| 2094 | 2172 | @ <h1>Select a report to show:</h1> |
| 2095 | 2173 | @ <ul> |
| 2096 | 2174 | @ <li><a href='?view=byyear'>Events by year</a></li> |
| 2097 | 2175 | @ <li><a href='?view=bymonth'>Events by month</a></li> |
| 2176 | + @ <li><a href='?view=byweek'>Events by calendar week</a></li> | |
| 2098 | 2177 | @ <li><a href='?view=byuser'>Events by user</a></li> |
| 2099 | 2178 | @ </ul> |
| 2100 | 2179 | } |
| 2101 | 2180 | |
| 2102 | 2181 | style_footer(); |
| 2103 | 2182 | } |
| 2104 | 2183 |
| --- src/timeline.c | |
| +++ src/timeline.c | |
| @@ -2055,10 +2055,87 @@ | |
| 2055 | @ </tbody></table> |
| 2056 | db_finalize(&query); |
| 2057 | output_table_sorting_javascript("statsTable","tnx"); |
| 2058 | } |
| 2059 | |
| 2060 | /* |
| 2061 | ** WEBPAGE: stats_report |
| 2062 | ** |
| 2063 | ** Shows activity reports for the repository. |
| 2064 | ** |
| @@ -2077,27 +2154,29 @@ | |
| 2077 | url_add_parameter(&url,"user", zUserName); |
| 2078 | timeline_submenu(&url, "(Remove User Flag)", "view", zView, "user"); |
| 2079 | } |
| 2080 | timeline_submenu(&url, "By Year", "view", "byyear", 0); |
| 2081 | timeline_submenu(&url, "By Month", "view", "bymonth", 0); |
| 2082 | timeline_submenu(&url, "By User", "view", "byuser", "user"); |
| 2083 | url_reset(&url); |
| 2084 | style_header("Activity Reports"); |
| 2085 | if(0==fossil_strcmp(zView,"byyear")){ |
| 2086 | stats_report_by_month_year(0, zUserName); |
| 2087 | }else if(0==fossil_strcmp(zView,"bymonth")){ |
| 2088 | stats_report_by_month_year(1, zUserName); |
| 2089 | }else if(0==fossil_strcmp(zView,"byweek")){ |
| 2090 | @ TODO: by-week report. |
| 2091 | }else if(0==fossil_strcmp(zView,"byuser")){ |
| 2092 | stats_report_by_user(); |
| 2093 | }else{ |
| 2094 | @ <h1>Select a report to show:</h1> |
| 2095 | @ <ul> |
| 2096 | @ <li><a href='?view=byyear'>Events by year</a></li> |
| 2097 | @ <li><a href='?view=bymonth'>Events by month</a></li> |
| 2098 | @ <li><a href='?view=byuser'>Events by user</a></li> |
| 2099 | @ </ul> |
| 2100 | } |
| 2101 | |
| 2102 | style_footer(); |
| 2103 | } |
| 2104 |
| --- src/timeline.c | |
| +++ src/timeline.c | |
| @@ -2055,10 +2055,87 @@ | |
| 2055 | @ </tbody></table> |
| 2056 | db_finalize(&query); |
| 2057 | output_table_sorting_javascript("statsTable","tnx"); |
| 2058 | } |
| 2059 | |
| 2060 | |
| 2061 | /* |
| 2062 | ** Helper for stats_report_by_month_year(), which generates a list of |
| 2063 | ** week numbers. zTimeframe should be either a timeframe in the form YYYY |
| 2064 | ** or YYYY-MM. |
| 2065 | */ |
| 2066 | static void stats_report_year_weeks(){ |
| 2067 | char const * zYear = P("y"); |
| 2068 | int nYear = zYear ? strlen(zYear) : 0; |
| 2069 | int i = 0; |
| 2070 | Stmt qYears = empty_Stmt; |
| 2071 | char * zDefaultYear = NULL; |
| 2072 | cgi_printf("Select a year: "); |
| 2073 | db_prepare(&qYears, |
| 2074 | "SELECT DISTINCT substr(date(mtime),1,4) AS y " |
| 2075 | "FROM event GROUP BY y ORDER BY y"); |
| 2076 | while( SQLITE_ROW == db_step(&qYears) ){ |
| 2077 | char const * zT = db_column_text(&qYears, 0); |
| 2078 | if( i++ ){ |
| 2079 | cgi_printf(" "); |
| 2080 | } |
| 2081 | cgi_printf("<a href='?view=byweek&y=%s'>%s</a>", |
| 2082 | zT, zT); |
| 2083 | } |
| 2084 | db_finalize(&qYears); |
| 2085 | cgi_printf("<br/>"); |
| 2086 | if(!zYear || !*zYear){ |
| 2087 | zDefaultYear = db_text("????", "SELECT strftime('%%Y')"); |
| 2088 | zYear = zDefaultYear; |
| 2089 | nYear = 4; |
| 2090 | } |
| 2091 | if(4 == nYear){ |
| 2092 | int const nPixelsPerEvent = 3; /* for sizing the "graph" part */ |
| 2093 | Stmt stWeek = empty_Stmt; |
| 2094 | int rowCount = 0; |
| 2095 | cgi_printf("<h1>Timeline events for the calendar weeks of %h.</h1>", |
| 2096 | zYear); |
| 2097 | cgi_printf("<table class='statistics-report-table-events' " |
| 2098 | "border='0' cellpadding='2' " |
| 2099 | "cellspacing='0' id='statsTable'>"); |
| 2100 | cgi_printf("<thead><tr>" |
| 2101 | "<th>Week #</th>" |
| 2102 | "<th>Events</th>" |
| 2103 | "<th><!-- relative commits graph --></th>" |
| 2104 | "</tr></thead>" |
| 2105 | "<tbody>"); |
| 2106 | db_prepare(&stWeek, |
| 2107 | "SELECT DISTINCT strftime('%%W',mtime) AS wk, " |
| 2108 | "count(*) AS n " |
| 2109 | "FROM event " |
| 2110 | "WHERE %Q=substr(date(mtime),1,4) " |
| 2111 | "AND mtime < current_timestamp " |
| 2112 | "GROUP BY wk ORDER BY wk DESC", |
| 2113 | zYear); |
| 2114 | while( SQLITE_ROW == db_step(&stWeek) ){ |
| 2115 | char const * zWeek = db_column_text(&stWeek,0); |
| 2116 | int nCount = db_column_int(&stWeek,1); |
| 2117 | int const graphSize = nPixelsPerEvent * nCount; |
| 2118 | cgi_printf("<tr class='row%d'>", ++rowCount % 2 ); |
| 2119 | cgi_printf("<td><a href='%s/timeline?yw=%t-%s'>%s</a></td>", |
| 2120 | g.zTop, zYear, zWeek, zWeek); |
| 2121 | cgi_printf("<td>%d</td>",nCount); |
| 2122 | cgi_printf("<td>"); |
| 2123 | if(nCount){ |
| 2124 | cgi_printf("<div class='statistics-report-graph-line'" |
| 2125 | "style='height:16px;width:%dpx;'></div>", |
| 2126 | graphSize); |
| 2127 | } |
| 2128 | cgi_printf("</td></tr>"); |
| 2129 | } |
| 2130 | db_finalize(&stWeek); |
| 2131 | cgi_printf("</tbody></table>"); |
| 2132 | output_table_sorting_javascript("statsTable","tnx"); |
| 2133 | free(zDefaultYear); |
| 2134 | } |
| 2135 | } |
| 2136 | |
| 2137 | /* |
| 2138 | ** WEBPAGE: stats_report |
| 2139 | ** |
| 2140 | ** Shows activity reports for the repository. |
| 2141 | ** |
| @@ -2077,27 +2154,29 @@ | |
| 2154 | url_add_parameter(&url,"user", zUserName); |
| 2155 | timeline_submenu(&url, "(Remove User Flag)", "view", zView, "user"); |
| 2156 | } |
| 2157 | timeline_submenu(&url, "By Year", "view", "byyear", 0); |
| 2158 | timeline_submenu(&url, "By Month", "view", "bymonth", 0); |
| 2159 | timeline_submenu(&url, "By Week", "view", "byweek", 0); |
| 2160 | timeline_submenu(&url, "By User", "view", "byuser", "user"); |
| 2161 | url_reset(&url); |
| 2162 | style_header("Activity Reports"); |
| 2163 | if(0==fossil_strcmp(zView,"byyear")){ |
| 2164 | stats_report_by_month_year(0, zUserName); |
| 2165 | }else if(0==fossil_strcmp(zView,"bymonth")){ |
| 2166 | stats_report_by_month_year(1, zUserName); |
| 2167 | }else if(0==fossil_strcmp(zView,"byweek")){ |
| 2168 | stats_report_year_weeks(); |
| 2169 | }else if(0==fossil_strcmp(zView,"byuser")){ |
| 2170 | stats_report_by_user(); |
| 2171 | }else{ |
| 2172 | @ <h1>Select a report to show:</h1> |
| 2173 | @ <ul> |
| 2174 | @ <li><a href='?view=byyear'>Events by year</a></li> |
| 2175 | @ <li><a href='?view=bymonth'>Events by month</a></li> |
| 2176 | @ <li><a href='?view=byweek'>Events by calendar week</a></li> |
| 2177 | @ <li><a href='?view=byuser'>Events by user</a></li> |
| 2178 | @ </ul> |
| 2179 | } |
| 2180 | |
| 2181 | style_footer(); |
| 2182 | } |
| 2183 |