- """
- Representation of a row in the events table.
- """
-
- table_name = 'events'
- primary_key = 'event_id'
- fields = {
- 'event_id': Parameter(int, "Event identifier"),
- 'person_id': Parameter(int, "Identifier of person responsible for event"),
- 'event_type': Parameter(str, "Type of event"),
- 'object_type': Parameter(str, "Type of object affected by this event"),
- 'fault_code': Parameter(int, "Event fault code"),
- 'call': Parameter(str, "Call responsible for this event"),
- 'time': Parameter(str, "Date/Time the event took place"),
- 'object_ids': Parameter([int], "Ids of objects affected by this event")
- }
-
+ """
+ Representation of a row in the events table.
+ """
+
+ table_name = 'events'
+ primary_key = 'event_id'
+ fields = {
+ 'event_id': Parameter(int, "Event identifier"),
+ 'person_id': Parameter(int, "Identifier of person responsible for event, if any"),
+ 'node_id': Parameter(int, "Identifier of node responsible for event, if any"),
+ 'event_type': Parameter(str, "Type of event"),
+ 'object_type': Parameter(str, "Type of object affected by this event"),
+ 'fault_code': Parameter(int, "Event fault code"),
+ 'call': Parameter(str, "Call responsible for this event"),
+ 'runtime': Parameter(float, "Runtime of event"),
+ 'time': Parameter(int, "Date and time that the event took place, in seconds since UNIX epoch"),
+ 'object_ids': Parameter([int], "IDs of objects affected by this event")
+ }
+
+ def add_object(self, object_id, commit = True):
+ """
+ Relate object to this event.
+ """
+
+ assert 'event_id' in self
+
+ event_id = self['event_id']
+
+ if 'object_ids' not in self:
+ self['object_ids'] = []
+
+ if object_id not in self['object_ids']:
+ self.api.db.do("INSERT INTO event_object (event_id, object_id)" \
+ " VALUES(%(event_id)d, %(object_id)d)",
+ locals())
+
+ if commit:
+ self.api.db.commit()
+
+ self['object_ids'].append(object_id)
+