from typing import Counter
import operator


def get_top_topic(network):
    """
    Calculates the topic with highest edge weight sum
    :param network: networkx.Graph
            Graph with dict as edge attribute 'weight'
    :return:
        top:
         Topic with highest edge weight sum
        thresh: double
         Weight sum of top topic / number of edges
    """
    topic_dict = Counter({})
    for u, v, d in network.edges(data=True):
        topic_dict += Counter(d['weight'])
    topic_dict = dict(topic_dict)
    top = max(topic_dict.items(), key=operator.itemgetter(1))[0]
    thresh = max(topic_dict.values()) / len(network.edges())
    return top, thresh