def list_resource(session=None, **filters): """ :param session: :param filters: :return: list blocks """ return utils.list_db_objects(session, Resource, **filters)
def get_fan_by_time(session, start_time, end_time): return utils.list_db_objects(session, Fan, created_at={ 'ge': str(start_time), 'le': str(end_time) })
def _get_fan(session, gateway_id, uuid, order_by=[], limit=None, **kwargs): if isinstance(uuid, basestring): ids = {'eq': uuid} elif isinstance(uuid, list): ids = {'in': uuid} else: raise exception.InvalidParameter('parameter uuid format are not supported.') return \ utils.list_db_objects(session, Fan, order_by=order_by, limit=limit, gateway_id=gateway_id, uuid=ids, **kwargs)
def _get_history(session, gateway_id, uuid, order_by=[], limit=None, **kwargs): if isinstance(uuid, basestring): ids = {'eq': uuid} elif isinstance(uuid, list): ids = {'in': uuid} else: raise exception.InvalidParameter('parameter uuid format are not supported.') return \ utils.list_db_objects(session, SmsHistroy, order_by=order_by, limit=limit, gateway_id=gateway_id, uuid=ids, **kwargs)
def _get_fan(session, resource_id, order_by=[], limit=None, **kwargs): if isinstance(resource_id, int): resource_ids = {'eq': resource_id} elif isinstance(resource_id, list): resource_ids = {'in': resource_id} else: raise exception.InvalidParameter('parameter resource id format are not supported.') return \ utils.list_db_objects(session, Fan, order_by=order_by, limit=limit, resource_id=resource_ids, **kwargs)
def _get_buzzer(session, gateway_id, uuid, order_by=[], limit=None, **kwargs): if isinstance(uuid, basestring): ids = {"eq": uuid} elif isinstance(uuid, list): ids = {"in": uuid} else: raise exception.InvalidParameter("parameter uuid format are not supported.") return utils.list_db_objects( session, Buzzer, order_by=order_by, limit=limit, gateway_id=gateway_id, uuid=ids, **kwargs )
def get_weather_by_date(session, start_time, end_time, **kwargs): date_range = {'ge': str(start_time), 'le': str(end_time)} return utils.list_db_objects(session, ActualWeather, publish_date=date_range, **kwargs)
def get_power_by_date(session, start_time, end_time, **kwargs): date_range = {'ge': str(start_time), 'le': str(end_time)} return utils.list_db_objects(session, PredictedPower, publish_date=date_range, **kwargs)
def get_power_by_date(session, start_time, end_time, **kwargs): date_range = {'ge': str(start_time), 'le': str(end_time)} return utils.list_db_objects(session, ActualPower, collect_date=date_range, **kwargs)
def get_power(session, **kwargs): return utils.list_db_objects(session, PredictedPower, **kwargs)
def get_all_types(session): return utils.list_db_objects(session, SensorType)
def get_weather_by_date(session, start_time, end_time, **kwargs): date_range={'ge': str(start_time), 'le': str(end_time)} return utils.list_db_objects(session, ActualWeather, publish_date=date_range, **kwargs)
def list_gateways(session, **kwargs): return utils.list_db_objects(session, Gateway, **kwargs)
def get_all_groups(session, gateway_id): return utils.list_db_objects(session, SensorGroup, gateway_id=gateway_id)
def get_all_user_names(session): users = utils.list_db_objects(session, User, exception_when_missing=False, status=True) u_list = [u.username for u in users if u.username] return set(u_list)
def get_user_phone_by_gateway(session, gateway_id, exception_when_missing=True): users = utils.list_db_objects(session, User, exception_when_missing=exception_when_missing, gateway_id=gateway_id) return [u.phone for u in users]
def get_fan_by_time(session, start_time, end_time): return utils.list_db_objects(session, Fan, created_at={'ge': str(start_time), 'le': str(end_time)})
def get_power_by_date(session, start_time, end_time, **kwargs): date_range={'ge': str(start_time), 'le': str(end_time)} return utils.list_db_objects(session, ActualPower, collect_date=date_range, **kwargs)