def get_html(self, macroenv, req, content): def get_time(starttime, macroenv): ''' computes the computing time of the macro returned as HTML construct to be embeeded in HTML output ''' duration = (datetime.now() - starttime).microseconds / 1000 macroenv.tracenv.log.debug('macro computation time: %s ms: %s ' % (duration, macroenv.macrokw)) return (tag.span('It took %s ms to generate this visualization. ' % (duration, ), class_='ppstat')) #macroenv = PPEnv( env, req, content ) macrostart = datetime.now() if content == None: content = '' ts = ppFilter(macroenv).get_tickets() if macroenv.get_args('ppforcereload') == '1': noteForceReload = tag.span('The visualization was recreated.', class_='ppforcereloadinfo') else: noteForceReload = tag.span() renderer = ppRender(macroenv) # show text in the headline moretitle = '' macroenv.tracenv.log.debug( 'macroenv label=%s (%s)' % (macroenv.get_args('label'), macroenv.tracreq.args)) if macroenv.macrokw.get('label', None) != None: # use parameter: label moretitle = macroenv.macrokw.get('label', '') else: moretitle = renderer.getHeadline() # get the pre-defined headline return tag.div( tag.h5(tag.a(name=macroenv.macroid)('%s' % (moretitle, ))), renderer.render(ts), tag.div( tag.div( get_time(macrostart, macroenv), noteForceReload, tag.span( tag.a('Force recreation of the visualization.', href='?ppforcereload=1', class_='ppforcereload')))), style=macroenv.macrokw.get('style', '') # CSS style )
def expand_macro(self, formatter, name, content): ''' Wiki Macro Method which generates a Genshi Markup Stream ''' macrostart = datetime.now() addExternFiles(formatter.req) # needed because of ajax call while showing ticket details add_stylesheet(formatter.req, 'common/css/ticket.css') if content == None: content = '' macroenv = PPEnv(self.env, formatter.req, content) ts = ppFilter(macroenv).get_tickets() if macroenv.get_args('ppforcereload') == '1': noteForceReload = tag.span('The visualization was recreated.', class_='ppforcereloadinfo') else: noteForceReload = tag.span() renderer = ppRender(macroenv) # show text in the headline moretitle = '' #macroenv.tracenv.log.warning('macroenv label=%s (%s)' % (macroenv.get_args('label'),macroenv.tracreq.args)) if macroenv.macrokw.get('label', None) != None: # use parameter: label moretitle = macroenv.macrokw.get('label', '') else: moretitle = renderer.getHeadline() # get the pre-defined headline return tag.div( tag.h5(tag.a(name=macroenv.macroid)('%s' % (moretitle, ))), renderer.render(ts), tag.div( tag.div( tag.span('It took ' + str( (datetime.now() - macrostart).microseconds / 1000) + 'ms to generate this visualization. ', class_='ppstat'), noteForceReload, tag.span( tag.a('Force recreation of the visualization.', href='?ppforcereload=1', class_='ppforcereload')))), style=macroenv.macrokw.get('style', '') # CSS style )
def expand_macro( self, formatter, name, content ): ''' Wiki Macro Method which generates a Genshi Markup Stream ''' macrostart = datetime.now() addExternFiles( formatter.req ) # needed because of ajax call while showing ticket details add_stylesheet( formatter.req, 'common/css/ticket.css' ) if content == None: content = '' macroenv = PPEnv( self.env, formatter.req, content ) ts = ppFilter( macroenv ).get_tickets() if macroenv.get_args('ppforcereload') == '1': noteForceReload = tag.span('The visualization was recreated.', class_ = 'ppforcereloadinfo' ) else: noteForceReload = tag.span() renderer = ppRender( macroenv ) # show text in the headline moretitle = '' #macroenv.tracenv.log.warning('macroenv label=%s (%s)' % (macroenv.get_args('label'),macroenv.tracreq.args)) if macroenv.macrokw.get('label', None) != None: # use parameter: label moretitle = macroenv.macrokw.get('label', '') else: moretitle = renderer.getHeadline() # get the pre-defined headline return tag.div( tag.h5( tag.a( name=macroenv.macroid )( '%s' % (moretitle,) ) ), renderer.render( ts ), tag.div( tag.div( tag.span('It took '+str((datetime.now()-macrostart).microseconds/1000)+'ms to generate this visualization. ' , class_ = 'ppstat' ), noteForceReload, tag.span(tag.a('Force recreation of the visualization.', href='?ppforcereload=1', class_ = 'ppforcereload' ) ) ) ), style=macroenv.macrokw.get('style', '') # CSS style )
def get_html(self, macroenv, req, content): def get_time( starttime, macroenv ): ''' computes the computing time of the macro returned as HTML construct to be embeeded in HTML output ''' duration = (datetime.now()-starttime).microseconds/1000; macroenv.tracenv.log.debug('macro computation time: %s ms: %s ' % (duration,macroenv.macrokw) ) return(tag.span('It took %s ms to generate this visualization. ' % (duration,), class_ = 'ppstat' )) #macroenv = PPEnv( env, req, content ) macrostart = datetime.now() if content == None: content = '' ts = ppFilter( macroenv ).get_tickets() if macroenv.get_args('ppforcereload') == '1': noteForceReload = tag.span('The visualization was recreated.', class_ = 'ppforcereloadinfo' ) else: noteForceReload = tag.span() renderer = ppRender( macroenv ) # show text in the headline moretitle = '' macroenv.tracenv.log.debug('macroenv label=%s (%s)' % (macroenv.get_args('label'),macroenv.tracreq.args)) if macroenv.macrokw.get('label', None) != None: # use parameter: label moretitle = macroenv.macrokw.get('label', '') else: moretitle = renderer.getHeadline() # get the pre-defined headline return tag.div( tag.h5( tag.a( name=macroenv.macroid )( '%s' % (moretitle,) ) ), renderer.render( ts ), tag.div( tag.div( get_time(macrostart, macroenv), noteForceReload, tag.span(tag.a('Force recreation of the visualization.', href='?ppforcereload=1', class_ = 'ppforcereload' ) ) ) ), style=macroenv.macrokw.get('style', '') # CSS style )
def render(self, ticketset): return_div = tag.div(class_=self.cssclass+' projectplanrender' ) # check for missing parameters missingparameter = False if self.rows == [] or self.rows == None: return_div(tag.div('Missing parameter "rows": use a semicolon-separated list to input the "'+self.rowtype+'".', class_='ppwarning')) missingparameter = True if self.rowtype == None or str(self.rowtype).strip() == '': return_div(tag.div('Missing parameter "rowtype": specifies the ticket attribute that should be showed at the rows.', class_='ppwarning')) missingparameter = True if self.cols == [] or self.cols == None: return_div(tag.div('Missing parameter: use a semicolon-separated list to input the "cols".', class_='ppwarning')) missingparameter = True if self.coltype == None or str(self.coltype).strip() == '': return_div(tag.div('Missing parameter "coltype": specifies the ticket attribute that should be showed in the columns.', class_='ppwarning')) missingparameter = True if missingparameter: return return_div #ul = tag.ul() #for tid in ticketset.getIDSortedList(): #ticket = ticketset.getTicket(tid) #ul( tag.li(tid, " ",ticket.getfield('component') , " ", ticket.getfield('owner') )) #return_div(ul) def getstatistictitle( statusdict ): mytitle = '' mysum = 0 for status in statusdict: mytitle += "%s: %s\n" % (status, str(statusdict[status]) ) mysum += int(statusdict[status]) mytitle += "%s: %s" % ('number', mysum) return mytitle def setKV( myStruct, myKey, newValue ): ''' shortcut to set the values correctly used to reduce the code needed while using a list as key of a dict ''' myStruct[str(myKey)] = newValue def tableKeyPrettyPrint( mylist ) : ''' transform a list of keys to a user readable string in: ['a','b'] --> out: 'a|b' ''' return '|'.join(mylist) def tableKeyQueryParameter( parameter, mylist ) : ''' transform a list of keys to a Trac query string parameter (OR) in: x, ['a','b'] --> out: 'x=a&x=b' ''' return '&'.join([ "%s=%s" % (parameter, s) for s in mylist ]) chartheight=80 chartwidth=170 data = {} statistics = {} # init table data for row in self.rows : colstatistics = {} colkeys = {} for col in self.cols : # colkeys[col] = [] setKV( colkeys, col, [] ) # colstatistics[col] = {} setKV( colstatistics, col, {} ) # data[row] = colkeys setKV( data, row, colkeys ) # statistics[row] = colstatistics setKV( statistics, row, colstatistics ) for tid in ticketset.getIDSortedList(): ticket = ticketset.getTicket(tid) ticket_rowtype = ticket.getfield(self.rowtype) ticket_coltype = ticket.getfield(self.coltype) # determine the data cell where the ticket has to be added, keep in mind that rows and cols are list of lists for row in self.rows : for col in self.cols : if ticket_rowtype in row and ticket_coltype in col : data[str(row)][str(col)].append(ticket) # save tickets at precise values of row and col self.log_debug('row:%s col:%s append:%s' % (row,col,tid)) # if ticket_rowtype in self.rows and ticket_coltype in self.cols : # create HTML table table = tag.table( class_="data pptableticketperday" , border = "1", style = 'width:auto;') # create HTML table head thead = tag.thead() tr = tag.tr() tr( tag.th("%s vs %s" % (self.rowtype,self.coltype) ) ) for colkey in self.cols : tr( tag.th(tag.h4(tag.a( tableKeyPrettyPrint(colkey), href=self.macroenv.tracenv.href()+('/query?%s&order=%s' % ( tableKeyQueryParameter(self.coltype, colkey),self.rowtype)) )),title="%s is %s" % (self.coltype, tableKeyPrettyPrint(colkey) ) ) ) # first line with all colkeys if self.showsummarypiechart: tr( tag.th(tag.h4( "Ticket Overview" ) ) ) thead(tr) table(thead) # create HTML table body tbody = tag.tbody() counter=0 for rowkey in self.rows : # switch line color if counter % 2 == 1: class_ = 'odd' else: class_ = 'even' counter += 1 tr = tag.tr( class_=class_ ) # new line td = tag.td() # new cell td(tag.h5(tag.a( tableKeyPrettyPrint(rowkey), href=self.macroenv.tracenv.href()+('/query?%s&order=%s' % ( tableKeyQueryParameter( self.rowtype,rowkey),self.coltype)) )),title="%s is %s" % (self.rowtype, tableKeyPrettyPrint(rowkey) ) ) # first cell contains row key tr(td) for colkey in self.cols : td = tag.td() for ticket in data[str(rowkey)][str(colkey)] : td( tag.span(self.createTicketLink(ticket), class_ = 'ticket_inner' ), " " , mytitle="%s is %s and %s is %s" % (self.rowtype,rowkey,self.coltype,colkey) ) # mytitle might be used later by javascript if not statistics[str(rowkey)][str(colkey)].has_key( ticket.getstatus() ) : statistics[str(rowkey)][str(colkey)][ticket.getstatus()] = 0 statistics[str(rowkey)][str(colkey)][ticket.getstatus()] += 1 tr(td) # compute statistics rowstatistics = {} count = 0 for colkey in statistics[str(rowkey)] : for status in statistics[str(rowkey)][str(colkey)] : if not rowstatistics.has_key(status) : rowstatistics[status] = 0 try: rowstatistics[status] += statistics[str(rowkey)][str(colkey)][status] count += statistics[str(rowkey)][str(colkey)][status] except: pass if self.showsummarypiechart: tr(tag.td(tag.img(src=self.createGoogleChartFromDict('ColorForStatus', rowstatistics, '%s tickets' % (count,), height=chartheight )), class_='ppstatistics' , title=getstatistictitle(rowstatistics)) ) # Summary tbody(tr) table(tbody) # create HTML table foot if self.showsummarypiechart : fullstatistics = {} tfoot = tag.tfoot() tr = tag.tr() tr( tag.td(tag.h5('Ticket Overview') ) ) # create statistics for col fullcount = 0 for colkey in self.cols : colstatistics = {} colcount = 0 for rowkey in self.rows : for status in statistics[str(rowkey)][str(colkey)] : if not fullstatistics.has_key(status) : fullstatistics[status] = 0 if not colstatistics.has_key(status) : colstatistics[status] = 0 try: colstatistics[status] += statistics[str(rowkey)][str(colkey)][status] colcount += statistics[str(rowkey)][str(colkey)][status] fullstatistics[status] += statistics[str(rowkey)][str(colkey)][status] fullcount += statistics[str(rowkey)][str(colkey)][status] except: pass tr(tag.td(tag.img(src=self.createGoogleChartFromDict('ColorForStatus', colstatistics, '%s tickets' % (colcount,), height=chartheight)), title=getstatistictitle(colstatistics) )) # Col Summary tr(tag.td(tag.img(src=self.createGoogleChartFromDict('ColorForStatus', fullstatistics, '%s tickets' % (fullcount,), height=chartheight)), class_='ppstatistics', title=getstatistictitle(fullstatistics))) # Full Summary tfoot(tr) table(tfoot) return_div(table) return return_div
try: consideredDate = self.getDateOfSegment(segment) calendar[segment] = {} calendar[segment]['isocalendar'] = consideredDate.isocalendar() calendar[segment]['date'] = consideredDate subtitle = weekdays[calendar[segment]['isocalendar'][2]] + ', week '+str(calendar[segment]['isocalendar'][1]) if consideredDate == currentDate: myclass = 'today' # overwrite except Exception,e: self.macroenv.tracenv.log.error(str(e)+' '+segment) calendar[segment]['isocalendar'] = (None, None, None) calendar[segment]['date'] = None subtitle = "--" mystyle = 'color:#000;' mytitle = 'date could not be resolved' tr(tag.th(tag.h4(segment, class_ = myclass ), tag.h5( subtitle, style = mystyle, title = mytitle, class_ = myclass ))) counttickets[segment] = 0 if self.showsummarypiechart: tr(tag.th(tag.h4('Summary', class_ = myclass_org ), tag.h5( 'of all tickets', style = mystyle_org, title = mytitle_org, class_ = myclass_org ))) table(tag.thead(tr)) # Summary self.macroenv.tracenv.log.debug('tickets in table: '+repr(orderedtickets)) # table body tbody = tag.tbody() counter=0 for o in self.rows: if counter % 2 == 1: class_ = 'odd'
def render(self, ticketset): return_div = tag.div(class_=self.cssclass + ' projectplanrender') # check for missing parameters missingparameter = False if self.rows == [] or self.rows == None: return_div( tag.div( 'Missing parameter "rows": use a semicolon-separated list to input the "' + self.rowtype + '".', class_='ppwarning')) missingparameter = True if self.rowtype == None or str(self.rowtype).strip() == '': return_div( tag.div( 'Missing parameter "rowtype": specifies the ticket attribute that should be showed at the rows.', class_='ppwarning')) missingparameter = True if self.cols == [] or self.cols == None: return_div( tag.div( 'Missing parameter: use a semicolon-separated list to input the "cols".', class_='ppwarning')) missingparameter = True if self.coltype == None or str(self.coltype).strip() == '': return_div( tag.div( 'Missing parameter "coltype": specifies the ticket attribute that should be showed in the columns.', class_='ppwarning')) missingparameter = True if missingparameter: return return_div #ul = tag.ul() #for tid in ticketset.getIDSortedList(): #ticket = ticketset.getTicket(tid) #ul( tag.li(tid, " ",ticket.getfield('component') , " ", ticket.getfield('owner') )) #return_div(ul) def getstatistictitle(statusdict): mytitle = '' mysum = 0 for status in statusdict: mytitle += "%s: %s\n" % (status, str(statusdict[status])) mysum += int(statusdict[status]) mytitle += "%s: %s" % ('number', mysum) return mytitle def setKV(myStruct, myKey, newValue): ''' shortcut to set the values correctly used to reduce the code needed while using a list as key of a dict ''' myStruct[str(myKey)] = newValue def tableKeyPrettyPrint(mylist): ''' transform a list of keys to a user readable string in: ['a','b'] --> out: 'a|b' ''' return '|'.join(mylist) def tableKeyQueryParameter(parameter, mylist): ''' transform a list of keys to a Trac query string parameter (OR) in: x, ['a','b'] --> out: 'x=a&x=b' ''' return '&'.join(["%s=%s" % (parameter, s) for s in mylist]) chartheight = 80 chartwidth = 170 data = {} statistics = {} # init table data for row in self.rows: colstatistics = {} colkeys = {} for col in self.cols: # colkeys[col] = [] setKV(colkeys, col, []) # colstatistics[col] = {} setKV(colstatistics, col, {}) # data[row] = colkeys setKV(data, row, colkeys) # statistics[row] = colstatistics setKV(statistics, row, colstatistics) for tid in ticketset.getIDSortedList(): ticket = ticketset.getTicket(tid) ticket_rowtype = ticket.getfield(self.rowtype) ticket_coltype = ticket.getfield(self.coltype) # determine the data cell where the ticket has to be added, keep in mind that rows and cols are list of lists for row in self.rows: for col in self.cols: if ticket_rowtype in row and ticket_coltype in col: data[str(row)][str(col)].append( ticket ) # save tickets at precise values of row and col self.log_debug('row:%s col:%s append:%s' % (row, col, tid)) # if ticket_rowtype in self.rows and ticket_coltype in self.cols : # create HTML table table = tag.table(class_="data pptableticketperday", border="1", style='width:auto;') # create HTML table head thead = tag.thead() tr = tag.tr() tr(tag.th("%s vs %s" % (self.rowtype, self.coltype))) for colkey in self.cols: tr( tag.th(tag.h4( tag.a(tableKeyPrettyPrint(colkey), href=self.macroenv.tracenv.href() + ('/query?%s&order=%s' % (tableKeyQueryParameter( self.coltype, colkey), self.rowtype)))), title="%s is %s" % (self.coltype, tableKeyPrettyPrint(colkey))) ) # first line with all colkeys if self.showsummarypiechart: tr(tag.th(tag.h4("Ticket Overview"))) thead(tr) table(thead) # create HTML table body tbody = tag.tbody() counter = 0 for rowkey in self.rows: # switch line color if counter % 2 == 1: class_ = 'odd' else: class_ = 'even' counter += 1 tr = tag.tr(class_=class_) # new line td = tag.td() # new cell td(tag.h5( tag.a(tableKeyPrettyPrint(rowkey), href=self.macroenv.tracenv.href() + ('/query?%s&order=%s' % (tableKeyQueryParameter( self.rowtype, rowkey), self.coltype)))), title="%s is %s" % (self.rowtype, tableKeyPrettyPrint(rowkey))) # first cell contains row key tr(td) for colkey in self.cols: td = tag.td() for ticket in data[str(rowkey)][str(colkey)]: td(tag.span(self.createTicketLink(ticket), class_='ticket_inner'), " ", mytitle="%s is %s and %s is %s" % (self.rowtype, rowkey, self.coltype, colkey)) # mytitle might be used later by javascript if not statistics[str(rowkey)][str(colkey)].has_key( ticket.getstatus()): statistics[str(rowkey)][str(colkey)][ ticket.getstatus()] = 0 statistics[str(rowkey)][str(colkey)][ ticket.getstatus()] += 1 tr(td) # compute statistics rowstatistics = {} count = 0 for colkey in statistics[str(rowkey)]: for status in statistics[str(rowkey)][str(colkey)]: if not rowstatistics.has_key(status): rowstatistics[status] = 0 try: rowstatistics[status] += statistics[str(rowkey)][str( colkey)][status] count += statistics[str(rowkey)][str(colkey)][status] except: pass if self.showsummarypiechart: tr( tag.td(tag.img(src=self.createGoogleChartFromDict( 'ColorForStatus', rowstatistics, '%s tickets' % (count, ), height=chartheight)), class_='ppstatistics', title=getstatistictitle(rowstatistics))) # Summary tbody(tr) table(tbody) # create HTML table foot if self.showsummarypiechart: fullstatistics = {} tfoot = tag.tfoot() tr = tag.tr() tr(tag.td(tag.h5('Ticket Overview'))) # create statistics for col fullcount = 0 for colkey in self.cols: colstatistics = {} colcount = 0 for rowkey in self.rows: for status in statistics[str(rowkey)][str(colkey)]: if not fullstatistics.has_key(status): fullstatistics[status] = 0 if not colstatistics.has_key(status): colstatistics[status] = 0 try: colstatistics[status] += statistics[str(rowkey)][ str(colkey)][status] colcount += statistics[str(rowkey)][str( colkey)][status] fullstatistics[status] += statistics[str(rowkey)][ str(colkey)][status] fullcount += statistics[str(rowkey)][str( colkey)][status] except: pass tr( tag.td( tag.img(src=self.createGoogleChartFromDict( 'ColorForStatus', colstatistics, '%s tickets' % (colcount, ), height=chartheight)), title=getstatistictitle(colstatistics))) # Col Summary tr( tag.td( tag.img(src=self.createGoogleChartFromDict( 'ColorForStatus', fullstatistics, '%s tickets' % (fullcount, ), height=chartheight)), class_='ppstatistics', title=getstatistictitle(fullstatistics))) # Full Summary tfoot(tr) table(tfoot) return_div(table) return return_div
[2]] + ', week ' + str( calendar[segment]['isocalendar'][1]) if consideredDate == currentDate: myclass = 'today' # overwrite except Exception, e: self.macroenv.tracenv.log.error(str(e) + ' ' + segment) calendar[segment]['isocalendar'] = (None, None, None) calendar[segment]['date'] = None subtitle = "--" mystyle = 'color:#000;' mytitle = 'date could not be resolved' tr( tag.th( tag.h4(segment, class_=myclass), tag.h5(subtitle, style=mystyle, title=mytitle, class_=myclass))) counttickets[segment] = 0 if self.showsummarypiechart: tr( tag.th( tag.h4('Summary', class_=myclass_org), tag.h5('of all tickets', style=mystyle_org, title=mytitle_org, class_=myclass_org))) table(tag.thead(tr)) # Summary self.macroenv.tracenv.log.debug('tickets in table: ' + repr(orderedtickets))