Esempio n. 1
0
def add_graph_infos(graph, folder, ego):
    infos_commenters = main_jsons.calculate_info_commenters(folder, ego)
    infos_likers = main_jsons.calculate_info_likers(folder, ego)
    for v in graph.vs:
        name = v['name'].decode('utf-8')
        v['nb_likes'] = int(infos_likers.get(name, 0))
        v['nb_comments'] = int(infos_commenters.get(name, {}).get('nb_of_comments', 0))
        v['sum_comments_likes'] = int(v['nb_comments']) + int(v['nb_likes'])
Esempio n. 2
0
def print_info_communities(folder, ego, graph):
    clusters_list_temp = graph.community_multilevel()
    clusters_list = []
    for cluster in clusters_list_temp:
        temp = []
        for index in cluster:
            temp.append(graph.vs[index]['name'].decode('utf-8'))
        clusters_list.append(temp)
        
    info_commenters = main_jsons.calculate_info_commenters(folder, ego)
    info_likers = main_jsons.calculate_info_likers(folder, ego)
    info_likers_of_comment = main_jsons.calculate_info_likers_of_comment(folder, ego)

    info_per_cluster = {}
    for cluster in clusters_list:
        info_per_cluster[str(cluster)] = {'nb_comments' : 0, 'nb_likes' : 0, 'nb_likes_of_comments' : 0}
    for cluster in clusters_list:
        info_current = info_per_cluster[str(cluster)]
        for name in cluster:
            if name in info_commenters:
                info_current['nb_comments'] += info_commenters[name]['nb_of_comments']
            if name in info_likers:
                info_current['nb_likes'] += info_likers[name]
            if name in info_likers_of_comment:
                info_current['nb_likes_of_comments'] += info_likers_of_comment[name]
    index_cluster = 0
    sorted_info = []
    for cluster in clusters_list:
        index_cluster += 1
        info_current = info_per_cluster[str(cluster)]
        sorted_info.append((cluster, 
                            info_current['nb_comments'], 
                            info_current['nb_likes'], 
                            info_current['nb_likes_of_comments'],
                            index_cluster))
    sorted_info.sort(key=lambda tup: 3*tup[1]+2*tup[2]+tup[1], reverse = True)
    csv_file = open('GALLERY/'+folder+'/'+ego+'/CSV/list_of_clusters.csv', 'wb')
    writer = csv.writer(csv_file, delimiter = ';')
    for info in sorted_info:
        temp = [info[4]]
        for name in info[0]:
            friend_info = main_jsons.find_friend(folder, ego, name)
            if 'name' in friend_info:
                temp.append(friend_info['name'])
            else:
                temp.append(friend_info['id'])
        writer.writerow([unicode(elem).encode('utf-8') for elem in temp])
        writer.writerow(['nombre de commentaires', 
                         'nombre de likes', 
                         'nombre de likes de commentaires'])
        to_write = []
        writer.writerow(info[1:len(info)-1])
    csv_file.close()
    return clusters_list
Esempio n. 3
0
def add_graph_infos(graph, folder, ego):
    infos_commenters = main_jsons.calculate_info_commenters(folder, ego)
    infos_likers = main_jsons.calculate_info_likers(folder, ego)
    for v in graph.vs:
        if v['name'] in infos_likers:
            v['nb_likes'] = int(infos_likers[v['name']])
        else:
            v['nb_likes'] = 0
        if v['name'] in infos_commenters:
            v['nb_comments'] = int(infos_commenters[v['name']]['nb_of_comments'])
        else:
            v['nb_comments'] = 0
    for v in graph.vs:
        v['sum_comments_likes'] = int(v['nb_comments']) + int(v['nb_likes'])
        v['name'] = v['name'].encode('utf8')
Esempio n. 4
0
def print_info_commenters_likers(folder, ego, clusters_list):
    list_of_friends = main_jsons.list_of_friends(folder, ego)
    info_commenters = main_jsons.calculate_info_commenters(folder, ego)
    info_likers = main_jsons.calculate_info_likers(folder, ego)
    info_likers_of_comment = main_jsons.calculate_info_likers_of_comment(folder, ego)
    csv_file = open('GALLERY/'+folder+'/'+ego+'/'+'CSV/list_of_commenters_likers.csv', 'wb')
    writer = csv.writer(csv_file, delimiter=';')
    writer.writerow(['id/nom', 'nombre de commentaires', 'nombre de statuts commentés', 'nombre de likes de statuts', 'nombre de likes de commentaires', 'cluster']) 
    
    sorted_info = []
    for friend in list_of_friends:
        cluster_of_this_friend = 0
        for cluster in clusters_list:
            cluster_of_this_friend += 1
            if friend in cluster:
                break
        if friend in info_commenters:
            info_commenter = info_commenters[friend]
        else:
            info_commenter = {'nb_of_comments' : 0, 'nb_of_statuses' : 0}
        if friend in info_likers:
            info_liker = info_likers[friend]
        else:
            info_liker = 0
        if friend in info_likers_of_comment:
            info_liker_of_comment = info_likers_of_comment[friend]
        else:
            info_liker_of_comment = 0
        friend_info = main_jsons.find_friend(folder, ego, friend)
        if 'name' in friend_info:
            friend = friend_info['name']
        infos_list = ((friend, 
                            info_commenter['nb_of_comments'], 
                            info_commenter['nb_of_statuses'], 
                            info_liker, 
                            info_liker_of_comment,
                            cluster_of_this_friend))
        
        sorted_info.append([unicode(s).encode("utf-8") for s in infos_list])
        
    sorted_info.sort(key=lambda tup: 4*tup[1]+3*tup[3]+2*tup[4]+tup[1], reverse = True) 
    
    for info in sorted_info:
        writer.writerow(info) 
        
    csv_file.close()