125 lines
3.5 KiB
Python
125 lines
3.5 KiB
Python
|
|
# coding: utf-8
|
|
import MySQLdb
|
|
import json
|
|
import time
|
|
import random
|
|
import urllib2
|
|
import pandas as pd
|
|
import matplotlib.mlab as mlab
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
with open("../.config.json") as fp:
|
|
config = json.load(fp)
|
|
local_db_config = config["local_db"]
|
|
conn = MySQLdb.connect(host=local_db_config["db_host"],user=local_db_config["db_user"],
|
|
passwd=local_db_config["db_passwd"],db=local_db_config["db_name"],port=3306,charset='utf8mb4')
|
|
cursor = conn.cursor()
|
|
|
|
|
|
|
|
def profile_type(doc):
|
|
doc_id,repo_id,doc_location,doc_name,doc_type = doc
|
|
if doc_location.lower() in ["root",".github","docs"] and doc_type=="blob":
|
|
doc_name = doc_name.lower()
|
|
for fi in ["readme"]:
|
|
if doc_name.lower().find(fi) != -1:
|
|
return "readme"
|
|
for fi in ["license"]:
|
|
if doc_name.lower().find(fi) != -1:
|
|
return "license"
|
|
for fi in ["issue_template","pull_request_template"]:
|
|
if doc_name.lower().find(fi) != -1:
|
|
return "template"
|
|
for fi in ["code_of_conduct"]:
|
|
if doc_name.lower().find(fi) != -1:
|
|
return "COC"
|
|
for fi in ["contributing"]:
|
|
if doc_name.lower().find(fi) != -1:
|
|
return "contributing"
|
|
return None
|
|
elif doc_location.lower() in ["issue_template", "pull_request_template"] and doc_type=="blob":
|
|
return "template"
|
|
else:
|
|
return None
|
|
return None
|
|
|
|
import math
|
|
|
|
def repos_dis(repos):
|
|
|
|
import collections
|
|
creation = collections.OrderedDict()
|
|
creation["readme"]=[]
|
|
creation["license"]=[]
|
|
creation["contributing"]=[]
|
|
creation["COC"]=[]
|
|
creation["template"]=[]
|
|
|
|
prf_files = []
|
|
cursor.execute("select * from files")
|
|
files = cursor.fetchall()
|
|
for f in files:
|
|
doc_id,repo_id,doc_location,doc_name,doc_type = f
|
|
if repo_id in repos:
|
|
doc_kind = profile_type(f)
|
|
if doc_kind is None:
|
|
continue
|
|
# 获取文档时间
|
|
cursor.execute("select author from file_history where file_id=%s and author is not null",
|
|
(doc_id,))
|
|
authors = set([item[0] for item in cursor.fetchall()])
|
|
if len(authors) == 0:
|
|
continue
|
|
# creation[doc_kind].append(math.log(len(authors)))
|
|
creation[doc_kind].append(len(authors))
|
|
|
|
data = []
|
|
for key, value in creation.items():
|
|
print key
|
|
# print pd.Series(value).describe()
|
|
ss = pd.Series(value)
|
|
print "%.2f (median: %s)"%(ss.mean(),ss.median())
|
|
data.append(value)
|
|
return data
|
|
if __name__ == "__main__":
|
|
|
|
|
|
plt.figure(figsize=(10,4),num="correlation")
|
|
|
|
cursor.execute("select id from random_repos")
|
|
repos = set([item[0] for item in cursor.fetchall()])
|
|
data = repos_dis(repos)
|
|
# plt.boxplot(x=data,positions=range(1,len(data)+1),widths=[0.3]*len(data))
|
|
|
|
vp = plt.violinplot(data, widths = 0.9, showmeans=False,showmedians=True)
|
|
for pc in vp['bodies']:
|
|
pc.set_facecolor('#C0C0C0')
|
|
pc.set_edgecolor(None)
|
|
pc.set_alpha(1)
|
|
pc.set_linewidths(0.5)
|
|
for partname in ('cbars', 'cmins','cmaxes','cmedians'):
|
|
vpp = vp[partname]
|
|
vpp.set_edgecolor("#252525")
|
|
vpp.set_linewidth(0.5)
|
|
if partname == 'cmedians':
|
|
vpp.set_linewidth(0)
|
|
for md in vpp.get_segments():
|
|
xn = (md[1][0] - md[0][0])*1.0/2
|
|
ml = plt.plot([md[0][0]-xn,md[1][0]+xn],[md[0][1],md[1][1]],linestyle='-', lw=1, color="black")
|
|
|
|
if partname in ["cmins","cmaxes"] :
|
|
vpp.set_linewidth(0)
|
|
|
|
|
|
xtcks = ["Readme","License","Contributing","Code-of-conduct","Template"]
|
|
plt.xticks(range(1,len(xtcks)+1),xtcks)
|
|
# plt.xlim(0,None)
|
|
plt.xticks(range(1,6),["README", "LICENSE", "CONTRIBUTING", "CONDUCT", "TEMPLATE"])
|
|
plt.ylabel("The number of maintainers")
|
|
plt.xlabel("Documentation type")
|
|
plt.savefig("../../resources/maintainers.pdf",dpi=200)
|
|
plt.show()
|
|
plt.close()
|
|
|