def TicketDealOneMonth(conn, year, month): xxutils.sp_debug("Processing month : " + year + "-" + month) all_tickets = GetTicketStatByMonth(conn, year, month) all_comments = GetCommentStatByMonth(conn, year, month) all_tickets = GetAllCommentsInMonth(conn, year, month, all_tickets) # 将所有comments添加到相应的ticket中。 title = year + "年" + month + "月 Ticket统计" header = "<html>\n\ \t<head>\n\ \t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n\ \t\t<title>" + title + "</title>\n\ \t\t<style>\n\ \t\t tr { background-color: #DDDDDD}\n\ \t\t .initial { background-color: #DDDDDD; color:#000000 }\n\ \t\t .normal { background-color: #DDDDDD }\n\ \t\t .highlight { background-color: #8888FF }\n\ \t\t</style>\n\ \t</head>\n\ \t<body>\n" header += "\t\t<h1 id=\"top\">" + title + "</h1>\n" output = "" index = "" no_sort_ticket = {} no_sort_ticket_count_other = {} no_sort_reply_in_my_ticket = {} # 回复自己的帖子 no_sort_warmhearted_reply = {} # 热心回复 # 分别遍历所有ticket和所有comment从而形成一个用户列表。 users_list = [] users_list = GetAllUsersInTrac(all_tickets) # 打印debug信息:列出所有开发人员。 xxutils.sp_debug("Active developer in this month : " + str(users_list)) # 统计每个开发者的帖子/回复的个数/字数。 for user in users_list : # new ticket for myself count = 0 # count of ticket words = 0 times = 0 # change times of ticket, include one description and many comments. # new ticket (type is task only) for other, means you are his leader. count_other = 0 words_other = 0 times_other = 0 # 计算发帖个数和字数,包括。 for ticket_id, item in all_tickets.iteritems() : # 自己的帖子 if item["owner"] == user : # 自己开贴。 if item["reporter"] == user : count += 1 words += item["words"] # 别人开贴。 #else : # 别人的帖子,自己开贴。 if item["owner"] != user and item["reporter"] == user : words += item["words"] # 只计算给别人发的task贴。 # task in glue trac named "1_task" and "2_task". if item["type"] == "task" or item["type"] == "1_task" or item["type"] == "2_task" : count_other += 1 # 计算发回复的个数和字数。 for ticket_id, item in all_comments.iteritems() : if item["author"] != user : continue # 回复owner是自己的帖子。 if item["owner"] == user : words += item["words"] # 回复owner不是自己的帖子,属于热心回复。 else : words_other += item["words"] no_sort_ticket[user] = count no_sort_ticket_count_other[user] = count_other for user in users_list : xxutils.sp_debug("Processing developer : " + user) no_sort_warmhearted_reply[user] = 0 no_sort_reply_in_my_ticket[user] = 0 wikitext = "" output += "<h2><span id=" + user + "><font color=red> " + user + "</font></span></h2>\n" # Show details ticket list, these tickets are mine. output += "<h3><span id=\"" + user + "-create4myself\">我的帖子</span></h3>\n" output += "<table width='100%' border=1><tr><th width=\"5%\">Ticket</th><th width=\"30%\">Summary</th><th width=\"5%\">Reporter</th><th width=\"5%\">Owner</th><th>我的回复</th><th width=\"10%\">我的回复总字数</th></tr>\n" wikitext += "=== 我的帖子 ===\n" for ticket_id, ticket in all_tickets.iteritems() : # 略过其他人的帖子。 if ticket["owner"] != user : continue # 统计该用户所有回复。 coment_id_list = "" # 保存该用户在该ticket中所有comment id,"1,3,4" comments_word_count = 0 for comment_id, comment in ticket["comment"].iteritems() : # 略过别人的回复。 if comment["author"] != user : continue comment_word_count = xxutils.ticket_wc(comment["content"]) comments_word_count += comment_word_count coment_id_list += xxutils.createCommentLink( config.TRAC_URL, ticket_id, # URL帖子号部分 comment_id, # URL的comment号部分。 comment_id + "楼(" + str(comment_word_count) + "字)" # 链接名称 ) coment_id_list += ", " output += "<tr onmouseover=\"this.className='highlight'\" onmouseout=\"this.className='normal'\">\n" output += "<td>" + xxutils.createTicketLink(config.TRAC_URL, ticket_id, "#"+ticket_id) + "</td>\n" output += "<td>" + xxutils.createTicketLink(config.TRAC_URL, ticket_id, ticket["name"]) + "</td>\n" output += "<td>" + ticket["reporter"] + "</td>\n" output += "<td>" + ticket["owner"] + "</td>\n" output += "<td>" + coment_id_list + "</td>\n" output += "<td>" + str(comments_word_count) + "</td>\n" output += "</tr>\n" wikitext += "|| #" + ticket_id + " || " + '[#' + ticket_id + ' "' + ticket["name"] + '"] ||' + "\n" # 计算用户在自己帖子中的回复字数。 no_sort_reply_in_my_ticket[user] += comments_word_count output += "</table>\n" # Show details ticket list, these tickets are created by myself, and for others. # And the ticket type must be "task", means you are his leader. xxutils.sp_debug("Create table: 为别人创建任务贴") output += "<h3><span id=\"" + user + "-create4others\">为别人创建任务贴</span></h3>\n" output += "<table width='100%' border=1>\n<tr>\n<th width=\"5%\">Ticket</th><th>Summary</th><th width=\"5%\">Reporter</th><th width=\"5%\">Owner</th><th width=\"10%\">Description字数</th>\n</tr>\n" wikitext += "=== 为别人创建任务贴 ===\n" for ticket_id, ticket in all_tickets.iteritems() : if ticket["reporter"] == user and ticket["owner"] != user : if ticket["type"] != "task" : continue words_of_summary_and_description = xxutils.ticket_wc(ticket["name"] + config.EOL + ticket["description"]) output += "<tr onmouseover=\"this.className='highlight'\" onmouseout=\"this.className='normal'\">\n" output += "<td>" + xxutils.createTicketLink(config.TRAC_URL, ticket_id, "#"+ticket_id) + "</td>\n" output += "<td>" + xxutils.createTicketLink(config.TRAC_URL, ticket_id, ticket["name"]) + "</td>\n" output += "<td>" + str(ticket["reporter"]) + "</td>\n" output += "<td>" + str(ticket["owner"]) + "</td>\n" output += "<td>" + str(words_of_summary_and_description) + "</td>\n" output += "</tr>\n" wikitext += "|| #" + ticket_id + " || " + '[#' + ticket_id + ' "' + ticket["name"] + '"] ||' + "\n" output += "</table>\n" output += "<h3>热心回复</h3>\n" wikitext += "=== 热心回复 ===\n" output += "<table width='100%' border=1><tr><th width=\"5%\">Ticket</th><th width=\"30%\">Summary</th><th width=\"5%\">Reporter</th><th width=\"5%\">Owner</th><th>我的回复</th><th width=\"10%\">我的回复总字数</th></tr>\n " for ticket_id, ticket in all_tickets.iteritems() : # 略过自己的帖子。 if ticket["owner"] == user : continue #xxutils.sp_debug("Processing ticket : " + ticket_id)##大大的拖慢运行时间,调试需谨慎。 found_user = False # 记录用户是否在这个帖子中回复了 coment_id_list = "" # 保存该用户在该ticket中所有comment id,"1,3,4" comments_word_count = 0 for comment_id, comment in ticket["comment"].iteritems() : # 略过别人的回复。 if comment["author"] != user : continue comment_word_count = xxutils.ticket_wc(comment["content"]) comments_word_count += comment_word_count coment_id_list += xxutils.createCommentLink( config.TRAC_URL, ticket_id, # URL帖子号部分 comment_id, # URL的comment号部分。 comment_id + "楼(" + str(comment_word_count) + "字)" # 链接名称 ) coment_id_list += ", " found_user = True # 用户没有在这个帖子中回复过。 if found_user == False : continue # 构建该ticket的行。 output += "<tr onmouseover=\"this.className='highlight'\" onmouseout=\"this.className='normal'\">\n" output += "<td>" + xxutils.createTicketLink(config.TRAC_URL, ticket_id, "#"+ticket_id) + "</td>\n" output += "<td>" + xxutils.createTicketLink(config.TRAC_URL, ticket_id, ticket["name"]) + "</td>\n" output += "<td>" + str(ticket["reporter"]) + "</td>\n" output += "<td>" + str(ticket["owner"]) + "</td>\n" output += "<td width="">" + coment_id_list + "</td>\n" output += "<td>" + str(comments_word_count) + "</td>\n" output += "</tr>\n" wikitext += "|| #" + ticket_id + " || " + '[#' + ticket_id + ' "' + ticket["name"] + '"] ||' + "\n" # 计算该用户在这个帖子中所有回复的总字数。 no_sort_warmhearted_reply[user] += comments_word_count output += "</table>" wikitext += "=== 统计信息 ===\n" wikitext += "|| 为自己开贴数 || 为別人开任务贴数 || 自行发回贴字数 || 热心回复字数 ||\n" wikitext += "|| " + str(no_sort_ticket[user]) + " || " + str(no_sort_ticket_count_other[user]) + " || " + str(no_sort_reply_in_my_ticket[user]) + " || " + str(no_sort_warmhearted_reply[user]) + " ||\n" output += "<h3>复制如下内容,替换自评贴中的“{Ticket内容列表}”</h3>\n" output += "<textarea cols=100 rows=10>" + wikitext + "</textarea>\n" output += "<div align=\"right\"><a href=\"#top\">返回顶部</a></div>\n" output += "<hr>\n" output += "</body></html>" # Sort all people in one month, the better the upper. sort_ticket = xxutils.asort( no_sort_ticket ) sort_ticket_count_other = xxutils.asort( no_sort_ticket_count_other ) sort_reply_in_my_ticket = xxutils.asort( no_sort_reply_in_my_ticket ) sort_warmhearted_reply = xxutils.asort( no_sort_warmhearted_reply ) config.REPLY_MY_TICKET[str(year+month)] = sort_reply_in_my_ticket config.REPLY_OTHER_TICKET[str(year+month)] = sort_warmhearted_reply current = year + month + ".html" index += "<table width=100% border=0><tr><td><table border=1>\n" index += "<tr><th>姓名</th><th>为自己开贴数</th></tr>\n" for user, words in sort_ticket : index += "<tr><td><a href='" + current + "#" + user + "-create4myself'> " + user + "</a> </td><td> " + str(words) + "</tr>\n" index += "</table></td><td>\n<table border=1>\n" index += "<tr><th>姓名</th><th>为别人开任务贴数</th></tr>\n" for user, words in sort_ticket_count_other : index += "<tr><td><a href='" + current + "#" + user + "-create4others'> " + user + "</a> </td><td> " + str(words) + "</tr>\n" index += "</table></td><td>\n<table border=1>" index += "<tr><th>姓名</th><th>自行发贴字数</th></tr>\n" for user, words in sort_reply_in_my_ticket : index += "<tr><td><a href='" + current + "#" + user + "'> " + user + "</a> </td><td> " + str(words) + "</tr>\n" index += "</table></td><td>\n<table border=1>\n" index += "<tr><th>姓名</th><th>热心回复字数</th></tr>\n" for user, words in sort_warmhearted_reply : index += "<tr><td><a href='" + current + "#" + user + "'> " + user + "</a> </td><td> " + str(words) + "</tr>\n" index += "</table></td></tr></table>" pathname = config.TRAC_OUTPUT_PATH + "/ticket" + "/" + year + month + ".html" f = open(pathname, 'w') f.write(header + index + output) f.close() return index
def WikiWritePage(conn, year, month) : wiki = GetWikiStatByMonth(conn, year, month) title = year + "年" + month + "月 Wiki统计" index = "" output = "" header = "<html>\n" header += "\t<head>\n" header += "\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" header += "\t\t<title>" + title + "</title>\n\t</head>\n\t<body>\n<h1>" + title + "</h1>\n" not_sort = {} for user, items in wiki.iteritems() : # 当月的总的wiki字数 words = 0 wikitext = "" # show this in <texteare> output += "<h2><span id=" + user + "><font color=red>" + user + "</font></span></h2>\n" output += "<h3>创建</h3>\n" output += "<table width='100%' border=1>\n<tr><td>标题</td><td>修改记录</td><td>操作次数</td><td>字数统计</td></tr>\n" wikitext += "=== 本月创建Wiki列表\n" for name, item in items.iteritems() : if item["create"] == 1 : output += "<tr>\n" output += "<td><a target=_blank href='" + config.TRAC_WIKI_URL + "/" + name + "'>" + name + "</a></td>\n"#xxdebug output += "<td>\n" versions = str(item["versions"]).split(";") for version in versions : version = int(version) if version != 1 : output += " <a target=_blank href='" + config.TRAC_WIKI_URL + "/" + name + "?action=diff&version=" + str(version) + "&old_version=" + str(version - 1) + "'>V" + str(version) + "</a>"#xxdebug output += "</td>\n" output += "<td>" + str(item["times"]) + "</td>\n" output += "<td>" + str(item["words"]) + "</td>\n" output += "</tr>\n" words += item["words"] wikitext += "|| wiki:" + name + " ||\n" output += "</table>\n" output += "<h3>修改</h3>\n" output += "<table width='100%' border=1><tr><td>标题</td><td>修改记录</td><td>操作次数</td><td>字数统计</td></tr>\n " wikitext += "=== 本月修改Wiki列表\n" for name, item in items.iteritems() : if item["create"] == 0 : output += "<tr><td><a target=_blank href='" + config.TRAC_WIKI_URL + "/" + name + "'>" + name + "</a></td><td>"#xxdebug versions = str(item["versions"]).split(";") for version in versions : version = int(version) if version != 1 : output += " <a target=_blank href='" + config.TRAC_WIKI_URL + "/" + name + "?action=diff&version=" + str(version) + "&old_version=" + str(version - 1) + "'>V" + str(version) + "</a>"#xxdebug output += "</td>\n<td>" + str(item["times"]) + "</td>\n<td>" output += str(item["words"]) + "</td>\n</tr>\n" words += item["words"] wikitext += "|| wiki:" + name + " ||\n" output += "</table>\n" output += "<h3>字数统计:" + str(words) + "</h3>\n" wikitext += "=== 统计信息\n" wikitext += "|| 字数统计 ||\n" + "|| " + str(words) + " ||\n" # Copy this to your ticket. output += "<h3>复制如下内容,替换自评贴中的“{Wiki内容列表}”</h3>\n<textarea cols=100 rows=10>\n" + wikitext + "\n</textarea>\n<br><br><hr>" not_sort[ user ] = words output += "</body></html>" sort = xxutils.asort( not_sort ) current = year + month + ".html" index += "<table width=30% border=1>\n" index += "<tr><td>姓名</td><td>字数</tr>\n" for user, word in sort : index += "<tr><td><a href='" + current + "#" + user + "'> " + user + "</a> </td><td> " + str(word) + "</tr>\n" index += "</table>" pathname = config.TRAC_OUTPUT_PATH + "/code/" + year + month + ".html"#xxdebug f = open(pathname, 'w') f.write(header + index + output) f.close() return index
def WikiWritePage(conn, year, month) : wiki = GetWikiStatByMonth(conn, year, month) title = year + "年" + month + "月 Wiki统计" index = "" output = "" header = "<html>\n" header += "\t<head>\n" header += "\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" header += "\t\t<title>" + title + "</title>\n\t</head>\n\t<body>\n<h1>" + title + "</h1>\n" not_sort = {} for user, items in wiki.iteritems() : # 当月的总的wiki字数 words = 0 wikitext = "" # show this in <texteare> output += "<h2><span id=" + user + "><font color=red>" + user + "</font></span></h2>\n" output += "<h3>创建</h3>\n" output += "<table width='100%' border=1>\n<tr><td>标题</td><td>修改记录</td><td>操作次数</td><td>字数统计</td></tr>\n" wikitext += "=== 本月创建Wiki列表\n" for name, item in items.iteritems() : if item["create"] == 1 : output += "<tr>\n" output += "<td><a target=_blank href='" + config.TRAC_URL + "/wiki/" + name + "'>" + name + "</a></td>\n" output += "<td>\n" versions = str(item["versions"]).split(";") for version in versions : version = int(version) if version != 1 : output += " <a target=_blank href='" + config.TRAC_URL + "/wiki/" + name + "?action=diff&version=" + str(version) + "&old_version=" + str(version - 1) + "'>V" + str(version) + "</a>" output += "</td>\n" output += "<td>" + str(item["times"]) + "</td>\n" output += "<td>" + str(item["words"]) + "</td>\n" output += "</tr>\n" words += item["words"] wikitext += "|| wiki:" + name + " ||\n" output += "</table>\n" output += "<h3>修改</h3>\n" output += "<table width='100%' border=1><tr><td>标题</td><td>修改记录</td><td>操作次数</td><td>字数统计</td></tr>\n " wikitext += "=== 本月修改Wiki列表\n" for name, item in items.iteritems() : if item["create"] == 0 : output += "<tr><td><a target=_blank href='" + config.TRAC_URL + "/wiki/" + name + "'>" + name + "</a></td><td>" versions = str(item["versions"]).split(";") for version in versions : version = int(version) if version != 1 : output += " <a target=_blank href='" + config.TRAC_URL + "/wiki/" + name + "?action=diff&version=" + str(version) + "&old_version=" + str(version - 1) + "'>V" + str(version) + "</a>" output += "</td>\n<td>" + str(item["times"]) + "</td>\n<td>" output += str(item["words"]) + "</td>\n</tr>\n" words += item["words"] wikitext += "|| wiki:" + name + " ||\n" output += "</table>\n" output += "<h3>字数统计:" + str(words) + "</h3>\n" wikitext += "=== 统计信息\n" wikitext += "|| 字数统计 ||\n" + "|| " + str(words) + " ||\n" # Copy this to your ticket. output += "<h3>复制如下内容,替换自评贴中的“{Wiki内容列表}”</h3>\n<textarea cols=100 rows=10>\n" + wikitext + "\n</textarea>\n<br><br><hr>" not_sort[ user ] = words output += "</body></html>" sort = xxutils.asort( not_sort ) current = year + month + ".html" index += '''<script type="text/javascript" src="http://ajax.googleapis.com/ajax/static/modules/gviz/1.0/chart.js"> { "dataSourceUrl":"http://docs.google.com/a/masols.com/spreadsheet/tq?key=0AqwnDQvWEnMgdFlxUXo3VVU4YmRJR0NDSTZMWmZPWVE&transpose=1&headers=1&range=A1%3AE18&gid=0&pub=1", "options":{ "vAxes":[{ "title":"\u5b57\u6570", "minValue":null, "viewWindowMode":"pretty", "viewWindow":{"min":null,"max":null}, "maxValue":null },{ "viewWindowMode":"pretty", "viewWindow":{} }], "reverseCategories":false, "title":"Wiki\u5b57\u6570\u8d8b\u52bf\u56fe", "interpolateNulls":false, "pointSize":"7", "backgroundColor":"#FFFFFF", "legend":"right", "lineWidth":2, "logScale":false, "hAxis":{ "maxAlternations":1 }, "hasLabelsColumn":true, "reverseAxis":false, "width":600, "height":525 }, "state":{}, "view":"{\"columns\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]}", "chartType":"LineChart", "chartName":"Chart 1" } </script>''' index += "<table width=30% border=1>\n" index += "<tr><td>姓名</td><td>字数</tr>\n" for user, word in sort : index += "<tr><td><a href='" + current + "#" + user + "'> " + user + "</a> </td><td> " + str(word) + "</tr>\n" index += "</table>" pathname = config.TRAC_OUTPUT_PATH + "/wiki" + "/" + year + month + ".html" f = open(pathname, 'w') f.write(header + index + output) f.close() return index