Skip to content

Commit

Permalink
wip network #157
Browse files Browse the repository at this point in the history
  • Loading branch information
csae8092 committed Feb 26, 2024
1 parent d0775a5 commit 34a0cc5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,5 @@ listevent.xml
relations.csv
hansi.*
media/relations.gexf
edges.csv
nodes.csv
20 changes: 20 additions & 0 deletions apis_core/apis_entities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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)
Expand All @@ -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)

Expand Down
13 changes: 9 additions & 4 deletions apis_core/apis_relations/management/commands/dump_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand All @@ -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"],
},
)
]
Expand All @@ -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"],
},
)
]
Expand Down
18 changes: 14 additions & 4 deletions apis_core/apis_relations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 0 additions & 9 deletions pmb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,3 @@
],
},
}

PMB_COLORS = {
"Person": "#720e07",
"Ort": "#5bc0eb",
"Werk": "#ff8600",
"Ereignis": "#9bc53d",
"Institution": "#1d3461",
"PMB": "#9B5F98",
}

0 comments on commit 34a0cc5

Please sign in to comment.