import copy
import matplotlib.pyplot as plt
import networkx as nx
from networkx.algorithms import bipartite

repos = {'khughitt': ['pandas-dev/pandas', 'conda-forge/staged-recipes'], 'skyline75489': ['pytorch/tutorials', 'pallets/werkzeug'], 'jart': ['django/django', 'django-extensions/django-extensions', 'tensorflow/models', 'tensorflow/tensorboard'], 'rodrigoberriel': ['keras-team/keras'], 'allenwang28': ['tensorflow/models', 'tensorflow/tensorboard'], 'mdmueller': ['astropy/astropy', 'pandas-dev/pandas', 'scikit-image/scikit-image', 'sympy/sympy'], 'kyleabeauchamp': ['pandas-dev/pandas', 'pymc-devs/pymc', 'scipy/scipy', 'conda-forge/staged-recipes', 'statsmodels/statsmodels'], 'ksunden': ['psf/black', 'matplotlib/matplotlib'], 'DatenBiene': ['scikit-learn/scikit-learn'], 'jona-sassenhagen': ['mne-tools/mne-python', 'scikit-learn/scikit-learn', 'scipy/scipy'], 'bhack': ['isocpp/CppCoreGuidelines', 'keras-team/keras', 'tensorflow/models', 'tensorflow/tensorboard'], 'kmh4321': ['tensorflow/datasets'], 'anushkrishnav': ['matplotlib/matplotlib', 'TheAlgorithms/Python'], 'kbrose': ['matplotlib/matplotlib', 'python/typeshed'], 'superbobry': ['python/cpython', 'cython/cython', 'google/jax', 'PyCQA/pylint', 'Theano/Theano'], 'tomMoral': ['python/cpython', 'dask/distributed', 'scikit-learn/scikit-learn'], 'benzyx': ['openai/gym'], 'xinan-jiang': ['tensorflow/tensor2tensor'], 'albertvillanova': ['huggingface/datasets', 'nltk/nltk', 'pandas-dev/pandas', 'pytest-dev/pytest', 'huggingface/transformers', 'scikit-learn/scikit-learn', 'tensorflow/datasets', 'tensorflow/models'], 'ashraf-bhuiyan': ['tensorflow/models'], 'teng-li': ['pytorch/tutorials'], 'fgb': ['wbond/package_control_channel'], 'franslarsson': ['scikit-learn/scikit-learn'], 'zblz': ['matplotlib/matplotlib', 'mlflow/mlflow', 'scipy/scipy'], 'wdirons': ['tensorflow/tensorboard'], 'tguillemot': ['jupyterhub/jupyterhub', 'scikit-image/scikit-image', 'scikit-learn/scikit-learn'], 'shashvatshahi1998': ['django/django', 'tensorflow/models', 'scipy/scipy', 'tensorflow/tensorboard'], 'jeromefv': ['matplotlib/matplotlib'], 'ppwwyyxx': ['open-mmlab/mmdetection', 'sphinx-doc/sphinx'], 'f0k': ['matplotlib/matplotlib', 'scikit-learn/scikit-learn', 'Theano/Theano'], 'charliec443': ['apache/airflow'], 'forrestm': ['matplotlib/matplotlib'], 'varunkumar-dev': ['networkx/networkx', 'pandas-dev/pandas', 'scikit-learn/scikit-learn'], 'genvalen': ['scikit-learn/scikit-learn'], 'kastnerkyle': ['dask/dask', 'pytorch/fairseq', 'getpelican/pelican-plugins', 'pymc-devs/pymc', 'Theano/Theano'], 'ciyongch': ['keras-team/keras', 'intel/Theano'], 'r1chardj0n3s': ['pallets/flask', 'openstack/horizon', 'kivy/kivy', 'pypa/pip', 'psf/requests', 'tox-dev/tox', 'pypa/warehouse', 'pallets/werkzeug'], 'cmarmo': ['astropy/astropy', 'numpy/numpy', 'scikit-learn/scikit-learn'], 'jianyuh': ['apache/tvm'], 'MartinPerez': ['mne-tools/mne-python'], 'soumith': ['pytorch/pytorch', 'conda-forge/staged-recipes'], 'chebee7i': ['ipython/ipython', 'matplotlib/matplotlib', 'networkx/networkx', 'pandas-dev/pandas', 'pymc-devs/pymc', 'getsentry/raven-python', 'readthedocs/readthedocs.org', 'sagemath/sage', 'scrapy/scrapy', 'statsmodels/statsmodels'], 'HH-MWB': ['pandas-dev/pandas'], 'xmunoz': ['python/peps', 'matrix-org/synapse', 'pypa/warehouse'], 'rjpower': ['conda/conda', 'google/jax', 'keras-team/keras', 'tensorflow/tensor2tensor'], 'jvdillon': ['tensorflow/probability'], 'k-w-w': ['nkconnor/models', 'tensorflow/tensorboard'], 'HastingsGreer': ['matplotlib/matplotlib'], 'heathhenley': ['python/cpython', 'keras-team/keras', 'matplotlib/matplotlib', 'scikit-learn/scikit-learn'], 'gvalkov': ['ansible/ansible', 'buildbot/buildbot', 'gitpython-developers/GitPython', 'home-assistant/core', 'pypa/pip', 'pypa/pipenv', 'qtile/qtile', 'tornadoweb/tornado'], 'mzeitlin11': ['pandas-dev/pandas'], 'benoit-pierre': ['python-pillow/Pillow', 'pypa/pip', 'pyinstaller/pyinstaller', 'pypa/setuptools', 'tox-dev/tox'], 'cjc7373': ['pypa/pip'], 'bmzhao': ['tensorflow/models'], 'cimarronm': ['matplotlib/matplotlib', 'numpy/numpy', 'saltstack/salt', 'scipy/scipy'], 'qinhanmin2014': ['scikit-learn/scikit-learn', 'huggingface/transformers'], 'realead': ['cython/cython', 'pandas-dev/pandas', 'scikit-learn/scikit-learn'], 'emcastillo': ['chainer/chainer', 'cupy/cupy'], 'sohero': ['matplotlib/matplotlib'], 'ebetica': ['pytorch/fairseq', 'ray-project/ray'], 'ryanbelt': ['matplotlib/matplotlib'], 'julianser': ['Theano/Theano'], 'mrocklin': ['cupy/cupy', 'dask/dask', 'dask/distributed', 'networkx/networkx', 'numpy/numpy', 'pandas-dev/pandas', 'scikit-image/scikit-image', 'zzzeek/sqlalchemy', 'conda-forge/staged-recipes', 'sympy/sympy', 'Theano/Theano', 'tornadoweb/tornado', 'pydata/xarray'], 'jucor': ['tensorflow/models', 'scikit-learn/scikit-learn', 'pallets/werkzeug'], 'sdegryze': ['pandas-dev/pandas', 'scikit-learn/scikit-learn'], 'garymm': ['pytorch/fairseq', 'pytorch/tutorials', 'pytorch/vision'], 'Licht-T': ['python/cpython', 'Guake/guake', 'apache/airflow', 'pandas-dev/pandas', 'pyinstaller/pyinstaller', 'scikit-learn/scikit-learn', 'scipy/scipy'], 'AlexKirko': ['pandas-dev/pandas'], 'bstriner': ['python/cpython', 'openai/gym', 'keras-team/keras', 'mlflow/mlflow', 'Theano/Theano'], 'topper-123': ['python/cpython', 'pandas-dev/pandas'], 'baam25simo': ['scikit-learn/scikit-learn'], 'behzadnouri': ['pandas-dev/pandas', 'scipy/scipy'], 'unutbu': ['ipython/ipython', 'matplotlib/matplotlib', 'pandas-dev/pandas', 'scipy/scipy'], 'amroamroamro': ['scikit-image/scikit-image'], 'nschloe': ['pandas-dev/pandas', 'scipy/scipy'], 'zaxtax': ['nltk/nltk', 'pymc-devs/pymc', 'scikit-learn/scikit-learn', 'sympy/sympy'], 'notoraptor': ['apache/tvm', 'Theano/Theano'], 'aitikgupta': ['coala/coala-bears'], 'wonghang': ['cupy/cupy', 'Theano/Theano'], 'meeseeksmachine': ['ipython/ipython', 'matplotlib/matplotlib', 'pandas-dev/pandas', 'scikit-image/scikit-image'], 'vaibhavhrt': ['pandas-dev/pandas'], 'kynan': ['pandas-dev/pandas', 'pypa/pip', 'OpenMined/PySyft', 'conda-forge/staged-recipes'], 'yui-knk': ['pandas-dev/pandas'], 'rafaelcaricio': ['encode/django-rest-framework', 'python/mypy', 'pypa/pip', 'saltstack/salt', 'tox-dev/tox', 'pallets/werkzeug'], 'hameerabbasi': ['numba/numba', 'scipy/scipy', 'conda-forge/staged-recipes'], 'lc0': ['chainer/chainer', 'tensorflow/datasets', 'tensorflow/models', 'OpenMined/PySyft'], 'kemaleren': ['scikit-image/scikit-image'], 'glemaitre': ['dask/dask', 'pandas-dev/pandas', 'pytorch/pytorch', 'scikit-image/scikit-image', 'scikit-learn/scikit-learn', 'scipy/scipy', 'conda-forge/staged-recipes', 'statsmodels/statsmodels'], 'botev': ['openai/gym', 'google/jax', 'Sarasra/models', 'Theano/Theano'], 'imaginary-person': ['apache/tvm'], 'simpkins': ['tornadoweb/tornado', 'python/typeshed'], 'shackenberg': ['celery/celery', 'keras-team/keras', 'Theano/Theano'], 'royxue': ['keras-team/keras', 'tensorflow/models', 'Theano/Theano'], 'niedbalski': ['ansible/ansible', 'buildbot/buildbot', 'benoitc/gunicorn', 'openstack/kolla', 'openstack/kolla-ansible', 'pypa/pip', 'tornadoweb/tornado'], 'wxs': ['keras-team/keras'], 'jnmclarty': ['vinta/awesome-python', 'python/cpython', 'dask/dask', 'python/mypy', 'pandas-dev/pandas'], 'vincentqb': ['pytorch/fairseq'], 'bburan-galenea': ['mne-tools/mne-python', 'pandas-dev/pandas'], 'tonyyli': ['matplotlib/matplotlib', 'pandas-dev/pandas', 'scipy/scipy'], 'tusharsadhwani': ['python/mypy'], 'adamklein': ['cython/cython', 'pandas-dev/pandas'], 'gdesjardins': ['Theano/Theano'], 'magnunor': ['dask/distributed', 'matplotlib/matplotlib', 'conda-forge/staged-recipes'], 'yifeif': ['keras-team/keras'], 'neggert': ['keras-team/keras', 'matplotlib/matplotlib', 'PyTorchLightning/pytorch-lightning'], 'NNemec': ['matplotlib/matplotlib', 'mesonbuild/meson'], 'frankchn': ['jupyterhub/jupyterhub', 'tensorflow/models'], 'pradyunsg': ['psf/black', 'python/cpython', 'PyCQA/isort', 'python/peps', 'pypa/pip', 'pypa/pipenv', 'pypa/packaging.python.org', 'psf/requests', 'RustPython/RustPython', 'pypa/setuptools', 'python/typeshed'], 'tonysyu': ['ipython/ipython', 'matplotlib/matplotlib', 'scikit-image/scikit-image'], 'carljm': ['ansible/ansible-modules-extras', 'psf/black', 'python/cpython', 'django/django', 'benoitc/gunicorn', 'PyCQA/isort', 'python/mypy', 'pypa/pip', 'getsentry/raven-python', 'python/typeshed'], 'alex': ['ansible/ansible', 'boto/boto', 'cookiecutter/cookiecutter', 'python/cpython', 'pyca/cryptography', 'django/django', 'jazzband/django-debug-toolbar', 'benoitc/gunicorn', 'HypothesisWorks/hypothesis', 'certbot/josepy', 'celery/kombu', 'certbot/certbot', 'apache/libcloud', 'MongoEngine/mongoengine', 'pypa/pip', 'Pylons/pyramid', 'pytest-dev/pytest', 'realpython/python-guide', 'getsentry/raven-python', 'readthedocs/readthedocs.org', 'psf/requests', 'getsentry/sentry', 'pypa/setuptools', 'sphinx-doc/sphinx', 'zzzeek/sqlalchemy', 'urllib3/urllib3', 'pypa/warehouse', 'pallets/werkzeug', 'zulip/zulip'], 'ionelmc': ['vinta/awesome-python', 'borgbackup/borg', 'celery/celery', 'pallets/click', 'cookiecutter/cookiecutter', 'django-cms/django-cms', 'jazzband/django-debug-toolbar', 'PyCQA/isort', 'celery/kombu', 'getpelican/pelican', 'getpelican/pelican-plugins', 'pypa/pip', 'pytest-dev/pytest', 'pypa/packaging.python.org', 'psf/requests', 'sphinx-doc/sphinx', 'tox-dev/tox'], 'smessmer': ['python/typeshed'], 'mingfeima': ['pytorch/fairseq', 'huggingface/transformers'], 'danFromTelAviv': ['keras-team/keras'], 'ashahba': ['kubeflow/pipelines', 'pytorch/pytorch', 'tensorflow/models'], 'edgarriba': ['pytorch/pytorch'], 'mynameisfiber': ['ipython/ipython', 'keras-team/keras', 'tornadoweb/tornado'], 'adbrebs': ['Theano/Theano'], 'nelson-liu': ['allenai/allennlp', 'pytorch/fairseq', 'scikit-learn/scikit-learn', 'conda-forge/staged-recipes', 'huggingface/transformers', 'pytorch/tutorials']}



g = nx.Graph(repos)
B = g


components = sorted(nx.connected_components(B), key=len, reverse=True)
largest_component = components[0]
C = B.subgraph(largest_component)


X, Y = bipartite.sets(C)

G = nx.Graph()

for repo in Y:
    repo = str(repo)
    contrs = C.neighbors(repo)
    contr_list = [n for n in contrs]
    for user in contr_list:
        usr_list = copy.deepcopy(contr_list)
        usr_list.remove(user)
        # iterate over other contributors and add edges 
        for other_user in usr_list:
            if G.has_edge(other_user, user):
                G[user][other_user]['weight'] += 1
            else:
                G.add_edge(other_user, user, weight=0)




pos = dict()
pos.update( (n, (1, i)) for i, n in enumerate(X) ) # put nodes from X at x=1
pos.update( (n, (2, i)) for i, n in enumerate(Y) ) # put nodes from Y at x=2
nx.draw(C, pos=pos)
plt.show()


