bot-replication/code/figs/statisticsFig.py

74 lines
2.6 KiB
Python

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from models import getStatis
def projects_bots():
data = [1684, 902, 580, 380, 231, 151, 92, 49, 30, 49]
print(sum(data))
labels = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10+']
plt.bar(range(1, 11), data, tick_label=labels, width=0.7)
plt.xlabel('Number of bots used')
plt.ylabel('Number of projects')
ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
plt.savefig("projects_bots.pdf", format="pdf")
def bots_projects1():
data = [2420, 678, 605, 539, 506, 460, 440, 287, 266, 231]
labels = ['dependabot[bot]', 'github-actions[bot]', 'coveralls[bot]', 'stale[bot]', 'codecov-io[bot]', 'codecov[bot]',
'dependabot-preview[bot]', 'CLAassistant', 'greenkeeper[bot]', 'googlebot']
plt.barh(range(1, 11), data, tick_label=labels, height=0.7)
plt.xlabel('Number of projects')
plt.ylabel('Top 10 bots')
ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
plt.tight_layout()
plt.savefig("bots_projects1.pdf", format="pdf")
def bots_projects2():
data = [106, 33, 18, 9, 4, 5, 3, 3, 1, 0, 2]
labels = ['[3-10)', '[10,20)', '[20,40)', '[40,60)', '[60,80)', '[80,100)',
'[100,120)', '[120,140)', '[140,160)', '[160,180)', '[180,200)']
plt.tick_params(axis='x', labelsize=7.2) # 设置x轴标签大小
plt.bar(range(1, 12), data, tick_label=labels, width=0.7)
plt.xlabel('Number of projects served')
plt.ylabel('Number of bots ')
ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
plt.tight_layout()
plt.savefig("bots_projects2.pdf", format="pdf")
# df = pd.DataFrame(data)
# print(df.quantile(0.75))
# 箱线图
def stars_difference_using_bots():
sql_query1 = 'SELECT stargazers_count FROM repos WHERE refine2 = 1 '
sql_query2 = 'SELECT stargazers_count FROM repos WHERE refine2 = 1 AND bots_num = 0'
sql_query3 = 'SELECT stargazers_count FROM repos WHERE refine2 = 1 AND bots_num > 0'
data1 = getStatis.get_project_stars(sql_query1)
data2 = getStatis.get_project_stars(sql_query2)
df2 = pd.DataFrame(data2)
data3 = getStatis.get_project_stars(sql_query3)
df3 = pd.DataFrame(data3)
print(df2.quantile(0.5))
print(df3.quantile(0.5))
plt.boxplot([data3, data2], showfliers=False, showmeans=True, labels=[ "Projects with bots", "Projects without bots"]) # labels表示分组
plt.ylabel("Number of stars")
plt.tight_layout()
plt.savefig('test.pdf', format='pdf')
if __name__ == '__main__':
projects_bots()