<commit_before>from trac.core import *
from pkg_resources import resource_filename
from trac.config import Option, IntOption, ListOption, BoolOption
from trac.web.api import IRequestHandler, Href
from trac.util.translation import _
from trac.web.chrome import add_stylesheet, add_script, INavigationContributor, ITemplateProvider
import datetime
from trac.web.chrome import Chrome
from trac.util.datefmt import utc, to_timestamp
from genshi.template import TemplateLoader
from genshi.filters.transform import Transformer
from trac.web.api import ITemplateStreamFilter



class TracSprints(Component):
    implements(IRequestHandler, ITemplateProvider)
    
    #key = Option('github', 'apitoken', '', doc=""" """)

    def __init__(self):
        self.db = self.env.get_db_cnx()
        self.defaultOrder = ['closed', 'accepted', 'assigned', 'new', 'reopened']
        self.colors = ['green', 'yellow', 'orange', 'red', 'purple']
        self.scaleFactor = 3
        self.currentMilestone = False

   
    # IRequestHandler methods
    def match_request(self, req):
        self.env.log.debug("Match Request")
        serve = req.path_info.rstrip('/') == '/burndown'
        self.env.log.debug("Handle Request: %s" % serve)
        if req.args.get('milestone'):
            cursor = self.db.cursor()
            sql = "select name from milestone where (name = '%s')" % req.args.get('milestone')
            cursor.execute(sql)
            for name in cursor:
                self.currentMilestone = req.args.get('milestone')

        return serve
 
    def get_milestones(self):
        cursor = self.db.cursor()
        sql = "select name from milestone where (completed = 0)"
        cursor.execute(sql)
        self.env.log.debug("sql: %s" % sql)
        m = []
        for name in cursor:
            self.env.log.debug("name: %s" % name)
            n = {
                'name': name,
                'count': 0
            }
            m.append(n)
        
        for item in m:
            sql = "select count(*) as nCount from ticket where (milestone = '%s')" % item['name']
            cursor.execute(sql)
            for count in cursor:
                item['count'] = count

        return m
    
    def get_users(self):
        devs = self.env.get_known_users()
        odevs = []
        for username,name,email in devs:
            data = {
                'username': username,
                'name': name,
                'email': email
            }
            odevs.append(data)
        self.env.log.debug("devs: %s" % odevs)
        return odevs

    def get_dev_totals(self):
        users = self.get_users()
        data = []
        for u in users:
            tot = self.get_ordered_totals(u['username'])
            u['totals'] = tot
            data.append(u)

        return data

    def get_totals(self, user=None):
        cursor = self.db.cursor()
        if not user == None:
            sql = 'select status, count(*) as ncount from ticket where (milestone = "%s") and (owner = "%s") group by status' % (self.currentMilestone, user)
        else:
            sql = 'select status, count(*) as ncount from ticket where (milestone = "%s") group by status' % self.currentMilestone
        cursor.execute(sql)
        data = {}
        c = 0
        for status, count in cursor:
            data[status] = {
                'status': status,
                'count': count,
                'percent': 0,
                'width': 0
            }
            c = c + 1
        return data

    def get_ordered_totals(self, user=None):
        data = self.get_totals(user)
        ordered = []

        for k in self.defaultOrder:
            try:
                ordered.append(data[k])
            except KeyError:<commit_msg>Removed users from the list that didn't have tickets for a milestone<commit_after>from trac.core import *
from pkg_resources import resource_filename
from trac.config import Option, IntOption, ListOption, BoolOption
from trac.web.api import IRequestHandler, Href
from trac.util.translation import _
from trac.web.chrome import add_stylesheet, add_script, INavigationContributor, ITemplateProvider
import datetime
from trac.web.chrome import Chrome
from trac.util.datefmt import utc, to_timestamp
from genshi.template import TemplateLoader
from genshi.filters.transform import Transformer
from trac.web.api import ITemplateStreamFilter



class TracSprints(Component):
    implements(IRequestHandler, ITemplateProvider)
    
    #key = Option('github', 'apitoken', '', doc=""" """)

    def __init__(self):
        self.db = self.env.get_db_cnx()
        self.defaultOrder = ['closed', 'accepted', 'assigned', 'new', 'reopened']
        self.colors = ['green', 'yellow', 'orange', 'red', 'purple']
        self.scaleFactor = 3
        self.currentMilestone = False

   
    # IRequestHandler methods
    def match_request(self, req):
        self.env.log.debug("Match Request")
        serve = req.path_info.rstrip('/') == '/burndown'
        self.env.log.debug("Handle Request: %s" % serve)
        if req.args.get('milestone'):
            cursor = self.db.cursor()
            sql = "select name from milestone where (name = '%s')" % req.args.get('milestone')
            cursor.execute(sql)
            for name in cursor:
                self.currentMilestone = req.args.get('milestone')

        return serve
 
    def get_milestones(self):
        cursor = self.db.cursor()
        sql = "select name from milestone where (completed = 0)"
        cursor.execute(sql)
        self.env.log.debug("sql: %s" % sql)
        m = []
        for name in cursor:
            self.env.log.debug("name: %s" % name)
            n = {
                'name': name,
                'count': 0
            }
            m.append(n)
        
        for item in m:
            sql = "select count(*) as nCount from ticket where (milestone = '%s')" % item['name']
            cursor.execute(sql)
            for count in cursor:
                item['count'] = count

        return m
    
    def get_users(self):
        devs = self.env.get_known_users()
        odevs = []
        for username,name,email in devs:
            data = {
                'username': username,
                'name': name,
                'email': email
            }
            odevs.append(data)
        self.env.log.debug("devs: %s" % odevs)
        return odevs

    def get_dev_totals(self):
        users = self.get_users()
        data = []
        for u in users:
            tot = self.get_ordered_totals(u['username'])
            count = 0
            for i in tot:
                count = count + i['count']

            if count > 0:
                u['totals'] = tot
                data.append(u)

        return data

    def get_totals(self, user=None):
        cursor = self.db.cursor()
        if not user == None:
            sql = 'select status, count(*) as ncount from ticket where (milestone = "%s") and (owner = "%s") group by status' % (self.currentMilestone, user)
        else:
            sql = 'select status, count(*) as ncount from ticket where (milestone = "%s") group by status' % self.currentMilestone
        cursor.execute(sql)
        data = {}
        c = 0
        for status, count in cursor:
            data[status] = {
                'status': status,
                'count': count,
                'percent': 0,
                'width': 0
            }
            c = c + 1
        return data

    def get_ordered_totals(self, user=None):
        data = self.get_totals(user)
        ordered = []

        for k in self.defaultOrder:
            try:
                ordered.append(data[k])
            except KeyError:
{'fraction_non_alphanumeric': 0.11388131411505, 'fraction_numerical': 0.0020776522529541617, 'mean_word_length': 1.894400601277715, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1523400', 'n_tokens_mistral': 2269, 'n_tokens_neox': 2164, 'n_words': 600}