コード例 #1
0
ファイル: model.py プロジェクト: nyuhuhuu/trachacks
    def get_commit_by_date(self):

        numdates = drange(self.start_date, self.stop_date, timedelta(days=1))

        numcommits = [0 for i in numdates]

        for rev, time, author in self.changesets:

            date = to_datetime(time, utc).date()
            #get index of day in the dates list
            index = bisect(numdates, date2num(date)) - 1

            numcommits[index] += 1

        return (numdates, numcommits)
コード例 #2
0
    def get_commit_by_date(self):

        numdates = drange(self.start_date, self.stop_date, timedelta(days=1))

        numcommits = [0 for i in numdates]

        for rev, time, author in self.changesets:

            date = to_datetime(time, utc).date()
            #get index of day in the dates list
            index = bisect(numdates, date2num(date)) - 1

            numcommits[index] += 1

        return (numdates, numcommits)
コード例 #3
0
start = end - datetime.timedelta(days=4)
dt = datetime.timedelta(hours=1)

print "Finding from %s to %s"%(start,end)
data = []
for item in d.wrange(start,end,dt):
  try:
    data.append( item["pressure"] )
  except KeyError:
    data.append( data[-1] )

print "Plotting"
import pylab
import matplotlib
import matplotlib.dates

fig = pylab.figure()
ax = fig.gca()

ax.plot_date(pylab.drange(start,end,dt),data,"b.-")
pylab.xlabel("Date")
pylab.ylabel("Pressure")
pylab.title("Pressure vs Date")

ax.xaxis.set_major_locator(matplotlib.dates.HourLocator(byhour=[12]))
ax.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%H:%M\n%d/%m/%y'))

fig.savefig("pressure-test.png")
fig.show()

コード例 #4
0
    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
コード例 #5
0
ファイル: model.py プロジェクト: nyuhuhuu/trachacks
    def get_daily_backlog_history(self, start_date, end_date):
        """
            returns list of tuple (date,stats)
                date is date value in epoc time
                stats is dictionary of {'created':[], 'opened':[], 'closed':[]}
        """

        # this is array of date in numpy
        numdates = drange(start_date, end_date + timedelta(days=1), timedelta(days=1))

#        for date in numdates:
#            self.env.log.info(num2date(date))

        end_date = end_date.replace(hour=23, minute=59, second=59)


        # each key is the list of list of ticket.  The index of the list is corresponding
        # to the index of the date in numdates list.
        backlog_stats = {'created':[], 'opened':[], 'closed':[]}

        # initialize backlog_stats

        for date in numdates:
            for key in backlog_stats:
                backlog_stats[key].append([])

        # start by getting the list of opened ticket at the end of the start date.        
        backlog_stats['opened'][0] = self.get_remaning_opened_ticket_on(start_date)

        for ticket in self.tickets:

            # only consider the ticket that was created before end dates.
            if ticket.time_created <= end_date:

                # only track the ticket that create since start_date
                if ticket.time_created >= start_date:
                    # determine index
                    date = ticket.time_created.date()
                    #get index of day in the dates list
                    index = bisect(numdates, date2num(date)) - 1

                    # add ticket created ticket list
                    backlog_stats['created'][index].append(ticket.id)

                for t, author, field, oldvalue, newvalue, permanent in ticket.get_changelog():

                    # determine index
                    date = t.date()
                    #get index of day in the dates list
                    index = bisect(numdates, date2num(date)) - 1

                    if field == 'status' and start_date <= t <= end_date:

                        if newvalue == 'closed':
                            # add ticket created ticket list
                            backlog_stats['closed'][index].append(ticket.id)

                        elif newvalue == 'reopen':
                            backlog_stats['opened'][index].append(ticket.id)

        # update opened ticket list
        for idx, list in enumerate(backlog_stats['opened']):

            if idx > 0:

                # merge list of opened ticket from previous day
                list.extend(backlog_stats['opened'][idx - 1])

                # add created ticket to opened ticket list
                list.extend(backlog_stats['created'][idx])

                # remove closed ticket from opened ticket list.
                for id in backlog_stats['closed'][idx]:
                    try:
                        list.remove(id)
                    except ValueError, e:
                        pass


                list.sort()
コード例 #6
0
    def get_daily_backlog_history(self, start_date, end_date):
        """
            returns list of tuple (date,stats)
                date is date value in epoc time
                stats is dictionary of {'created':[], 'opened':[], 'closed':[]}
        """

        # this is array of date in numpy
        numdates = drange(start_date, end_date + timedelta(days=1),
                          timedelta(days=1))

        #        for date in numdates:
        #            self.env.log.info(num2date(date))

        end_date = end_date.replace(hour=23, minute=59, second=59)

        # each key is the list of list of ticket.  The index of the list is corresponding
        # to the index of the date in numdates list.
        backlog_stats = {'created': [], 'opened': [], 'closed': []}

        # initialize backlog_stats

        for date in numdates:
            for key in backlog_stats:
                backlog_stats[key].append([])

        # start by getting the list of opened ticket at the end of the start date.
        backlog_stats['opened'][0] = self.get_remaning_opened_ticket_on(
            start_date)

        for ticket in self.tickets:

            # only consider the ticket that was created before end dates.
            if ticket.time_created <= end_date:

                # only track the ticket that create since start_date
                if ticket.time_created >= start_date:
                    # determine index
                    date = ticket.time_created.date()
                    #get index of day in the dates list
                    index = bisect(numdates, date2num(date)) - 1

                    # add ticket created ticket list
                    backlog_stats['created'][index].append(ticket.id)

                for t, author, field, oldvalue, newvalue, permanent in ticket.get_changelog(
                ):

                    # determine index
                    date = t.date()
                    #get index of day in the dates list
                    index = bisect(numdates, date2num(date)) - 1

                    if field == 'status' and start_date <= t <= end_date:

                        if newvalue == 'closed':
                            # add ticket created ticket list
                            backlog_stats['closed'][index].append(ticket.id)

                        elif newvalue == 'reopen':
                            backlog_stats['opened'][index].append(ticket.id)

        # update opened ticket list
        for idx, list in enumerate(backlog_stats['opened']):

            if idx > 0:

                # merge list of opened ticket from previous day
                list.extend(backlog_stats['opened'][idx - 1])

                # add created ticket to opened ticket list
                list.extend(backlog_stats['created'][idx])

                # remove closed ticket from opened ticket list.
                for id in backlog_stats['closed'][idx]:
                    try:
                        list.remove(id)
                    except ValueError, e:
                        pass

                list.sort()
コード例 #7
0
    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