Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions all_contribution_total.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# AUTHOR: hieulq

import copy
import time
import requests

# Change this list based on your member's info
USER_LIST = ['hieulq', 'duonghq', 'namnh', 'daidv', 'trungnv', 'kiennt26', 'tovin07']

# No need to change in case of changing Stackalytics API or changing cycle
CONTRIB_URL = "http://stackalytics.com/api/1.0/contribution"
RELEASE = "pike"

# Common query info
PROJECT_TYPE = "openstack"
COMPANY = "fujitsu"
PAYLOAD = {'release': RELEASE, 'project_type': PROJECT_TYPE,
'company': COMPANY}


def get_statistics(is_member=False):
total_ps, total_cm, total_rv, total_mbp, total_rbp = 0, 0, 0, 0, 0
params = copy.deepcopy(PAYLOAD)
if is_member:
params['start_date'] = int(time.time() - 604800)
params['end_date'] = int(time.time())

for user in USER_LIST:
params['user_id'] = user
resp = requests.get(CONTRIB_URL, params=params)
if resp.ok:
parsed = resp.json()['contribution']
user_ps_count = parsed['patch_set_count']
user_cm_count = parsed['commit_count']
user_bp_merge = parsed['completed_blueprint_count']
user_bp_review = parsed['drafted_blueprint_count']
user_rv_count = parsed['marks']['-1'] + parsed['marks']['1'] + \
parsed['marks']['-2'] + parsed['marks']['2']

if is_member:
print("* %s's review increase: %d" % (user, user_rv_count))
else:
print("* %s's review: %d" % (user, user_rv_count))

total_ps += user_ps_count
total_cm += user_cm_count
total_rv += user_rv_count
total_mbp += user_bp_merge
total_rbp += user_bp_review
else:
print("There are something wrong with user %s !" % user)
return None

return total_ps, total_cm, total_rv, total_mbp, total_rbp


def main():
print("===== Member's total review count =====")
team_res = get_statistics(is_member=False)
if team_res:
print("===== %s: Team contribution report =====" % time.ctime())
print("* Total in-review BP: %d" % team_res[4])
print("* Total merged BP: %d" % team_res[3])
print("* Total commits count: %d" % team_res[1])
print("* Total reviews count: %d" % team_res[2])
print("* Total in-review patches: %d" % (team_res[0] - team_res[1]))
print("===== FIN ======")

print("===== Member's contribution compare with last week =====")
member_res = get_statistics(is_member=True)
if member_res:
print("* Total commits since last week: %d" % member_res[1])
print("* Total patches since last week: %d" %
(member_res[0] - member_res[1]))


if __name__ == '__main__':
main()
184 changes: 184 additions & 0 deletions all_v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
from datetime import *
import datetime
import prettytable
import xlsxwriter
import urllib, json

today = datetime.date.today()

#Input member launchpad id here.
members = ["hieulq", "duonghq", "tovin07", "kiennt2609", "daidv", "namnh"]
maps = {"hieulq": "Hieu", "duonghq": "Duong", "tovin07": "Vinh", "kiennt2609": "Kien", "daidv": "Dai", "namnh": "Nam"}
#Input target
review_target = 1219
commit_target = 213

# Create a new Excel file and add a worksheet.
year = today.year
month = today.month
day = today.day
a = date(year, month, day).isocalendar()[1]
a1 = date(2017, 12, 31).isocalendar()[1]
b = date(2018, 3, 2).isocalendar()[1]
if a > b:
week = (a1 - a) + b
else:
week = b - a
# Cal start date and end date of a week
def _range_date_of_week(year, week):
d = date(year,1,1)
if(d.weekday()>3):
d = d+timedelta(7-d.weekday())
else:
d = d - timedelta(d.weekday())
dlt = timedelta(days = (week-1)*7)
start = str(d + dlt)
end = str(d + dlt + timedelta(days=4))
return start, end

filename = 'FVL_UC_Contribution_Summarization_R-' + str(week) + '.xlsx'
workbook = xlsxwriter.Workbook(filename)
worksheet = workbook.add_worksheet()
def output_xlsx (member, reviews, commits, index, sum=None):
# Widen the first column to make the text clearer.
worksheet.set_column('E:E', 30)
worksheet.set_column('H:H', 15)
worksheet.set_column('I:I', 15)

# Add a bold format to use to highlight cells.
bold = workbook.add_format({'bold': False})
bold.set_border()
bold.set_font('Times New Roman')
bold.set_font_size(13)
bold_color = workbook.add_format({'bold': False, 'font_color': 'black'})
bold_color.set_font('Times New Roman')
bold_color.set_font_size(13)
bold_color.set_border()
bold_color.set_pattern(1)
bold_color.set_bg_color('yellow')
# Create a format to use in the merged range.
merge_format = workbook.add_format({
'bold': 0,
'border': 1,
'align': 'center',
'valign': 'vcenter',
'font': 'Times New Roman',
'font_size': 13})

