| | @@ -1032,10 +1032,11 @@ |
| 1032 | 1032 | const char *zTagName = P("t"); /* Show events with this tag */ |
| 1033 | 1033 | const char *zBrName = P("r"); /* Show events related to this tag */ |
| 1034 | 1034 | const char *zSearch = P("s"); /* Search string */ |
| 1035 | 1035 | const char *zUses = P("uf"); /* Only show checkins hold this file */ |
| 1036 | 1036 | const char *zYearMonth = P("ym"); /* Show checkins for the given YYYY-MM */ |
| 1037 | + const char *zYearWeek = P("yw"); /* Show checkins for the given YYYY-WW (weak-of-year) */ |
| 1037 | 1038 | int useDividers = P("nd")==0; /* Show dividers if "nd" is missing */ |
| 1038 | 1039 | int renameOnly = P("namechng")!=0; /* Show only checkins that rename files */ |
| 1039 | 1040 | int tagid; /* Tag ID */ |
| 1040 | 1041 | int tmFlags; /* Timeline flags */ |
| 1041 | 1042 | const char *zThisTag = 0; /* Suppress links to this tag */ |
| | @@ -1218,10 +1219,14 @@ |
| 1218 | 1219 | } |
| 1219 | 1220 | if( zYearMonth ){ |
| 1220 | 1221 | blob_appendf(&sql, " AND %Q=strftime('%%Y-%%m',event.mtime) ", |
| 1221 | 1222 | zYearMonth); |
| 1222 | 1223 | } |
| 1224 | + else if( zYearWeek ){ |
| 1225 | + blob_appendf(&sql, " AND %Q=strftime('%%Y-%%W',event.mtime) ", |
| 1226 | + zYearWeek); |
| 1227 | + } |
| 1223 | 1228 | if( tagid>0 ){ |
| 1224 | 1229 | blob_appendf(&sql, |
| 1225 | 1230 | "AND (EXISTS(SELECT 1 FROM tagxref" |
| 1226 | 1231 | " WHERE tagid=%d AND tagtype>0 AND rid=blob.rid)", tagid); |
| 1227 | 1232 | |
| | @@ -1350,10 +1355,12 @@ |
| 1350 | 1355 | db_multi_exec("%s", blob_str(&sql)); |
| 1351 | 1356 | |
| 1352 | 1357 | n = db_int(0, "SELECT count(*) FROM timeline WHERE etype!='div' /*scan*/"); |
| 1353 | 1358 | if( zYearMonth ){ |
| 1354 | 1359 | blob_appendf(&desc, "%s events for %h", zEType, zYearMonth); |
| 1360 | + }else if( zYearWeek ){ |
| 1361 | + blob_appendf(&desc, "%s events for year/week %h", zEType, zYearWeek); |
| 1355 | 1362 | }else if( zAfter==0 && zBefore==0 && zCirca==0 ){ |
| 1356 | 1363 | blob_appendf(&desc, "%d most recent %ss", n, zEType); |
| 1357 | 1364 | }else{ |
| 1358 | 1365 | blob_appendf(&desc, "%d %ss", n, zEType); |
| 1359 | 1366 | } |
| | @@ -1829,20 +1836,48 @@ |
| 1829 | 1836 | } |
| 1830 | 1837 | db_finalize(&q); |
| 1831 | 1838 | style_footer(); |
| 1832 | 1839 | } |
| 1833 | 1840 | |
| 1834 | | - |
| 1841 | +/* |
| 1842 | +** Helper for stats_report_by_month_year(), which generates a list of |
| 1843 | +** week numbers. zTimeframe should be either a timeframe in the form YYYY |
| 1844 | +** or YYYY-MM. |
| 1845 | +*/ |
| 1846 | +static void stats_report_output_week_links(char const * zTimeframe){ |
| 1847 | + Stmt stWeek = empty_Stmt; |
| 1848 | + char yearPart[5] = {0,0,0,0,0}; |
| 1849 | + memcpy(yearPart, zTimeframe, 4); |
| 1850 | + db_prepare(&stWeek, |
| 1851 | + "SELECT DISTINCT strftime('%%W',mtime) AS wk, " |
| 1852 | + "count(*) AS n, " |
| 1853 | + "substr(date(mtime),1,%d) AS ym " |
| 1854 | + "FROM event " |
| 1855 | + "WHERE ym=%Q AND mtime < current_timestamp " |
| 1856 | + "GROUP BY wk ORDER BY wk", |
| 1857 | + strlen(zTimeframe), |
| 1858 | + zTimeframe); |
| 1859 | + while( SQLITE_ROW == db_step(&stWeek) ){ |
| 1860 | + char const * zWeek = db_column_text(&stWeek,0); |
| 1861 | + int const nCount = db_column_int(&stWeek,1); |
| 1862 | + cgi_printf("<a href='%s/timeline?" |
| 1863 | + "yw=%t-%t&n=%d'>%s</a>", |
| 1864 | + g.zTop, yearPart, zWeek, |
| 1865 | + nCount, zWeek); |
| 1866 | + } |
| 1867 | + db_finalize(&stWeek); |
| 1868 | +} |
| 1835 | 1869 | |
| 1836 | 1870 | /* |
| 1837 | 1871 | ** Implements the "byyear" and "bymonth" reports for /stats_report. |
| 1838 | 1872 | ** If includeMonth is true then it generates the "bymonth" report, |
| 1839 | 1873 | ** else the "byyear" report. If zUserName is not NULL and not empty |
| 1840 | 1874 | ** then the report is restricted to events created by the named user |
| 1841 | 1875 | ** account. |
| 1842 | 1876 | */ |
| 1843 | 1877 | static void stats_report_by_month_year(char includeMonth, |
| 1878 | + char includeWeeks, |
| 1844 | 1879 | char const * zUserName){ |
| 1845 | 1880 | Stmt query = empty_Stmt; |
| 1846 | 1881 | int const nPixelsPerEvent = 1; /* for sizing the "graph" part */ |
| 1847 | 1882 | int nRowNumber = 0; /* current TR number */ |
| 1848 | 1883 | int nEventTotal = 0; /* Total event count */ |
| | @@ -1906,17 +1941,17 @@ |
| 1906 | 1941 | memcpy(zPrevYear,zTimeframe,4); |
| 1907 | 1942 | rowClass = ++nRowNumber % 2; |
| 1908 | 1943 | @ <tr class='row%d(rowClass)'> |
| 1909 | 1944 | @ <th colspan='3' class='statistics-report-row-year'>%s(zPrevYear)</th> |
| 1910 | 1945 | @ </tr> |
| 1911 | | - } |
| 1912 | | - } |
| 1913 | | - rowClass = ++nRowNumber % 2; |
| 1914 | | - nEventTotal += nCount; |
| 1915 | | - nEventsPerYear += nCount; |
| 1916 | | - @<tr class='row%d(rowClass)'> |
| 1917 | | - @ <td> |
| 1946 | + } |
| 1947 | + } |
| 1948 | + rowClass = ++nRowNumber % 2; |
| 1949 | + nEventTotal += nCount; |
| 1950 | + nEventsPerYear += nCount; |
| 1951 | + @<tr class='row%d(rowClass)'> |
| 1952 | + @ <td> |
| 1918 | 1953 | if(includeMonth){ |
| 1919 | 1954 | cgi_printf("<a href='%s/timeline?" |
| 1920 | 1955 | "ym=%t&n=%d", |
| 1921 | 1956 | g.zTop, zTimeframe, nCount ); |
| 1922 | 1957 | /* Reminder: n=nCount is not actually correct for bymonth unless |
| | @@ -1925,18 +1960,32 @@ |
| 1925 | 1960 | if( zUserName && *zUserName ){ |
| 1926 | 1961 | cgi_printf("&u=%t", zUserName); |
| 1927 | 1962 | } |
| 1928 | 1963 | cgi_printf("' target='_new'>%s</a>",zTimeframe); |
| 1929 | 1964 | }else { |
| 1930 | | - @ %s(zTimeframe) |
| 1965 | + cgi_printf("<a href='?view=byweek&y=%s", zTimeframe); |
| 1966 | + if(zUserName && *zUserName){ |
| 1967 | + cgi_printf("&u=%t", zUserName); |
| 1968 | + } |
| 1969 | + cgi_printf("'>%s</a>", zTimeframe); |
| 1931 | 1970 | } |
| 1932 | 1971 | @ </td><td>%d(nCount)</td> |
| 1933 | 1972 | @ <td> |
| 1934 | 1973 | @ <div class='statistics-report-graph-line' |
| 1935 | 1974 | @ style='height:16px;width:%d(nSize)px;'> |
| 1936 | 1975 | @ </div></td> |
| 1937 | 1976 | @</tr> |
| 1977 | + if(includeWeeks){ |
| 1978 | + /* This part works fine for months but it terribly slow (4.5s on my PC), |
| 1979 | + so it's only shown for by-year for now. Suggestions/patches for |
| 1980 | + a better/faster layout are welcomed. */ |
| 1981 | + @ <tr class='row%d(rowClass)'> |
| 1982 | + @ <td colspan='2' class='statistics-report-week-number-label'>Week #:</td> |
| 1983 | + @ <td class='statistics-report-week-of-year-list'> |
| 1984 | + stats_report_output_week_links(zTimeframe); |
| 1985 | + @ </td></tr> |
| 1986 | + } |
| 1938 | 1987 | |
| 1939 | 1988 | /* |
| 1940 | 1989 | Potential improvement: calculate the min/max event counts and |
| 1941 | 1990 | use percent-based graph bars. |
| 1942 | 1991 | */ |
| | @@ -2014,10 +2063,120 @@ |
| 2014 | 2063 | @ </tbody></table> |
| 2015 | 2064 | db_finalize(&query); |
| 2016 | 2065 | output_table_sorting_javascript("statsTable","tnx"); |
| 2017 | 2066 | } |
| 2018 | 2067 | |
| 2068 | + |
| 2069 | +/* |
| 2070 | +** Helper for stats_report_by_month_year(), which generates a list of |
| 2071 | +** week numbers. zTimeframe should be either a timeframe in the form YYYY |
| 2072 | +** or YYYY-MM. |
| 2073 | +*/ |
| 2074 | +static void stats_report_year_weeks(char const * zUserName){ |
| 2075 | + char const * zYear = P("y"); |
| 2076 | + int nYear = zYear ? strlen(zYear) : 0; |
| 2077 | + int i = 0; |
| 2078 | + Stmt qYears = empty_Stmt; |
| 2079 | + char * zDefaultYear = NULL; |
| 2080 | + Blob sql = empty_blob; |
| 2081 | + cgi_printf("Select year: "); |
| 2082 | + |
| 2083 | + blob_append(&sql, |
| 2084 | + "SELECT DISTINCT substr(date(mtime),1,4) AS y " |
| 2085 | + "FROM event WHERE 1 ", -1); |
| 2086 | + if(zUserName&&*zUserName){ |
| 2087 | + blob_appendf(&sql,"AND user=%Q ", zUserName); |
| 2088 | + } |
| 2089 | + blob_append(&sql,"GROUP BY y ORDER BY y", -1); |
| 2090 | + db_prepare(&qYears, blob_str(&sql)); |
| 2091 | + blob_reset(&sql); |
| 2092 | + while( SQLITE_ROW == db_step(&qYears) ){ |
| 2093 | + char const * zT = db_column_text(&qYears, 0); |
| 2094 | + if( i++ ){ |
| 2095 | + cgi_printf(" "); |
| 2096 | + } |
| 2097 | + cgi_printf("<a href='?view=byweek&y=%s", zT); |
| 2098 | + if(zUserName && *zUserName){ |
| 2099 | + cgi_printf("&user=%t",zUserName); |
| 2100 | + } |
| 2101 | + cgi_printf("'>%s</a>",zT); |
| 2102 | + } |
| 2103 | + db_finalize(&qYears); |
| 2104 | + cgi_printf("<br/>"); |
| 2105 | + if(!zYear || !*zYear){ |
| 2106 | + zDefaultYear = db_text("????", "SELECT strftime('%%Y')"); |
| 2107 | + zYear = zDefaultYear; |
| 2108 | + nYear = 4; |
| 2109 | + } |
| 2110 | + if(4 == nYear){ |
| 2111 | + int const nPixelsPerEvent = 3; /* for sizing the "graph" part */ |
| 2112 | + Stmt stWeek = empty_Stmt; |
| 2113 | + int rowCount = 0; |
| 2114 | + int total = 0; |
| 2115 | + Blob header = empty_blob; |
| 2116 | + blob_appendf(&header, "Timeline events for the calendar weeks " |
| 2117 | + "of %h", zYear); |
| 2118 | + blob_appendf(&sql, |
| 2119 | + "SELECT DISTINCT strftime('%%%%W',mtime) AS wk, " |
| 2120 | + "count(*) AS n " |
| 2121 | + "FROM event " |
| 2122 | + "WHERE %Q=substr(date(mtime),1,4) " |
| 2123 | + "AND mtime < current_timestamp ", |
| 2124 | + zYear); |
| 2125 | + if(zUserName&&*zUserName){ |
| 2126 | + blob_appendf(&sql, " AND user=%Q ", zUserName); |
| 2127 | + blob_appendf(&header," for user %h", zUserName); |
| 2128 | + } |
| 2129 | + blob_appendf(&sql, "GROUP BY wk ORDER BY wk DESC"); |
| 2130 | + cgi_printf("<h1>%h</h1>", blob_str(&header)); |
| 2131 | + blob_reset(&header); |
| 2132 | + cgi_printf("<table class='statistics-report-table-events' " |
| 2133 | + "border='0' cellpadding='2' " |
| 2134 | + "cellspacing='0' id='statsTable'>"); |
| 2135 | + cgi_printf("<thead><tr>" |
| 2136 | + "<th>Week</th>" |
| 2137 | + "<th>Events</th>" |
| 2138 | + "<th><!-- relative commits graph --></th>" |
| 2139 | + "</tr></thead>" |
| 2140 | + "<tbody>"); |
| 2141 | + db_prepare(&stWeek, blob_str(&sql)); |
| 2142 | + blob_reset(&sql); |
| 2143 | + while( SQLITE_ROW == db_step(&stWeek) ){ |
| 2144 | + char const * zWeek = db_column_text(&stWeek,0); |
| 2145 | + int const nCount = db_column_int(&stWeek,1); |
| 2146 | + int const graphSize = nPixelsPerEvent * nCount; |
| 2147 | + total += nCount; |
| 2148 | + cgi_printf("<tr class='row%d'>", ++rowCount % 2 ); |
| 2149 | + cgi_printf("<td><a href='%s/timeline?yw=%t-%s&n=%d", |
| 2150 | + g.zTop, zYear, zWeek, nCount); |
| 2151 | + if(zUserName && *zUserName){ |
| 2152 | + cgi_printf("&u=%t",zUserName); |
| 2153 | + } |
| 2154 | + cgi_printf("'>%s</a></td>",zWeek); |
| 2155 | + |
| 2156 | + cgi_printf("<td>%d</td>",nCount); |
| 2157 | + cgi_printf("<td>"); |
| 2158 | + if(nCount){ |
| 2159 | + cgi_printf("<div class='statistics-report-graph-line'" |
| 2160 | + "style='height:16px;width:%dpx;'></div>", |
| 2161 | + graphSize); |
| 2162 | + } |
| 2163 | + cgi_printf("</td></tr>"); |
| 2164 | + } |
| 2165 | + db_finalize(&stWeek); |
| 2166 | + free(zDefaultYear); |
| 2167 | + if(total){ |
| 2168 | + cgi_printf("<tr class='row%d'>", ++rowCount%2); |
| 2169 | + cgi_printf("<td colspan='2'>Total events:</td><td>%d</td>", |
| 2170 | + total); |
| 2171 | + cgi_printf("</tr>"); |
| 2172 | + } |
| 2173 | + cgi_printf("</tbody></table>"); |
| 2174 | + output_table_sorting_javascript("statsTable","tnx"); |
| 2175 | + } |
| 2176 | +} |
| 2177 | + |
| 2019 | 2178 | /* |
| 2020 | 2179 | ** WEBPAGE: stats_report |
| 2021 | 2180 | ** |
| 2022 | 2181 | ** Shows activity reports for the repository. |
| 2023 | 2182 | ** |
| | @@ -2028,35 +2187,38 @@ |
| 2028 | 2187 | */ |
| 2029 | 2188 | void stats_report_page(){ |
| 2030 | 2189 | HQuery url; /* URL for various branch links */ |
| 2031 | 2190 | char const * zView = P("view"); /* Which view/report to show. */ |
| 2032 | 2191 | char const *zUserName = P("user"); |
| 2192 | + if(!zUserName) zUserName = P("u"); |
| 2033 | 2193 | url_initialize(&url, "stats_report"); |
| 2034 | 2194 | |
| 2035 | 2195 | if(zUserName && *zUserName){ |
| 2036 | 2196 | url_add_parameter(&url,"user", zUserName); |
| 2037 | 2197 | timeline_submenu(&url, "(Remove User Flag)", "view", zView, "user"); |
| 2038 | 2198 | } |
| 2039 | 2199 | timeline_submenu(&url, "By Year", "view", "byyear", 0); |
| 2040 | 2200 | timeline_submenu(&url, "By Month", "view", "bymonth", 0); |
| 2201 | + timeline_submenu(&url, "By Week", "view", "byweek", 0); |
| 2041 | 2202 | timeline_submenu(&url, "By User", "view", "byuser", "user"); |
| 2042 | 2203 | url_reset(&url); |
| 2043 | 2204 | style_header("Activity Reports"); |
| 2044 | 2205 | if(0==fossil_strcmp(zView,"byyear")){ |
| 2045 | | - stats_report_by_month_year(0, zUserName); |
| 2206 | + stats_report_by_month_year(0, 0, zUserName); |
| 2046 | 2207 | }else if(0==fossil_strcmp(zView,"bymonth")){ |
| 2047 | | - stats_report_by_month_year(1, zUserName); |
| 2208 | + stats_report_by_month_year(1, 0, zUserName); |
| 2048 | 2209 | }else if(0==fossil_strcmp(zView,"byweek")){ |
| 2049 | | - @ TODO: by-week report. |
| 2210 | + stats_report_year_weeks(zUserName); |
| 2050 | 2211 | }else if(0==fossil_strcmp(zView,"byuser")){ |
| 2051 | 2212 | stats_report_by_user(); |
| 2052 | 2213 | }else{ |
| 2053 | 2214 | @ <h1>Select a report to show:</h1> |
| 2054 | 2215 | @ <ul> |
| 2055 | 2216 | @ <li><a href='?view=byyear'>Events by year</a></li> |
| 2056 | 2217 | @ <li><a href='?view=bymonth'>Events by month</a></li> |
| 2218 | + @ <li><a href='?view=byweek'>Events by calendar week</a></li> |
| 2057 | 2219 | @ <li><a href='?view=byuser'>Events by user</a></li> |
| 2058 | 2220 | @ </ul> |
| 2059 | 2221 | } |
| 2060 | 2222 | |
| 2061 | 2223 | style_footer(); |
| 2062 | 2224 | } |
| 2063 | 2225 | |