Changes between Version 7 and Version 8 of CookBook/Configuration/Reports
- Timestamp:
- Aug 4, 2015, 6:50:11 PM (9 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
CookBook/Configuration/Reports
v7 v8 1 = Custom Reports Configuration =1 = Custom Reports Configuration 2 2 3 3 TracReports#CreatingCustomReports describes how to create custom reports. 4 4 5 5 This page contains SQL for reports that may be of interest to many users. 6 6 7 [[PageOutline(2-3,Available Examples,inline)]] 7 8 8 == Ticket reports == 9 10 === User Report === 11 12 When one visits a Trac system as a user of a product and not as a developer of the product, one often wants to search for those tickets of personal interest. Such tickets could be defined as those tickets where the user is the Reporter, in the CC or additionally as a commenter. 13 14 Query for Report: 15 {{{ 16 #!sql 9 == Ticket reports 10 11 === User Report 12 13 When one visits a Trac system as a user of a product and not as a developer of the product, one often wants to search for those tickets of personal interest. Such tickets could be defined as those tickets where the user is the Reporter, in the CC or additionally as a commenter: 14 15 {{{#!sql 17 16 SELECT 18 17 DISTINCT … … 32 31 OR cc LIKE '% $USER,%' 33 32 OR cc = '$USER' 34 OR (tc.author ='$USER' AND tc.field = 'comment')33 OR (tc.author = '$USER' AND tc.field = 'comment') 35 34 ORDER BY 36 35 (status = 'closed'), … … 42 41 43 42 To include tickets that the user made any changes to, whether a comment was included or not, change the following: 44 {{{ 45 #!diff 43 {{{#!diff 46 44 --- Report.sql 47 45 +++ Report.sql … … 50 48 OR cc LIKE '% $USER,%' 51 49 OR cc = '$USER' 52 - OR (tc.author ='$USER' AND tc.field = 'comment')53 + OR tc.author ='$USER'50 - OR (tc.author = '$USER' AND tc.field = 'comment') 51 + OR tc.author = '$USER' 54 52 ORDER BY 55 53 (status = 'closed'), 56 54 (CASE status 57 55 }}} 56 58 57 To exclude tickets that the user made comments to and thus just those they are the reporter or in the CC, delete the following: 59 {{{ 60 #!diff 58 {{{#!diff 61 59 --- Report.sql 62 60 +++ Report.sql … … 71 69 OR cc LIKE '% $USER,%' 72 70 OR cc = '$USER' 73 - OR (tc.author ='$USER' AND tc.field = 'comment')71 - OR (tc.author = '$USER' AND tc.field = 'comment') 74 72 ORDER BY 75 73 (status = 'closed'), … … 78 76 79 77 80 === Popular tickets - to do ===78 === Popular tickets - to do 81 79 82 80 This lists tickets that are on the TODO list for a long time. … … 84 82 The criteria for inclusion is that the feature request or bug report is that '''at least 10 different people participated to the ticket activity'''. 85 83 86 Tickets are ordered by ''popularity'', defined as the amount of activity on a ticket over time (using a secret formula taking into account the number of participants in the discussion, the number of people on CC:, ...)84 Tickets are ordered by ''popularity'', defined as the amount of activity on a ticket over time, using a formula taking into account the number of participants in the discussion and the number of people on CC:. 87 85 88 86 This is report {32} on this site. … … 101 99 component, 102 100 version, 103 time ascreated101 time AS created 104 102 FROM ticket t LEFT JOIN 105 (SELECT ticket, count(distinct author) as author_cnt, 106 count(*) as change_cnt 103 (SELECT ticket, COUNT(DISTINCT author) AS author_cnt, COUNT(*) AS change_cnt 107 104 FROM ticket_change 108 105 WHERE field = 'comment' GROUP BY ticket) tc ON (t.id = tc.ticket), 109 106 enum p, 110 (SELECT extract(epoch from current_timestamp) asnow) time107 (SELECT EXTRACT(epoch FROM current_timestamp) AS now) time 111 108 WHERE t.status != 'closed' 112 109 -- AND time.now - t.time > 86400.0 * 30 * 2 113 -- well, the above was not really needed as they are all older than 1 year...110 -- well, the above was not needed as they are all older than 1 year 114 111 AND tc.author_cnt >= 10 115 112 AND p.name = t.priority AND p.type = 'priority' 116 113 ORDER BY 117 114 ( (tc.author_cnt + tc.change_cnt * 0.5 + LENGTH(t.cc) * 1.5) 118 / ((time.now * 1000000 - changetime) / 1000000.0) ) desc,115 / ((time.now * 1000000 - changetime) / 1000000.0) ) DESC, 119 116 p.value, t.severity, time 120 117 121 118 }}} 122 119 123 124 === Popular tickets - done === 125 126 In order to balance report {32} (tickets that are on the TODO list for a long time), we can also show that we managed to implement popular feature requests over time ;-) 120 === Popular tickets - done 121 122 In order to balance report {32} (tickets that are on the TODO list for a long time), we can also show that we managed to implement popular feature requests over time. 127 123 128 124 The criteria for inclusion for the feature request or bug report is that '''at least 10 different people participated to the ticket activity'''. … … 141 137 ) AS ct 142 138 ) AS Popularity, 143 --144 -- ROUND(((tc.author_cnt + tc.change_cnt * 0.5 + LENGTH(COALESCE(t.cc, '')) * 1.5)145 -- / ((time.now - t.time)/(86400.0 * 30))) * 10.0) / 10.0 AS Popularity,146 --147 139 t.type, 148 140 id AS ticket, summary, component, 149 141 milestone, version, 150 time ascreated142 time AS created 151 143 FROM ticket t LEFT JOIN 152 (SELECT ticket, count(distinct author) as author_cnt, 153 count(*) as change_cnt 144 (SELECT ticket, COUNT(DISTINCT author) AS author_cnt, COUNT(*) AS change_cnt 154 145 FROM ticket_change 155 146 WHERE field = 'comment' GROUP BY ticket) tc ON (t.id = tc.ticket), 156 147 enum p, 157 (SELECT extract(epoch from current_timestamp) asnow) time148 (SELECT EXTRACT(epoch FROM current_timestamp) AS now) time 158 149 WHERE t.status = 'closed' AND t.resolution = 'fixed' 159 150 -- AND time.now - t.time > 86400.0 * 30 * 2 160 -- well, the above was not really needed as they are all older than 1 year...151 -- well, the above was not needed as they are all older than 1 year 161 152 AND tc.author_cnt >= 10 162 153 AND p.name = t.priority AND p.type = 'priority' 163 154 ORDER BY 164 155 ( (tc.author_cnt + tc.change_cnt * 0.5 + LENGTH(COALESCE(t.cc, '')) * 1.5) 165 / ((time.now * 1000000 - changetime) / 1000000.0) ) desc,156 / ((time.now * 1000000 - changetime) / 1000000.0) ) DESC, 166 157 p.value, t.severity, time 167 158 }}} 168 159 169 160 170 === Popular Voted Tickets ===171 172 Tickets ordered by number of votes (> 1).161 === Popular Voted Tickets 162 163 Tickets ordered by number of votes, where there are at least 2 votes. 173 164 174 165 This is report {34} on this site. 175 166 {{{#!sql 176 167 SELECT p.value AS __color__, 177 t.type AS type, id AS ticket, sum(v.vote) as votes, summary, component, version, 178 milestone, 168 t.type AS type, id AS ticket, SUM(v.vote) AS votes, summary, component, version, milestone, 179 169 time AS created, 180 170 changetime AS _changetime, description AS _description, … … 184 174 AND p.name = t.priority AND p.type = 'priority' 185 175 AND v.resource = 'ticket/' || id 186 GROUP BY id, summary, component, version, milestone, t.type, owner, 187 time, 176 GROUP BY id, summary, component, version, milestone, t.type, owner, time, 188 177 changetime, description, reporter, p.value, status 189 HAVING sum(v.vote) > 1 190 ORDER BY votes DESC, milestone, t.type, time 191 }}} 192 178 HAVING SUM(v.vote) > 1 179 ORDER BY votes DESC, milestone, t.type, time 180 }}} 193 181 194 182 === Overview for next Milestones === … … 201 189 name AS id, 'milestone' AS _realm, 202 190 (SELECT count(*) FROM ticket 203 WHERE milestone =m.name AND type='enhancement' AND status != 'closed') as Enhancements,191 WHERE milestone = m.name AND type = 'enhancement' AND status != 'closed') as Enhancements, 204 192 (SELECT count(*) FROM ticket 205 WHERE milestone =m.name AND type='defect' AND status != 'closed') as Defects,193 WHERE milestone = m.name AND type = 'defect' AND status != 'closed') as Defects, 206 194 (SELECT count(*) FROM ticket 207 WHERE milestone =m.name AND type='task' AND status != 'closed') as Tasks195 WHERE milestone = m.name AND type = 'task' AND status != 'closed') as Tasks 208 196 FROM milestone AS m 209 197 WHERE completed = 0 … … 211 199 }}} 212 200 213 214 == Non Ticket Reports == 215 216 SQL reports do not have to be limited to tickets. They can report on revisions, wiki pages, or user activity. 217 218 === User Changesets === 219 220 The follow report will lists all of the changes for the current user, or add "?USER=''user''" to the end of the URL to report on another user. 221 {{{ 222 #!sql 223 SELECT 224 'changeset' AS _realm, rev as id, 201 == Non Ticket Reports 202 203 SQL reports do not have to be limited to tickets. They can report on revisions, wiki pages, or user activity. 204 205 === User Changesets 206 207 The follow report will lists all of the changes for the current user, or add "?USER = ''user''" to the end of the URL to report on another user: 208 {{{#!sql 209 SELECT 210 'changeset' AS _realm, rev AS id, 225 211 time AS date, time, 226 SUBSTR(message, 1, 80 )AS message212 SUBSTR(message, 1, 80) AS message 227 213 FROM revision 228 214 WHERE author='$USER' 229 215 ORDER BY time DESC 230 216 }}} 231 This report only gives the first 80 characters of the check-in message. To give the full message, make the following change: 232 {{{ 233 #!diff217 218 This report only gives the first 80 characters of the check-in message. To give the full message, make the following change: 219 {{{#!diff 234 220 --- Report.sql 235 221 +++ Report.sql … … 238 224 'changeset' AS _realm, rev as id, 239 225 time AS date, time, 240 - SUBSTR(message, 1, 80 )AS message226 - SUBSTR(message, 1, 80) AS message 241 227 + message AS _message_ 242 228 FROM revision … … 245 231 }}} 246 232 247 248 === Wiki Changes === 249 250 This reports the wiki pages ever modified by the current user, or add "?USER=''user''" to the end of the URL to report on another user. Version is the highest version that the user modified. 251 {{{ 252 #!sql 233 === Wiki Changes 234 235 This reports the wiki pages ever modified by the current user, or add "?USER = ''user''" to the end of the URL to report on another user. Version is the highest version that the user modified: 236 {{{#!sql 253 237 SELECT 254 238 'wiki' AS _realm, 255 239 name AS id, 256 max(version) AS Version,240 MAX(version) AS Version, 257 241 time AS date, time, 258 242 comment 259 243 FROM wiki 260 WHERE author ='$USER'244 WHERE author = '$USER' 261 245 GROUP BY name 262 246 }}} 247 263 248 For wiki pages that were last modified by the current user: 264 {{{ 265 #!sql 249 {{{#!sql 266 250 SELECT 267 251 'wiki' AS _realm, … … 270 254 comment 271 255 FROM wiki, 272 (SELECT max(version) AS maxVer, name256 (SELECT MAX(version) AS maxVer, name 273 257 FROM wiki 274 258 GROUP BY name) maxResults