def get_avg_duration(self, startDate = None, endDate = None, repos = None): """get avg duration of pull requests args: startDate: endDate: repos: rackhd repository return: the prs avg duration """ if self.db == None: self.db = SQLiteDB() try: items = [] items.append("select avg(julianday(endDate)-julianday(createDate)) from PullRequests where user = '******' " % self.name) if startDate != None : items.append("and createDate >= '%s' " % startDate) if endDate != None : items.append("and createDate < '%s' " % endDate) if repos != None : items.append("and repo in ( " ) buffer_repo = None for repo in repos: if buffer_repo != None: items.append("'%s'," % buffer_repo) #add the previous repo buffer_repo = repo items.append("'%s')" % buffer_repo) select_sql = ' '.join(items) result = self.db.getResult(select_sql) if result[0][0] == None: return 0.0 else: return result[0][0] except Exception as e: print ("Error: %s" % e)
def get_pr_duration(self, startDate = None, endDate = None, repos = None): """get pull requests' duration list args: startDate: endDate: repos: rackhd repository return: all pr duration list """ if self.db == None: self.db = SQLiteDB() try: items = [] items.append("select julianday(endDate)-julianday(createDate) from PullRequests where user = '******' " % self.name) if startDate != None : items.append("and createDate >= '%s' " % startDate) if endDate != None : items.append("and createDate < '%s' " % endDate) if repos != None : items.append("and repo in ( " ) buffer_repo = None for repo in repos: # 添加上一个repo if buffer_repo != None: items.append("'%s'," % buffer_repo) #add the previous repo buffer_repo = repo items.append("'%s')" % buffer_repo) select_sql = ' '.join(items) result = self.db.getResult(select_sql) if len(result)!= 0: return [x[0] for x in result] else: return result except Exception as e: print ("Error: %s" % e)
def get_three_top_review_from(self, startDate, endDate, repos = None): """get the three top users that he or her be reviewed from args: startDate: endDate repos: rackhd repository return: the three top (user, count) """ if self.db == None: self.db = SQLiteDB() try: items = [] items.append("select from_user, count(*) Count from Comments where from_user != to_user and to_user = '******'" % self.name) items.append("and submitDate >= '%s'" % startDate) items.append("and submitDate < '%s'" % endDate) if repos != None: items.append("and repo in (" ) buffer_repo = None for repo in repos: if buffer_repo != None: items.append("'%s'," % buffer_repo) buffer_repo = repo items.append("'%s')" % buffer_repo) items.append("group by from_user order by Count DESC") select_sql = ' '.join(items) #print(select_sql) result = self.db.getResult(select_sql) if result[0][0] == None: print("result is None. Comments Table is Null. Or select sql may be wrong!") #print(result[0:15]) return result[0:3] except Exception as e: print ("Error: %s" % e)
def get_comments_count(self, startDate = None, endDate = None, repos = None): """get review comments count args: startDate: endDate: repos: rackhd repository return: the count of comments """ if self.db == None: self.db = SQLiteDB() try: items = [] items.append("select count(*) from Comments where from_user = '******'" % self.name) if startDate != None : items.append("and submitDate >= '%s'" % startDate) if endDate != None : items.append("and submitDate < '%s'" % endDate) if repos != None : items.append("and repo in (" ) buffer_repo = None for repo in repos: if buffer_repo != None: items.append("'%s'," % buffer_repo) #add the previous repo buffer_repo = repo items.append("'%s')" % buffer_repo) select_sql = ' '.join(items) result = self.db.getResult(select_sql) if result[0][0] == None: return 0.0 else: return result[0][0] except Exception as e: print ("Error: %s" % e)
def set_rackhd(self): """select all users from USERS table and set rackhd members """ if self.db == None: self.db = SQLiteDB() try: sql = "select distinct userName from USERS" result = self.db.getResult(sql) if result[0][0] != None: team_members = [x[0] for x in result] self.rackhd.set_team_members(team_members) else: print("USERS table is empty") except Exception as e: print("Error: %s" % e)
def set_no_rackhd(self): """select from DB and set the no_rackhd members """ if self.db == None: self.db = SQLiteDB() try: sql = "select distinct user from PullRequests where user NOT IN (select distinct userName from USERS)" result = self.db.getResult(sql) if result[0][0] != None: team_members = [x[0] for x in result] self.no_rackhd.set_team_members(team_members) else: print( " select sql may wrong, or pull request don't have no_rackhd members' pr" ) except Exception as e: print("Error: %s" % e)
def get_pr_rank(self, startDate, endDate, repos = None, isMerged=None): """get the pr count rank in all users args: startDate: endDate repos: rackhd repository isMerged: True or False (pr be merged or not) return: the len(less count)/len(result)*100 """ if self.db == None: self.db = SQLiteDB() try: items = [] items.append("select user, count(*) Count from PullRequests where") if isMerged == None: items.append("createDate >= '%s'" % startDate) items.append("and createDate < '%s'" % endDate) else: items.append("merged == '%s'" % isMerged) items.append("and endDate >= '%s'" % startDate) items.append("and endDate < '%s'" % endDate) if repos != None: items.append("and repo in (" ) buffer_repo = None for repo in repos: if buffer_repo != None: items.append("'%s'," % buffer_repo) buffer_repo = repo items.append("'%s')" % buffer_repo) items.append("group by user order by Count") select_sql = ' '.join(items) #print(select_sql) result = self.db.getResult(select_sql) if result[0][0] == None: print("result is None. Select sql may be wrong!") for line in result: if line[0] == self.name: user_info = line break beat_rank = round(result.index(user_info)/len(result)*100, 2) #print(beat_rank) return beat_rank except Exception as e: print ("Error: %s" % e)
def get_pr_count(self, startDate = None, endDate = None, repos = None, isMerged=None): """ get user commit pr count args: startDate: endDate: repos: rackhd repository isMerged: True or False (pr be merged or not) return: the count of pr """ #count = SQLiteDB().selectUserPRcount(self.name, startDate, endDate, repos) if self.db == None: self.db = SQLiteDB() try: items = [] items.append("select count(*) from PullRequests where user = '******'" % self.name) if isMerged == None: if startDate != None: items.append("and createDate >= '%s'" % startDate) if endDate != None: items.append("and createDate < '%s'" % endDate) else: items.append("and merged == '%s'" % isMerged) if startDate != None: items.append("and endDate >= '%s'" % startDate) if endDate != None: items.append("and endDate < '%s'" % endDate) if repos != None: items.append("and repo in (" ) buffer_repo = None for repo in repos: if buffer_repo != None: items.append("'%s'," % buffer_repo) #add the previous repo buffer_repo = repo items.append("'%s')" % buffer_repo) select_sql = ' '.join(items) result = self.db.getResult(select_sql) if result[0][0] == None: return 0.0 else: return result[0][0] except Exception as e: print ("Error: %s" % e)
def get_comments_rank(self, startDate, endDate, repos = None): """get the comments count rank in all users args: startDate: endDate repos: rackhd repository return: the len(less count)/len(result)*100 """ if self.db == None: self.db = SQLiteDB() try: items = [] items.append("select from_user, count(*) Count from Comments where") items.append("submitDate >= '%s'" % startDate) items.append("and submitDate < '%s'" % endDate) if repos != None: items.append("and repo in (" ) buffer_repo = None for repo in repos: if buffer_repo != None: items.append("'%s'," % buffer_repo) buffer_repo = repo items.append("'%s')" % buffer_repo) items.append("group by from_user order by Count") select_sql = ' '.join(items) #print(select_sql) result = self.db.getResult(select_sql) if result[0][0] == None: print("result is None. Comments Table is Null. Or select sql may be wrong!") for line in result: if line[0] == self.name: user_info = line break beat_rank = round(result.index(user_info)/len(result)*100, 2) #print(beat_rank) return beat_rank except Exception as e: print ("Error: %s" % e)
class User(object): """ """ def __init__(self, name, teamName): self.name = name self.teamName = teamName self.db = SQLiteDB() def get_pr_rank(self, startDate, endDate, repos = None, isMerged=None): """get the pr count rank in all users args: startDate: endDate repos: rackhd repository isMerged: True or False (pr be merged or not) return: the len(less count)/len(result)*100 """ if self.db == None: self.db = SQLiteDB() try: items = [] items.append("select user, count(*) Count from PullRequests where") if isMerged == None: items.append("createDate >= '%s'" % startDate) items.append("and createDate < '%s'" % endDate) else: items.append("merged == '%s'" % isMerged) items.append("and endDate >= '%s'" % startDate) items.append("and endDate < '%s'" % endDate) if repos != None: items.append("and repo in (" ) buffer_repo = None for repo in repos: if buffer_repo != None: items.append("'%s'," % buffer_repo) buffer_repo = repo items.append("'%s')" % buffer_repo) items.append("group by user order by Count") select_sql = ' '.join(items) #print(select_sql) result = self.db.getResult(select_sql) if result[0][0] == None: print("result is None. Select sql may be wrong!") for line in result: if line[0] == self.name: user_info = line break beat_rank = round(result.index(user_info)/len(result)*100, 2) #print(beat_rank) return beat_rank except Exception as e: print ("Error: %s" % e) def get_comments_rank(self, startDate, endDate, repos = None): """get the comments count rank in all users args: startDate: endDate repos: rackhd repository return: the len(less count)/len(result)*100 """ if self.db == None: self.db = SQLiteDB() try: items = [] items.append("select from_user, count(*) Count from Comments where") items.append("submitDate >= '%s'" % startDate) items.append("and submitDate < '%s'" % endDate) if repos != None: items.append("and repo in (" ) buffer_repo = None for repo in repos: if buffer_repo != None: items.append("'%s'," % buffer_repo) buffer_repo = repo items.append("'%s')" % buffer_repo) items.append("group by from_user order by Count") select_sql = ' '.join(items) #print(select_sql) result = self.db.getResult(select_sql) if result[0][0] == None: print("result is None. Comments Table is Null. Or select sql may be wrong!") for line in result: if line[0] == self.name: user_info = line break beat_rank = round(result.index(user_info)/len(result)*100, 2) #print(beat_rank) return beat_rank except Exception as e: print ("Error: %s" % e) def get_three_top_review_to(self, startDate, endDate, repos = None): """get the three top users who he or her reviews to args: startDate: endDate repos: rackhd repository return: the three top (user, count) """ if self.db == None: self.db = SQLiteDB() try: items = [] items.append("select to_user, count(*) Count from Comments where from_user != to_user and from_user = '******'" % self.name) items.append("and submitDate >= '%s'" % startDate) items.append("and submitDate < '%s'" % endDate) if repos != None: items.append("and repo in (" ) buffer_repo = None for repo in repos: if buffer_repo != None: items.append("'%s'," % buffer_repo) buffer_repo = repo items.append("'%s')" % buffer_repo) items.append("group by to_user order by Count DESC") select_sql = ' '.join(items) #print(select_sql) result = self.db.getResult(select_sql) if result[0][0] == None: print("result is None. Comments Table is Null. Or select sql may be wrong!") #print(result) return result[0:3] except Exception as e: print ("Error: %s" % e) def get_three_top_review_from(self, startDate, endDate, repos = None): """get the three top users that he or her be reviewed from args: startDate: endDate repos: rackhd repository return: the three top (user, count) """ if self.db == None: self.db = SQLiteDB() try: items = [] items.append("select from_user, count(*) Count from Comments where from_user != to_user and to_user = '******'" % self.name) items.append("and submitDate >= '%s'" % startDate) items.append("and submitDate < '%s'" % endDate) if repos != None: items.append("and repo in (" ) buffer_repo = None for repo in repos: if buffer_repo != None: items.append("'%s'," % buffer_repo) buffer_repo = repo items.append("'%s')" % buffer_repo) items.append("group by from_user order by Count DESC") select_sql = ' '.join(items) #print(select_sql) result = self.db.getResult(select_sql) if result[0][0] == None: print("result is None. Comments Table is Null. Or select sql may be wrong!") #print(result[0:15]) return result[0:3] except Exception as e: print ("Error: %s" % e) def get_pr_count(self, startDate = None, endDate = None, repos = None, isMerged=None): """ get user commit pr count args: startDate: endDate: repos: rackhd repository isMerged: True or False (pr be merged or not) return: the count of pr """ #count = SQLiteDB().selectUserPRcount(self.name, startDate, endDate, repos) if self.db == None: self.db = SQLiteDB() try: items = [] items.append("select count(*) from PullRequests where user = '******'" % self.name) if isMerged == None: if startDate != None: items.append("and createDate >= '%s'" % startDate) if endDate != None: items.append("and createDate < '%s'" % endDate) else: items.append("and merged == '%s'" % isMerged) if startDate != None: items.append("and endDate >= '%s'" % startDate) if endDate != None: items.append("and endDate < '%s'" % endDate) if repos != None: items.append("and repo in (" ) buffer_repo = None for repo in repos: if buffer_repo != None: items.append("'%s'," % buffer_repo) #add the previous repo buffer_repo = repo items.append("'%s')" % buffer_repo) select_sql = ' '.join(items) result = self.db.getResult(select_sql) if result[0][0] == None: return 0.0 else: return result[0][0] except Exception as e: print ("Error: %s" % e) def get_comments_count(self, startDate = None, endDate = None, repos = None): """get review comments count args: startDate: endDate: repos: rackhd repository return: the count of comments """ if self.db == None: self.db = SQLiteDB() try: items = [] items.append("select count(*) from Comments where from_user = '******'" % self.name) if startDate != None : items.append("and submitDate >= '%s'" % startDate) if endDate != None : items.append("and submitDate < '%s'" % endDate) if repos != None : items.append("and repo in (" ) buffer_repo = None for repo in repos: if buffer_repo != None: items.append("'%s'," % buffer_repo) #add the previous repo buffer_repo = repo items.append("'%s')" % buffer_repo) select_sql = ' '.join(items) result = self.db.getResult(select_sql) if result[0][0] == None: return 0.0 else: return result[0][0] except Exception as e: print ("Error: %s" % e) def get_avg_duration(self, startDate = None, endDate = None, repos = None): """get avg duration of pull requests args: startDate: endDate: repos: rackhd repository return: the prs avg duration """ if self.db == None: self.db = SQLiteDB() try: items = [] items.append("select avg(julianday(endDate)-julianday(createDate)) from PullRequests where user = '******' " % self.name) if startDate != None : items.append("and createDate >= '%s' " % startDate) if endDate != None : items.append("and createDate < '%s' " % endDate) if repos != None : items.append("and repo in ( " ) buffer_repo = None for repo in repos: if buffer_repo != None: items.append("'%s'," % buffer_repo) #add the previous repo buffer_repo = repo items.append("'%s')" % buffer_repo) select_sql = ' '.join(items) result = self.db.getResult(select_sql) if result[0][0] == None: return 0.0 else: return result[0][0] except Exception as e: print ("Error: %s" % e) def get_pr_duration(self, startDate = None, endDate = None, repos = None): """get pull requests' duration list args: startDate: endDate: repos: rackhd repository return: all pr duration list """ if self.db == None: self.db = SQLiteDB() try: items = [] items.append("select julianday(endDate)-julianday(createDate) from PullRequests where user = '******' " % self.name) if startDate != None : items.append("and createDate >= '%s' " % startDate) if endDate != None : items.append("and createDate < '%s' " % endDate) if repos != None : items.append("and repo in ( " ) buffer_repo = None for repo in repos: # 添加上一个repo if buffer_repo != None: items.append("'%s'," % buffer_repo) #add the previous repo buffer_repo = repo items.append("'%s')" % buffer_repo) select_sql = ' '.join(items) result = self.db.getResult(select_sql) if len(result)!= 0: return [x[0] for x in result] else: return result except Exception as e: print ("Error: %s" % e)
def __init__(self, name, teamName): self.name = name self.teamName = teamName self.db = SQLiteDB()
def __init__(self): self.rackhd = Team("rackhd", []) self.no_rackhd = Team("no_rackhd", []) self.db = SQLiteDB() self.set_rackhd() self.set_no_rackhd()
class Organization(object): """rackhd and no_rackhd organization """ def __init__(self): self.rackhd = Team("rackhd", []) self.no_rackhd = Team("no_rackhd", []) self.db = SQLiteDB() self.set_rackhd() self.set_no_rackhd() def set_rackhd(self): """select all users from USERS table and set rackhd members """ if self.db == None: self.db = SQLiteDB() try: sql = "select distinct userName from USERS" result = self.db.getResult(sql) if result[0][0] != None: team_members = [x[0] for x in result] self.rackhd.set_team_members(team_members) else: print("USERS table is empty") except Exception as e: print("Error: %s" % e) def set_no_rackhd(self): """select from DB and set the no_rackhd members """ if self.db == None: self.db = SQLiteDB() try: sql = "select distinct user from PullRequests where user NOT IN (select distinct userName from USERS)" result = self.db.getResult(sql) if result[0][0] != None: team_members = [x[0] for x in result] self.no_rackhd.set_team_members(team_members) else: print( " select sql may wrong, or pull request don't have no_rackhd members' pr" ) except Exception as e: print("Error: %s" % e) def draw_pr_count_monthly(self, startDate, endDate, repos=None): """ 1.1 draw pr count monthly with rackhd and no-rackhd args: startDate: endDate: repos: rackhd repository """ month, rackhd_created_count = self.rackhd.get_pr_count_monthly( startDate, endDate, repos) _, rackhd_merged_count = self.rackhd.get_pr_count_monthly( startDate, endDate, repos, isMerged=True) _, rackhd_unmerged_count = self.rackhd.get_pr_count_monthly( startDate, endDate, repos, isMerged=False) _, no_rackhd_created_count = self.no_rackhd.get_pr_count_monthly( startDate, endDate, repos) _, no_rackhd_merged_count = self.no_rackhd.get_pr_count_monthly( startDate, endDate, repos, isMerged=True) _, no_rackhd_unmerged_count = self.no_rackhd.get_pr_count_monthly( startDate, endDate, repos, isMerged=False) ind = np.linspace(0.5, 9.5, len(month)) # y_ind = range(0, max(rackhd_created_count)+200, 100) fig, ax = plt.subplots(figsize=(12, 6)) plt.plot(ind, rackhd_created_count, 'r--^', linewidth=1, label='rackhd create pr count') plt.plot(ind, rackhd_merged_count, 'r-*', linewidth=1, label='rackhd merged pr count') plt.plot(ind, rackhd_unmerged_count, 'r-.o', linewidth=1, label='rackhd unmerged pr count') plt.plot(ind, no_rackhd_created_count, 'c--^', linewidth=1, label='norackhd create pr count') plt.plot(ind, no_rackhd_merged_count, 'c-*', linewidth=1, label='norackhd merged pr count') plt.plot(ind, no_rackhd_unmerged_count, 'c-.o', linewidth=1, label='norackhd unmerged pr count') plt.xticks(ind, month, rotation=30) # plt.yticks(y_ind) plt.xlabel('Month') plt.ylabel('PR Count') plt.title('PR Count Monthly') plt.legend() canvas = FigureCanvas(fig) png_output = BytesIO() canvas.print_png(png_output) return png_output.getvalue() def draw_comments_monthly(self, startDate, endDate, repos=None): """ 1.2 draw review count monthly with rackhd and no-rackhd args: startDate: endDate: repos: rackhd repository """ month, rackhd_comments_count = self.rackhd.get_comments_count_monthly( startDate, endDate, repos) _, no_rackhd_comments_count = self.no_rackhd.get_comments_count_monthly( startDate, endDate, repos) x_ind = np.linspace(0.5, 9.5, len(month)) y_ind = range( 0, max(rackhd_comments_count + no_rackhd_comments_count) + 400, 100) fig, ax = plt.subplots(figsize=(12, 6)) plt.plot(x_ind, rackhd_comments_count, 'r--^', linewidth=1, label='rackhd comments count') plt.plot(x_ind, no_rackhd_comments_count, 'c--^', linewidth=1, label='norackhd comments count') plt.xticks(x_ind, month, rotation=30) plt.yticks(y_ind) plt.xlabel('Month') plt.ylabel('Review Count') plt.title('Review Count Monthly') plt.legend() canvas = FigureCanvas(fig) png_output = BytesIO() canvas.print_png(png_output) return png_output.getvalue()