2015-02-23 67 views
3

有沒有一些可以在Phabricator上打印差異統計信息的開源庫?如果沒有,那麼有人能指出我如何編寫一些代碼來做到這一點的正確方向?Phabricator的評論統計

以下是我想要的一些示例統計信息: 接受審閱前所需的平均補丁數量。 平均回覆評論所花費的時間。 有我作爲評論者的評論的平均數量,我最終審查。

+0

我無法找到一個,但這裏有可能減少代碼你」量的包裝d需要寫信e:http://bloomberg.github.io/phabricator-tools/ – 2016-03-20 13:55:40

回答

8

是否有一些開源庫,可以打印Pharizicator上的差異統計數據?如果沒有,那麼有人能指出我如何編寫一些代碼來做到這一點的正確方向?

我還沒有找到一個庫來做到這一點,但Phabricator提供Conduit這是一個「非正式的傳輸臨時JSON斑點機制」。它提供了一個variety of methods,可用於查詢Phabricator的信息。

如果您使用Arcanist與Phabricator進行交互(並且擁有~/.arcrc文件),那麼您可以使用Python綁定編寫腳本(並將Conduit的身份驗證和通信抽象出來)。

已經安裝了Python phabricator庫後,我能找到我phid使用我的用戶名user.find被警告,這種方法已經過時):

# Import favourite statistics library 
import numpy as np 

# Import the datetime library to print time deltas 
import datetime as dt 

# Setup Phabricator connection 
from phabricator import Phabricator 
ph = Phabricator() 

# Find username's phid 
username = 'chris.fournier' 
phid = ph.user.find(aliases=[username])[username] 

# Print pid 
print phid 

這應該打印phid(像我):

PHID-USER-2h22hnj6t5sxyfq4lzox 

補丁的平均數量是用盡我的評論被接受之前。

以我phid,我可以查詢,我已經使用differential.query創作了所有的比較和計算多少diff文件(即「補丁」),每個差異了。然後,我可以計算出我喜歡的任何描述性統計量(使用像numpy這樣的Python庫)。

# Find all authored diffs 
diffs_authored = ph.differential.query(authors=[phid]) 

# A diff can be either closed or accepted if it has passed review 
passed_status_names = set(['Closed', 'Accepted']) 

# Find out how many revisions each diff had before it was passed 
diff_revisions = list() 
for diff in diffs_authored: 
    if diff['statusName'] in passed_status_names: 
     diff_revisions.append(len(diff['diffs'])) 

# Generate some results 
print 'Mean\t\t\t', np.mean(diff_revisions) 
print 'Standard deviation\t', np.std(diff_revisions) 
print 'Max\t\t\t', np.max(diff_revisions) 
print 'Reviews\t\t\t', len(diff_revisions) 

這將打印有關我多少補丁需要作出之前,被我的同事們在工作中接受了我的diff如下統計:

Mean    1.80404040404 
Standard deviation 1.36920822006 
Max     13 
Reviews    495 

的時間平均長度需要爲我回複評論。

以我phid,我可以查詢,我列爲審閱,然後遍歷每個差分註釋的所有的diff文件(使用differential.getrevisioncomments; 被警告,這種方法不建議使用)。在這些評論中,我可以第一次看到我發表了評論(或接受或拒絕),然後從創建第一條評論時減去差異創建時間。

我可以在評論中包裝整個搜索以產生一個響應時間到一個函數(如果我沒有對該差異進行評論,返回None)。

def reviewer_response_time(reviewer_phid, diff): 
    response_time = None 
    creation_time = long(diff['dateCreated']) 

    # Get comments 
    diff_id = diff['id'] 
    comments = ph.differential.getrevisioncomments(
     ids=[int(diff_id)])[diff_id] 

    # Get date of first comment typed into Phabricator by reviewer 
    first_comment_time = None 
    for comment in comments: 
     if comment['authorPHID'] == reviewer_phid: 
      first_comment_time = long(comment['dateCreated']) 
      break 

    # If the reviewer provided a review calculate the response time 
    if first_comment_time: 
     response_time = first_comment_time - creation_time 

    return response_time 

然後我就可以使用該函數來獲取的響應時間爲我所有的diff文件(使用differential.query),我回顧(迭代中的100批,因爲,在我的情況,我做了足夠的評論中,查詢功能如果我一次問他們所有人,會超時)。

# Find all diffs that the user is listed as a reviewer for 
offset = 0 
limit = 100 
diffs = ph.differential.query(reviewers=[phid], 
           limit=limit, 
           offset=offset) 
response_times = list() 

while len(diffs.response) > 0: 
    for diff in diffs: 
     response_times.append(reviewer_response_time(phid, diff)) 
    offset += limit 
    diffs = ph.differential.query(reviewers=[phid], 
            limit=limit, 
            offset=offset) 

只選擇那些我回顧過的評論,然後我可以計算和打印統計數據,如下所示。

# Choose only those reviews that the user was asked to review and did 
reviewed_response_times = \ 
    [response_time for response_time in response_times 
    if response_time is not None] 

# Generate some results 
mean_reviewed_response_time = np.mean(reviewed_response_times) 
std_reviewed_response_time = np.std(reviewed_response_times) 
max_reviewed_response_time = np.max(reviewed_response_times) 

# Print results 
print 'Mean\t\t\t', dt.timedelta(seconds=mean_reviewed_response_time) 
print 'Standard deviation\t', dt.timedelta(seconds=std_reviewed_response_time) 
print 'Max\t\t\t', dt.timedelta(seconds=max_reviewed_response_time) 
print 'Reviews\t\t\t', len(reviewed_response_times) 

這將打印大約花了多長時間我才能到每個評論如下統計:

Mean    10:04:15.351555 
Standard deviation 2 days, 11:18:40.778145 
Max     66 days, 23:04:10 
Reviews    1061 

條評論中有我作爲一個評論家,我最終審查的平均數。

我可以重用我前面生成確定的評論,我檢討與我被列爲審閱和評論我被分配了我參與的百分比數的數量的數據。

# Generate some results 
print 'Diffs reviewed\t\t', len(reviewed_response_times) 
print 'Diffs asked to review\t', len(response_times) 
print 'Percentage\t\t', \ 
    float(len(reviewed_response_times))/len(response_times) 

這將打印有關我多少評論是能夠執行與分配給我的如下統計:

Diffs reviewed   1061 
Diffs asked to review 1302 
Percentage    0.81490015361