Difference between revisions of "TopicLink"
Jump to navigation
Jump to search
| Line 4: | Line 4: | ||
[https://diagrams.bitplan.com/render/txt/0x6dc5850a.txt plantuml source] | [https://diagrams.bitplan.com/render/txt/0x6dc5850a.txt plantuml source] | ||
| + | = Example = | ||
| + | <source lang='python'> | ||
| + | """ | ||
| + | Created on 2024-11-07 | ||
| + | @author: wf | ||
| + | """ | ||
| + | from mogwai.core.mogwaigraph import MogwaiGraph, MogwaiGraphConfig | ||
| + | from mogwai.core.traversal import MogwaiGraphTraversalSource | ||
| + | |||
| + | from typing import Dict, Optional | ||
| + | import os | ||
| + | import json | ||
| + | from basemkit.yamlable import lod_storable | ||
| + | |||
| + | class RQM: | ||
| + | """ | ||
| + | Requirements Management subgraph | ||
| + | """ | ||
| + | def __init__(self): | ||
| + | """ | ||
| + | constructor | ||
| + | """ | ||
| + | config = MogwaiGraphConfig( | ||
| + | name_field='_node_name', | ||
| + | index_config='minimal' | ||
| + | ) | ||
| + | self.graph=MogwaiGraph(config=config) | ||
| + | self.g=MogwaiGraphTraversalSource(self.graph) | ||
| + | |||
| + | def create_relationships(self): | ||
| + | """Creates graph relationships""" | ||
| + | self.graph.join('RQ', 'RQProfile', 'RQProfilename', 'RQProfilename', 'has_rqprofile') | ||
| + | self.graph.join('AK', 'RQ', 'myRQ_RQid', 'RQid', 'has_rq') | ||
| + | |||
| + | @classmethod | ||
| + | def from_json(cls,root_path:str,with_join:bool=True)->'RQM': | ||
| + | rqm=cls() | ||
| + | for data_class,pk in [ | ||
| + | (RQProfile,"oid"), | ||
| + | (RQ,"oid"), | ||
| + | (AK,"oid")]: | ||
| + | node_name=data_class.__name__ | ||
| + | json_path = os.path.join(root_path, f"{node_name.lower()}.json") | ||
| + | |||
| + | # load JSON data | ||
| + | with open(json_path, 'r') as json_file: | ||
| + | data = json.load(json_file) | ||
| + | for record in data: | ||
| + | name=record.get(pk) | ||
| + | non_null_props = {k: v for k, v in record.items() if v is not None} | ||
| + | rqm.graph.add_labeled_node( | ||
| + | node_name, | ||
| + | name=name, | ||
| + | properties=non_null_props | ||
| + | ) | ||
| + | #instance=from_dict(data_class=data_class,data=record) | ||
| + | pass | ||
| + | if with_join: | ||
| + | rqm.create_relationships() | ||
| + | return rqm | ||
| + | |||
| + | @lod_storable | ||
| + | class RQProfile: | ||
| + | oid: str | ||
| + | RQProfilename: str | ||
| + | RQProfileNumber: Optional[str] = None | ||
| + | longname: Optional[str] = None | ||
| + | comment: Optional[str] = None | ||
| + | startdate: Optional[str] = None # isodate | ||
| + | customer: Optional[str] = None | ||
| + | projectNo: Optional[str] = None | ||
| + | |||
| + | |||
| + | @lod_storable | ||
| + | class RQ: | ||
| + | oid: str | ||
| + | RQid: str | ||
| + | name: str | ||
| + | what: str | ||
| + | RQProfilename: Optional[str] = None | ||
| + | RQnumber: Optional[str] = None | ||
| + | description: Optional[str] = None | ||
| + | why: Optional[str] = None | ||
| + | comment: Optional[str] = None | ||
| + | enteredOn: Optional[str] = None # isodate | ||
| + | enteredBy: Optional[str] = None | ||
| + | owner: Optional[str] = None | ||
| + | priority: Optional[str] = None | ||
| + | weight: Optional[str] = None | ||
| + | state: Optional[str] = None | ||
| + | kind: Optional[str] = None | ||
| + | design: Optional[int] = None #bool | ||
| + | negative: Optional[int] = None #bool | ||
| + | basedOn: Optional[str] = None | ||
| + | qualityAcceptance: Optional[str] = None | ||
| + | myRQProfile_RQProfilename: Optional[str] = None | ||
| + | myReport_ReportId: Optional[str] = None | ||
| + | |||
| + | |||
| + | @lod_storable | ||
| + | class AK: | ||
| + | oid: str | ||
| + | AKid: str | ||
| + | name: str | ||
| + | situation: str | ||
| + | action: str | ||
| + | expectedResult: str | ||
| + | RQProfilename: Optional[str] = None | ||
| + | RQnumber: Optional[str] = None | ||
| + | RQname: Optional[str] = None | ||
| + | AKnumber: Optional[str] = None | ||
| + | project: Optional[str] = None | ||
| + | description: Optional[str] = None | ||
| + | manualOnly: Optional[int] = None #bool | ||
| + | comment: Optional[str] = None | ||
| + | enteredBy: Optional[str] = None | ||
| + | enteredOn: Optional[str] = None# isodate | ||
| + | owner: Optional[str] = None | ||
| + | qualityAcceptance: Optional[str] = None | ||
| + | state: Optional[str] = None | ||
| + | rejection: Optional[int] = None #bool | ||
| + | disabled: Optional[int] = None #bool | ||
| + | done: Optional[int] = None #bool | ||
| + | doneDate: Optional[str] = None # isodate | ||
| + | difficulty: Optional[str] = None | ||
| + | acceptance: Optional[str] = None | ||
| + | accDate: Optional[str] = None # isodate | ||
| + | responsible: Optional[str] = None | ||
| + | myRQ_RQid: Optional[str] = None | ||
| + | |||
| + | </source> | ||
= Links = | = Links = | ||
* https://en.wikipedia.org/wiki/Property_graph | * https://en.wikipedia.org/wiki/Property_graph | ||
Revision as of 09:08, 9 July 2025
Example
"""
Created on 2024-11-07
@author: wf
"""
from mogwai.core.mogwaigraph import MogwaiGraph, MogwaiGraphConfig
from mogwai.core.traversal import MogwaiGraphTraversalSource
from typing import Dict, Optional
import os
import json
from basemkit.yamlable import lod_storable
class RQM:
"""
Requirements Management subgraph
"""
def __init__(self):
"""
constructor
"""
config = MogwaiGraphConfig(
name_field='_node_name',
index_config='minimal'
)
self.graph=MogwaiGraph(config=config)
self.g=MogwaiGraphTraversalSource(self.graph)
def create_relationships(self):
"""Creates graph relationships"""
self.graph.join('RQ', 'RQProfile', 'RQProfilename', 'RQProfilename', 'has_rqprofile')
self.graph.join('AK', 'RQ', 'myRQ_RQid', 'RQid', 'has_rq')
@classmethod
def from_json(cls,root_path:str,with_join:bool=True)->'RQM':
rqm=cls()
for data_class,pk in [
(RQProfile,"oid"),
(RQ,"oid"),
(AK,"oid")]:
node_name=data_class.__name__
json_path = os.path.join(root_path, f"{node_name.lower()}.json")
# load JSON data
with open(json_path, 'r') as json_file:
data = json.load(json_file)
for record in data:
name=record.get(pk)
non_null_props = {k: v for k, v in record.items() if v is not None}
rqm.graph.add_labeled_node(
node_name,
name=name,
properties=non_null_props
)
#instance=from_dict(data_class=data_class,data=record)
pass
if with_join:
rqm.create_relationships()
return rqm
@lod_storable
class RQProfile:
oid: str
RQProfilename: str
RQProfileNumber: Optional[str] = None
longname: Optional[str] = None
comment: Optional[str] = None
startdate: Optional[str] = None # isodate
customer: Optional[str] = None
projectNo: Optional[str] = None
@lod_storable
class RQ:
oid: str
RQid: str
name: str
what: str
RQProfilename: Optional[str] = None
RQnumber: Optional[str] = None
description: Optional[str] = None
why: Optional[str] = None
comment: Optional[str] = None
enteredOn: Optional[str] = None # isodate
enteredBy: Optional[str] = None
owner: Optional[str] = None
priority: Optional[str] = None
weight: Optional[str] = None
state: Optional[str] = None
kind: Optional[str] = None
design: Optional[int] = None #bool
negative: Optional[int] = None #bool
basedOn: Optional[str] = None
qualityAcceptance: Optional[str] = None
myRQProfile_RQProfilename: Optional[str] = None
myReport_ReportId: Optional[str] = None
@lod_storable
class AK:
oid: str
AKid: str
name: str
situation: str
action: str
expectedResult: str
RQProfilename: Optional[str] = None
RQnumber: Optional[str] = None
RQname: Optional[str] = None
AKnumber: Optional[str] = None
project: Optional[str] = None
description: Optional[str] = None
manualOnly: Optional[int] = None #bool
comment: Optional[str] = None
enteredBy: Optional[str] = None
enteredOn: Optional[str] = None# isodate
owner: Optional[str] = None
qualityAcceptance: Optional[str] = None
state: Optional[str] = None
rejection: Optional[int] = None #bool
disabled: Optional[int] = None #bool
done: Optional[int] = None #bool
doneDate: Optional[str] = None # isodate
difficulty: Optional[str] = None
acceptance: Optional[str] = None
accDate: Optional[str] = None # isodate
responsible: Optional[str] = None
myRQ_RQid: Optional[str] = None