row = 13 + index*4
# Write some simple text.
if sum:
worksheet.merge_range('D' + str(row - 5) + ':J' + str(row - 5),
'Week (From ' + _range_date_of_week(year, a)[0] +
' to ' + _range_date_of_week(year, a)[1] + ' )', merge_format)
worksheet.merge_range('D' + str(row - 4) + ':D' + str(row - 2), 'Team', merge_format)
worksheet.write('E' + str(row - 4), 'R-' + str(week), bold)
worksheet.write('E' + str(row - 3), 'Reviews (Until 2018/02/23)', bold)
worksheet.write('E' + str(row - 2), 'Commits (Until 2018/01/26)', bold)
worksheet.write('F' + str(row - 4), 'Target', bold)
worksheet.write('G' + str(row - 4), 'Actual', bold)
worksheet.write('H' + str(row - 4), 'Target remain', bold)
worksheet.write('I' + str(row - 4), 'Actual remain', bold)
worksheet.write('J' + str(row - 4), 'Status', bold)
worksheet.write('F' + str(row - 3), review_target, bold)
worksheet.write('F' + str(row - 2), commit_target, bold)
worksheet.write('G' + str(row - 3), reviews, bold_color)
worksheet.write('G' + str(row - 2), commits, bold_color)
m1 = review_target - (review_target/25)*(26-week) #25 is total week of the cycle
n1 = commit_target - (commit_target/21)*(26-week) #21 is the week of RC1
m2 = review_target - reviews
n2 = commit_target - commits
worksheet.write('H' + str(row - 3), round(m1), bold)
worksheet.write('H' + str(row - 2), round(n1), bold)
worksheet.write('I' + str(row - 3), m2, bold)
worksheet.write('I' + str(row - 2), n2, bold)
worksheet.write('J' + str(row - 3), round(m1 - m2), bold_color)
worksheet.write('J' + str(row - 2), round(n1 - n2), bold_color)
else:
worksheet.merge_range('D' + str(row) + ':D' + str(row + 2), member, merge_format)
worksheet.write('E' + str(row ), '', bold)
worksheet.write('E' + str(row + 1), 'Reviews', bold)
worksheet.write('E' + str(row + 2), 'Commits', bold)
worksheet.write('F' + str(row), 'Target', bold)
worksheet.write('G' + str(row), 'Actual', bold)
worksheet.write('H' + str(row), 'Target remain', bold)
worksheet.write('I' + str(row), 'Actual remain', bold)
worksheet.write('J' + str(row), 'Status', bold)
q = review_target / len(members)
p = commit_target / len(members)
q1 = q - (q/25)*(26 - week)
p1 = p - (p/21)*(26 - week)
q2 = q - reviews
p2 = p - commits
worksheet.write('F' + str(row + 1), q, bold)
worksheet.write('F' + str(row + 2), p, bold)
worksheet.write('G' + str(row + 1), reviews, bold_color)
worksheet.write('G' + str(row + 2), commits, bold_color)
worksheet.write('H' + str(row + 1), round(q1), bold)
worksheet.write('H' + str(row + 2), round(p1), bold)
worksheet.write('I' + str(row + 1), q2, bold)
worksheet.write('I' + str(row + 2), p2, bold)
worksheet.write('J' + str(row + 1), round(q1-q2), bold_color)
worksheet.write('J' + str(row + 2), round(p1-p2), bold_color)
# Create an new Excel file and add a worksheet...End

patches = prettytable.PrettyTable(["UC team results on the community summary", str(today) + " (R-" + str(week) + ")"])
table = prettytable.PrettyTable(["Team/Members", "Reviews", "Commits"])
table.align = "l"

team_stats_patches = 0
team_stats_commits = 0
team_stats_reviews = 0
i = 0
for member in members:
url = "http://stackalytics.com/api/1.0/contribution?release=queens&company=fujitsu&user_id=" + member
member_url = urllib.urlopen(url)
try:
member_stats = json.loads(member_url.read())
except ValueError:
print "Something wrong with member " + member
continue
member_stats_patches = member_stats['contribution']['patch_set_count']
member_stats_commits = member_stats['contribution']['commit_count']
member_stats_reviews = (
member_stats['contribution']['marks']['-1'] +
member_stats['contribution']['marks']['1'] +
member_stats['contribution']['marks']['-2'] +
member_stats['contribution']['marks']['2'])

