-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
48 lines (41 loc) · 1.53 KB
/
Copy pathmodels.py
File metadata and controls
48 lines (41 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from datetime import datetime
import json
from typing import List
from uuid import uuid4
from sqlmodel import SQLModel, Field
class Node(SQLModel, table=True):
id: str = Field(default_factory=lambda: str(uuid4()), primary_key=True)
type: str # valor, interes, proyecto, persona, etapa, otro
label: str
description: str
created_at: datetime = Field(default_factory=datetime.utcnow)
tags_raw: str = Field(default="[]", description="JSON list of tags")
@property
def tags(self) -> List[str]:
try:
return json.loads(self.tags_raw)
except Exception:
return []
@tags.setter
def tags(self, val: List[str]) -> None:
self.tags_raw = json.dumps(val)
class Edge(SQLModel, table=True):
id: str = Field(default_factory=lambda: str(uuid4()), primary_key=True)
source_id: str
target_id: str
relation: str # influye, contrasta, nacio_de, alimenta, bloquea
weight: float = Field(default=1.0)
class Snapshot(SQLModel, table=True):
id: str = Field(default_factory=lambda: str(uuid4()), primary_key=True)
date: datetime = Field(default_factory=datetime.utcnow)
active_nodes_raw: str = Field(default="[]", description="JSON list of active node IDs")
notes: str
@property
def active_nodes(self) -> List[str]:
try:
return json.loads(self.active_nodes_raw)
except Exception:
return []
@active_nodes.setter
def active_nodes(self, val: List[str]) -> None:
self.active_nodes_raw = json.dumps(val)