mirror of
https://github.com/lukefleed/imdb-graph.git
synced 2026-10-06 21:34:51 +00:00
now the both work fine
This commit is contained in:
Executable
BIN
Binary file not shown.
@@ -226,7 +226,7 @@ vector<pair<int, double>> closeness(const size_t k) {
|
|||||||
|
|
||||||
ofstream output_file("visualization/top_actors_c.txt");
|
ofstream output_file("visualization/top_actors_c.txt");
|
||||||
for (const auto& [actor_id, farness] : top_actors) {
|
for (const auto& [actor_id, farness] : top_actors) {
|
||||||
output_file << actor_id << "\t" << 1.0/farness << endl;
|
output_file << actor_id << "\t" << A[actor_id].name << "\t" << 1.0/farness << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return top_actors;
|
return top_actors;
|
||||||
@@ -317,7 +317,7 @@ vector<pair<int, double>> harmonic(const size_t k) { //
|
|||||||
|
|
||||||
ofstream output_file("visualization/top_actors_h.txt");
|
ofstream output_file("visualization/top_actors_h.txt");
|
||||||
for (const auto& [actor_id, harmonic] : top_actors) {
|
for (const auto& [actor_id, harmonic] : top_actors) {
|
||||||
output_file << actor_id << "\t" << harmonic << endl;
|
output_file << actor_id << "\t" << A[actor_id].name << "\t" << harmonic << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Executable
BIN
Binary file not shown.
@@ -76,7 +76,7 @@ void DataRead()
|
|||||||
|
|
||||||
void BuildGraph()
|
void BuildGraph()
|
||||||
{
|
{
|
||||||
ifstream relations("data/Relazioni.txt");
|
ifstream relations("../data/data_movie_graph/Relazioni.txt");
|
||||||
string s;
|
string s;
|
||||||
const string space = "\t";
|
const string space = "\t";
|
||||||
|
|
||||||
@@ -213,7 +213,7 @@ vector<pair<int, double>> closeness(const size_t k) {
|
|||||||
top_movies.pop_back();
|
top_movies.pop_back();
|
||||||
top_movies_mutex.unlock(); // Release the ownerhsip (we are done with top_movies)
|
top_movies_mutex.unlock(); // Release the ownerhsip (we are done with top_movies)
|
||||||
|
|
||||||
cout << film_id << " " << F[film_id].name << "\n\t\x1b[36m"CC: " << 1.0/farness "<< endl;
|
cout << film_id << " " << F[film_id].name << "\n\tCC: " << 1.0/farness << endl;
|
||||||
// top_actors_lock gets destroyed after this line, releasing the mutex
|
// top_actors_lock gets destroyed after this line, releasing the mutex
|
||||||
}
|
}
|
||||||
}, i));
|
}, i));
|
||||||
@@ -225,7 +225,7 @@ vector<pair<int, double>> closeness(const size_t k) {
|
|||||||
|
|
||||||
ofstream output_file("../visualization/movie_graph/data/top_movies_c.txt");
|
ofstream output_file("../visualization/movie_graph/data/top_movies_c.txt");
|
||||||
for (const auto& [film_id, farness] : top_movies) {
|
for (const auto& [film_id, farness] : top_movies) {
|
||||||
output_file << film_id << "\t" << 1.0/farness << endl;
|
output_file << film_id << "\t" << F[film_id].name << "\t" << 1.0/farness << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return top_movies;
|
return top_movies;
|
||||||
@@ -316,7 +316,7 @@ vector<pair<int, double>> harmonic(const size_t k) { //
|
|||||||
|
|
||||||
ofstream output_file("../visualization/movie_graph/data/top_movies_h.txt");
|
ofstream output_file("../visualization/movie_graph/data/top_movies_h.txt");
|
||||||
for (const auto& [film_id, harmonic] : top_movies) {
|
for (const auto& [film_id, harmonic] : top_movies) {
|
||||||
output_file << film_id << "\t" << harmonic << endl;
|
output_file << film_id << "\t" << F[film_id].name << "\t" << harmonic << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
from itertools import combinations
|
|
||||||
from math import comb
|
|
||||||
from matplotlib.pyplot import title
|
|
||||||
import networkx as nx
|
|
||||||
from pyvis.network import Network
|
|
||||||
|
|
||||||
net = Network(height='100%', width='100%', directed=False, bgcolor='#1e1f29', font_color='white')
|
|
||||||
|
|
||||||
actors_to_keep = []
|
|
||||||
farness_to_keep= []
|
|
||||||
with open('data/top_actors_c.txt') as ifs:
|
|
||||||
for line in ifs:
|
|
||||||
if line.strip():
|
|
||||||
actor_id, farness = line.split(maxsplit=1)
|
|
||||||
actors_to_keep.append(int(actor_id))
|
|
||||||
farness_to_keep.append(float(farness))
|
|
||||||
|
|
||||||
with open('data/Attori.txt') as ifs:
|
|
||||||
for line in ifs:
|
|
||||||
if line.strip():
|
|
||||||
actor_id, actor_name = line.split(maxsplit=1)
|
|
||||||
actor_id = int(actor_id)
|
|
||||||
farness = float(farness)
|
|
||||||
if actor_id in actors_to_keep:
|
|
||||||
if farness in farness_to_keep:
|
|
||||||
net.add_node(actor_id, label=actor_name, size =pow(5,1.0/(farness*2)))
|
|
||||||
|
|
||||||
movies = {} # {movie_id: [actor_id, ...]}
|
|
||||||
with open('data/Relazioni.txt') as ifs:
|
|
||||||
for line in ifs:
|
|
||||||
if line.strip():
|
|
||||||
movie_id, actor_id = line.split(maxsplit=1)
|
|
||||||
actor_id = int(actor_id)
|
|
||||||
movie_id = int(movie_id)
|
|
||||||
if actor_id not in net.node_ids:
|
|
||||||
continue
|
|
||||||
if movie_id in movies:
|
|
||||||
movies[movie_id].append(actor_id)
|
|
||||||
else:
|
|
||||||
movies[movie_id] = [actor_id]
|
|
||||||
|
|
||||||
edges = set() # set of unique tuples (actor_id, actor_id)
|
|
||||||
for movie_id, actors in movies.items():
|
|
||||||
actors.sort()
|
|
||||||
for actor_id_1, actor_id_2 in combinations(actors, 2):
|
|
||||||
edges.add((actor_id_1, actor_id_2))
|
|
||||||
for actor_id_1, actor_id_2 in edges:
|
|
||||||
net.add_edge(actor_id_1, actor_id_2)
|
|
||||||
|
|
||||||
# net.hrepulsion(node_distance=500, central_gravity=0.3, spring_length=500, spring_strength=0.05, damping=0.2)
|
|
||||||
# net.repulsion(node_distance=500, central_gravity=0.3, spring_length=200, spring_strength=0.05, damping=0.2)
|
|
||||||
# net.show_buttons()
|
|
||||||
|
|
||||||
net.set_options("""
|
|
||||||
var options = {
|
|
||||||
"nodes": {
|
|
||||||
"borderWidthSelected": 3
|
|
||||||
},
|
|
||||||
"edges": {
|
|
||||||
"color": {
|
|
||||||
"inherit": true
|
|
||||||
},
|
|
||||||
"smooth": false
|
|
||||||
},
|
|
||||||
"physics": {
|
|
||||||
"repulsion": {
|
|
||||||
"centralGravity": 8.95,
|
|
||||||
"springLength": 500,
|
|
||||||
"springConstant": 0.015,
|
|
||||||
"nodeDistance": 600,
|
|
||||||
"damping": 0.67
|
|
||||||
},
|
|
||||||
"minVelocity": 0.75,
|
|
||||||
"solver": "repulsion"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
""")
|
|
||||||
|
|
||||||
net.show('html-files/closeness-graph.html')
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
from itertools import combinations
|
|
||||||
from math import comb
|
|
||||||
from matplotlib.pyplot import title
|
|
||||||
import networkx as nx
|
|
||||||
from pyvis.network import Network
|
|
||||||
|
|
||||||
net = Network(height='100%', width='100%', directed=False, bgcolor='#1e1f29', font_color='white')
|
|
||||||
|
|
||||||
actors_to_keep = []
|
|
||||||
harmonic_to_keep =[]
|
|
||||||
with open('data/top_actors_h.txt') as ifs:
|
|
||||||
for line in ifs:
|
|
||||||
if line.strip():
|
|
||||||
actor_id, harmonic = line.split(maxsplit=1)
|
|
||||||
actors_to_keep.append(int(actor_id))
|
|
||||||
harmonic_to_keep.append(float(harmonic))
|
|
||||||
|
|
||||||
with open('data/Attori.txt') as ifs:
|
|
||||||
for line in ifs:
|
|
||||||
if line.strip():
|
|
||||||
actor_id, actor_name = line.split(maxsplit=1)
|
|
||||||
actor_id = int(actor_id)
|
|
||||||
harmonic = float(harmonic)
|
|
||||||
if actor_id in actors_to_keep:
|
|
||||||
if harmonic in harmonic_to_keep:
|
|
||||||
net.add_node(actor_id, label=actor_name, size = harmonic/350)
|
|
||||||
|
|
||||||
movies = {} # {movie_id: [actor_id, ...]}
|
|
||||||
with open('data/Relazioni.txt') as ifs:
|
|
||||||
for line in ifs:
|
|
||||||
if line.strip():
|
|
||||||
movie_id, actor_id = line.split(maxsplit=1)
|
|
||||||
actor_id = int(actor_id)
|
|
||||||
movie_id = int(movie_id)
|
|
||||||
if actor_id not in net.node_ids:
|
|
||||||
continue
|
|
||||||
if movie_id in movies:
|
|
||||||
movies[movie_id].append(actor_id)
|
|
||||||
else:
|
|
||||||
movies[movie_id] = [actor_id]
|
|
||||||
|
|
||||||
edges = set() # set of unique tuples (actor_id, actor_id)
|
|
||||||
for movie_id, actors in movies.items():
|
|
||||||
actors.sort()
|
|
||||||
for actor_id_1, actor_id_2 in combinations(actors, 2):
|
|
||||||
edges.add((actor_id_1, actor_id_2))
|
|
||||||
for actor_id_1, actor_id_2 in edges:
|
|
||||||
net.add_edge(actor_id_1, actor_id_2)
|
|
||||||
|
|
||||||
# net.hrepulsion(node_distance=500, central_gravity=0.3, spring_length=500, spring_strength=0.05, damping=0.2)
|
|
||||||
# net.repulsion(node_distance=500, central_gravity=0.3, spring_length=200, spring_strength=0.05, damping=0.2)
|
|
||||||
# net.show_buttons()
|
|
||||||
|
|
||||||
net.set_options("""
|
|
||||||
var options = {
|
|
||||||
"edges": {
|
|
||||||
"color": {
|
|
||||||
"inherit": true
|
|
||||||
},
|
|
||||||
"smooth": false
|
|
||||||
},
|
|
||||||
"physics": {
|
|
||||||
"repulsion": {
|
|
||||||
"springLength": 1205,
|
|
||||||
"nodeDistance": 1190
|
|
||||||
},
|
|
||||||
"maxVelocity": 23,
|
|
||||||
"minVelocity": 0.75,
|
|
||||||
"solver": "repulsion"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
""")
|
|
||||||
|
|
||||||
net.show('html-files/harmonic-graph.html')
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
from itertools import combinations
|
|
||||||
from math import comb
|
|
||||||
import networkx as nx
|
|
||||||
from pyvis.network import Network
|
|
||||||
|
|
||||||
net = Network(height='100%', width='100%', directed=False, bgcolor='#1e1f29', font_color='white')
|
|
||||||
with open('data/FilmFiltrati.txt') as ifs:
|
|
||||||
for line in ifs:
|
|
||||||
if line.strip():
|
|
||||||
movie_id, movie_name = line.split(maxsplit=1)
|
|
||||||
net.add_node(int(movie_id), label=movie_name)
|
|
||||||
|
|
||||||
actors = {} # {movie_id: [actor_id, ...]}
|
|
||||||
with open('data/Relazioni.txt') as ifs:
|
|
||||||
for line in ifs:
|
|
||||||
if line.strip():
|
|
||||||
movie_id, actor_id = line.split(maxsplit=1)
|
|
||||||
actor_id = int(actor_id)
|
|
||||||
movie_id = int(movie_id)
|
|
||||||
if movie_id not in net.node_ids:
|
|
||||||
continue
|
|
||||||
if actor_id in actors:
|
|
||||||
actors[actor_id].append(movie_id)
|
|
||||||
else:
|
|
||||||
actors[actor_id] = [movie_id]
|
|
||||||
|
|
||||||
edges = set() # set of unique tuples (actor_id, actor_id)
|
|
||||||
for actor_id, actors in actors.items():
|
|
||||||
actors.sort()
|
|
||||||
for movie_id_1, movie_id_2 in combinations(actors, 2):
|
|
||||||
edges.add((movie_id_1, movie_id_2))
|
|
||||||
for movie_id_1, movie_id_2 in edges:
|
|
||||||
net.add_edge(movie_id_1, movie_id_2)
|
|
||||||
|
|
||||||
# net.hrepulsion(node_distance=500, central_gravity=0.3, spring_length=500, spring_strength=0.05, damping=0.2)
|
|
||||||
# net.repulsion(node_distance=500, central_gravity=0.3, spring_length=200, spring_strength=0.05, damping=0.2)
|
|
||||||
# net.show_buttons()
|
|
||||||
|
|
||||||
net.set_options(""""
|
|
||||||
var options = {
|
|
||||||
"edges": {
|
|
||||||
"color": {
|
|
||||||
"inherit": true
|
|
||||||
},
|
|
||||||
"smooth": false
|
|
||||||
},
|
|
||||||
"physics": {
|
|
||||||
"repulsion": {
|
|
||||||
"centralGravity": 0.25,
|
|
||||||
"nodeDistance": 500,
|
|
||||||
"damping": 0.67
|
|
||||||
},
|
|
||||||
"maxVelocity": 48,
|
|
||||||
"minVelocity": 0.39,
|
|
||||||
"solver": "repulsion"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
""")
|
|
||||||
|
|
||||||
net.show('html-files/imdb-graph.html')
|
|
||||||
Reference in New Issue
Block a user