team_stats_patches += member_stats_patches
team_stats_reviews += member_stats_reviews
team_stats_commits += member_stats_commits

table.add_row([maps.get(member), member_stats_reviews, member_stats_commits])

output_xlsx(maps.get(member), member_stats_reviews, member_stats_commits, i)
i += 1
if i == len(members):
output_xlsx('Team', team_stats_reviews, team_stats_commits, 0, sum=True)

workbook.close()
patches.add_row(["Total patches uploaded", team_stats_patches])
print patches
table.add_row(["*** Team ***", team_stats_reviews, team_stats_commits])
print table


rranking = urllib.urlopen("http://stackalytics.com/api/1.0/stats/companies?release=queens")
rranking_results = json.loads(rranking.read())
rranking_count = rranking_results['stats']
for i in rranking_count:
if i['name'] == "Fujitsu":
print "===============REVIEWS - Fujitsu contribution==============="
print "Total reviews count = %d" % i['metric']
print "Ranking = %d" % i['index']

ranking = urllib.urlopen("http://stackalytics.com/api/1.0/stats/companies?release=queens&metric=commits")
ranking_results = json.loads(ranking.read())
ranking_count = ranking_results['stats']
for i in ranking_count:
if i['name'] == "Fujitsu":
print "===============COMMITS - Fujitsu contribution==============="
print "Total commits count = %d" % i['metric']
print "Ranking = %d" % i['index']

80 changes: 80 additions & 0 deletions ct_contribution_total.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# AUTHOR: hieulq

import copy
import time
import requests

# Change this list based on your member's info
USER_LIST = ['hieulq', 'tovin07']

# No need to change in case of changing Stackalytics API or changing cycle
CONTRIB_URL = "http://stackalytics.com/api/1.0/contribution"
RELEASE = "queen"

# Common query info
PROJECT_TYPE = "openstack"
COMPANY = "fujitsu"
PAYLOAD = {'release': RELEASE, 'project_type': PROJECT_TYPE,
'company': COMPANY}


def get_statistics(is_member=False):
total_ps, total_cm, total_rv, total_mbp, total_rbp = 0, 0, 0, 0, 0
params = copy.deepcopy(PAYLOAD)
if is_member:
params['start_date'] = int(time.time() - 604800)
params['end_date'] = int(time.time())

for user in USER_LIST:
params['user_id'] = user
resp = requests.get(CONTRIB_URL, params=params)
if resp.ok:
parsed = resp.json()['contribution']
user_ps_count = parsed['patch_set_count']
user_cm_count = parsed['commit_count']
user_bp_merge = parsed['completed_blueprint_count']
user_bp_review = parsed['drafted_blueprint_count']
user_rv_count = parsed['marks']['-1'] + parsed['marks']['1'] + \
parsed['marks']['-2'] + parsed['marks']['2']

if is_member:
print("* %s's review increase: %d" % (user, user_rv_count))
else:
print("* %s's review: %d" % (user, user_rv_count))

total_ps += user_ps_count
total_cm += user_cm_count
total_rv += user_rv_count
total_mbp += user_bp_merge
total_rbp += user_bp_review
else:
print("There are something wrong with user %s !" % user)
return None

return total_ps, total_cm, total_rv, total_mbp, total_rbp


def main():
print("===== Member's total review count =====")
team_res = get_statistics(is_member=False)
if team_res:
print("===== %s: Team contribution report =====" % time.ctime())
print("* Total in-review BP: %d" % team_res[4])
print("* Total merged BP: %d" % team_res[3])
print("* Total commits count: %d" % team_res[1])
print("* Total reviews count: %d" % team_res[2])
print("* Total in-review patches: %d" % (team_res[0] - team_res[1]))
print("===== FIN ======")

print("===== Member's contribution compare with last week =====")
member_res = get_statistics(is_member=True)
if member_res:
print("* Total commits since last week: %d" % member_res[1])
print("* Total patches since last week: %d" %
(member_res[0] - member_res[1]))


if __name__ == '__main__':
main()
9 changes: 9 additions & 0 deletions gerritssh/gerritsite.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ class InvalidCommandError(GerritsshException):
pass


class InvalidUserError(GerritsshException):
'''
Raised when an username is not found.
'''
pass


class Site(object):
'''
An individual Gerrit site.
Expand Down Expand Up @@ -186,6 +193,8 @@ def __do_command(self, command, args=''):
retval = [(l if isinstance(l, str) else l.encode('utf8', 'replace'))
for l in retval]
_logger.debug('Returning:{0}'.format(retval))
if '"type":"error"' in retval[0]:
raise InvalidUserError()
return s.encode('utf-8', 'replace'), retval

def connect(self):
Expand Down
Loading