Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit 22baefb

Browse files
committed
Merge branch 'master' into release
2 parents e7cd5d6 + 605caaf commit 22baefb

File tree

1 file changed

+8
-6
lines changed
  • apps/topics-map/src/python/topics_map

1 file changed

+8
-6
lines changed

apps/topics-map/src/python/topics_map/map.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def int_or_zero(value: str) -> int:
301301
return 0
302302

303303

304-
def assign_colors(db: DatabaseHandler, graph: nx.Graph, color_by: str, boolean: bool=False) -> None:
304+
def assign_colors(db: DatabaseHandler, graph: nx.Graph, color_by: str, bool: bool=False) -> None:
305305
"""Assign a 'color' attribute to each node in the graph.
306306
307307
Each color will be in '#FFFFFF' format.
@@ -311,7 +311,7 @@ def assign_colors(db: DatabaseHandler, graph: nx.Graph, color_by: str, boolean:
311311
log.warning(f'assign colors by {color_by}')
312312
for n in graph.nodes:
313313
value = str(graph.nodes[n].get(color_by, 'null'))
314-
if boolean:
314+
if bool:
315315
graph.nodes[n]['color'] = 'b4771f' if int_or_zero(value) > 0 else 'dddddd'
316316
else:
317317
graph.nodes[n]['color'] = get_consistent_color(db, color_by, value)
@@ -597,7 +597,7 @@ def get_giant_component(graph: nx.Graph) -> nx.Graph:
597597
return graph.subgraph(components[-1]) if len(components) > 0 else graph
598598

599599

600-
def generate_graph(db: DatabaseHandler, timespans_id: int) -> nx.Graph:
600+
def generate_graph(db: DatabaseHandler, timespans_id: int, remove_platforms: bool = True) -> nx.Graph:
601601
"""Generate a graph of the network of media for the given timespan, but do not layout."""
602602
media = get_media_network(db=db, timespans_id=timespans_id)
603603
graph = get_media_graph(media=media)
@@ -608,9 +608,10 @@ def generate_graph(db: DatabaseHandler, timespans_id: int) -> nx.Graph:
608608

609609
log.info(f"graph after giant component: {len(graph.nodes())} nodes")
610610

611-
graph = remove_platforms_from_graph(graph=graph)
611+
if remove_platforms:
612+
graph = remove_platforms_from_graph(graph=graph)
612613

613-
log.info(f"graph after platform removal: {len(graph.nodes())} nodes")
614+
log.info(f"graph after platform removal: {len(graph.nodes())} nodes")
614615

615616
return graph
616617

@@ -644,12 +645,13 @@ def get_default_size_attribute(db: DatabaseHandler, timespans_id: int) -> str:
644645
def generate_and_layout_graph(db: DatabaseHandler,
645646
timespans_id: int,
646647
memory_limit_mb: int,
648+
remove_platforms: bool = True,
647649
color_by: str = 'community') -> nx.Graph:
648650
"""Generate and layout a graph of the network of media for the given timespan.
649651
650652
The layout algorithm is force atlas 2, and the resulting is 'position' attribute added to each node.
651653
"""
652-
graph = generate_graph(db=db, timespans_id=timespans_id)
654+
graph = generate_graph(db=db, timespans_id=timespans_id, remove_platforms=remove_platforms)
653655
# run layout with all nodes in giant component, before reducing to smaler number to display
654656
run_fa2_layout(graph=graph, memory_limit_mb=memory_limit_mb)
655657

0 commit comments

Comments
 (0)