def _render_view(self, req, db, version): db = self.env.get_db_cnx() sql = "SELECT name FROM milestone " \ "INNER JOIN milestone_version ON (name = milestone) " \ "WHERE version = %s " \ "ORDER BY due" cursor = db.cursor() cursor.execute(sql, (version.name,)) milestones = [] tickets = [] milestone_stats = [] for row in cursor: milestone = Milestone(self.env, row[0]) milestones.append(milestone) mtickets = get_tickets_for_milestone(self.env, db, milestone.name, 'owner') mtickets = apply_ticket_permissions(self.env, req, mtickets) tickets += mtickets stat = get_ticket_stats(self.milestone_stats_provider, mtickets) milestone_stats.append(milestone_stats_data(self.env, req, stat, milestone.name)) stats = get_ticket_stats(self.version_stats_provider, tickets) interval_hrefs = version_interval_hrefs(self.env, req, stats, [milestone.name for milestone in milestones]) version.resource = Resource('version', version.name) context = Context.from_request(req, version.resource) version.is_released = version.time and version.time.date() < date.today() version.stats = stats version.interval_hrefs = interval_hrefs version.stats_href = [] # Not implemented yet, see th:#10349 data = { 'context': context, 'version': version, 'attachments': AttachmentModule(self.env).attachment_data(context), 'milestones': milestones, 'milestone_stats': milestone_stats, 'show_milestone_description': self.show_milestone_description # Not implemented yet } add_stylesheet(req, 'extendedversion/css/version.css') add_script(req, 'common/js/folding.js') add_ctxtnav(req, _("Back to Versions"), req.href.versions()) return 'version_view.html', data, None
def _render_view(self, req, version): milestones = [] tickets = [] milestone_stats = [] for name, in self.env.db_query( """ SELECT name FROM milestone INNER JOIN milestone_version ON (name = milestone) WHERE version = %s ORDER BY due """, (version.name, )): milestone = Milestone(self.env, name) milestones.append(milestone) mtickets = get_tickets_for_milestone(self.env, milestone.name, 'owner') mtickets = apply_ticket_permissions(self.env, req, mtickets) tickets += mtickets stat = get_ticket_stats(self.milestone_stats_provider, mtickets) milestone_stats.append( milestone_stats_data(self.env, req, stat, milestone.name)) stats = get_ticket_stats(self.version_stats_provider, tickets) interval_hrefs = version_interval_hrefs( self.env, req, stats, [milestone.name for milestone in milestones]) version.resource = Resource('version', version.name) context = web_context(req, version.resource) version.is_released = version.time \ and version.time < datetime.now(utc) version.stats = stats version.interval_hrefs = interval_hrefs names = [milestone.name for milestone in milestones] version.stats_href = version_stats_href(self.env, req, names) data = { 'version': version, 'attachments': AttachmentModule(self.env).attachment_data(context), 'milestones': milestones, 'milestone_stats': milestone_stats, 'show_milestone_description': self.show_milestone_description # Not implemented yet } add_stylesheet(req, 'extendedversion/css/version.css') add_script(req, 'common/js/folding.js') add_ctxtnav(req, _("Back to Versions"), req.href.versions()) return 'version_view.html', data, None
def _versions_and_stats(self, req, filter_projects): req.perm.require('MILESTONE_VIEW') db = self.env.get_db_cnx() versions = Version.select(self.env, db) filtered_versions = [] stats = [] show = req.args.getlist('show') for version in sorted(versions, key=lambda v: self._version_time(v)): project = self.__SmpModel.get_project_version(version.name) if not filter_projects or (project and project[0] in filter_projects): if not version.time or version.time.replace(tzinfo=None) >= datetime.now() or 'completed' in show: if version.time: if version.time.replace(tzinfo=None) >= datetime.now(): version.is_due = True; else: version.is_completed = True; filtered_versions.append(version) tickets = get_tickets_for_any(self.env, db, 'version', version.name, 'owner') tickets = apply_ticket_permissions(self.env, req, tickets) stat = get_ticket_stats(self.stats_provider, tickets) stats.append(any_stats_data(self.env, req, stat, 'version', version.name)) return filtered_versions, stats
def expand_macro(self, formatter, name, content): req = formatter.req stats_provider, kwargs = self._parse_macro_content(content, req) # Create & execute the query string qstr = '&'.join(['%s=%s' % item for item in kwargs.iteritems()]) query = Query.from_string(self.env, qstr, max=0) try: constraints = query.constraints[0] except IndexError: constraints = query.constraints # Calculate stats qres = query.execute(req) tickets = apply_ticket_permissions(self.env, req, qres) stats = get_ticket_stats(stats_provider, tickets) stats_data = query_stats_data(req, stats, constraints) # ... and finally display them add_stylesheet(req, 'common/css/roadmap.css') chrome = Chrome(self.env) return chrome.render_template(req, 'progressmeter.html', stats_data, fragment=True)
def expand_macro(self, formatter, name, content): req = formatter.req stats_provider, kwargs, is_preview_with_self = self._parse_macro_content(content, req) if is_preview_with_self: # previewing newticket, without a number but with a reference # to current ticket number; show a helpful message return tag.div('Progress meter will be inserted here in final ticket') # Create & execute the query string qstr = '&'.join(['%s=%s' % item for item in kwargs.iteritems()]) query = Query.from_string(self.env, qstr, max=0) try: constraints = query.constraints[0] except IndexError: constraints = query.constraints # Calculate stats qres = query.execute(req) tickets = apply_ticket_permissions(self.env, req, qres) stats = get_ticket_stats(stats_provider, tickets) stats_data = query_stats_data(req, stats, constraints) # ... and finally display them add_stylesheet(req, 'common/css/roadmap.css') chrome = Chrome(self.env) return chrome.render_template(req, 'progressmeter.html', stats_data, fragment=True)
def _versions_and_stats(self, req, filter_projects): req.perm.require('MILESTONE_VIEW') db = self.env.get_db_cnx() versions = Version.select(self.env, db) filtered_versions = [] stats = [] show = req.args.getlist('show') for version in sorted(versions, key=lambda v: self._version_time(v)): project = self.__SmpModel.get_project_version(version.name) if not filter_projects or (project and project[0] in filter_projects): if not version.time or version.time.replace( tzinfo=None) >= datetime.now() or 'completed' in show: if version.time: if version.time.replace(tzinfo=None) >= datetime.now(): version.is_due = True else: version.is_completed = True filtered_versions.append(version) tickets = get_tickets_for_any(self.env, db, 'version', version.name, 'owner') tickets = apply_ticket_permissions(self.env, req, tickets) stat = get_ticket_stats(self.stats_provider, tickets) stats.append( any_stats_data(self.env, req, stat, 'version', version.name)) return filtered_versions, stats
def expand_macro(self, formatter, name, content): req = formatter.req stats_provider, kwargs, preview = self._parse_macro_content(content, req) # Create & execute the query string qstr = '&'.join(['%s=%s' % item for item in kwargs.iteritems()]) query = Query.from_string(self.env, qstr) try: # XXX: simplification, may cause problems with more complex queries constraints = query.constraints[0] except IndexError: constraints = {} # Calculate stats qres = query.execute(req) tickets = apply_ticket_permissions(self.env, req, qres) stats = get_ticket_stats(stats_provider, tickets) stats_data = query_stats_data(req, stats, constraints) # ... and finally display them add_stylesheet(req, 'common/css/roadmap.css') chrome = Chrome(self.env) stats_data.update({'preview': preview}) # displaying a preview? return chrome.render_template(req, 'progressmeter.html', stats_data, fragment=True)
def render_widget(self, name, context, options): """Prepare ticket stats """ req = context.req params = ('query', 'stats_provider', 'skin', 'title', 'legend', 'desc', 'view') qstr, pnm, skin, title, legend, desc, view = \ self.bind_params(name, options, *params) statsp = resolve_ep_class(ITicketGroupStatsProvider, self, pnm, default=RoadmapModule(self.env).stats_provider) if skin is not None : skin = (skin or '').split('-', 2) tickets = exec_query(self.env, req, qstr) tickets = apply_ticket_permissions(self.env, req, tickets) stat = get_ticket_stats(statsp, tickets) add_stylesheet(req, 'dashboard/css/bootstrap.css') add_stylesheet(req, 'dashboard/css/bootstrap-responsive.css') add_stylesheet(req, 'dashboard/css/roadmap.css') return 'widget_progress.html', \ { 'title' : title, 'data' : dict( desc=desc, legend=legend, bar_styles=skin, stats=stat, view=view, ), }, \ context
def render_widget(self, name, context, options): """Prepare ticket stats """ req = context.req params = ('query', 'stats_provider', 'skin', 'title', 'legend', 'desc', 'view') qstr, pnm, skin, title, legend, desc, view = \ self.bind_params(name, options, *params) statsp = resolve_ep_class(ITicketGroupStatsProvider, self, pnm, default=RoadmapModule( self.env).stats_provider) if skin is not None: skin = (skin or '').split('-', 2) tickets = exec_query(self.env, req, qstr) tickets = apply_ticket_permissions(self.env, req, tickets) stat = get_ticket_stats(statsp, tickets) add_stylesheet(req, 'dashboard/css/bootstrap.css') add_stylesheet(req, 'dashboard/css/bootstrap-responsive.css') add_stylesheet(req, 'dashboard/css/roadmap.css') return 'widget_progress.html', \ { 'title' : title, 'data' : dict( desc=desc, legend=legend, bar_styles=skin, stats=stat, view=view, ), }, \ context
def expand_macro(self, formatter, name, content): req = formatter.req stats_provider, kwargs, preview = self._parse_macro_content( content, req) # Create & execute the query string qstr = '&'.join(['%s=%s' % item for item in kwargs.iteritems()]) query = Query.from_string(self.env, qstr) try: # XXX: simplification, may cause problems with more complex queries constraints = query.constraints[0] except IndexError: constraints = {} # Calculate stats qres = query.execute(req) tickets = apply_ticket_permissions(self.env, req, qres) stats = get_ticket_stats(stats_provider, tickets) stats_data = query_stats_data(req, stats, constraints) # ... and finally display them add_stylesheet(req, 'common/css/roadmap.css') chrome = Chrome(self.env) stats_data.update({'preview': preview}) # displaying a preview? return chrome.render_template(req, 'progressmeter.html', stats_data, fragment=True)
def expand_macro(self, formatter, name, content): req = formatter.req # Parse arguments args, kwargs = parse_args(content, strict=False) assert not args and not ('status' in kwargs or 'format' in kwargs), \ "Invalid input!" # hack the `format` kwarg in order to display all-tickets stats # when no kwargs are supplied kwargs['format'] = 'count' # special case for values equal to 'self': replace with current # ticket number, if available for key in kwargs.keys(): if kwargs[key] == 'self': current_ticket = self._this_ticket(req) if current_ticket: kwargs[key] = current_ticket # Create & execute the query string qstr = '&'.join(['%s=%s' % item for item in kwargs.iteritems()]) query = Query.from_string(self.env, qstr, max=0) # Calculate stats qres = query.execute(req) tickets = apply_ticket_permissions(self.env, req, qres) stats = get_ticket_stats(self.stats_provider, tickets) stats_data = query_stats_data(req, stats, query.constraints) # ... and finally display them add_stylesheet(req, 'common/css/roadmap.css') chrome = Chrome(self.env) return chrome.render_template(req, 'progressmeter.html', stats_data, fragment=True)
def process_request(self, req): req.perm.require('MILESTONE_VIEW') show = req.args.getlist('show') if 'all' in show: show = ['completed'] db = self.env.get_db_cnx() milestones = Milestone.select(self.env, 'completed' in show, db) if 'noduedate' in show: milestones = [ m for m in milestones if m.due is not None or m.completed ] milestones = [ m for m in milestones if 'MILESTONE_VIEW' in req.perm(m.resource) ] stats = [] queries = [] for milestone in milestones: tickets = get_tickets_for_milestone(self.env, db, milestone.name, 'owner') tickets = apply_ticket_permissions(self.env, req, tickets) stat = get_ticket_stats(self.stats_provider, tickets) stats.append( milestone_stats_data(self.env, req, stat, '^' + milestone.name)) #milestone['tickets'] = tickets # for the iCalendar view if req.args.get('format') == 'ics': self.render_ics(req, db, milestones) return # FIXME should use the 'webcal:' scheme, probably username = None if req.authname and req.authname != 'anonymous': username = req.authname icshref = req.href.roadmap(show=show, user=username, format='ics') add_link(req, 'alternate', icshref, _('iCalendar'), 'text/calendar', 'ics') data = { 'milestones': milestones, 'milestone_stats': stats, 'queries': queries, 'show': show, } add_stylesheet(req, 'common/css/roadmap.css') return 'roadmap.html', data, None
def _construct_progress(self, req, ticket): chrome = Chrome(self.env) query = Query.from_string(self.env, "parent=%d" % ticket.id, max=0) try: constraints = query.constraints[0] except IndexError: constraints = query.constraints qres = query.execute(req) tickets = apply_ticket_permissions(self.env, req, qres) stats = get_ticket_stats(self._stats_provider, tickets) stats_data = query_stats_data(req, stats, constraints) progress = chrome.render_template(req, 'progressmeter.html', stats_data, fragment=True) return progress
def _render_view(self, req, db, version): version_groups = [] available_groups = [] component_group_available = False ticket_fields = TicketSystem(self.env).get_ticket_fields() # collect fields that can be used for grouping for field in ticket_fields: if field['type'] == 'select' and field['name'] != 'version' \ or field['name'] in ('owner', 'reporter'): available_groups.append({ 'name': field['name'], 'label': field['label'] }) if field['name'] == 'component': component_group_available = True # determine the field currently used for grouping by = None if component_group_available: by = 'component' elif available_groups: by = available_groups[0]['name'] by = req.args.get('by', by) tickets = get_tickets_for_any(self.env, db, 'version', version.name, by) tickets = apply_ticket_permissions(self.env, req, tickets) stat = get_ticket_stats(self.stats_provider, tickets) context = Context.from_request(req) infodivclass = '' if VERSION <= '0.12': infodivclass = 'info' else: infodivclass = 'info trac-progress' data = { 'context': context, 'version': version, 'attachments': AttachmentModule(self.env).attachment_data(context), 'available_groups': available_groups, 'grouped_by': by, 'groups': version_groups, 'infodivclass': infodivclass } data.update( any_stats_data(self.env, req, stat, 'version', version.name)) if by: groups = [] for field in ticket_fields: if field['name'] == by: if 'options' in field: groups = field['options'] if field.get('optional'): groups.insert(0, '') else: cursor = db.cursor() cursor.execute( """ SELECT DISTINCT COALESCE(%s,'') FROM ticket ORDER BY COALESCE(%s,'') """, [by, by]) groups = [row[0] for row in cursor] max_count = 0 group_stats = [] for group in groups: values = group and (group, ) or (None, group) group_tickets = [t for t in tickets if t[by] in values] if not group_tickets: continue gstat = get_ticket_stats(self.stats_provider, group_tickets) if gstat.count > max_count: max_count = gstat.count group_stats.append(gstat) gs_dict = {'name': group} gs_dict.update( any_stats_data(self.env, req, gstat, 'version', version.name, by, group)) version_groups.append(gs_dict) for idx, gstat in enumerate(group_stats): gs_dict = version_groups[idx] percent = 1.0 if max_count: percent = float(gstat.count) / float(max_count) * 100 gs_dict['percent_of_max_total'] = percent add_stylesheet(req, 'common/css/roadmap.css') add_script(req, 'common/js/folding.js') return 'version_view.html', data, None
def _render_view(self, req, db, milestone): milestone_groups = [] available_groups = [] component_group_available = False ticket_fields = TicketSystem(self.env).get_ticket_fields() # collect fields that can be used for grouping for field in ticket_fields: if field['type'] == 'select' and field['name'] != 'milestone' \ or field['name'] in ('owner', 'reporter'): available_groups.append({'name': field['name'], 'label': field['label']}) if field['name'] == 'component': component_group_available = True # determine the field currently used for grouping by = None if component_group_available: by = 'component' elif available_groups: by = available_groups[0]['name'] by = req.args.get('by', by) tickets = get_tickets_for_milestone(self.env, db, milestone.name, by) stat = get_ticket_stats(self.stats_provider, tickets) tstat = get_ticket_stats(self.tickettype_stats_provider, tickets) # Parse the from date and adjust the timestamp to the last second of # the day today = datetime.now(req.tz) # Get milestone start date from session or use default day back. # TODO: add logic to remember the start date either in db or session. # if req.session.get('mdashboard.fromdate') != None: # # fromdate = parse_date(req.session.get('mdashboard.fromdate'), req.tz) # else: fromdate = today - timedelta(days=self.default_daysback + 1) fromdate = fromdate.replace(hour=23, minute=59, second=59) # Data for milestone and timeline data = {'fromdate': fromdate, 'milestone': milestone, 'tickethistory' : [], 'dates' : [], 'ticketstat' : {}, 'yui_base_url': self.yui_base_url } data.update(milestone_stats_data(self.env, req, stat, milestone.name)) ticketstat = {'name':'ticket type'} ticketstat.update(milestone_stats_data(self.env, req, tstat, milestone.name)) data['ticketstat'] = ticketstat #self.env.log.info("ticketstat = %s" % (ticketstat,)) # get list of ticket ids that in the milestone #ctickets = get_tickets_for_milestone(self.env, db, milestone.name, 'type') everytickets = get_every_tickets_in_milestone(db, milestone.name) if everytickets != []: #tkt_history = {} # collect_tickets_status_history(self.env, db, tkt_history, \ # everytickets, milestone) tkt_history = collect_tickets_status_history(self.env, db, everytickets, milestone) if tkt_history != {}: # Sort the key in the history list # returns sorted list of tuple of (key, value) sorted_events = sorted(tkt_history.items(), key=lambda(k,v):(k)) #debug self.env.log.info("sorted_event content") for event in sorted_events: self.env.log.info("date: %s: event: %s" % (format_date(to_datetime(event[0])), event[1])) # Get first date that ticket enter the milestone begin_date = to_datetime(min(sorted_events)[0]); if milestone.completed != None: end_date = milestone.completed else: end_date = datetime.now(utc).date() # this is array of date in numpy numdates = drange(begin_date, end_date + timedelta(days=1), timedelta(days=1)) tkt_history_table = make_ticket_history_table(self.env, numdates, sorted_events) #debug #self.env.log.info("tkt_history_table: %s", (tkt_history_table,)) #Create a data for the cumulative flow chart. tkt_cumulative_table = make_cumulative_data(self.env, tkt_history_table) #debug #self.env.log.info(tkt_cumulative_table) # creat list of dateobject from dates dates = [] for numdate in numdates: utc_date = num2date(numdate) dates.append(utc_date) #self.env.log.info("%s: %s" % (utc_date, format_date(utc_date, tzinfo=utc))) #prepare Yahoo datasource for comulative flow chart dscumulative = '' for idx, date in enumerate(dates): dscumulative = dscumulative + '{ date: "%s", enter: %d, leave: %d, finish: %d}, ' \ % (format_date(date,tzinfo=utc), tkt_cumulative_table['Enter'][idx], \ tkt_cumulative_table['Leave'][idx], tkt_cumulative_table['Finish'][idx]) data['tickethistory'] = tkt_cumulative_table data['dates'] = dates data['dscumulative'] = '[ ' + dscumulative + ' ];' return 'mdashboard.html', data, None
def _render_view(self, req, milestone): available_groups = [] component_group_available = False project_id = req.data['project_id'] ticket_fields = TicketSystem(self.env).get_ticket_fields(pid=project_id) # collect fields that can be used for grouping for name, field in ticket_fields.iteritems(): if field['type'] == 'select' and name != 'milestone' \ or name in ('owner', 'reporter'): available_groups.append({'name': name, 'label': field['label']}) if name == 'component': component_group_available = True # determine the field currently used for grouping by = None if component_group_available: by = 'component' elif available_groups: by = available_groups[0]['name'] by = req.args.get('by', by) db = self.env.get_read_db() tickets = get_tickets_for_milestone(self.env, db, milestone, by) stat = get_ticket_stats(self.stats_provider, tickets, project_id) tstat = get_ticket_stats(self.tickettype_stats_provider, tickets, project_id) # Data for milestone and timeline data = { 'milestone': milestone, 'tickethistory' : [], 'dates' : [], 'ticketstat' : {}, 'yui_base_url': self.tm.yui_base_url, '_': _, } data.update(milestone_stats_data(self.env, req, stat, milestone)) ticketstat = {'name':'ticket type'} ticketstat.update(milestone_stats_data(self.env, req, tstat, milestone)) data['ticketstat'] = ticketstat # get list of ticket ids that in the milestone everytickets = get_every_tickets_in_milestone(db, project_id, milestone.name) if everytickets: tkt_history = collect_tickets_status_history(db, everytickets, milestone) if tkt_history: # Sort the key in the history list # returns sorted list of tuple of (key, value) sorted_events = sorted(tkt_history.items(), key=lambda(t,events):(t)) # Get first date that ticket enter the milestone min_time = sorted_events[0][0] begin_date = to_datetime(min_time, tzinfo=req.tz) if milestone.is_completed: end_date = milestone.completed else: end_date = None end_date = to_datetime(end_date, tzinfo=req.tz) dates = list(date_generator(begin_date, end_date)) #Create a data for the cumulative flow chart. date_history = prepare_to_cumulate(sorted_events) tkt_cumulative_table = make_cumulative_data(dates, date_history) #prepare Yahoo datasource for comulative flow chart dscumulative = '' for idx, date in enumerate(dates): dscumulative = dscumulative + '{ date: "%s", enter: %d, leave: %d, finish: %d}, ' \ % (format_date(date,tzinfo=utc), tkt_cumulative_table['Enter'][idx], \ tkt_cumulative_table['Leave'][idx], tkt_cumulative_table['Finish'][idx]) data['tickethistory'] = tkt_cumulative_table data['dates'] = dates data['dscumulative'] = '[ ' + dscumulative + ' ];' return 'mdashboard.html', data, None
def _render_project_stats(self, req, data): project_id = req.data['project_id'] defaults = { # summary 'tkt_summary': True, 'milestones_stats': True, 'tkt_extra_stats': False, # time range 'tkt_activity': False, 'repos_stats': True, 'backlog_daily': True, # time groups 'repos_activity': True, 'backlog_table': False, 'wiki_activity': True, } metrics = self._enabled_metrics(req, defaults) show_completed = req.args.has_key('show_completed') data.update({ 'metrics': metrics, 'show_completed': show_completed, }) groupsize = data['groupsize'] groupcnt = data['groupcnt'] first_day = data['first_day'] first_day_group = data['first_day_group'] last_day = data['last_day'] db = self.env.get_read_db() if metrics['milestones_stats']: # Get list of milestone object for the project milestones = list(Milestone.select(self.env, project_id, show_completed, db)) stats = [] for milestone in milestones: tickets = get_tickets_for_milestone(self.env, db, milestone, 'owner') stat = get_ticket_stats(self.stats_provider, tickets, project_id) stats.append(milestone_stats_data(self.env, req, stat, milestone)) add_stylesheet(req, 'common/css/roadmap.css') data.update({ 'milestones': milestones, 'milestone_stats': stats, }) project_tickets = get_project_tickets(self.env, project_id) if metrics['tkt_summary']: # Get project progress stats proj_stat = self.stats_provider.get_ticket_group_stats(project_tickets, project_id) data['proj_progress_stat'] = {'stats': proj_stat, 'stats_href': req.href.query(proj_stat.qry_args, project_id=project_id), 'interval_hrefs': [req.href.query(interval['qry_args']) for interval in proj_stat.intervals]} closed_stat = self.stats_provider.get_ticket_resolution_group_stats(project_tickets, project_id) data['proj_closed_stat'] = {'stats': closed_stat, 'stats_href': req.href.query(closed_stat.qry_args, project_id=project_id), 'interval_hrefs': [req.href.query(interval['qry_args']) for interval in closed_stat.intervals]} if metrics['backlog_daily'] or metrics['backlog_table'] or metrics['tkt_extra_stats']: tkt_group_metrics = TicketGroupMetrics(self.env, project_tickets) if metrics['tkt_extra_stats']: tkt_frequency_stats = tkt_group_metrics.get_frequency_metrics_stats() tkt_duration_stats = tkt_group_metrics.get_duration_metrics_stats() data.update({ 'ticket_frequency_stats': tkt_frequency_stats, 'ticket_duration_stats': tkt_duration_stats, }) if metrics['backlog_table']: bmi_stats = [] d = first_day_group fday = datetime(d.year, d.month, d.day, tzinfo=req.tz) for _i in xrange(groupcnt): lday = fday + timedelta(groupsize, microseconds=-1) bstats = tkt_group_metrics.get_bmi_stats(fday, lday) bmi_stats.append(('%s - %s' % (format_date(fday), format_date(lday)),) + bstats) fday += timedelta(groupsize) data['project_bmi_stats'] = bmi_stats if metrics['backlog_daily']: # get daily backlog history backlog_history = tkt_group_metrics.get_daily_backlog_history(first_day, last_day) daily_backlog_chart = tkt_group_metrics.get_daily_backlog_chart(backlog_history) data['ds_daily_backlog'] = daily_backlog_chart if metrics['repos_stats']: # Get daily commits history changeset_group_stats = ChangesetsStats(self.env, project_id, first_day, last_day) commits_by_date = changeset_group_stats.get_commit_by_date() commits_by_date_chart = changeset_group_stats.get_commit_by_date_chart(commits_by_date) data['ds_commit_by_date'] = commits_by_date_chart data_json = {} if metrics['tkt_activity']: data['ticket_activity'] = reports.ticket_activity(project_id, first_day, last_day, db, req) data_json['ticket_activity'] = simplejson.dumps(data['ticket_activity'].get_data()) if metrics['repos_activity']: data['repository_activity'] = reports.repository_activity(project_id, first_day_group, last_day, groupsize, groupcnt, db, req, authors_limit=self.tm.authors_limit_repos) data_json['repository_activity'] = simplejson.dumps(data['repository_activity'].get_data()) if metrics['wiki_activity']: data['wiki_activity'] = reports.wiki_activity(project_id, first_day, last_day, groupsize, groupcnt, db, req, authors_limit=self.tm.authors_limit_wiki) data_json['wiki_activity'] = simplejson.dumps(data['wiki_activity'].get_data()) data['json'] = data_json return ('pdashboard.html', data, None)
def expand_macro(self, formatter, name, content): req = formatter.req query_string, kwargs, format = self.parse_args(content) if query_string: query_string += '&' query_string += '&'.join('%s=%s' % item for item in kwargs.iteritems()) env = ProductEnvironment.lookup_global_env(self.env) query = ProductQuery.from_string(env, query_string) if format == 'count': cnt = query.count(req) return tag.span(cnt, title='%d tickets for which %s' % (cnt, query_string), class_='query_count') tickets = query.execute(req) if format == 'table': data = query.template_data(formatter.context, tickets, req=formatter.context.req) add_stylesheet(req, 'common/css/report.css') return Chrome(env).render_template( req, 'query_results.html', data, None, fragment=True) if format == 'progress': from trac.ticket.roadmap import (RoadmapModule, apply_ticket_permissions, get_ticket_stats, grouped_stats_data) add_stylesheet(req, 'common/css/roadmap.css') def query_href(extra_args, group_value = None): q = ProductQuery.from_string(env, query_string) if q.group: extra_args[q.group] = group_value q.group = None for constraint in q.constraints: constraint.update(extra_args) if not q.constraints: q.constraints.append(extra_args) return q.get_href(formatter.context) chrome = Chrome(env) tickets = apply_ticket_permissions(env, req, tickets) stats_provider = RoadmapModule(env).stats_provider by = query.group if not by: stat = get_ticket_stats(stats_provider, tickets) data = { 'stats': stat, 'stats_href': query_href(stat.qry_args), 'interval_hrefs': [query_href(interval['qry_args']) for interval in stat.intervals], 'legend': True, } return tag.div( chrome.render_template(req, 'progress_bar.html', data, None, fragment=True), class_='trac-progress') def per_group_stats_data(gstat, group_name): return { 'stats': gstat, 'stats_href': query_href(gstat.qry_args, group_name), 'interval_hrefs': [query_href(interval['qry_args'], group_name) for interval in gstat.intervals], 'percent': '%d / %d' % (gstat.done_count, gstat.count), 'legend': False, } groups = grouped_stats_data(env, stats_provider, tickets, by, per_group_stats_data) data = { 'groups': groups, 'grouped_by': by, 'summary': _("Ticket completion status for each %(group)s", group=by), } return tag.div( chrome.render_template(req, 'progress_bar_grouped.html', data, None, fragment=True), class_='trac-groupprogress') # Formats above had their own permission checks, here we need to # do it explicitly: tickets = [t for t in tickets if 'TICKET_VIEW' in req.perm('ticket', t['id'])] if not tickets: return tag.span(_("No results"), class_='query_no_results') # Cache resolved href targets hrefcache = {} def ticket_anchor(ticket): try: pvalue = ticket.get('product') or GLOBAL_PRODUCT envhref = hrefcache[pvalue] except KeyError: try: env = lookup_product_env(self.env, prefix= pvalue, name=pvalue) except LookupError: return tag.a('#%s' % ticket['id'], class_='missing product') hrefcache[pvalue] = envhref = resolve_product_href( to_env=env, at_env=self.env) return tag.a('#%s' % ticket['id'], class_=ticket['status'], href=envhref.ticket(int(ticket['id'])), title=shorten_line(ticket['summary'])) def ticket_groups(): groups = [] for v, g in groupby(tickets, lambda t: t[query.group]): q = ProductQuery.from_string(env, query_string) # produce the hint for the group q.group = q.groupdesc = None order = q.order q.order = None title = _("%(groupvalue)s %(groupname)s tickets matching " "%(query)s", groupvalue=v, groupname=query.group, query=q.to_string()) # produce the href for the query corresponding to the group for constraint in q.constraints: constraint[str(query.group)] = v q.order = order href = q.get_href(formatter.context) groups.append((v, [t for t in g], href, title)) return groups if format == 'compact': if query.group: groups = [(v, ' ', tag.a('#%s' % u',\u200b'.join(str(t['id']) for t in g), href=href, class_='query', title=title)) for v, g, href, title in ticket_groups()] return tag(groups[0], [(', ', g) for g in groups[1:]]) else: alist = [ticket_anchor(ticket) for ticket in tickets] return tag.span(alist[0], *[(', ', a) for a in alist[1:]]) else: if query.group: return tag.div( [(tag.p(tag_('%(groupvalue)s %(groupname)s tickets:', groupvalue=tag.a(v, href=href, class_='query', title=title), groupname=query.group)), tag.dl([(tag.dt(ticket_anchor(t)), tag.dd(t['summary'])) for t in g], class_='wiki compact')) for v, g, href, title in ticket_groups()]) else: return tag.div(tag.dl([(tag.dt(ticket_anchor(ticket)), tag.dd(ticket['summary'])) for ticket in tickets], class_='wiki compact'))
def _render_view(self, req, db): showall = req.args.get('show') == 'all' showmetrics = req.args.get('showmetrics') == 'true' # Get list of milestone object for the project milestones = list(Milestone.select(self.env, showall, db)) stats = [] queries = [] self.env.log.info("getting milestones statistics") for milestone in milestones: tickets = get_tickets_for_milestone(self.env, db, milestone.name, 'owner') stat = get_ticket_stats(self.stats_provider, tickets) stats.append( milestone_stats_data(self.env, req, stat, milestone.name)) project = { 'name': self.env.project_name, 'description': self.env.project_description } data = { 'context': Context.from_request(req), 'milestones': milestones, 'milestone_stats': stats, 'queries': queries, 'showall': showall, 'showmetrics': showmetrics, 'project': project, 'yui_base_url': self.yui_base_url } self.env.log.info("getting project statistics") # Get project progress stats query = Query.from_string(self.env, 'max=0&order=id') tickets = query.execute(req) proj_stat = get_ticket_stats(self.stats_provider, tickets) data['proj_progress_stat'] = { 'stats': proj_stat, 'stats_href': req.href.query(proj_stat.qry_args), 'interval_hrefs': [ req.href.query(interval['qry_args']) for interval in proj_stat.intervals ] } ticket_ids = [t['id'] for t in tickets] closed_stat = self.stats_provider.get_ticket_resolution_group_stats( ticket_ids) data['proj_closed_stat'] = { 'stats': closed_stat, 'stats_href': req.href.query(closed_stat.qry_args), 'interval_hrefs': [ req.href.query(interval['qry_args']) for interval in closed_stat.intervals ] } tkt_frequency_stats = {} tkt_duration_stats = {} bmi_stats = [] daily_backlog_chart = {} today = to_datetime(None) if showmetrics: self.env.log.info("getting ticket metrics") tkt_group_metrics = TicketGroupMetrics(self.env, ticket_ids) tkt_frequency_stats = tkt_group_metrics.get_frequency_metrics_stats( ) tkt_duration_stats = tkt_group_metrics.get_duration_metrics_stats() #stat for this month first_day = datetime(today.year, today.month, 1, tzinfo=utc) last_day = last_day_of_month(today.year, today.month) bmi_stats.append( tkt_group_metrics.get_bmi_monthly_stats(first_day, last_day)) # stat for last month last_day = first_day - timedelta(days=1) first_day = datetime(last_day.year, last_day.month, 1, tzinfo=utc) bmi_stats.append( tkt_group_metrics.get_bmi_monthly_stats(first_day, last_day)) # get daily backlog history last_day = datetime(today.year, today.month, today.day, tzinfo=utc) first_day = last_day - timedelta(days=DAYS_BACK) self.env.log.info("getting backlog history") backlog_history = tkt_group_metrics.get_daily_backlog_history( first_day, last_day) daily_backlog_chart = tkt_group_metrics.get_daily_backlog_chart( backlog_history) # Get dialy commits history last_day = datetime(today.year, today.month, today.day, tzinfo=utc) first_day = last_day - timedelta(days=DAYS_BACK) changeset_group_stats = ChangesetsStats(self.env, first_day, last_day) commits_by_date = changeset_group_stats.get_commit_by_date() commits_by_date_chart = changeset_group_stats.get_commit_by_date_chart( commits_by_date) data['project_bmi_stats'] = bmi_stats #self.env.log.info(bmi_stats) data['ticket_frequency_stats'] = tkt_frequency_stats data['ticket_duration_stats'] = tkt_duration_stats data['ds_daily_backlog'] = daily_backlog_chart data['ds_commit_by_date'] = commits_by_date_chart add_stylesheet(req, 'pd/css/dashboard.css') add_stylesheet(req, 'common/css/report.css') return ('pdashboard.html', data, None)
def _render_view(self, req, db, version): version_groups = [] available_groups = [] component_group_available = False ticket_fields = TicketSystem(self.env).get_ticket_fields() # collect fields that can be used for grouping for field in ticket_fields: if field['type'] == 'select' and field['name'] != 'version' \ or field['name'] in ('owner', 'reporter'): available_groups.append({'name': field['name'], 'label': field['label']}) if field['name'] == 'component': component_group_available = True # determine the field currently used for grouping by = None if component_group_available: by = 'component' elif available_groups: by = available_groups[0]['name'] by = req.args.get('by', by) tickets = get_tickets_for_any(self.env, db, 'version', version.name, by) tickets = apply_ticket_permissions(self.env, req, tickets) stat = get_ticket_stats(self.stats_provider, tickets) context = Context.from_request(req) infodivclass = '' if VERSION <= '0.12': infodivclass = 'info' else: infodivclass = 'info trac-progress' data = { 'context': context, 'version': version, 'attachments': AttachmentModule(self.env).attachment_data(context), 'available_groups': available_groups, 'grouped_by': by, 'groups': version_groups, 'infodivclass': infodivclass } data.update(any_stats_data(self.env, req, stat, 'version', version.name)) if by: groups = [] for field in ticket_fields: if field['name'] == by: if 'options' in field: groups = field['options'] if field.get('optional'): groups.insert(0, '') else: cursor = db.cursor() cursor.execute(""" SELECT DISTINCT COALESCE(%s,'') FROM ticket ORDER BY COALESCE(%s,'') """, [by, by]) groups = [row[0] for row in cursor] max_count = 0 group_stats = [] for group in groups: values = group and (group,) or (None, group) group_tickets = [t for t in tickets if t[by] in values] if not group_tickets: continue gstat = get_ticket_stats(self.stats_provider, group_tickets) if gstat.count > max_count: max_count = gstat.count group_stats.append(gstat) gs_dict = {'name': group} gs_dict.update(any_stats_data(self.env, req, gstat, 'version', version.name, by, group)) version_groups.append(gs_dict) for idx, gstat in enumerate(group_stats): gs_dict = version_groups[idx] percent = 1.0 if max_count: percent = float(gstat.count) / float(max_count) * 100 gs_dict['percent_of_max_total'] = percent add_stylesheet(req, 'common/css/roadmap.css') add_script(req, 'common/js/folding.js') return 'version_view.html', data, None
def _render_view(self, req, db): showall = req.args.get('show') == 'all' showmetrics = req.args.get('showmetrics') == 'true' # Get list of milestone object for the project milestones = list(Milestone.select(self.env, showall, db)) stats = [] queries = [] self.env.log.info("getting milestones statistics") for milestone in milestones: tickets = get_tickets_for_milestone(self.env, db, milestone.name, 'owner') stat = get_ticket_stats(self.stats_provider, tickets) stats.append(milestone_stats_data(self.env, req, stat, milestone.name)) project = { 'name': self.env.project_name, 'description': self.env.project_description } data = { 'context': Context.from_request(req), 'milestones': milestones, 'milestone_stats': stats, 'queries': queries, 'showall': showall, 'showmetrics': showmetrics, 'project' : project, 'yui_base_url': self.yui_base_url } self.env.log.info("getting project statistics") project_tickets = get_project_tickets(self.env) # Get project progress stats proj_stat = self.stats_provider.get_ticket_group_stats(project_tickets) data['proj_progress_stat'] = {'stats': proj_stat, 'stats_href': req.href.query(proj_stat.qry_args), 'interval_hrefs': [req.href.query(interval['qry_args']) for interval in proj_stat.intervals]} closed_stat = self.stats_provider.get_ticket_resolution_group_stats(project_tickets) data['proj_closed_stat'] = {'stats': closed_stat, 'stats_href': req.href.query(closed_stat.qry_args), 'interval_hrefs': [req.href.query(interval['qry_args']) for interval in closed_stat.intervals]} tkt_frequency_stats = {} tkt_duration_stats = {} bmi_stats = [] daily_backlog_chart = {} today = datetime.now() if showmetrics: self.env.log.info("getting ticket metrics") tkt_group_metrics = TicketGroupMetrics(self.env, project_tickets) tkt_frequency_stats = tkt_group_metrics.get_frequency_metrics_stats() tkt_duration_stats = tkt_group_metrics.get_duration_metrics_stats() #stat for this month first_day = datetime(today.year, today.month, 1, tzinfo=utc) last_day = last_day_of_month(today.year, today.month) bmi_stats.append(tkt_group_metrics.get_bmi_monthly_stats(first_day, last_day)) # stat for last month last_day = first_day - timedelta(days=1) first_day = datetime(last_day.year, last_day.month, 1, tzinfo=utc) bmi_stats.append(tkt_group_metrics.get_bmi_monthly_stats(first_day, last_day)) # get daily backlog history last_day = datetime(today.year, today.month, today.day, tzinfo=utc) first_day = last_day - timedelta(days=DAYS_BACK) self.env.log.info("getting backlog history") backlog_history = tkt_group_metrics.get_daily_backlog_history(first_day, last_day) daily_backlog_chart = tkt_group_metrics.get_daily_backlog_chart(backlog_history) # Get dialy commits history last_day = datetime(today.year, today.month, today.day, tzinfo=utc) first_day = last_day - timedelta(days=DAYS_BACK) changeset_group_stats = ChangesetsStats(self.env, first_day, last_day) commits_by_date = changeset_group_stats.get_commit_by_date() commits_by_date_chart = changeset_group_stats.get_commit_by_date_chart(commits_by_date) data['project_bmi_stats'] = bmi_stats #self.env.log.info(bmi_stats) data['ticket_frequency_stats'] = tkt_frequency_stats data['ticket_duration_stats'] = tkt_duration_stats data['ds_daily_backlog'] = daily_backlog_chart data['ds_commit_by_date'] = commits_by_date_chart add_stylesheet(req, 'pd/css/dashboard.css') add_stylesheet(req, 'common/css/report.css') return ('pdashboard.html', data, None)
def _render_view(self, req, db, milestone): milestone_groups = [] available_groups = [] component_group_available = False ticket_fields = TicketSystem(self.env).get_ticket_fields() # collect fields that can be used for grouping for field in ticket_fields: if field['type'] == 'select' and field['name'] != 'milestone' \ or field['name'] in ('owner', 'reporter'): available_groups.append({ 'name': field['name'], 'label': field['label'] }) if field['name'] == 'component': component_group_available = True # determine the field currently used for grouping by = None if component_group_available: by = 'component' elif available_groups: by = available_groups[0]['name'] by = req.args.get('by', by) tickets = get_tickets_for_milestone(self.env, db, milestone.name, by) stat = get_ticket_stats(self.stats_provider, tickets) tstat = get_ticket_stats(self.tickettype_stats_provider, tickets) # Parse the from date and adjust the timestamp to the last second of # the day today = to_datetime(None, req.tz) # Get milestone start date from session or use default day back. # TODO: add logic to remember the start date either in db or session. # if req.session.get('mdashboard.fromdate') != None: # # fromdate = parse_date(req.session.get('mdashboard.fromdate'), req.tz) # else: fromdate = today - timedelta(days=self.default_daysback + 1) fromdate = fromdate.replace(hour=23, minute=59, second=59) # Data for milestone and timeline data = { 'fromdate': fromdate, 'milestone': milestone, 'tickethistory': [], 'dates': [], 'ticketstat': {}, 'yui_base_url': self.yui_base_url } data.update(milestone_stats_data(self.env, req, stat, milestone.name)) ticketstat = {'name': 'ticket type'} ticketstat.update( milestone_stats_data(self.env, req, tstat, milestone.name)) data['ticketstat'] = ticketstat #self.env.log.info("ticketstat = %s" % (ticketstat,)) # get list of ticket ids that in the milestone #ctickets = get_tickets_for_milestone(self.env, db, milestone.name, 'type') everytickets = get_every_tickets_in_milestone(db, milestone.name) if everytickets != []: #tkt_history = {} # collect_tickets_status_history(self.env, db, tkt_history, \ # everytickets, milestone) tkt_history = collect_tickets_status_history( self.env, db, everytickets, milestone) if tkt_history != {}: # Sort the key in the history list # returns sorted list of tuple of (key, value) sorted_events = sorted(tkt_history.items(), key=lambda (k, v): (k)) #debug self.env.log.info("sorted_event content") for event in sorted_events: self.env.log.info( "date: %s: event: %s" % (format_date(to_datetime(event[0])), event[1])) # Get first date that ticket enter the milestone min_time = min(sorted_events)[0] #in Epoch Seconds begin_date = to_datetime(min_time).date() end_date = milestone.completed or to_datetime(None).date() # this is array of date in numpy numdates = drange(begin_date, end_date + timedelta(days=1), timedelta(days=1)) tkt_history_table = make_ticket_history_table( self.env, numdates, sorted_events) #debug #self.env.log.info("tkt_history_table: %s", (tkt_history_table,)) #Create a data for the cumulative flow chart. tkt_cumulative_table = make_cumulative_data( self.env, tkt_history_table) #debug #self.env.log.info(tkt_cumulative_table) # creat list of dateobject from dates dates = [] for numdate in numdates: utc_date = num2date(numdate) dates.append(utc_date) #self.env.log.info("%s: %s" % (utc_date, format_date(utc_date, tzinfo=utc))) #prepare Yahoo datasource for comulative flow chart dscumulative = '' for idx, date in enumerate(dates): dscumulative = dscumulative + '{ date: "%s", enter: %d, leave: %d, finish: %d}, ' \ % (format_date(date, tzinfo=utc), tkt_cumulative_table['Enter'][idx], \ tkt_cumulative_table['Leave'][idx], tkt_cumulative_table['Finish'][idx]) data['tickethistory'] = tkt_cumulative_table data['dates'] = dates data['dscumulative'] = '[ ' + dscumulative + ' ];' return 'mdashboard.html', data, None