1
1
from pydantic import BaseModel
2
2
from typing import List , Dict
3
3
from enum import Enum
4
+ import copy
4
5
import json
5
6
6
7
19
20
############################ Base Schema #############################
20
21
#####################################################################
21
22
class NodeSchema (BaseModel ):
23
+ type : str
22
24
ID : int = None # depend on id-str
23
25
id : str
24
26
# depend on user's difine
@@ -27,20 +29,32 @@ class NodeSchema(BaseModel):
27
29
description : str
28
30
gdb_timestamp : int
29
31
32
+ def attributes (self , ):
33
+ attrs = copy .deepcopy (vars (self ))
34
+ for k in ["ID" , "type" , "id" ]:
35
+ attrs .pop (k )
36
+ attrs .update (json .loads (attrs .pop ("extra" , '{}' ) or '{}' ))
37
+ return attrs
30
38
31
39
32
40
class EdgeSchema (BaseModel ):
41
+ type : str
33
42
# entity_id, ekg_node:{graph_id}:{node_type}:{content_md5}
34
43
SRCID : int = None
35
44
original_src_id1__ : str
36
45
# entity_id, ekg_node:{graph_id}:{node_type}:{content_md5}
37
46
DSTID : int = None
38
47
original_dst_id2__ : str
39
48
#
40
- timestamp : int
49
+ timestamp : int = None
41
50
gdb_timestamp : int
42
51
43
-
52
+ def attributes (self , ):
53
+ attrs = copy .deepcopy (vars (self ))
54
+ for k in ["SRCID" , "DSTID" , "type" , "timestamp" , "original_src_id1__" , "original_dst_id2__" ]:
55
+ attrs .pop (k )
56
+ attrs .update (json .loads (attrs .pop ("extra" , '{}' ) or '{}' ))
57
+ return attrs
44
58
#####################################################################
45
59
############################ EKG Schema #############################
46
60
#####################################################################
@@ -64,47 +78,20 @@ class EKGNodeSchema(NodeSchema):
64
78
extra : str = ''
65
79
66
80
67
-
68
81
class EKGEdgeSchema (EdgeSchema ):
69
82
# teamids: str
70
83
# version:str # yyyy-mm-dd HH:MM:SS
71
84
extra : str = ''
72
85
73
- def attrbutes (self , ):
74
- extra_attr = json .loads (self .extra )
75
- return extra_attr
76
-
77
86
78
87
class EKGIntentNodeSchema (EKGNodeSchema ):
79
- # path: str = ''
80
-
81
- def attrbutes (self , ):
82
- extra_attr = json .loads (self .extra )
83
- return {
84
- ** {
85
- "name" : self .name ,
86
- "description" : self .description ,
87
- "teamids" : self .teamids ,
88
- "path" : self .path
89
- },
90
- ** extra_attr
91
- }
88
+ pass
89
+
92
90
93
91
class EKGScheduleNodeSchema (EKGNodeSchema ):
94
92
# do action or not
95
93
enable : bool
96
94
97
- def attrbutes (self , ):
98
- extra_attr = json .loads (self .extra )
99
- return {
100
- ** {
101
- "name" : self .name ,
102
- "description" : self .description ,
103
- "teamids" : self .teamids ,
104
- "enable" : self .enable
105
- },
106
- ** extra_attr
107
- }
108
95
109
96
class EKGTaskNodeSchema (EKGNodeSchema ):
110
97
# tool: str
@@ -114,20 +101,6 @@ class EKGTaskNodeSchema(EKGNodeSchema):
114
101
executetype : str
115
102
#
116
103
# owner: str
117
-
118
- def attrbutes (self , ):
119
- extra_attr = json .loads (self .extra )
120
- return {
121
- ** {
122
- "name" : self .name ,
123
- "description" : self .description ,
124
- "teamids" : self .teamids ,
125
- "accesscriteria" : self .accesscriteria ,
126
- "executetype" : self .executetype ,
127
- # "tool": self.tool
128
- },
129
- ** extra_attr
130
- }
131
104
132
105
133
106
class EKGAnalysisNodeSchema (EKGNodeSchema ):
@@ -138,33 +111,9 @@ class EKGAnalysisNodeSchema(EKGNodeSchema):
138
111
# summary template
139
112
dsltemplate : str
140
113
141
- def attrbutes (self , ):
142
- extra_attr = json .loads (self .extra )
143
- return {
144
- ** {
145
- "name" : self .name ,
146
- "description" : self .description ,
147
- "teamids" : self .teamids ,
148
- "accesscriteria" : self .accesscriteria ,
149
- "summaryswtich" : self .summaryswtich ,
150
- "dsltemplate" : self .dsltemplate
151
- },
152
- ** extra_attr
153
- }
154
-
155
114
156
115
class EKGPhenomenonNodeSchema (EKGNodeSchema ):
157
-
158
- def attrbutes (self , ):
159
- extra_attr = json .loads (self .extra )
160
- return {
161
- ** {
162
- "name" : self .name ,
163
- "description" : self .description ,
164
- "teamids" : self .teamids ,
165
- },
166
- ** extra_attr
167
- }
116
+ pass
168
117
169
118
170
119
# Ekg Tool Schemas
@@ -196,13 +145,17 @@ class EKGGraphSlsSchema(BaseModel):
196
145
# ADD/DELETE
197
146
operation_type : str = ''
198
147
# {tool_id},{tool_id},{tool_id}
199
- tool : str = ''
200
- access_criteria : str = ''
148
+ executetype : str = ''
149
+ accesscriteria : str = ''
201
150
teamids : str = ''
202
151
extra : str = ''
203
152
enable : bool = False
204
- dslTemplate : str = ''
153
+ dsltemplate : str = ''
154
+ summaryswtich : bool = False
205
155
156
+ gdb_timestamp : int
157
+ original_src_id1__ : str = ""
158
+ original_dst_id2__ : str = ""
206
159
207
160
class EKGNodeTbaseSchema (BaseModel ):
208
161
node_id : str
0 commit comments