Esempio n. 1
0
def compute_developer_flows(names_and_networks, project_name, kind='years'):
    connectivity = get_structural_cohesion_results(project_name, kind)
    years = python_years if project_name == 'python' else debian_years
    flows = []
    last = None
    for name, G in names_and_networks():
        kcomps = connectivity[name]['k_components']
        max_k = max(kcomps)
        if project_name == 'python':
            devs = {n for n, d in G.nodes(data=True) if d['bipartite'] == 1}
        else:
            devs = {n for n, d in G.nodes(data=True) if d['bipartite'] == 0}
        try:
            these_devs = {
                u
                for u in set.union(*[v[1] for v in kcomps[max_k]]) if u in devs
            }
        except TypeError:  # Calling set.union without arguments
            if not flows or not any(flows[-1]):
                flows.append([0, 0])
            else:
                flows.append([0, 0, 0, 0])
            continue
        if last is None:
            flows.append([len(these_devs), -len(these_devs)])
            last = these_devs
        else:
            flows.append([
                len(last),  # number of developers at time t - 1
                len(these_devs - last),  # incoming new developers
                -len(last - these_devs),  # outgoing developers
                -len(these_devs)
            ])  # number of developers at time t
            last = these_devs
    return flows
Esempio n. 2
0
def all_3d_scatter_plots(names_and_networks,
                         project_name,
                         kind,
                         directory=tmp_dir):
    layouts = get_layouts(project_name, kind)
    conn = get_structural_cohesion_results(project_name, kind)
    conn_null = get_structural_cohesion_null_model_results(project_name, kind)

    print('Scatter 3d plots for {}:'.format(project_name))
    for name, G in names_and_networks():
        k_number = conn[name]['k_num']
        max_k = max(ak for k, ak in k_number.values())
        k_number_null = conn_null[name]['k_num']
        pos = layouts[name]
        print('    Plotting {} actual network'.format(name))
        scatter_3d_connectivity(G,
                                k_number,
                                pos,
                                name,
                                project_name,
                                max_k=None,
                                null=False,
                                directory=directory)
        print('    Plotting {} null model network'.format(name))
        Gr = generate_random_configuration_2mode(G)
        pos_r = utils.relabel_layout(G, Gr, pos)
        scatter_3d_connectivity(Gr,
                                k_number_null,
                                pos_r,
                                name,
                                project_name,
                                max_k=max_k,
                                null=True,
                                directory=directory)
Esempio n. 3
0
def build_mobility_network(names_and_networks, project_name, kind='years'):
    H = nx.DiGraph()
    years = python_years if project_name == 'python' else debian_years
    connectivity = get_structural_cohesion_results(project_name, kind)
    for year, G in names_and_networks():
        if project_name == 'python':
            devs = {n for n, d in G.nodes(data=True) if d['bipartite'] == 1}
        else:
            devs = {n for n, d in G.nodes(data=True) if d['bipartite'] == 0}
        kcomps = connectivity[year]['k_components']
        max_k = max(kcomps)
        these_devs = set(u for u in set.union(*[v[1] for v in kcomps[max_k]])
                         if u in devs)
        H.add_node(year,
                   devs=these_devs,
                   number_devs=len(these_devs),
                   total_devs=len(devs))
    for year in years:
        seen = set()
        for future_year in range(year + 1, max(years) + 1):
            common = H.node[year]['devs'] & H.node[future_year]['devs']
            if common:
                to_add = common - seen
                if to_add:
                    H.add_edge(year,
                               future_year,
                               devs=to_add,
                               weight=len(to_add))
                    seen.update(to_add)
    seen = set()
    for year in years:
        devs = H.node[year]['devs']
        if year == max(years):
            future_devs = set()
        else:
            future_devs = set.union(
                *[H.node[n]['devs'] for n in range(year + 1,
                                                   max(years) + 1)])
        out_devs = devs - future_devs
        if out_devs:
            if year != max(years):
                H.add_node("%s-out" % year,
                           devs=out_devs,
                           number_devs=len(out_devs))
                H.add_edge(year,
                           "%s-out" % year,
                           devs=out_devs,
                           weight=len(out_devs))
        new_devs = devs - seen
        if new_devs:
            H.add_node("%s-in" % year,
                       devs=new_devs,
                       number_devs=len(new_devs))
            H.add_edge("%s-in" % year,
                       year,
                       devs=new_devs,
                       weight=len(new_devs))
        seen.update(devs)
    return H
Esempio n. 4
0
def get_developers_top_connectivity(devs_by_year=None):
    if devs_by_year is None:
        devs_by_year = get_developers_by_years()
    if connectivity is None:
        connectivity = get_structural_cohesion_results('python', 'years')
    all_devs = set.union(*[v for k, v in devs_by_year.items()])
    top_devs = set()
    for year in connectivity:
        kcomponents = connectivity[year]['k_components']
        max_k = max(kcomponents)
        nodes = set.union(*[c[1] for c in kcomponents[max_k]])
        top_devs.update(n for n in nodes if n in all_devs)
    return top_devs
Esempio n. 5
0
def main():
    # Print help when we find an error in arguments
    class DefaultHelpParser(argparse.ArgumentParser):
        def error(self, message):
            sys.stderr.write('error: %s\n' % message)
            self.print_help()
            sys.exit(2)

    #parser = argparse.ArgumentParser()
    parser = DefaultHelpParser()

    group_project = parser.add_mutually_exclusive_group(required=True)
    group_project.add_argument('-d',
                               '--debian',
                               action='store_true',
                               help='Debian networks')
    group_project.add_argument('-p',
                               '--python',
                               action='store_true',
                               help='Python networks')

    args = parser.parse_args()

    if args.debian:
        project_name = 'debian'
        kind = 'years'
        names_and_networks = debian_networks_by_year
    elif args.python:
        project_name = 'python'
        kind = 'years'
        names_and_networks = python_networks_by_year

    connectivity = get_structural_cohesion_results(project_name, kind)
    plot_developers_by_connectivity(names_and_networks, connectivity,
                                    project_name, kind)
    plot_contributions_by_connectivity(names_and_networks, connectivity,
                                       project_name, kind)
Esempio n. 6
0
def structural_cohesion_results(project_name, kind):
    actual = get_structural_cohesion_results(project_name, kind)
    null = get_structural_cohesion_null_model_results(project_name, kind)
    return actual, null