Improve citations graph

This commit is contained in:
Maximilian Blochberger committed 2021-03-17 08:48:32 +01:00
1 parent 7d007f0283
commit 47a0070aa6
2 files changed
+19 -6

No files matched your search

+13 -6
View File
@@ -3,13 +3,13 @@ from typing import Set, Tuple
from django.core.management.base import BaseCommand, CommandParser
from django.db.models import Count, Q
from sok.models import Publication
from sok.models import Publication, PublicationReference
class Command(BaseCommand):
def echo(self, msg: str):
self.stdout.write(msg)
def echo(self, msg: str, nl: bool = True):
self.stdout.write(msg, ending='\n' if nl else '')
# BaseCommand
@@ -27,7 +27,7 @@ class Command(BaseCommand):
).filter(citation_count__gte=min_citations)
self.echo("digraph G {")
self.echo("\trankdir = RL;")
self.echo("\trankdir = BT;")
graph: Set[Tuple[int, int]] = set()
@@ -48,9 +48,16 @@ class Command(BaseCommand):
))
if pk:
self.echo(f'\t"{publication.pk}" -> "{reference.pk}";')
self.echo(f'\t"{publication.pk}" -> "{reference.pk}"',nl=False)
else:
self.echo(f'\t"{publication.cite_key}" -> "{reference.cite_key}";')
self.echo(f'\t"{publication.cite_key}" -> "{reference.cite_key}"', nl=False)
rel = PublicationReference.objects.get(publication=publication, reference=reference)
if rel.is_self_cite:
self.echo(" [style=dashed]", nl=False)
self.echo(";")
self.echo("}")