本文整理汇总了Python中HydraServer.db.DBSession.expunge_all方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.expunge_all方法的具体用法?Python DBSession.expunge_all怎么用?Python DBSession.expunge_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HydraServer.db.DBSession
的用法示例。
在下文中一共展示了DBSession.expunge_all方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_dataset
# 需要导入模块: from HydraServer.db import DBSession [as 别名]
# 或者: from HydraServer.db.DBSession import expunge_all [as 别名]
def convert_dataset(dataset_id, to_unit,**kwargs):
"""Convert a whole dataset (specified by 'dataset_id' to new unit
('to_unit'). Conversion ALWAYS creates a NEW dataset, so function
returns the dataset ID of new dataset.
"""
ds_i = DBSession.query(Dataset).filter(Dataset.dataset_id==dataset_id).one()
dataset_type = ds_i.data_type
dsval = ds_i.get_val()
old_unit = ds_i.data_units
if old_unit is not None:
if dataset_type == 'scalar':
new_val = hydra_units.convert(float(dsval), old_unit, to_unit)
elif dataset_type == 'array':
dim = array_dim(dsval)
vecdata = arr_to_vector(dsval)
newvec = hydra_units.convert(vecdata, old_unit, to_unit)
new_val = vector_to_arr(newvec, dim)
elif dataset_type == 'timeseries':
new_val = []
for ts_time, ts_val in dsval.items():
dim = array_dim(ts_val)
vecdata = arr_to_vector(ts_val)
newvec = hydra_units.convert(vecdata, old_unit, to_unit)
newarr = vector_to_arr(newvec, dim)
new_val.append(ts_time, newarr)
elif dataset_type == 'descriptor':
raise HydraError('Cannot convert descriptor.')
new_dataset = Dataset()
new_dataset.data_units = to_unit
new_dataset.set_val(dataset_type, new_val)
new_dataset.data_dimen = ds_i.data_dimen
new_dataset.data_name = ds_i.data_name
new_dataset.data_type = ds_i.data_type
new_dataset.hidden = 'N'
new_dataset.set_metadata(ds_i.get_metadata_as_dict())
new_dataset.set_hash()
existing_ds = DBSession.query(Dataset).filter(Dataset.data_hash==new_dataset.data_hash).first()
if existing_ds is not None:
DBSession.expunge_all()
return existing_ds.dataset_id
DBSession.add(new_dataset)
DBSession.flush()
return new_dataset.dataset_id
else:
raise HydraError('Dataset has no units.')
示例2: get_resource_data
# 需要导入模块: from HydraServer.db import DBSession [as 别名]
# 或者: from HydraServer.db.DBSession import expunge_all [as 别名]
def get_resource_data(ref_key, ref_id, scenario_id, type_id,**kwargs):
"""
Get all the resource scenarios for a given resource
in a given scenario. If type_id is specified, only
return the resource scenarios for the attributes
within the type.
"""
user_id = kwargs.get('user_id')
#THis can be either a single ID or list, so make them consistent
if not isinstance(scenario_id, list):
scenario_id = [scenario_id]
resource_data_qry = DBSession.query(ResourceScenario).filter(
ResourceScenario.dataset_id == Dataset.dataset_id,
ResourceAttr.resource_attr_id == ResourceScenario.resource_attr_id,
ResourceScenario.scenario_id.in_(scenario_id),
ResourceAttr.ref_key == ref_key,
or_(
ResourceAttr.network_id==ref_id,
ResourceAttr.node_id==ref_id,
ResourceAttr.link_id==ref_id,
ResourceAttr.group_id==ref_id
)).distinct().options(joinedload('resourceattr')).options(joinedload_all('dataset.metadata'))
if type_id is not None:
attr_ids = []
rs = DBSession.query(TypeAttr).filter(TypeAttr.type_id==type_id).all()
for r in rs:
attr_ids.append(r.attr_id)
resource_data_qry = resource_data_qry.filter(ResourceAttr.attr_id.in_(attr_ids))
resource_data = resource_data_qry.all()
for rs in resource_data:
try:
rs.dataset.value = zlib.decompress(rs.dataset.value)
except zlib.error:
pass
if rs.dataset.hidden == 'Y':
try:
rs.dataset.check_read_permission(user_id)
except:
rs.dataset.value = None
rs.dataset.frequency = None
rs.dataset.start_time = None
DBSession.expunge_all()
return resource_data
示例3: get_scenario_data
# 需要导入模块: from HydraServer.db import DBSession [as 别名]
# 或者: from HydraServer.db.DBSession import expunge_all [as 别名]
def get_scenario_data(scenario_id,**kwargs):
"""
Get all the datasets from the group with the specified name
@returns a list of dictionaries
"""
user_id = kwargs.get('user_id')
scenario_data = DBSession.query(Dataset).filter(Dataset.dataset_id==ResourceScenario.dataset_id, ResourceScenario.scenario_id==scenario_id).options(joinedload_all('metadata')).distinct().all()
for sd in scenario_data:
if sd.hidden == 'Y':
try:
sd.check_read_permission(user_id)
except:
sd.value = None
sd.frequency = None
sd.start_time = None
sd.metadata = []
DBSession.expunge_all()
log.info("Retrieved %s datasets", len(scenario_data))
return scenario_data