def load_data(self, start_limit=None, stop_limit=None): return_records = DataCollection() for trace in self.trace_files: log.info("Loading file: " + trace.loc) if start_limit and trace.get_date() < start_limit: continue if stop_limit and trace.get_date() > stop_limit: continue return_records.append(trace.get_data()) return return_records
class SensorTrace(object): def __init__(self, sensor_name, start_limit=None, stop_limit=None): self.name = sensor_name self.trace_data = DataCollection(start_limit, stop_limit) self.start_limit = start_limit self.stop_limit = stop_limit self.initialize() def initialize(self): pass def __repr__(self): return repr(Name(self.name)) def get_name(self): return Name(self.name) def get_type(self): return self.get_name().type def __str__(self): return repr(self) def get_length(self): """Returns the length of the trace as a timedelta object""" return self.trace_data.get_length() def get_data_tuples(self, start_limit=None, stop_limit=None): """Retrieve data and timestamps from the data collection. start_limit and stop_limit are optional arguments that describe the subsection of the trace to operate on. If these options are not provided, then any arguments provided on object intialization will be used.""" start_limit, stop_limit = self.get_limits(start_limit, stop_limit) data = self.load_data(start_limit, stop_limit) self.trace_data = DataCollection(start_limit, stop_limit) self.trace_data.append(data) return self.trace_data.get_data_tuples(start_limit, stop_limit) def get_data_collection(self): self.get_data_tuples() return self.trace_data def load_data(self, start_limit=None, stop_limit=None): log.warn('Empty load data is called. This should typically not happen') pass def is_room(self, room=None): """Checks whether the sensor is within a room or not""" if room != None: return self.get_name().is_in_room(room) return self.get_name().is_room() def get_summary(self): self.get_data_tuples() vals = [data for data in self.trace_data.get_data() if data > 0] if vals: return {'min': np.amin(vals), 'ave': np.mean(vals), 'max': np.amax(vals)} else: return {'min': np.nan, 'ave': np.nan, 'max': np.nan} def get_limits(self, start_limit, stop_limit): if not start_limit: start_limit = self.start_limit if not start_limit: start_limit = datetime.datetime(2011, 1, 01) if not stop_limit: stop_limit = self.stop_limit return start_limit, stop_limit
def get_data(self): data = DataCollection() for line in open(self.loc, 'r'): parts = line.split(',') data.append(DataRecord(parts[4], parts[1], parts[2])) return data
class SensorTrace(object): def __init__(self, sensor_name, start_limit=None, stop_limit=None): self.name = sensor_name self.trace_data = DataCollection(start_limit, stop_limit) self.start_limit = start_limit self.stop_limit = stop_limit self.initialize() def initialize(self): pass def __repr__(self): return repr(Name(self.name)) def get_name(self): return Name(self.name) def get_type(self): return self.get_name().type def __str__(self): return repr(self) def get_length(self): """Returns the length of the trace as a timedelta object""" return self.trace_data.get_length() def get_data_tuples(self, start_limit=None, stop_limit=None): """Retrieve data and timestamps from the data collection. start_limit and stop_limit are optional arguments that describe the subsection of the trace to operate on. If these options are not provided, then any arguments provided on object intialization will be used.""" start_limit, stop_limit = self.get_limits(start_limit, stop_limit) data = self.load_data(start_limit, stop_limit) self.trace_data = DataCollection(start_limit, stop_limit) self.trace_data.append(data) return self.trace_data.get_data_tuples(start_limit, stop_limit) def get_data_collection(self): self.get_data_tuples() return self.trace_data def load_data(self, start_limit=None, stop_limit=None): log.warn('Empty load data is called. This should typically not happen') pass def is_room(self, room=None): """Checks whether the sensor is within a room or not""" if room != None: return self.get_name().is_in_room(room) return self.get_name().is_room() def get_summary(self): self.get_data_tuples() vals = [data for data in self.trace_data.get_data() if data > 0] if vals: return { 'min': np.amin(vals), 'ave': np.mean(vals), 'max': np.amax(vals) } else: return {'min': np.nan, 'ave': np.nan, 'max': np.nan} def get_limits(self, start_limit, stop_limit): if not start_limit: start_limit = self.start_limit if not start_limit: start_limit = datetime.datetime(2011, 1, 01) if not stop_limit: stop_limit = self.stop_limit return start_limit, stop_limit