<commit_before>#
# compute critical path and constrained subpaths given time and blocked-by data
#
import sys
import pytz, tzlocal
from dateutil.parser import parse as parse_dt
from collections import defaultdict
import github3
import jira

def clean_cr(s):
    if s == None:
        return ''
    return s.replace('\r', '\n').rstrip()

class issue(object):
#     num = 0                 #int
#     assignee = ""           #string
#     title = ""              #string
#     body = ""               #string
#     blocked_by = []         #list of ints / issues
#     auto_bb = []            #list of int id's of auto-blocked (don't display)
#     estimate = 0.5          #float, days
#     labels = []             #list of strings
#     mil_name = ''           #string
#     mil_start = ''          #datetime or ''
#     mil_due = ''            #datetime or ''

    def __init__(self, num=0, ass='', title="", body="", bb=[], est=0.5, name=""):
        self.num = num
        self.name = name
        self.assignee = ass
        self.title = title
        self.body = body
        self.estimate = est
        self.labels = []
        self.comments = []
        self.blocked_by = []
        self.auto_bb = []
        self.mil_name = ''
        self.mil_start = ''
        self.mil_due = ''
        self.closed = False

    def crit_path(self):
        days = 0
        path = []
        for bb in self.blocked_by:
            crit, nupth = bb.crit_path()
            if crit > days:
                days = crit
                path = nupth
        return self.estimate + days, path + [self]
    
    def is_bb(self, issue):
        return issue in self.blocked_by

    def __repr__(self):
#         return "<issue %d %s>" % (self.num, self.title)
        return "<#%d|%s|%s>" % (self.num, self.assignee, clean_cr(self.title))
    
    def bigrepr(self):
        return "<#%d|%s|%s|%s est: %.2f mil: %s|%s|%s bb: %s labels: %s>" % (self.num, self.assignee, 
                        clean_cr(self.title), clean_cr(self.body).replace('\n', ' '), self.estimate,
                        clean_cr(self.mil_name), 
                        self.mil_start.strftime("%Y-%m-%d_%H:%M") if self.mil_start else '', 
                        self.mil_due.strftime("%Y-%m-%d_%H:%M") if self.mil_due else '',
                        [x.num for x in self.blocked_by], 
                        self.labels)

#find previous issue numerically for assignee
def map_prev_assignee(map, iss):
    i = iss.num - 1
    while i >= 0:
        if i in map and map[i].assignee == iss.assignee:
            return map[i]
        i -= 1
    return None

#make sure issues cannot overlap
#we do this by setting up a block between all issues for a given assignee
def self_block(map, issues):
    assignees = defaultdict(list)
    for iss in map.values():
        assignees[iss.assignee].append(iss)
    for ass in assignees:
        unblocked = []
        for iss in assignees[ass]:
            #determine if any of our bb's are assigned to us
            flag = False
            for bb in iss.blocked_by:
                if bb.assignee == ass:
                    flag = True
                    break
            #if not, auto-bb previous issue if any
            if not flag:
                unblocked.append(iss)
        for iss in unblocked:
            prev = map_prev_assignee(map, iss)
#             print "prev for", iss.num, "is:", (prev.num if prev else "NONE")
            if prev != None and not prev.is_bb(iss):
                iss.blocked_by.append(prev)
                iss.auto_bb.append(prev.num)

#parse BB and TE
#ensure no parallel work for one assignee
def parse_issues(issues):
    print "ISSUES:", type(issues[0])
    map = {}
    for iss in issues:
        if iss == None:
            continue
        map[iss.num] = iss
    print"MAP:", map
    for iss in issues:
        if iss == None:
            continue
        #replace id nums w issue object
        for i in range(len(iss.blocked_by)):
            bb = iss.blocked_by[i]
            if bb in map:
                iss.blocked_by[i] = map[bb]
            else:<commit_msg>bugaboo<commit_after>#
# compute critical path and constrained subpaths given time and blocked-by data
#
import sys
import pytz, tzlocal
from dateutil.parser import parse as parse_dt
from collections import defaultdict
import github3
import jira

