Skip to content

Commit

Permalink
Merge pull request #74 from LuuMing/dev
Browse files Browse the repository at this point in the history
analy 功能的标准模块实现
  • Loading branch information
bestony authored Nov 12, 2018
2 parents 1c37904 + b247037 commit 7db753a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions grank/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from grank import analy
1 change: 1 addition & 0 deletions grank/analy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .core import *
16 changes: 16 additions & 0 deletions grank/analy/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
__all__ = ['get_analy']

def get_analy(token=None,start=None,stop=None,owner=None,repo=None):
from ..script.crawler import fetch_repo_data
from ..libs.helpers import get_config_instance
from ..script.activity import analyse_repo
from ..script.social import analyse_repo as analyse_social
if owner is None:
raise ValueError('owner invalid!')
if repo is None:
raise ValueError('repo invalid!')
config = get_config_instance(token=token,start=start,stop=stop)
data = fetch_repo_data(owner,repo,config)
activity = analyse_repo(owner, repo, data, config, ret_score = True)
social = analyse_social(owner, repo, data, config, ret_score = True)
return {'activity': activity, 'social':social}
6 changes: 4 additions & 2 deletions grank/script/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import click
import math


def analyse_repo(owner, repository, data, config):
def analyse_repo(owner, repository, data, config, ret_score = False):
click.echo("开始活跃度分析:%s/%s" % (owner, repository))
"""查询 Repo 数据"""
pullRequestArray = data["pullRequestArray"]
Expand Down Expand Up @@ -75,6 +74,9 @@ def analyse_repo(owner, repository, data, config):

# 求活跃分数平均值
target_score = new_df["score"].sum() / len(new_df)

if ret_score is True:
return target_score

# 获取平均分实例,用于后续排序
instance = helpers.get_activity_average_instance()
Expand Down
5 changes: 4 additions & 1 deletion grank/script/social.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def analyse_email(data,config):

pass

def analyse_repo(owner, repository, data, config):
def analyse_repo(owner, repository, data, config, ret_score = False):
click.echo("开始社区化分析:%s/%s" % (owner, repository))
pullRequestArray = data["pullRequestArray"]
commitArray = data["commitArray"]
Expand Down Expand Up @@ -84,6 +84,9 @@ def analyse_repo(owner, repository, data, config):

target_social_score = social_df["score"].mean()

if ret_score is True:
return target_social_score

instance = helpers.get_social_average_instance()

helpers.export_pickle(social_df, 'social', owner, repository)
Expand Down

0 comments on commit 7db753a

Please sign in to comment.