diff --git a/.gitignore b/.gitignore index 8062951..e0235b5 100644 --- a/.gitignore +++ b/.gitignore @@ -183,3 +183,5 @@ listevent.xml relations.csv hansi.* media/relations.gexf +edges.csv +nodes.csv diff --git a/apis_core/apis_entities/models.py b/apis_core/apis_entities/models.py index 9efe364..6e4870d 100644 --- a/apis_core/apis_entities/models.py +++ b/apis_core/apis_entities/models.py @@ -528,6 +528,10 @@ def get_api_url(self): def get_icon(self): return "bi bi-people apis-person" + @classmethod + def get_color(self): + return "#720e07" + class Place(AbstractEntity): kind = models.ForeignKey( @@ -559,6 +563,10 @@ def get_api_url(self): def get_icon(self): return "bi bi-map apis-place" + @classmethod + def get_color(self): + return "#5bc0eb" + class Institution(AbstractEntity): kind = models.ForeignKey( @@ -582,6 +590,10 @@ def get_api_url(self): def get_icon(self): return "bi bi-building-gear apis-institution" + @classmethod + def get_color(self): + return "#1d3461" + class Event(AbstractEntity): kind = models.ForeignKey( @@ -605,6 +617,10 @@ def get_api_url(self): def get_icon(self): return "bi bi-calendar3 apis-event" + @classmethod + def get_color(self): + return "#9bc53d" + class Work(AbstractEntity): kind = models.ForeignKey(WorkType, blank=True, null=True, on_delete=models.SET_NULL) @@ -626,6 +642,10 @@ def get_api_url(self): def get_icon(self): return "bi bi-book apis-work" + @classmethod + def get_color(self): + return "#ff8600" + a_ents = getattr(settings, "APIS_ADDITIONAL_ENTITIES", False) diff --git a/apis_core/apis_relations/management/commands/dump_relations.py b/apis_core/apis_relations/management/commands/dump_relations.py index 5eb777a..14d79dc 100644 --- a/apis_core/apis_relations/management/commands/dump_relations.py +++ b/apis_core/apis_relations/management/commands/dump_relations.py @@ -43,7 +43,13 @@ def handle(self, *args: Any, **options: Any) -> str | None: df.set_index("relation_pk", inplace=True, drop=False) indexer = recordlinkage.Index() indexer.block( - ["relation_type", "source_id", "target_id", "start_date", "end_date"] + [ + "relation_type", + "source_id", + "target_id", + "relation_start_date_written", + "relation_end_date_written", + ] ) duplicates = indexer.index(df) print(f"deleting {len(duplicates)} duplicated relations") @@ -71,7 +77,6 @@ def handle(self, *args: Any, **options: Any) -> str | None: except Exception as e: ic(e) print("and now serialize relations as network graph") - colors = settings.PMB_COLORS G = nx.Graph() for i, row in tqdm(df.iterrows(), total=len(df)): G.add_nodes_from( @@ -81,7 +86,7 @@ def handle(self, *args: Any, **options: Any) -> str | None: { "label": row["source"], "type": row["source_type"], - "color": colors[row["source_type"]], + "color": row["source_color"], }, ) ] @@ -93,7 +98,7 @@ def handle(self, *args: Any, **options: Any) -> str | None: { "label": row["target"], "type": row["target_type"], - "color": colors[row["target_type"]], + "color": row["target_color"], }, ) ] diff --git a/apis_core/apis_relations/models.py b/apis_core/apis_relations/models.py index 06cd335..1578633 100644 --- a/apis_core/apis_relations/models.py +++ b/apis_core/apis_relations/models.py @@ -52,14 +52,24 @@ def get_web_object(self): result = { "relation_pk": self.pk, "relation_type": self.relation_type.name, - "source": namea, + "relation_class": f"{namea._meta.verbose_name} -> {nameb._meta.verbose_name}", + "relation_name": self.__str__(), + "relation_start_date": f"{self.start_date}", + "relation_end_date": f"{self.end_date}", + "relation_start_date_written": f"{self.start_date_written}", + "relation_end_date_written": f"{self.end_date_written}", + "source": namea.__str__(), "source_id": namea.id, "source_type": namea._meta.verbose_name, - "target": nameb, + "source_start_date": f"{namea.start_date}", + "source_start_date_written": f"{namea.start_date_written}", + "source_color": namea.get_color(), + "target": nameb.__str__(), "target_id": nameb.id, "target_type": nameb._meta.verbose_name, - "start_date": self.start_date_written, - "end_date": self.end_date_written, + "target_start_date": f"{nameb.start_date}", + "target_start_date_written": f"{nameb.start_date_written}", + "target_color": nameb.get_color(), } return result diff --git a/pmb/settings.py b/pmb/settings.py index 6b2dd75..0ce631e 100644 --- a/pmb/settings.py +++ b/pmb/settings.py @@ -298,12 +298,3 @@ ], }, } - -PMB_COLORS = { - "Person": "#720e07", - "Ort": "#5bc0eb", - "Werk": "#ff8600", - "Ereignis": "#9bc53d", - "Institution": "#1d3461", - "PMB": "#9B5F98", -}