def clean_cr(s):
    if s == None:
        return ''
    return s.replace('\r', '\n').rstrip()

class issue(object):
#     num = 0                 #int
#     assignee = ""           #string
#     title = ""              #string
#     body = ""               #string
#     blocked_by = []         #list of ints / issues
#     auto_bb = []            #list of int id's of auto-blocked (don't display)
#     estimate = 0.5          #float, days
#     labels = []             #list of strings
#     mil_name = ''           #string
#     mil_start = ''          #datetime or ''
#     mil_due = ''            #datetime or ''

    def __init__(self, num=0, ass='', title="", body="", bb=[], est=0.5, name=""):
        self.num = num
        self.name = name
        self.assignee = ass
        self.title = title
        self.body = body
        self.estimate = est
        self.labels = []
        self.comments = []
        self.blocked_by = []
        self.auto_bb = []
        self.mil_name = ''
        self.mil_start = ''
        self.mil_due = ''
        self.closed = False

    def crit_path(self):
        days = 0
        path = []
        for bb in self.blocked_by:
            crit, nupth = bb.crit_path()
            if crit > days:
                days = crit
                path = nupth
        return self.estimate + days, path + [self]
    
    def is_bb(self, issue):
        return issue in self.blocked_by

    def __repr__(self):
#         return "<issue %d %s>" % (self.num, self.title)
        return "<#%d|%s|%s>" % (self.num, self.assignee, clean_cr(self.title))
    
    def bigrepr(self):
        return "<#%d|%s|%s|%s est: %.2f mil: %s|%s|%s bb: %s labels: %s>" % (self.num, self.assignee, 
                        clean_cr(self.title), clean_cr(self.body).replace('\n', ' '), self.estimate,
                        clean_cr(self.mil_name), 
                        self.mil_start.strftime("%Y-%m-%d_%H:%M") if self.mil_start else '', 
                        self.mil_due.strftime("%Y-%m-%d_%H:%M") if self.mil_due else '',
                        [x.num for x in self.blocked_by], 
                        self.labels)

#find previous issue numerically for assignee
def map_prev_assignee(map, iss):
    i = iss.num - 1
    while i >= 0:
        if i in map and map[i].assignee == iss.assignee:
            return map[i]
        i -= 1
    return None

#make sure issues cannot overlap
#we do this by setting up a block between all issues for a given assignee
def self_block(map, issues):
    assignees = defaultdict(list)
    for iss in map.values():
        assignees[iss.assignee].append(iss)
    for ass in assignees:
        unblocked = []
        for iss in assignees[ass]:
            #determine if any of our bb's are assigned to us
            flag = False
            for bb in iss.blocked_by:
                if bb.assignee == ass:
                    flag = True
                    break
            #if not, auto-bb previous issue if any
            if not flag:
                unblocked.append(iss)
        print "UNBLOCKED:", unblocked
        prev = None
        for iss in unblocked:
#             prev = map_prev_assignee(map, iss)
            print "prev for", iss.num, "is:", (prev.num if prev else "NONE")
            if prev != None and not prev.is_bb(iss):
                iss.blocked_by.append(prev)
                iss.auto_bb.append(prev.num)
            prev = iss

#parse BB and TE
#ensure no parallel work for one assignee
def parse_issues(issues):
    print "ISSUES:", type(issues[0])
    map = {}
    for iss in issues:
        if iss == None:
            continue
        map[iss.num] = iss
    print"MAP:", map
    for iss in issues:
        if iss == None:
            continue
        #replace id nums w issue object
        for i in range(len(iss.blocked_by)):
            bb = iss.blocked_by[i]
            if bb in map:
                iss.blocked_by[i] = map[bb]
            else:
{'fraction_non_alphanumeric': 0.11674088337946804, 'fraction_numerical': 0.0031291370802744014, 'mean_word_length': 1.6247631080227416, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '2800792', 'n_tokens_mistral': 2632, 'n_tokens_neox': 2513, 'n_words': 744}