From a1d891af0b66b24be830653e9f2fe136087504d5 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Wed, 16 May 2007 18:07:02 +0000 Subject: [PATCH] - fixed bug. Can now filter on 'time' field --- PLC/EventObjects.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/PLC/EventObjects.py b/PLC/EventObjects.py index d96b9014..142fee7d 100644 --- a/PLC/EventObjects.py +++ b/PLC/EventObjects.py @@ -4,7 +4,7 @@ # Tony Mack # Copyright (C) 2006 The Trustees of Princeton University # -# $Id: EventObjects.py,v 1.1 2007/02/27 18:54:32 tmack Exp $ +# $Id: EventObjects.py,v 1.2 2007/05/07 20:07:42 tmack Exp $ # from PLC.Faults import * @@ -42,27 +42,25 @@ class EventObjects(Table): def __init__(self, api, event_filter = None, columns = None): Table.__init__(self, api, EventObject, columns) + all_fields = EventObject.fields.keys() + if not columns: + columns = all_fields + else: + columns = filter(lambda column: column in all_fields, columns) + # Since we are querying a table (not a view) ensure that timestamps # are converted to ints in the db before being returned timestamps = ['time'] - for col in self.columns: + for col in columns: if col in timestamps: - if isinstance(self.columns, (list, tuple, set)): - index = self.columns.index(col) - self.columns[index] = "CAST(date_part('epoch', events.time) AS bigint) AS time" - elif isinstance(self.columns, dict): - type = self.columns.pop(col) - self.columns["CAST(date_part('epoch', events.time) AS bigint) AS time"] = type + index = columns.index(col) + columns[index] = "CAST(date_part('epoch', events.time) AS bigint) AS time" elif col in [EventObject.primary_key]: - if isinstance(self.columns, (list, tuple, set)): - index = self.columns.index(col) - self.columns[index] = EventObject.table_name+"."+EventObject.primary_key - elif isinstance(self.columns, dict): - type = self.columns.pop(col) - self.columns[EventObject.table_name+"."+EventObject.primary_key] = type + index = columns.index(col) + columns[index] = EventObject.table_name+"."+EventObject.primary_key sql = "SELECT %s FROM event_object, events WHERE True" % \ - ", ".join(self.columns) + ", ".join(columns) if event_filter is not None: if isinstance(event_filter, (list, tuple, set)): -- 2.47.0