def do_chart21(self, tickets, tstatus): """Compute pie charts for ticket types, ticket severity and ticket status, project wise, chart21_data, { projectname : [ [ [ type1, count ], [ type2, count ] .... ], [ [ severity1, count ], [ severity2, count ] .... ], [ [ status1, count ], [ status2, count ] .... ], ], ... }""" data = {} for t in tickets: ts = tstatus.get(t.tsh_id) data.setdefault(t.project.id, []).append([ t.type.tck_typename, t.severity.tck_severityname, ts.status.tck_statusname ]) chart21_data = {} for p, vals in data.iteritems(): chart21_data[p] = [ sorted(list(h.computecount(vals, lambda x: x[0]).items()), key=lambda x: x[0]), sorted(list(h.computecount(vals, lambda x: x[1]).items()), key=lambda x: x[0]), sorted(list(h.computecount(vals, lambda x: x[2]).items()), key=lambda x: x[0]) ] return chart21_data
def do_chart19(self, wikis): """Compute wiki commentors, projectwise chart19_data, { project.id : [ [ wikipath, [ [commentor, count], ... ] ] ... ], ... } """ from zeta.lib.base import BaseController wdets = [] allcmtrs = {} cntlr = BaseController() for w in wikis: cmtrs = h.computecount(w.comments, lambda x: x.commentby.username) allcmtrs.setdefault(w.project.id, []).extend(cmtrs.keys()) wdets.append([w.project.id, h.wiki_parseurl(w.wikiurl), cmtrs]) allcmtrs = dict([(p, sorted(set(allcmtrs[p]))) for p in allcmtrs]) for w in wdets: pid = w[0] cmtrs = w[2] w[2] = [[u, cmtrs.get(u, 0)] for u in allcmtrs[pid]] chart19_usrs = dict([(pid, [[u, cntlr.url_user(u)] for u in users]) for pid, users in allcmtrs.iteritems()]) chart19_data = {} [chart19_data.setdefault(w[0], []).append(w[1:]) for w in wdets] return chart19_data, chart19_usrs
def do_chart18(self, wikicomp, wikis): """Compute wiki authors, projectwise chart18_data, { project.id : [ [ wikipath, [ [author, edits], ... ] ] ... ], ... } """ from zeta.lib.base import BaseController wdets = [] allauthors = {} cntlr = BaseController() for w in wikis: wcnts = wikicomp.get_content(w, all=True) authors = h.computecount(wcnts, lambda x: x.author) allauthors.setdefault(w.project.id, []).extend(authors.keys()) wdets.append([w.project.id, h.wiki_parseurl(w.wikiurl), authors]) allauthors = dict([(p, sorted(set(allauthors[p]))) for p in allauthors]) for w in wdets: pid = w[0] authors = w[2] w[2] = [[u, authors.get(u, 0)] for u in allauthors[pid]] chart18_usrs = dict([(pid, [[u, cntlr.url_user(u)] for u in users]) for pid, users in allauthors.iteritems()]) chart18_data = {} [chart18_data.setdefault(w[0], []).append(w[1:]) for w in wdets] return chart18_data, chart18_usrs
def do_chart26(self, tickets): """Compute wiki commentors, projectwise chart26_data, { project.id : [ [ t.id, [ [commentor, count], ... ] ] ... ], ... } """ from zeta.lib.base import BaseController tdets = [] allcmtrs = {} cntlr = BaseController() for t in tickets: cmtrs = h.computecount(t.comments, lambda x: x.commentby.username) allcmtrs.setdefault(t.project.id, []).extend(cmtrs.keys()) tdets.append([t.project.id, t.id, cmtrs]) allcmtrs = dict([(p, sorted(set(allcmtrs[p]))) for p in allcmtrs]) for t in tdets: pid = t[0] cmtrs = t[2] t[2] = [[u, cmtrs.get(u, 0)] for u in allcmtrs[pid]] chart26_usrs = dict([(pid, [[u, cntlr.url_user(u)] for u in users]) for pid, users in allcmtrs.iteritems()]) chart26_data = {} [chart26_data.setdefault(t[0], []).append(t[1:]) for t in tdets] return chart26_data, chart26_usrs
def do_chart2(self, attcomp, attachs): """Compute chart relating files and its uploaders chart2_data, [ [ username, totalfiles, totalpayload ], ... ] chart2_fcnt Integer - no. of attachments chart2_payld Integet - Total payload """ filelen = lambda a: a and len(attcomp.content(a)) or 0 userfiles = [] userpayld = {} chart2_payld = 0 for a in attachs: uploader = a.uploader.username userfiles.append(uploader) userpayld.setdefault(uploader, []).append(filelen(a)) chart2_payld += filelen(a) userfiles = h.computecount(userfiles, lambda x: x) chart2_data = sorted( [[u, userfiles.get(u, 0), sum(userpayld.get(u, []))] for u in userfiles], key=lambda x: x[0]) chart2_fcnt = len(attachs) return chart2_data, chart2_fcnt, chart2_payld
def do_chart27(self, reviews): """Compute wiki commentors, projectwise chart26_data, { project.id : [ [ [author1, count], ... ], [ [moderator1, count], ... ], [ [participant1, count], ... ], ], ... } """ from zeta.lib.base import BaseController data = {} usrs = {} cntlr = BaseController() for r in reviews: data.setdefault(r.project.id, {}).setdefault('author', []).append(r.author.username) data.setdefault(r.project.id, {}).setdefault('moderator', []).append(r.moderator.username) data.setdefault(r.project.id, {}).setdefault('participant', []).extend( [partc.username for partc in r.participants]) usrs.setdefault(r.project.id, []).append(r.author.username) usrs.setdefault(r.project.id, []).append(r.moderator.username) usrs.setdefault(r.project.id, []).extend( [partc.username for partc in r.participants]) chart27_data = {} [ chart27_data.setdefault(p, [ sorted(h.computecount(data[p]['author'], lambda x: x).items(), key=lambda x: x[0]), sorted(h.computecount(data[p]['moderator'], lambda x: x).items(), key=lambda x: x[0]), sorted(h.computecount(data[p]['participant'], lambda x: x).items(), key=lambda x: x[0]), ]) for p in data ] chart27_usrs = dict([(p, [[u, cntlr.url_user(u)] for u in set(vals)]) for p, vals in usrs.iteritems()]) return chart27_data, chart27_usrs
def do_chart22(self, tickets): """Compute pie charts for project user's ticket types, ticket severity and ticket status chart22_data, { projectname : [ [ username, [ [ type1, count ], [ type2, count ] .... ], [ [ severity1, count ], [ severity2, count ] .... ], [ [ status1, count ], [ status2, count ] .... ], ], ... ], ... }""" from zeta.lib.base import BaseController data = {} cntlr = BaseController() for t in tickets: ts = t.statushistory[-1] data.setdefault(t.project.id, {}).setdefault(ts.owner.username, []).append([ t.type.tck_typename, t.severity.tck_severityname, ts.status.tck_statusname ]) chart22_data = {} for p, udict in data.iteritems(): chart22_data[p] = [] for u, vals in udict.iteritems(): chart22_data[p].append([ u, sorted(list(h.computecount(vals, lambda x: x[0]).items()), key=lambda x: x[0]), sorted(list(h.computecount(vals, lambda x: x[1]).items()), key=lambda x: x[0]), sorted(list(h.computecount(vals, lambda x: x[2]).items()), key=lambda x: x[0]) ]) chart22_usrs = dict([(p, [[u, cntlr.url_user(u)] for u in map(lambda x: x[0], vals)]) for p, vals in chart22_data.iteritems()]) return chart22_data, chart22_usrs
def do_chart25(self, tickets): """Compute pie charts for versions, ticket types, ticket severity and ticket status chart25_data, { projectname : [ [ version_name, [ [ type1, count ], [ type2, count ] .... ], [ [ severity1, count ], [ severity2, count ] .... ], [ [ status1, count ], [ status2, count ] .... ], ], ... ], ... }""" data = {} for t in tickets: ts = t.statushistory[-1] if not t.versions: continue data.setdefault(t.project.id, {}).setdefault(t.versions[0].version_name, []).append([ t.type.tck_typename, t.severity.tck_severityname, ts.status.tck_statusname ]) chart25_data = {} for p, vdict in data.iteritems(): chart25_data[p] = [] for ver, vals in vdict.iteritems(): chart25_data[p].append([ ver, sorted(h.computecount(vals, lambda x: x[0]).items(), key=lambda x: x[0]), sorted(h.computecount(vals, lambda x: x[1]).items(), key=lambda x: x[0]), sorted(h.computecount(vals, lambda x: x[2]).items(), key=lambda x: x[0]) ]) return chart25_data
def do_chart24(self, tickets): """Compute pie charts for milestones, ticket types, ticket severity and ticket status chart24_data, { projectname : [ [ milestone_name, [ [ type1, count ], [ type2, count ] .... ], [ [ severity1, count ], [ severity2, count ] .... ], [ [ status1, count ], [ status2, count ] .... ], ], ... ], ... }""" data = {} for t in tickets: if not t.milestones: continue ts = t.statushistory[-1] data.setdefault(t.project.id, {}).setdefault(t.milestones[0].milestone_name, []).append([ t.type.tck_typename, t.severity.tck_severityname, ts.status.tck_statusname ]) chart24_data = {} for p, mdict in data.iteritems(): chart24_data[p] = [] for mstn, vals in mdict.iteritems(): chart24_data[p].append([ mstn, sorted(list(h.computecount(vals, lambda x: x[0]).items()), key=lambda x: x[0]), sorted(list(h.computecount(vals, lambda x: x[1]).items()), key=lambda x: x[0]), sorted(list(h.computecount(vals, lambda x: x[2]).items()), key=lambda x: x[0]) ]) return chart24_data
def do_chart1(self, tags): """Compute data for chart1 chart1_data, { tagname : [ [ 'attachments', count ], [ 'licenses', count ], ], ... } chart1_rtags, { tagname : [ [ reltagname, percent-related ], ...., ], ... } """ attrs = [ 'attachments', 'licenses', 'projects', 'tickets', 'reviews', 'wikipages' ] chart1_data = dict([(tag.tagname, [[attr, len(getattr(tag, attr, []))] for attr in attrs]) for tag in tags]) chart1_rtags = {} for tag in tags: reltags = [] [reltags.extend(i.tags) for a in attrs for i in getattr(tag, a)] dtags = h.computecount(reltags, lambda x: x.tagname) vals = dtags.values() maxt = float(vals and max(vals) or 1) perct = sorted([[tagname, int((count / maxt) * 100)] for tagname, count in dtags.iteritems() if tagname != tag.tagname], key=lambda x: x[0]) chart1_rtags.setdefault(tag.tagname, perct) return chart1_data, chart1_rtags
def do_chart12(self, users): """Computer user activity across functions, chart12_data, { user.id : [ user.id, user.username, [ [ 'fnname', count ], ... ] ], ... }""" chart12_data = {} for u in users: byfn = [] byprj = [] for l in u.logs: if getattr(l, 'ticket', None): byfn.append('ticket') byprj.append(l.ticket.project.projectname) elif getattr(l, 'review', None): byfn.append('review') byprj.append(l.review.project.projectname) elif getattr(l, 'vcs', None): byfn.append('vcs') byprj.append(l.vcs.project.projectname) elif getattr(l, 'wiki', None): byfn.append('wiki') byprj.append(l.wiki.project.projectname) elif getattr(l, 'project', None): byfn.append('project') byprj.append(l.project.projectname) else: byfn.append('others') chart12_data.setdefault(u.id, [ u.id, u.username, [[k, v] for k, v in h.computecount(byfn, lambda x: x).iteritems()] ]) return chart12_data
def wiki(self, environ, projectname, wurl=None): """Project wiki pages. URLS : /p/{projectname}/wiki/*(wurl) /p/{projectname}/wiki/*(wurl)?ver=<num> /p/{projectname}/wiki/*(wurl)?wikiedit=1 /p/{projectname}/wiki/*(wurl)?wikitalkpage=1 /p/{projectname}/wiki/*(wurl)?wikihistory=1 /p/{projectname}/wiki/*(wurl)?wikidiff=1 /p/{projectname}/wiki/*(wurl)?translate=1 /p/{projectname}/wiki/*(wurl)?downloadas=text /p/{projectname}/wiki/*(wurl)?downloadas=ps /p/{projectname}/wiki/*(wurl)?downloadas=pdf /p/{projectname}/wiki/*(wurl)?jsonobj=wikicomments&view=js /p/{projectname}/wiki/*(wurl)?jsonobj=wikircomments&view=js /p/{projectname}/wiki/*(wurl)?jsonobj=wikiattach&view=js /p/{projectname}/wiki/*(wurl)?jsonobj=wikitag&view=js /p/{projectname}/wiki/*(wurl)?textobj=wikipreview&view=text /p/{projectname}/wiki/*(wurl)?form=submit&formname=addwikiattachs&view=js /p/{projectname}/wiki/*(wurl)?form=submit&formname=delwikiattachs&view=js /p/{projectname}/wiki/*(wurl)?form=submit&formname=addwikitags&view=js /p/{projectname}/wiki/*(wurl)?form=submit&formname=delwikitags&view=js /p/{projectname}/wiki/*(wurl)?form=submit&formname=wikicont&view=js /p/{projectname}/wiki/*(wurl)?form=submit&formname=createwcmt&view=js /p/{projectname}/wiki/*(wurl)?form=submit&formname=updatewcmt&view=js /p/{projectname}/wiki/*(wurl)?form=submit&formname=replywcmt&view=js /p/{projectname}/wiki/*(wurl)?wikidiff=1&form=submit&formname=wikidiff /p/{projectname}/wiki/*(wurl)?form=submit&formname=wikifav&view=js /p/{projectname}/wiki/*(wurl)?form=submit&formname=votewiki&view=js """ from zeta.config.environment import projcomp, wikicomp, votcomp, vfcomp version = request.params.get('ver', None) wurl = wurl.rstrip('/') c.rclose = h.ZResp() # Handle forms def errhandler(errmsg): c.errmsg = errmsg if self.formpermission(): c.errmsg = 'Do not have %s permission !!' % tckperm[c.formname] else: vfcomp.process(request, c, defer=True, errhandler=h.hitchfn(errhandler), formnames=[ 'addwikiattachs', 'delwikiattachs', 'addwikitags', 'delwikitags', 'wikicont', 'createwcmt', 'updatewcmt', 'replywcmt', 'wikidiff', 'wikifav', 'votewiki' ], user=c.authuser) # Setup context for page generation c.projsummary = c.project.summary if not c.jsonobj: c.wikipagenames = self.wikipagename(wikicomp.wikiurls(c.project)) c.wikipagename = wurl c.wikieditable = h.authorized(h.HasPermname('WIKI_CREATE')) c.wiki = c.wiki or wikicomp.get_wiki(unicode(c.pathinfo)) # If there is no wiki page by that name then create the wiki and # show the edit page. if not c.wiki and c.wikieditable: c.wiki = wikicomp.create_wiki(unicode(c.pathinfo), wtype=c.sysentries.get( 'def_wikitype', None), creator=c.authusername) c.project and wikicomp.config_wiki(c.wiki, project=c.project) c.wikiedit = '1' elif not c.wiki: raise NotAuthorizedError( 'Do not have permission to create wiki page, WIKI_CREATE') # If the wiki page is empty (ie) no wiki content ever created, then # show the edit page. if not c.wiki.latest_version and c.wikieditable: h.flash(MESSAGE_FLASH + 'Empty page, write some text ...') c.wikiedit = '1' elif not c.wiki.latest_version: raise NotAuthorizedError( 'Do not have permission to create wiki page, WIKI_CREATE') if c.wiki: c.isuserfavorite = wikicomp.isfavorite(c.authuser.id, c.wiki.id) c.title = wurl # HTML page generation html = '' typename = c.wiki.type.wiki_typename if c.errmsg: html = self.returnerrmsg(environ) if c.view == 'js' and c.formname in ['addwikiattachs']: html = IFRAME_RET elif c.view == 'js' and c.jsonobj: html = self.handlejson(environ) elif c.view == 'text' and c.textobj: html = self.handletext(environ) elif typename == h.WIKITYPE_REDIRECT and c.wiki.sourceurl: # Page redirect h.redirect_url(c.wiki.sourceurl) elif c.wikiedit: c.wcnt = wikicomp.get_content(c.wiki) c.wikitypenames = wikicomp.typenames c.title += ':edit' html = render('/derived/projects/wiki.html') elif c.wtalkpage: c.items_wikicomments = self._json_wikicomments() c.title += ':talkpage' html = render('/derived/projects/wiki.html') elif c.whistory: c.wikicontents = wikicomp.get_content(c.wiki, all=True) c.title += ':history' html = render('/derived/projects/wiki.html') elif c.wikidiff: v = c.oldver or 1 c.wcnt_oldver = wikicomp.get_content(c.wiki, version=v) c.wcnt_newver = wikicomp.get_content(c.wiki, version=c.newver) c.oldver = c.wcnt_oldver.id c.newver = c.wcnt_newver.id c.title += ':diff' html = render('/derived/projects/wiki.html') elif c.downloadas: c.wcnt = wikicomp.get_content(c.wiki) wikihtml = c.wcnt.translate( wiki=c.wiki, cache=True) if not c.wcnt.texthtml else c.wcnt.texthtml fmtobj = h.Html2Doc(wikihtml, format=c.downloadas) c.title = '-Skip-' html = fmtobj.convert() response.headers['Content-disposition'] = \ str( 'attachment; filename="%s.%s"' % (c.wiki.wikiurl, c.downloadas) ) elif c.view != 'js': # Refetch the wiki entry from DB with prepared query c.attachs = self._wikiattachs(c.wiki) c.tags = self._wikitags(c.wiki) c.att_editable = c.tag_editable = c.wikieditable c.wcnts = wikicomp.get_content(c.wiki, all=True) c.wikiauthors = h.computecount(c.wcnts, lambda x: x.author) c.wcnt = (version and c.wcnts[int(version) - 1] or c.wcnts[-1]) if c.wcnts else None c.wikitypenames = wikicomp.typenames c.wikihtml = '' if c.wcnt: if not c.wcnt.texthtml: c.wikihtml = c.wcnt.translate(wiki=c.wiki, cache=True) elif c.translate: c.wikihtml = c.wcnt.translate(wiki=c.wiki, cache=True) else: c.wikihtml = c.wcnt.texthtml lastver = c.wiki.latest_version fn = lambda v: [ self.url_wikiurl(projectname, wurl, ver=str(v)), str(v) ] c.wversions = map(fn, range(1, lastver + 1)) c.wdownload = [ [h.url_wikidownastext, 'as text'], [h.url_wikidownasps, 'as post-script'], [h.url_wikidownaspdf, 'as pdf'], ] uservote = votcomp.get_wikivote(c.authuser, c.wiki) votes = wikicomp.countvotes(votes=c.wiki.votes) c.upvotes = votes.get('up', 0) c.downvotes = votes.get('down', 0) c.currvote = uservote and uservote.votedas or '' h.url_reviewwiki = self.url_wikireview(projectname, c.wiki.wikiurl, c.wcnt.id) html = render('/derived/projects/wiki.html') c.rclose.append(html) return c.rclose