Skip to content

Commit

Permalink
Add relative attributes importer
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Jan 12, 2019
1 parent d08d3e3 commit ef6296f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
48 changes: 29 additions & 19 deletions pydbc/db/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,30 +346,40 @@ def insertAttributes(self, cur, attrs):
)

def insertRelativeAttributes(self, cur, attrs):
'''
CREATE TABLE IF NOT EXISTS AttributeRel_Value (
Object_ID INTEGER NOT NULL DEFAULT 0,
Attribute_Definition INTEGER NOT NULL DEFAULT 0,
Num_Value FLOAT8 DEFAULT 0,
String_Value TEXT,
Opt_Object_ID_1 INTEGER DEFAULT 0,
Opt_Object_ID_2 INTEGER DEFAULT 0,
BLOB_Value BLOB,
PRIMARY KEY(Object_ID,Attribute_Definition,Opt_Object_ID_1,Opt_Object_ID_2),
FOREIGN KEY(Attribute_Definition) REFERENCES Attribute_Definition(RID) ON UPDATE CASCADE ON DELETE RESTRICT
);
{'attributeName': 'GenSigTimeoutTime', 'attributeType': 'REL_SIGNAL', 'attributeValue': 1000,
'parent': {'nodeName': 'Bcu', 'signalName': 'Ucell60', 'messageID': 288},
}
'''
for attr in attrs:
attributeName = attr['attributeName']
attributeValue = attr['attributeValue']
attrributeType = self.getAttributeType(attr['attributeType'])
aid = self.queries.fetchAttributeId(attr['attributeName'])
print(attr)
#rid = self.getSignalByName(cur, attr['messageID'], attr['signalName'])
nodeId = self.queries.fetchNodeId(attr['nodeName'])
parent = attr['parent']
optOid1 = nodeId
optOid2 = None
stringValue = None
numValue = None
value = attr['attributeValue']
if isinstance(value, str):
stringValue = value
else:
numValue = value
if attrributeType == AttributeType.REL_SIGNAL:
messageID = parent['messageID']
optOid2 = messageID
rid = self.getSignalByName(cur, messageID, parent['signalName'])
#print("\t\tREL-SIGNAL!!!", parent)
elif attrributeType == AttributeType.REL_ENV_VAR:
evName = parent['evName']
rid = self.queries.fetchEnvVarId(evName)
#print("\t\tREL-ENV-VAR!!!", parent)
elif attrributeType == AttributeType.REL_NODE:
messageID = parent['messageID']
optOid2 = messageID
rid = self.queries.fetchMessageIdById(messageID)
#print("\t\tREL-NODE!!!", parent)
self.db.insertStatement(cur, "AttributeRel_Value",
"""Object_ID, Attribute_Definition, Num_Value, String_Value, Opt_Object_ID_1, Opt_Object_ID_2""",
rid, aid, numValue, stringValue, optOid1, optOid2
)

def insertNodes(self, cur, nodes):
nodeSet = set()
Expand Down
4 changes: 2 additions & 2 deletions pydbc/dbcListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ def exitRelativeAttributeValueForObject(self, ctx):
attributeName = ctx.attributeName.value
nodeName = ctx.nodeName.value
if attrType == "BU_BO_REL_":
nodeAddress = ctx.nodeAddress.value
messageID = ctx.nodeAddress.value
attributeType = "REL_NODE"
parent = dict(nodeAddress = nodeAddress)
parent = dict(messageID = messageID)
attrValue = ctx.attrValue.value
elif attrType == "BU_SG_REL_":
messageID = ctx.messageID.value
Expand Down

0 comments on commit ef6296f

Please sign in to comment.