def get_state_history(self,
                          name,
                          limit=None,
                          offset=None,
                          gateway_id=None):
        """
        Get an state history.

        :param name:
        :param limit:
        :param offset:
        :return:
        """
        if gateway_id is None:
            gateway_id = self.gateway_id
        if limit is None:
            limit = 1

        if offset is not None:
            limit = (limit, offset)

        where = {
            "name": name,
            "gateway_id": gateway_id,
        }
        sql_where = dictToWhere(where)

        results = yield States.find(where=sql_where, limit=limit)
        records = []
        for item in results:
            temp = clean_dict(item.__dict__)
            del temp["errors"]
            records.append(temp)
        return records
 def get_device_commands(self, **kwargs):
     limit = self._get_limit(**kwargs)
     records = yield DeviceCommand.find("device_commands",
                                        where=dictToWhere(kwargs["where"]),
                                        orderby="created_at DESC",
                                        limit=limit)
     return self.process_get_results(records, PICKLED_COLUMNS)
    def get_distinct_stat_names(self,
                                name=None,
                                search_name_all=None,
                                search_name_start=None,
                                search_name_end=None,
                                bucket_type=None):
        where = {}
        dictToWhere
        if bucket_type is not None:
            where["bucket_type"] = bucket_type
        if name is not None:
            where["bucket_name"] = name
        if search_name_all is not None:
            where["bucket_name"] = [f"%%{search_name_all}%%", "like"]
        if search_name_start is not None:
            where["bucket_name"] = [f"{search_name_start}%%", "like"]
        if search_name_end is not None:
            where["bucket_name"] = [f"%%{search_name_end}", "like"]

        records = yield self.dbconfig.select(
            "statistics",
            where=dictToWhere(where),
            select=
            "bucket_name, bucket_type, bucket_size, bucket_lifetime, MIN(bucket_time) as bucket_time_min, MAX(bucket_time) as bucket_time_max, count(*) as count",
            group="bucket_name")
        return records
Example #4
0
    def generic_item_get(self, name, **kwargs):
        """
        Replaces many generic database interactions for getting various items.
        :return:
        """
        attrs = GENERIC_ATTRIBUTES[name]

        if "pickled_columns" in kwargs:
            pickled_columns = kwargs["pickled_columns"]
        else:
            pickled_columns = attrs["pickled_columns"]

        if "where" in kwargs:
            where = dictToWhere(kwargs["where"])
        else:
            where = None

        if "orderby" in kwargs:
            orderby = kwargs["orderby"]
        else:
            orderby = attrs["orderby"]

        if "limit" in kwargs:
            limit = self._get_limit(**kwargs)
        else:
            limit = None

        records = yield attrs["class"].find(
            where=where,
            orderby=orderby,
            limit=limit,
        )
        # print(records)

        return self.process_get_results(records, pickled_columns)
    def get_device_states(self, where, **kwargs):
        limit = self._get_limit(**kwargs)

        records = yield DeviceState.find("device_states",
                                         where=dictToWhere(where),
                                         orderby="set_at DESC",
                                         limit=limit)
        return self.process_get_results(records, PICKLED_COLUMNS)
    def select_notifications(self, where):
        find_where = dictToWhere(where)
        records = yield Notification.find(where=find_where)
        items = []
        for record in records:
            items.append(instance_properties(record, "_"))

        return items
Example #7
0
 def get_dbitem_by_id_dict(self, dbitem, where=None, status=None):
     if dbitem not in MODULE_CLASSES:
         raise YomboWarning(
             "get_dbitem_by_id_dict expects dbitem to be a DBObject")
     if where is None:
         records = yield MODULE_CLASSES[dbitem].select()
     else:
         records = yield MODULE_CLASSES[dbitem].select(
             where=dictToWhere(where))
     return records
Example #8
0
    def findBy(klass, **attrs):
        """
        Find all instances of the given class based on an exact match of attributes.

        For instance:
        C{User.find(first_name='Bob', last_name='Smith')}

        Will return all matches.
        """
        where = dictToWhere(attrs)
        return klass.find(where=where)
Example #9
0
    def findBy(klass, **attrs):
        """
        Find all instances of the given class based on an exact match of attributes.

        For instance:
        C{User.find(first_name='Bob', last_name='Smith')}

        Will return all matches.
        """
        where = dictToWhere(attrs)
        return klass.find(where=where)
Example #10
0
    def get_dbitem_by_id_dict(self, dbitem, where=None, status=None):
        if dbitem not in MODULE_CLASSES:
            # print MODULE_CLASSES
            raise YomboWarning("get_dbitem_by_id_dict expects dbitem to be a DBObject")
#        print MODULE_CLASSES
        if where is None:
            records = yield MODULE_CLASSES[dbitem].find()
#            print "looking without status!"
        else:
            records = yield MODULE_CLASSES[dbitem].find(where=dictToWhere(where))
#        print "get_dbitem_by_id. class: %s, id: %s, status: %s" % (dbitem, id, status)
        results = []
        for record in records:
            results.append(record.__dict__)  # we need a dictionary, not an object
        returnValue(results)
Example #11
0
    def get_statistic(self, where):
        find_where = dictToWhere(where)
        records = yield Statistics.find(where=find_where)

        # print "stat records: %s" % records
        returnValue(records)
 def get_statistic(self, where):
     find_where = dictToWhere(where)
     records = yield Statistics.find(where=find_where)
     return records