本文整理汇总了Python中tardis.tardis_portal.models.ExperimentParameterSet类的典型用法代码示例。如果您正苦于以下问题:Python ExperimentParameterSet类的具体用法?Python ExperimentParameterSet怎么用?Python ExperimentParameterSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExperimentParameterSet类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: map_form_to_schemas
def map_form_to_schemas(extraInfo, publication):
for form_id, form in extraInfo.iteritems():
try: # Ignore form if no schema exists with this name
schema = Schema.objects.get(namespace=form['schema'])
except Schema.DoesNotExist:
continue
parameter_set = ExperimentParameterSet(
schema=schema, experiment=publication)
parameter_set.save()
for key, value in form.iteritems():
if key != 'schema':
try: # Ignore field if parameter name (key) doesn't match
parameter_name = ParameterName.objects.get(
schema=schema, name=key)
if parameter_name.isNumeric():
parameter = ExperimentParameter(
name=parameter_name,
parameterset=parameter_set,
numerical_value=float(value))
elif parameter_name.isLongString() or \
parameter_name.isString() or \
parameter_name.isURL() or \
parameter_name.isLink() or \
parameter_name.isFilename():
parameter = ExperimentParameter(
name=parameter_name,
parameterset=parameter_set,
string_value=str(value))
else:
# Shouldn't happen, but here in case the parameter type
# is non-standard
continue
parameter.save()
except ParameterName.DoesNotExist:
pass
开发者ID:keithschulze,项目名称:mytardis,代码行数:35,代码来源:views.py
示例2: save_rif_cs_profile
def save_rif_cs_profile(self, experiment, profile):
"""
Save selected profile choice as experiment parameter
"""
namespace = "http://monash.edu.au/rif-cs/profile/"
schema = None
try:
schema = Schema.objects.get(
namespace__exact=namespace)
except Schema.DoesNotExist:
logger.debug('Schema ' + namespace +
' does not exist. Creating.')
schema = Schema(namespace=namespace)
schema.save()
parametername = ParameterName.objects.get(
schema__namespace__exact=schema.namespace,
name="profile")
parameterset = None
try:
parameterset = \
ExperimentParameterSet.objects.get(\
schema=schema,
experiment=experiment)
except ExperimentParameterSet.DoesNotExist, e:
parameterset = ExperimentParameterSet(\
schema=schema,
experiment=experiment)
parameterset.save()
开发者ID:aaryani,项目名称:CoreTardis,代码行数:32,代码来源:__init__.py
示例3: create_draft_publication
def create_draft_publication(user, publication_title, publication_description):
# Note: Maybe this logic can be taken from the tardis_portal/views.py?
experiment = Experiment(created_by=user,
title=publication_title,
description=publication_description)
experiment.save()
ObjectACL(content_object=experiment,
pluginId=django_user,
entityId=str(user.id),
canRead=True,
canWrite=False,
canDelete=False,
isOwner=True,
aclOwnershipType=ObjectACL.OWNER_OWNED).save()
ObjectACL(content_object=experiment,
pluginId=django_group,
entityId=str(
Group.objects.get_or_create(
name=getattr(
settings, 'PUBLICATION_OWNER_GROUP',
default_settings.PUBLICATION_OWNER_GROUP))[0].id),
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True,
aclOwnershipType=ObjectACL.OWNER_OWNED).save()
publication_schema = Schema.objects.get(
namespace=getattr(settings, 'PUBLICATION_SCHEMA_ROOT',
default_settings.PUBLICATION_SCHEMA_ROOT))
# Attach draft schema
draft_publication_schema = Schema.objects.get(
namespace=getattr(settings, 'PUBLICATION_DRAFT_SCHEMA',
default_settings.PUBLICATION_DRAFT_SCHEMA))
ExperimentParameterSet(schema=draft_publication_schema,
experiment=experiment).save()
# Attach root schema and blank form_state parameter
publication_root_schema = Schema.objects.get(
namespace=getattr(settings, 'PUBLICATION_SCHEMA_ROOT',
default_settings.PUBLICATION_SCHEMA_ROOT))
publication_root_parameter_set = ExperimentParameterSet(
schema=publication_schema,
experiment=experiment)
publication_root_parameter_set.save()
form_state_param_name = ParameterName.objects.get(
schema=publication_root_schema, name='form_state')
ExperimentParameter(name=form_state_param_name,
parameterset=publication_root_parameter_set).save()
return experiment
开发者ID:keithschulze,项目名称:mytardis,代码行数:55,代码来源:views.py
示例4: _create_related_info
def _create_related_info(request, experiment_id):
if not authz.has_write_permissions(request, experiment_id):
return return_response_error(request)
form = RelatedInfoForm(json.loads(request.body))
if not form.is_valid():
return HttpResponse('', status=400)
ps = ExperimentParameterSet(experiment_id=experiment_id,
schema=_get_schema())
ps.save()
ParameterSetManager(ps).set_params_from_dict(form.cleaned_data)
return HttpResponse(json.dumps(_get_dict_from_ps(ps)),
content_type='application/json; charset=utf-8',
status=201)
开发者ID:conkiztador,项目名称:mytardis,代码行数:13,代码来源:views.py
示例5: _create
def _create(self, request, experiment_id):
from tardis.tardis_portal.auth.decorators import has_experiment_write
if not has_experiment_write(request, experiment_id):
return return_response_error(request)
form = self.form_cls(json.loads(request.body))
if not form.is_valid():
return HttpResponse('', status=400)
ps = ExperimentParameterSet(experiment_id=experiment_id,
schema=self.schema)
ps.save()
ParameterSetManager(ps).set_params_from_dict(form.cleaned_data)
return HttpResponse(json.dumps(self._get_dict_from_ps(ps)),
content_type='application/json; charset=utf-8',
status=201)
开发者ID:crawley,项目名称:mytardis,代码行数:14,代码来源:shortcuts.py
示例6: set_embargo_release_date
def set_embargo_release_date(publication, release_date):
pub_schema_root = Schema.objects.get(
namespace=getattr(settings, 'PUBLICATION_SCHEMA_ROOT',
default_settings.PUBLICATION_SCHEMA_ROOT))
pub_schema_root_parameter_set = ExperimentParameterSet(
schema=pub_schema_root,
experiment=publication)
pub_schema_root_parameter_set.save()
embargo_parameter_name = ParameterName.objects.get(
schema=pub_schema_root,
name='embargo')
ExperimentParameter(name=embargo_parameter_name,
parameterset=pub_schema_root_parameter_set,
datetime_value=release_date).save()
开发者ID:keithschulze,项目名称:mytardis,代码行数:14,代码来源:views.py
示例7: add_info
def add_info(self, cleaned_data):
logger.debug('adding info')
logger.debug(cleaned_data)
type = cleaned_data['type']
identifier_type = cleaned_data['identifier_type']
identifier = cleaned_data['identifier']
title = cleaned_data['title']
notes = cleaned_data['notes']
eps = ExperimentParameterSet(experiment_id=self.experiment_id, schema=self.schema)
eps.save()
_maybe_add(eps, self.type_name, type)
_maybe_add(eps, self.identifier_type_name, identifier_type, force=True)
_maybe_add(eps, self.identifier_name, identifier, force=True)
_maybe_add(eps, self.title_name, title)
_maybe_add(eps, self.notes_name, notes)
开发者ID:ANSTO,项目名称:related_info,代码行数:18,代码来源:related_info.py
示例8: _save_party_refs
def _save_party_refs(self, party, party_relation):
""" Save party and party relation information as parameters on the
experiment
"""
namespace = "http://rmit.edu.au/rif-cs/party/1.0/"
logger.debug("saving party")
schema = None
try:
schema = Schema.objects.get(
namespace__exact=namespace)
except Schema.DoesNotExist:
logger.debug('Schema ' + namespace +
' does not exist. Creating.')
schema = Schema(namespace=namespace)
schema.save()
exp = Experiment.objects.get(pk=self.experiment_id)
party_id_param = self._make_param(schema=schema,
name="party_id",
paramtype=ParameterName.NUMERIC)
relation_param = self._make_param(schema=schema,
name="relationtocollection_id",
paramtype=ParameterName.STRING)
parameterset = ExperimentParameterSet(schema=schema, experiment=exp)
parameterset.save()
ep = ExperimentParameter.objects.filter(name=party_id_param,
parameterset=parameterset,
parameterset__experiment=exp)
for p in ep:
p.delete()
ep = ExperimentParameter(
parameterset=parameterset,
name=party_id_param,
numerical_value=party.pk)
ep.save()
ep = ExperimentParameter.objects.filter(name=relation_param,
parameterset=parameterset,
parameterset__experiment=exp)
for p in ep:
p.delete()
ep = ExperimentParameter(
parameterset=parameterset,
name=relation_param,
string_value=party_relation)
ep.save()
开发者ID:aaryani,项目名称:hpctardis,代码行数:44,代码来源:rif_cs_PublishProvider.py
示例9: synchrotron_search_epn
def synchrotron_search_epn(publication):
# *** Synchrotron specific ***
# Search for beamline/EPN information associated with each dataset
# and add to the publication.
try:
synch_epn_schema = Schema.objects.get(
namespace='http://www.tardis.edu.au/schemas/as/'
'experiment/2010/09/21')
datasets = Dataset.objects.filter(experiments=publication)
synch_experiments = Experiment.objects.filter(
datasets__in=datasets,
experimentparameterset__schema=synch_epn_schema).exclude(
pk=publication.pk).distinct()
for exp in [s for s in
synch_experiments if not s.is_publication()]:
epn = ExperimentParameter.objects.get(
name__name='EPN',
name__schema=synch_epn_schema,
parameterset__experiment=exp).string_value
beamline = ExperimentParameter.objects.get(
name__name='beamline',
name__schema=synch_epn_schema,
parameterset__experiment=exp).string_value
epn_parameter_set = ExperimentParameterSet(
schema=synch_epn_schema,
experiment=publication)
epn_parameter_set.save()
epn_copy = ExperimentParameter(
name=ParameterName.objects.get(
name='EPN', schema=synch_epn_schema),
parameterset=epn_parameter_set)
epn_copy.string_value = epn
epn_copy.save()
beamline_copy = ExperimentParameter(
name=ParameterName.objects.get(
name='beamline', schema=synch_epn_schema),
parameterset=epn_parameter_set)
beamline_copy.string_value = beamline
beamline_copy.save()
except Schema.DoesNotExist:
pass
开发者ID:keithschulze,项目名称:mytardis,代码行数:42,代码来源:views.py
示例10: __init__
def __init__(self, experiment_id, create=False):
self.experiment = Experiment.objects.get(pk=experiment_id)
parametersets = ExperimentParameterSet.objects.filter(
schema__namespace=NAMESPACE, experiment__id=experiment_id)
self.schema, _ = Schema.objects.get_or_create(namespace=NAMESPACE, name='Embargo Details')
self.expiry_date, _ = ParameterName.objects.get_or_create(schema=self.schema, name=EXPIRY_DATE_KEY, full_name='Expiry', immutable=True, data_type=ParameterName.DATETIME)
self.never_expire, _ = ParameterName.objects.get_or_create(schema=self.schema, name=NEVER_EXPIRE_KEY, full_name='Never Expires', immutable=True, data_type=ParameterName.STRING)
if len(parametersets) == 1:
self.parameterset = parametersets[0]
elif create:
self.parameterset = ExperimentParameterSet(experiment=self.experiment, schema=self.schema)
self.parameterset.save()
else:
self.parameterset = None
开发者ID:aaryani,项目名称:aa-migration-test1,代码行数:17,代码来源:embargo.py
示例11: EmbargoHandler
class EmbargoHandler(object):
def __init__(self, experiment_id, create=False):
self.experiment = Experiment.objects.get(pk=experiment_id)
parametersets = ExperimentParameterSet.objects.filter(
schema__namespace=NAMESPACE, experiment__id=experiment_id)
self.schema, _ = Schema.objects.get_or_create(namespace=NAMESPACE, name='Embargo Details')
self.expiry_date, _ = ParameterName.objects.get_or_create(schema=self.schema, name=EXPIRY_DATE_KEY, full_name='Expiry', immutable=True, data_type=ParameterName.DATETIME)
self.never_expire, _ = ParameterName.objects.get_or_create(schema=self.schema, name=NEVER_EXPIRE_KEY, full_name='Never Expires', immutable=True, data_type=ParameterName.STRING)
if len(parametersets) == 1:
self.parameterset = parametersets[0]
elif create:
self.parameterset = ExperimentParameterSet(experiment=self.experiment, schema=self.schema)
self.parameterset.save()
else:
self.parameterset = None
def never_expires(self):
never_expire = self._get_or_none(NEVER_EXPIRE_KEY)
if never_expire:
return True
expiry_date = self._get_or_none(EXPIRY_DATE_KEY)
if expiry_date:
return False
else:
return self.experiment.end_time == None
def has_any_expiry(self):
return not self.never_expires()
def can_be_defaulted(self):
expiry_date = self._get_or_none(EXPIRY_DATE_KEY)
never_expires = self._get_or_none(NEVER_EXPIRE_KEY)
return never_expires or expiry_date
def because_no_end_date(self):
if self._get_or_none(NEVER_EXPIRE_KEY):
return False
return self.experiment.end_time == None
def get_expiry_date(self):
''' returns calculated or explicit expiry or None '''
import datetime
if self.never_expires():
return None
explicit_expiry = self._get_or_none(EXPIRY_DATE_KEY)
if explicit_expiry:
return explicit_expiry.datetime_value
else:
return self.experiment.end_time + datetime.timedelta(settings.EMBARGO_DAYS)
def _get_or_none(self, name):
if not self.parameterset:
return None
params = self.parameterset.experimentparameter_set.filter(name__name=name)
if params.count() == 0:
return None
else:
return params[0]
def prevent_expiry(self):
# delete any current expiry dates
# set never_expires = True
logger.fatal('preventing expiry')
if not self.parameterset:
raise Exception('incorrectly initialised, call with create=True')
params = self.parameterset.experimentparameter_set
params.all().delete()
param = ExperimentParameter(name=self.never_expire, string_value='True', parameterset=self.parameterset)
param.save()
self.experiment.public = False
self.experiment.save()
def reset_to_default(self):
import datetime
if self.parameterset:
self.parameterset.delete()
expiry_date = self.get_expiry_date()
if expiry_date and expiry_date.date() < datetime.date.today():
self.experiment.public = True
else:
self.experiment.public = False
self.experiment.save()
else:
logger.warn('tried to delete parameterset that does not exist')
def set_expiry(self, date_string):
if not self.parameterset:
raise Exception('incorrectly initialised, call with create=True')
params = self.parameterset.experimentparameter_set
params.all().delete()
import datetime
#.........这里部分代码省略.........
开发者ID:aaryani,项目名称:aa-migration-test1,代码行数:101,代码来源:embargo.py
示例12: ParameterSetManager
class ParameterSetManager(object):
parameterset = None
parameters = None # queryset of parameters
blank_param = None
# parameterset OR schema / datafile / dataset / experiment
# delete dataset creation code
# make parameterset / object arguments generic and test type
# create function to return generic parameter type for setting/getting
def __init__(self, parameterset=None, parentObject=None,
schema=None):
"""
instantiate new task or existing ParameterSet
:param dataset: optional parameter to instanciate task from
metadata, will be tested for completeness and copied into
new task if complete
:type dataset: Dataset
"""
if parameterset:
self.parameterset = parameterset
self.schema = self.parameterset.schema
self.namespace = self.schema.namespace
if type(self.parameterset).__name__ == "DatafileParameterSet":
self.parameters = DatafileParameter.objects.filter(\
parameterset=self.parameterset).order_by('name__full_name')
self.blank_param = DatafileParameter
elif type(self.parameterset).__name__ == "DatasetParameterSet":
self.parameters = DatasetParameter.objects.filter(\
parameterset=self.parameterset).order_by('name__full_name')
self.blank_param = DatasetParameter
elif type(self.parameterset).__name__ == "ExperimentParameterSet":
self.parameters = ExperimentParameter.objects.filter(\
parameterset=self.parameterset).order_by('name__full_name')
self.blank_param = ExperimentParameter
else:
raise TypeError("Invalid parameterset object given.")
elif parentObject and schema:
self.namespace = schema
if type(parentObject).__name__ == "Dataset_File":
self.parameterset = DatafileParameterSet(
schema=self.get_schema(), dataset_file=parentObject)
self.parameterset.save()
self.parameters = DatafileParameter.objects.filter(
parameterset=self.parameterset)
self.blank_param = DatafileParameter
elif type(parentObject).__name__ == "Dataset":
self.parameterset = DatasetParameterSet(
schema=self.get_schema(), dataset=parentObject)
self.parameterset.save()
self.parameters = DatasetParameter.objects.filter(
parameterset=self.parameterset)
self.blank_param = DatasetParameter
elif type(parentObject).__name__ == "Experiment":
self.parameterset = ExperimentParameterSet(
schema=self.get_schema(), experiment=parentObject)
self.parameterset.save()
self.parameters = ExperimentParameter.objects.filter(
parameterset=self.parameterset)
self.blank_param = ExperimentParameter
else:
raise TypeError("Invalid parent object." +
"Must be an experiment/dataset/datafile")
else:
raise TypeError("Missing arguments")
def get_schema(self):
try:
schema = Schema.objects.get(
namespace=self.namespace)
except ObjectDoesNotExist:
schema = Schema()
schema.namespace = self.namespace
schema.save()
self.schema = schema
return schema
#.........这里部分代码省略.........
开发者ID:aaryani,项目名称:aa-migration-test1,代码行数:101,代码来源:ParameterSetManager.py
示例13: delete_info
def delete_info(self, parameterset_id):
eps = ExperimentParameterSet(experiment_id=self.experiment_id, schema=self.schema, pk=parameterset_id)
eps.delete()
开发者ID:ANSTO,项目名称:related_info,代码行数:3,代码来源:related_info.py
示例14: ParameterSetManager
class ParameterSetManager(object):
parameterset = None
parameters = None # queryset of parameters
blank_param = None
# parameterset OR schema / datafile / dataset / experiment
# delete dataset creation code
# make parameterset / object arguments generic and test type
# create function to return generic parameter type for setting/getting
#
# 2011/07/20 (Ryan Braganza)
# changed type checking from:
# type(self.parameterset).__name__ == 'ClassName'
# to:
# isinstance(self.parameterset, Class)
# This is to solve an issue with models using deferred fields.
# When using deferred fields, a subclass is used, so the class name
# will not match when using type(self.parameterset).__name__
# isinstance deals with inheritance appropriately here
def __init__(self, parameterset=None, parentObject=None,
schema=None):
"""
instantiate new task or existing ParameterSet
:param dataset: optional parameter to instanciate task from
metadata, will be tested for completeness and copied into
new task if complete
:type dataset: Dataset
:param schema: Schema namespace
:type schema: string
"""
if parameterset:
self.parameterset = parameterset
self.schema = self.parameterset.schema
self.namespace = self.schema.namespace
if isinstance(self.parameterset, DatafileParameterSet):
self.parameters = DatafileParameter.objects.filter(\
parameterset=self.parameterset).order_by('name__full_name')
self.blank_param = DatafileParameter
elif isinstance(self.parameterset, DatasetParameterSet):
self.parameters = DatasetParameter.objects.filter(\
parameterset=self.parameterset).order_by('name__full_name')
self.blank_param = DatasetParameter
elif isinstance(self.parameterset, ExperimentParameterSet):
self.parameters = ExperimentParameter.objects.filter(\
parameterset=self.parameterset).order_by('name__full_name')
self.blank_param = ExperimentParameter
else:
raise TypeError("Invalid parameterset object given.")
elif parentObject and schema:
self.namespace = schema
if isinstance(parentObject, Dataset_File):
self.parameterset = DatafileParameterSet(
schema=self.get_schema(), dataset_file=parentObject)
self.parameterset.save()
self.parameters = DatafileParameter.objects.filter(
parameterset=self.parameterset)
self.blank_param = DatafileParameter
elif isinstance(parentObject, Dataset):
self.parameterset = DatasetParameterSet(
schema=self.get_schema(), dataset=parentObject)
self.parameterset.save()
self.parameters = DatasetParameter.objects.filter(
parameterset=self.parameterset)
self.blank_param = DatasetParameter
elif isinstance(parentObject, Experiment):
self.parameterset = ExperimentParameterSet(
schema=self.get_schema(), experiment=parentObject)
self.parameterset.save()
self.parameters = ExperimentParameter.objects.filter(
parameterset=self.parameterset)
self.blank_param = ExperimentParameter
else:
raise TypeError("Invalid parent object." +
"Must be an experiment/dataset/datafile not " + str(type(parentObject)))
else:
#.........这里部分代码省略.........
开发者ID:ANSTO,项目名称:mytardis,代码行数:101,代码来源:ParameterSetManager.py
示例15: process_form
#.........这里部分代码省略.........
form_state['selectedLicenseId'] = -1
# Set a default author (current user) if no previously saved data
# By default, the form sends a list of authors of one element
# with blank fields
if len(form_state['authors']) == 1 and \
not form_state['authors'][0]['name']:
form_state['authors'] = [
{'name': ' '.join([request.user.first_name,
request.user.last_name]),
'institution': getattr(settings, 'DEFAULT_INSTITUTION', ''),
'email': request.user.email}]
elif form_state['action'] == 'submit':
# any final form validation should occur here
# and specific error messages can be returned
# to the browser before the publication's draft
# status is removed.
if 'acknowledge' not in form_state or not form_state['acknowledge']:
return validation_error('You must confirm that you are '
'authorised to submit this publication')
set_publication_authors(form_state['authors'], publication)
institutions = '; '.join(
set([author['institution'] for author in form_state['authors']]))
publication.institution_name = institutions
# Attach the publication details schema
pub_details_schema = Schema.objects.get(
namespace=getattr(settings, 'PUBLICATION_DETAILS_SCHEMA',
default_settings.PUBLICATION_DETAILS_SCHEMA))
pub_details_parameter_set = ExperimentParameterSet(
schema=pub_details_schema,
experiment=publication)
pub_details_parameter_set.save()
# Add the acknowledgements
acknowledgements_parameter_name = ParameterName.objects.get(
schema=pub_details_schema,
name='acknowledgements')
ExperimentParameter(name=acknowledgements_parameter_name,
parameterset=pub_details_parameter_set,
string_value=form_state['acknowledgements']).save()
# Set the release date
set_embargo_release_date(
publication,
dateutil.parser.parse(
form_state[
'embargo']))
# Set the license
try:
publication.license = License.objects.get(
pk=form_state['selectedLicenseId'],
is_active=True,
allows_distribution=True)
except License.DoesNotExist:
publication.license = License.get_none_option_license()
publication.save()
# Send emails about publication in draft
subject, message_content = email_pub_requires_authorisation(
开发者ID:keithschulze,项目名称:mytardis,代码行数:67,代码来源:views.py
示例16: __init__
def __init__(self, parameterset=None, parentObject=None,
schema=None):
"""
instantiate new task or existing ParameterSet
:param dataset: optional parameter to instanciate task from
metadata, will be tested for completeness and copied into
new task if complete
:type dataset: Dataset
:param schema: Schema namespace
:type schema: string
"""
if parameterset:
self.parameterset = parameterset
self.schema = self.parameterset.schema
self.namespace = self.schema.namespace
if isinstance(self.parameterset, DatafileParameterSet):
self.parameters = DatafileParameter.objects.filter(\
parameterset=self.parameterset).order_by('name__full_name')
self.blank_param = DatafileParameter
elif isinstance(self.parameterset, DatasetParameterSet):
self.parameters = DatasetParameter.objects.filter(\
parameterset=self.parameterset).order_by('name__full_name')
self.blank_param = DatasetParameter
elif isinstance(self.parameterset, ExperimentParameterSet):
self.parameters = ExperimentParameter.objects.filter(\
parameterset=self.parameterset).order_by('name__full_name')
self.blank_param = ExperimentParameter
else:
raise TypeError("Invalid parameterset object given.")
elif parentObject and schema:
self.namespace = schema
if isinstance(parentObject, Dataset_File):
self.parameterset = DatafileParameterSet(
schema=self.get_schema(), dataset_file=parentObject)
self.parameterset.save()
self.parameters = DatafileParameter.objects.filter(
parameterset=self.parameterset)
self.blank_param = DatafileParameter
elif isinstance(parentObject, Dataset):
self.parameterset = DatasetParameterSet(
schema=self.get_schema(), dataset=parentObject)
self.parameterset.save()
self.parameters = DatasetParameter.objects.filter(
parameterset=self.parameterset)
self.blank_param = DatasetParameter
elif isinstance(parentObject, Experiment):
self.parameterset = ExperimentParameterSet(
schema=self.get_schema(), experiment=parentObject)
self.parameterset.save()
self.parameters = ExperimentParameter.objects.filter(
parameterset=self.parameterset)
self.blank_param = ExperimentParameter
else:
raise TypeError("Invalid parent object." +
"Must be an experiment/dataset/datafile not " + str(type(parentObject)))
else:
raise TypeError("Missing arguments")
开发者ID:ANSTO,项目名称:mytardis,代码行数:81,代码来源:ParameterSetManager.py
示例17: populate_pdb_pub_records
def populate_pdb_pub_records():
PUB_SCHEMA = getattr(settings, 'PUBLICATION_SCHEMA_ROOT',
default_settings.PUBLICATION_SCHEMA_ROOT)
PUB_SCHEMA_DRAFT = getattr(settings, 'PUBLICATION_DRAFT_SCHEMA',
default_settings.PUBLICATION_DRAFT_SCHEMA)
PDB_SCHEMA = getattr(settings, 'PDB_PUBLICATION_SCHEMA_ROOT',
default_settings.PDB_PUBLICATION_SCHEMA_ROOT)
publications = Experiment.objects \
.filter(experimentparameterset__schema__namespace=PDB_SCHEMA) \
.filter(experimentparameterset__schema__namespace=PUB_SCHEMA) \
.exclude(experimentparameterset__schema__namespace=PUB_SCHEMA_DRAFT) \
.distinct()
last_update_parameter_name = ParameterName.objects.get(
name='pdb-last-sync',
schema__namespace=PUB_SCHEMA)
def add_if_missing(parameterset, name, string_value=None,
numerical_value=None, datetime_value=None):
try:
ExperimentParameter.objects.get(
name__name=name, parameterset=parameterset)
except ExperimentParameter.DoesNotExist:
param_name = ParameterName.objects.get(
name=name, schema=parameterset.schema)
param = ExperimentParameter(name=param_name,
parameterset=parameterset)
param.string_value = string_value
param.numerical_value = numerical_value
param.datetime_value = datetime_value
param.save()
for pub in publications:
try:
# try to get the last update time for the PDB data
pdb_last_update_parameter = ExperimentParameter.objects.get(
parameterset__schema__namespace=PUB_SCHEMA,
name=last_update_parameter_name,
parameterset__experiment=pub
)
last_update = pdb_last_update_parameter.datetime_value
needs_update = last_update + \
getattr(settings,
'PDB_REFRESH_INTERVAL',
default_settings.PDB_REFRESH_INTERVAL) \
< timezone.now()
except ExperimentParameter.DoesNotExist:
# if the PDB last update time parameter doesn't exist,
# we definitely need to update the data and create a last
# update entry
needs_update = True
pdb_last_update_parameter = None
# If an update needs to happen...
if needs_update:
# 1. get the PDB info
pdb_parameter_set = ExperimentParameterSet.objects.get(
schema__namespace=getattr(
settings,
'PDB_PUBLICATION_SCHEMA_ROOT',
default_settings.PDB_PUBLICATION_SCHEMA_ROOT),
experiment=pub)
pdb = ExperimentParameter.objects.get(
name__name='pdb-id',
parameterset=pdb_parameter_set)
pdb_id = pdb.string_value
# 1a. cosmetic change of case for PDB ID, if entered incorrectly
if pdb_id != pdb_id.upper():
pdb.string_value = pdb_id.upper()
pdb.save()
try:
# 2. fetch the info from pdb.org
pdb = PDBCifHelper(pdb_id)
# 3. insert all standard pdb parameters
add_if_missing(pdb_parameter_set, 'title',
string_value=pdb.get_pdb_title())
add_if_missing(pdb_parameter_set, 'url',
string_value=pdb.get_pdb_url())
try:
add_if_missing(pdb_parameter_set, 'resolution',
numerical_value=pdb.get_resolution())
except ValueError:
logger.error(
'PDB field "resolution" could not be set for '
'publication Id %i \n %s' %
(pub.id, traceback.format_exc()))
try:
add_if_missing(pdb_parameter_set, 'r-value',
numerical_value=pdb.get_obs_r_value())
except ValueError:
logger.error(
'PDB field "r-value" could not be set for '
'publication Id %i \n %s' %
(pub.id, traceback.format_exc()))
try:
#.........这里部分代码省略.........
开发者ID:IntersectAustralia,项目名称:mytardis,代码行数:101,代码来源:tasks.py
注:本文中的tardis.tardis_portal.models.ExperimentParameterSet类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论