def create(self, _name, _geom, _type, _source, _active, _auth_needed, _extra={}): """creates a sensor entry""" new_type, _type = db_tools.check_tag( self.sensorweb.database_connection, 'sensors', 'type', _type) new_source, _source = db_tools.check_tag( self.sensorweb.database_connection, 'sensors', 'source', _source) query_string = "select max(sensor_int_id_caster(info -> 'sensor_int_id'::text) ) from sensors" sens_id = self.sensorweb.database_connection.query(query_string) id = sens_id[0][0] + 1 sensor = cl.Sensor(self.sensorweb.database_connection, _name, id, _geom, _active, _source, _type, _extra) sensor.link() if new_type: query_string = "update new_tags set info = case when info is not null \ then info||hstore('type','%s') else hstore('type','%s') end \ where table_name = 'sensors'" % (_type, _type) self.sensorweb.database_connection.insert(query_string) if new_source: query_string = "update new_tags set info = case when info is not null \ then info||hstore('source','%s') else hstore('source','%s') end \ where table_name = 'sensors'" % (_source, _source) self.sensorweb.database_connection.insert(query_string) return sensor
def create(self, _name, _geom, _type, _source, _active, _auth_needed,_extra={}): """creates a sensor entry""" new_type ,_type = db_tools.check_tag(self.sensorweb.database_connection,'sensors','type',_type) new_source,_source = db_tools.check_tag(self.sensorweb.database_connection,'sensors','source',_source) query_string = "select max(sensor_int_id_caster(info -> 'sensor_int_id'::text) ) from sensors" sens_id = self.sensorweb.database_connection.query(query_string) id = sens_id[0][0] +1 sensor = cl.Sensor( self.sensorweb.database_connection, _name, id, _geom, _active, _source, _type, _extra) sensor.link() if new_type: query_string = "update new_tags set info = case when info is not null \ then info||hstore('type','%s') else hstore('type','%s') end \ where table_name = 'sensors'" % (_type,_type) self.sensorweb.database_connection.insert(query_string) if new_source: query_string = "update new_tags set info = case when info is not null \ then info||hstore('source','%s') else hstore('source','%s') end \ where table_name = 'sensors'" % (_source,_source) self.sensorweb.database_connection.insert(query_string) return sensor
def get_or_create(self, _name, _geom, _type, _source, _active, _auth_needed,_extra ={}): """Creates sensor entry or updates one with with the matching name""" sensor = self.get(key='name', value=_name,active=False, not_flagged=False,logged_in=True) new_type ,_type = db_tools.check_tag(self.sensorweb.database_connection,'sensors','type',_type) new_source,_source = db_tools.check_tag(self.sensorweb.database_connection,'sensors','source',_source) if not sensor: sensor = self.create(_name, _geom, _type, _source, _active, _auth_needed) else: sensor = sensor[0] info_dict = {'geom':_geom, 'type':_type, 'source': _source, 'active':_active, 'auth_needed': _auth_needed} info_dict.update(_extra) sensor.update(info_dict) if new_type: query_string = "update new_tags set info = case when info is not null \ then info||hstore('type','%s') else hstore('type','%s') end \ where table_name = 'sensors'" % (_type,_type,) self.sensorweb.database_connection.insert(query_string) if new_source: query_string = "update new_tags set info = case when info is not null \ then info||hstore('source','%s') else hstore('source','%s') end \ where table_name = 'sensors'" % (_source,_source,) self.sensorweb.database_connection.insert(query_string) return sensor
def get_or_create(self, _name, _geom, _type, _source, _active, _auth_needed, _extra={}): """Creates sensor entry or updates one with with the matching name""" sensor = self.get(key='name', value=_name, active=False, not_flagged=False, logged_in=True) new_type, _type = db_tools.check_tag( self.sensorweb.database_connection, 'sensors', 'type', _type) new_source, _source = db_tools.check_tag( self.sensorweb.database_connection, 'sensors', 'source', _source) if not sensor: sensor = self.create(_name, _geom, _type, _source, _active, _auth_needed) else: sensor = sensor[0] info_dict = { 'geom': _geom, 'type': _type, 'source': _source, 'active': _active, 'auth_needed': _auth_needed } info_dict.update(_extra) sensor.update(info_dict) if new_type: query_string = "update new_tags set info = case when info is not null \ then info||hstore('type','%s') else hstore('type','%s') end \ where table_name = 'sensors'" % ( _type, _type, ) self.sensorweb.database_connection.insert(query_string) if new_source: query_string = "update new_tags set info = case when info is not null \ then info||hstore('source','%s') else hstore('source','%s') end \ where table_name = 'sensors'" % ( _source, _source, ) self.sensorweb.database_connection.insert(query_string) return sensor