Example #1
0
 def _get_one(self, query, params=None):
     cur = Database.Instance().dict_cursor()
     cur.execute(query, params)
     if cur.rowcount > 0:
         return self.to_object(cur.fetchone())
     else:
         return None
Example #2
0
	def get_time_range(self, filter = None):
		filter = self.filter_defaults(filter, 1)
		filterSql = self.__build_filter(filter, "WHERE")
		cur = Database.Instance().dict_cursor()
		cur.execute("SELECT MIN(m.datetime) AS min, MAX(m.datetime) AS max FROM Measurements m " + filterSql)
		if cur.rowcount > 0:
			return cur.fetchone()
		else:
			return None
Example #3
0
	def update(self):
		if self.id is None or self.sensor is None or self.location is None or self.value is None:
			return False

		cur = Database.Instance().dict_cursor()
		cur.execute("UPDATE Measurements SET value = %s, quality = %s, sensor = %s, location = %s, datetime = %s WHERE id = %s", [self.value, self.quality, self.sensor, self.location, self.datetime, self.id])
		if cur.rowcount > 0:
			return True
		else:
			return False
Example #4
0
    def delete(self):
        if self.id is None:
            return False

        cur = Database.Instance().cursor()
        cur.execute("DELETE FROM Locations WHERE id = %s", [self.id])
        if cur.rowcount > 0:
            self.id = None
            return True
        else:
            return False
Example #5
0
    def read(self):
        if self.id is None:
            return False

        cur = Database.Instance().dict_cursor()
        cur.execute("SELECT * FROM Notifiers WHERE id = %s", [self.id])
        if cur.rowcount > 0:
            self.from_dict(cur.fetchone())
            return True
        else:
            return False
Example #6
0
    def update(self):
        if self.id is None or self.lon is None or self.lat is None or self.height is None:
            return False

        cur = Database.Instance().dict_cursor()
        cur.execute(
            "UPDATE Locations SET name = %s, geom = ST_GeomFromText(%s, 4326), height = %s WHERE id = %s",
            [self.name, self.get_point_wkt(), self.height, self.id])
        if cur.rowcount > 0:
            return True
        else:
            return False
Example #7
0
    def read(self):
        if self.id is None:
            return False

        cur = Database.Instance().dict_cursor()
        cur.execute(
            "SELECT *, ST_X(geom) AS lon, ST_Y(geom) AS lat FROM Locations WHERE id = %s",
            [self.id])
        if cur.rowcount > 0:
            self.from_dict(cur.fetchone())
            return True
        else:
            return False
Example #8
0
	def create(self):
		if self.sensor is None or self.location is None or self.value is None:
			return False

		cur = Database.Instance().dict_cursor()
		cur.execute("INSERT INTO Measurements (value, quality, sensor, location) VALUES (%s, %s, %s, %s) RETURNING datetime, id", [self.value, self.quality, self.sensor, self.location])
		data = cur.fetchone()
		self.id = data['id']
		self.datetime = data['datetime']
		if self.id > 0:
			return True
		else:
			return False
Example #9
0
    def create(self):
        if self.lon is None or self.lat is None or self.height is None:
            return False

        cur = Database.Instance().dict_cursor()
        cur.execute(
            "INSERT INTO Locations (name, geom, height) VALUES (%s, ST_GeomFromText(%s, 4326), %s) RETURNING id",
            [self.name, self.get_point_wkt(), self.height])
        data = cur.fetchone()
        self.id = data['id']
        if self.id > 0:
            return True
        else:
            return False
Example #10
0
    def create(self):
        if self.sensor is None or self.notifier is None:
            return False

        cur = Database.Instance().dict_cursor()
        cur.execute(
            "INSERT INTO Subscribers (settings, sensor, notifier) VALUES (%s, %s, %s) RETURNING id",
            [self._settings_dump(self.settings), self.sensor, self.notifier])
        data = cur.fetchone()
        self.id = data['id']
        if self.id > 0:
            return True
        else:
            return False
Example #11
0
    def update(self):
        if self.id is None or self.sensor is None or self.notifier is None:
            return False

        cur = Database.Instance().dict_cursor()
        cur.execute(
            "UPDATE Subscribers SET settings = %s, sensor = %s, notifier = %s WHERE id = %s",
            [
                self._settings_dump(self.settings), self.sensor, self.notifier,
                self.id
            ])
        if cur.rowcount > 0:
            return True
        else:
            return False
Example #12
0
    def update(self):
        impl = self.get_notifier_impl()
        if self.id is None or impl is None or self.active is None:
            return False

        cur = Database.Instance().dict_cursor()
        cur.execute(
            "UPDATE Notifiers SET module = %s, class = %s, name = %s, description = %s, settings = %s, public = %s, active = %s WHERE id = %s",
            [
                self.module, self.class_name, self.name, self.description,
                self._settings_dump(self.settings), self.public, self.active,
                self.id
            ])
        if cur.rowcount > 0:
            return True
        else:
            return False
Example #13
0
    def create(self):
        impl = self.get_notifier_impl()
        if impl is None or self.active is None:
            return False

        cur = Database.Instance().dict_cursor()
        cur.execute(
            "INSERT INTO Notifiers (module, class, name, description, settings, public, active) VALUES (%s, %s, %s, %s, %s, %s, %s) RETURNING id",
            [
                self.module, self.class_name, self.name, self.description,
                self._settings_dump(self.settings), self.public, self.active
            ])
        data = cur.fetchone()
        self.id = data['id']
        if self.id > 0:
            return True
        else:
            return False
Example #14
0
    def update(self):
        impl = self.get_sensor_impl()
        if self.id is None or impl is None or self.active is None:
            return False

        cur = Database.Instance().dict_cursor()
        cur.execute(
            "UPDATE Sensors SET module = %s, class = %s, type = %s, description = %s, unit = %s, active = %s, settings = %s WHERE id = %s",
            [
                self.module, self.class_name,
                impl.get_type(), self.description,
                impl.get_unit(), self.active,
                self._settings_dump(self.settings), self.id
            ])
        if cur.rowcount > 0:
            return True
        else:
            return False
Example #15
0
    def create(self):
        impl = self.get_sensor_impl()
        if impl is None or self.active is None:
            return False

        cur = Database.Instance().dict_cursor()
        cur.execute(
            "INSERT INTO Sensors (module, class, type, description, unit, active, settings) VALUES (%s, %s, %s, %s, %s, %s, %s) RETURNING id",
            [
                self.module, self.class_name,
                impl.get_type(), self.description,
                impl.get_unit(), self.active,
                self._settings_dump(self.settings)
            ])
        data = cur.fetchone()
        self.id = data['id']
        if self.id > 0:
            return True
        else:
            return False