Esempio n. 1
0
def cumulative_blame(by, file_stub):
    settings = get_settings()
    project_dir = settings.get('project_dir', os.getcwd())
    extensions = settings.get('extensions', None)
    ignore_dir = settings.get('ignore_dir', None)

    repo = ProjectDirectory(working_dir=project_dir)
    print(extensions)
    print(ignore_dir)
    print(by)
    cb = repo.cumulative_blame(branch='master', extensions=extensions, ignore_dir=ignore_dir, by=by, num_datapoints=100, skip=None, limit=None)
    cb = cb[~cb.index.duplicated()]
    t = json.loads(cb.to_json(orient='columns'))

    d3_data = []
    for committer in t.keys():
        blob = dict()
        blob['key'] = committer
        blob['values'] = []
        for data_point in t[committer].keys():
            blob['values'].append([int(float(data_point)), t[committer][data_point]])
            blob['values'] = sorted(blob['values'], key=lambda x: x[0])
        d3_data.append(blob)

    # dump the data to disk
    filename = get_file_prefix() + file_stub
    json.dump(d3_data, open(str(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + os.sep + 'static' + os.sep + 'data' + os.sep + filename, 'w'), indent=4)

    return True
Esempio n. 2
0
def week_leader_board(n=5):
    settings = get_settings()
    project_dir = settings.get('project_dir', os.getcwd())
    extensions = settings.get('extensions', None)
    ignore_dir = settings.get('ignore_dir', None)
    repo = ProjectDirectory(working_dir=project_dir)
    ch = repo.commit_history(branch='master', extensions=extensions, ignore_dir=ignore_dir, limit=None, days=7)

    print(ch)
    leader_board = {
        'top_committers': [],
        'top_repositories': [],
        'top_extensions': []
    }

    committers = ch.groupby(['committer']).agg({'net': np.sum})
    committers.reset_index(inplace=True)
    committers = committers.sort_values(by=['net'], ascending=False)
    leader_board['top_committers'] = [{'label': x[0], 'net': int(x[1]), 'rank': idx + 1} for idx, x in enumerate(committers.values.tolist()[:n])]

    repos = ch.groupby(['repository']).agg({'net': np.sum})
    repos.reset_index(inplace=True)
    repos = repos.sort_values(by=['net'], ascending=False)
    leader_board['top_repositories'] = [{'label': x[0], 'net': int(x[1]), 'rank': idx + 1} for idx, x in enumerate(repos.values.tolist()[:n])]

    if extensions is not None:
        ext_ranks = []
        for ext in extensions:
            ch = repo.commit_history(branch='master', extensions=[ext], ignore_dir=ignore_dir, days=7)
            ext_ranks.append((ch['net'].sum(), ext))
        ext_ranks = sorted(ext_ranks, key=lambda x: x[0], reverse=True)[:n]
        leader_board['top_extensions'] = [{'label': x[1], 'net': int(x[0]), 'rank': idx + 1} for idx, x in enumerate(ext_ranks)]

    return leader_board
Esempio n. 3
0
def get_file_change_rates():
    settings = get_settings()
    project_dir = settings.get('project_dir', os.getcwd())
    extensions = settings.get('extensions', None)
    ignore_dir = settings.get('ignore_dir', None)
    repo = ProjectDirectory(working_dir=project_dir)
    cb = repo.file_change_rates(extensions=extensions,
                                ignore_dir=ignore_dir,
                                coverage=True,
                                days=7)
    cb.reset_index(level=0, inplace=True)
    data = json.loads(cb.to_json(orient='records'))

    output = {'data': []}
    for blob in data:
        row = [
            blob.get(x, None) for x in [
                'index', 'repository', 'unique_committers',
                'net_rate_of_change', 'edit_rate', 'total_lines', 'coverage'
            ]
        ]
        row = [round(x, 2) if isinstance(x, float) else x for x in row]
        output['data'].append(row)

    return output
Esempio n. 4
0
def settings():
    form = SettingsForm(request.form, csrf_enabled=False)
    if form.validate_on_submit():
        settings_services.update_profile(form.project_directory.data, form.extensions.data, form.ignore_dir.data)

    settings = settings_services.get_settings()
    extensions = settings.get('extensions', None)
    project_dir = settings.get('project_dir', None)
    ignore_dir = settings.get('ignore_dir', None)

    if project_dir is not None:
        if isinstance(project_dir, list):
            pdv = ','.join(project_dir)
        else:
            pdv = project_dir
    else:
        pdv = ''

    if extensions is not None:
        if isinstance(project_dir, list):
            ext = ','.join(extensions)
        else:
            ext = extensions
    else:
        ext = ''

    if ignore_dir is not None:
        if isinstance(project_dir, list):
            ign = ','.join(ignore_dir)
        else:
            ign = ignore_dir
    else:
        ign = ''

    return render_wrapper('public/settings.html', form=form, project_directory_values=pdv, ignore_dir_values=ign, extensions_values=ext)
Esempio n. 5
0
def week_leader_board(n=5):
    settings = get_settings()
    project_dir = settings.get('project_dir', os.getcwd())
    extensions = settings.get('extensions', None)
    ignore_dir = settings.get('ignore_dir', None)
    repo = ProjectDirectory(working_dir=project_dir)
    ch = repo.commit_history(branch='master',
                             extensions=extensions,
                             ignore_dir=ignore_dir,
                             limit=None,
                             days=7)

    print(ch)
    leader_board = {
        'top_committers': [],
        'top_repositories': [],
        'top_extensions': []
    }

    committers = ch.groupby(['committer']).agg({'net': np.sum})
    committers.reset_index(inplace=True)
    committers = committers.sort_values(by=['net'], ascending=False)
    leader_board['top_committers'] = [{
        'label': x[0],
        'net': int(x[1]),
        'rank': idx + 1
    } for idx, x in enumerate(committers.values.tolist()[:n])]

    repos = ch.groupby(['repository']).agg({'net': np.sum})
    repos.reset_index(inplace=True)
    repos = repos.sort_values(by=['net'], ascending=False)
    leader_board['top_repositories'] = [{
        'label': x[0],
        'net': int(x[1]),
        'rank': idx + 1
    } for idx, x in enumerate(repos.values.tolist()[:n])]

    if extensions is not None:
        ext_ranks = []
        for ext in extensions:
            ch = repo.commit_history(branch='master',
                                     extensions=[ext],
                                     ignore_dir=ignore_dir,
                                     days=7)
            ext_ranks.append((ch['net'].sum(), ext))
        ext_ranks = sorted(ext_ranks, key=lambda x: x[0], reverse=True)[:n]
        leader_board['top_extensions'] = [{
            'label': x[1],
            'net': int(x[0]),
            'rank': idx + 1
        } for idx, x in enumerate(ext_ranks)]

    return leader_board
Esempio n. 6
0
def get_punchcard():
    settings = get_settings()
    project_dir = settings.get('project_dir', os.getcwd())
    extensions = settings.get('extensions', None)
    ignore_dir = settings.get('ignore_dir', None)
    repo = ProjectDirectory(working_dir=project_dir)

    pc = repo.punchcard(branch='master', extensions=extensions, ignore_dir=ignore_dir)

    data_set = []
    for idx in range(pc.shape[0]):
        data_set.append([pc.loc[idx, 'day_of_week'], pc.loc[idx, 'hour_of_day'], pc.loc[idx, 'net']])

    return data_set
Esempio n. 7
0
def get_file_change_rates():
    settings = get_settings()
    project_dir = settings.get('project_dir', os.getcwd())
    extensions = settings.get('extensions', None)
    ignore_dir = settings.get('ignore_dir', None)
    repo = ProjectDirectory(working_dir=project_dir)
    cb = repo.file_change_rates(extensions=extensions, ignore_dir=ignore_dir, coverage=True, days=7)
    cb.reset_index(level=0, inplace=True)
    data = json.loads(cb.to_json(orient='records'))

    output = {'data': []}
    for blob in data:
        row = [blob.get(x, None) for x in ['index', 'repository', 'unique_committers', 'net_rate_of_change', 'edit_rate', 'total_lines', 'coverage']]
        row = [round(x, 2) if isinstance(x, float) else x for x in row]
        output['data'].append(row)

    return output
Esempio n. 8
0
def get_punchcard():
    settings = get_settings()
    project_dir = settings.get('project_dir', os.getcwd())
    extensions = settings.get('extensions', None)
    ignore_dir = settings.get('ignore_dir', None)
    repo = ProjectDirectory(working_dir=project_dir)

    pc = repo.punchcard(branch='master',
                        extensions=extensions,
                        ignore_dir=ignore_dir)

    data_set = []
    for idx in range(pc.shape[0]):
        data_set.append([
            pc.loc[idx, 'day_of_week'], pc.loc[idx, 'hour_of_day'],
            pc.loc[idx, 'net']
        ])

    return data_set
Esempio n. 9
0
def profile():
    select_form = ProfileForm(request.form)
    create_form = CreateProfileForm(request.form)

    select_form.profile.choices = settings_services.get_profiles()

    if select_form.validate_on_submit():
        settings_services.change_profile(select_form.profile.data)
        return redirect(url_for('admin.settings'))
    elif create_form.validate_on_submit():
        settings_services.create_profile(create_form.name.data)
        settings_services.change_profile(create_form.name.data)
        return redirect(url_for('admin.settings'))

    select_form.profile.choices = settings_services.get_profiles()
    select_form.profile.default = settings_services.get_settings()['profile_name']
    select_form.process()

    return render_wrapper('public/profile.html', create_form=create_form, select_form=select_form)
Esempio n. 10
0
def cumulative_blame(by, file_stub):
    settings = get_settings()
    project_dir = settings.get('project_dir', os.getcwd())
    extensions = settings.get('extensions', None)
    ignore_dir = settings.get('ignore_dir', None)

    repo = ProjectDirectory(working_dir=project_dir)
    print(extensions)
    print(ignore_dir)
    print(by)
    cb = repo.cumulative_blame(branch='master',
                               extensions=extensions,
                               ignore_dir=ignore_dir,
                               by=by,
                               num_datapoints=100,
                               skip=None,
                               limit=None)
    cb = cb[~cb.index.duplicated()]
    t = json.loads(cb.to_json(orient='columns'))

    d3_data = []
    for committer in t.keys():
        blob = dict()
        blob['key'] = committer
        blob['values'] = []
        for data_point in t[committer].keys():
            blob['values'].append(
                [int(float(data_point)), t[committer][data_point]])
            blob['values'] = sorted(blob['values'], key=lambda x: x[0])
        d3_data.append(blob)

    # dump the data to disk
    filename = get_file_prefix() + file_stub
    json.dump(
        d3_data,
        open(
            str(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +
            os.sep + 'static' + os.sep + 'data' + os.sep + filename, 'w'),
        indent=4)

    return True