You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This isn't a bug, but a question for help / hints.
I would like to use lolviz to create a graph of my python class structure. Every class-attribute is type annotated, so it should be possible to like their interactions without creating class instances. Here is a minimal example:
from copy import deepcopy
from lolviz import *
class Workout:
def __init__(
self,
date: dt.date,
name: str = "",
duration: int = 0
):
# assert isinstance(tss, (np.number, int))
self.date: dt.date = date
self.name: str = name
self.duration: int = duration # in seconds
self.done: boolean = False
class Athlete:
def __init__(
self,
name: str,
birthday: dt.date,
sports: List[str]
):
self.name: str = name
self.birthday: dt.date = birthday
self.sports: List[str] = sports
class DataContainer:
def __init__(self,
athlete: Athlete,
tasks: List[Workout] = [],
fulfilled: List[Workout] = []):
self.athelete: Athlete = athlete
self.tasks: List[Workout] = [w for w in tasks if isinstance(w, Workout)]
self.fulfilled: List[Workout] = [w for w in fulfilled if isinstance(w, Workout)]
me = Athlete("nico", dt(1990,3,1).date(), sports=["running","climbing"])
t1 = Workout(date=dt(2020,1,1).date(), name="5k Run")
f1 = deepcopy(t1)
f1.done = True
dc1 = DataContainer(me, tasks=[t1], fulfilled=[f1])
Now I can use objviz(dc1) to create the following diagram:
What I actually would like to achieve is a command like classviz(DataContainer) which will give me a similar chart, but not with the actual attribute values but their types. For sure there will be other small changes, but that's the basic idea.
What I already can do is something like:
def get_types(annotated_class):
return (annotated_class.__name__, {k: v.__name__ for k,v in annotated_class.__init__.__annotations__.items()})
get_types(Workout)
which gives me something like: ('Workout', {'date': 'date', 'name': 'str', 'duration': 'int'}). How ever I don't find a proper way to create similar table-elements which contain Workout in the header and the name-attribute mapping in it's body.
Can someone give me a hint, how to create such tables manually? I am also happy for any additional advices
The text was updated successfully, but these errors were encountered:
This isn't a bug, but a question for help / hints.
I would like to use lolviz to create a graph of my python class structure. Every class-attribute is type annotated, so it should be possible to like their interactions without creating class instances. Here is a minimal example:
Now I can use
objviz(dc1)
to create the following diagram:What I actually would like to achieve is a command like
classviz(DataContainer)
which will give me a similar chart, but not with the actual attribute values but their types. For sure there will be other small changes, but that's the basic idea.What I already can do is something like:
which gives me something like:
('Workout', {'date': 'date', 'name': 'str', 'duration': 'int'})
. How ever I don't find a proper way to create similar table-elements which containWorkout
in the header and the name-attribute mapping in it's body.Can someone give me a hint, how to create such tables manually? I am also happy for any additional advices
The text was updated successfully, but these errors were encountered: