Example #1
0
def _store_input_parameters(params, calc_mode, job_profile):
    """Store parameters in uiapi.oq_job_profile columns"""

    for name, param in PARAMS.items():
        if calc_mode in param.modes and param.default is not None:
            setattr(job_profile, param.column, param.default)

    for name, value in params.items():
        param = PARAMS[name]
        value = value.strip()

        if param.type in (models.BooleanField, models.NullBooleanField):
            value = value.lower() not in ('0', 'false')
        elif param.type == models.PolygonField:
            ewkt = shapes.polygon_ewkt_from_coords(value)
            value = GEOSGeometry(ewkt)
        elif param.type == models.MultiPointField:
            ewkt = shapes.multipoint_ewkt_from_coords(value)
            value = GEOSGeometry(ewkt)
        elif param.type == FloatArrayField:
            value = [float(v) for v in ARRAY_RE.split(value) if len(v)]
        elif param.type == CharArrayField:
            if param.to_db is not None:
                value = param.to_db(value)
            value = [str(v) for v in ARRAY_RE.split(value) if len(v)]
        elif param.to_db is not None:
            value = param.to_db(value)
        elif param.type == None:
            continue

        setattr(job_profile, param.column, value)

    if job_profile.imt != 'sa':
        job_profile.period = None
        job_profile.damping = None
Example #2
0
 def __getitem__(self, name):
     defined_param = PARAMS.get(name)
     if (hasattr(defined_param, 'to_job')
         and defined_param.to_job is not None
         and self.params.get(name) is not None):
         return defined_param.to_job(self.params.get(name))
     return self.params.get(name)
Example #3
0
def _store_input_parameters(params, calc_mode, job_profile):
    """Store parameters in uiapi.oq_job_profile columns"""

    for name, param in PARAMS.items():
        if calc_mode in param.modes and param.default is not None:
            setattr(job_profile, param.column, param.default)

    for name, value in params.items():
        param = PARAMS[name]
        value = value.strip()

        if param.type in (models.BooleanField, models.NullBooleanField):
            value = value.lower() not in ('0', 'false')
        elif param.type == models.PolygonField:
            ewkt = shapes.polygon_ewkt_from_coords(value)
            value = GEOSGeometry(ewkt)
        elif param.type == models.MultiPointField:
            ewkt = shapes.multipoint_ewkt_from_coords(value)
            value = GEOSGeometry(ewkt)
        elif param.type == FloatArrayField:
            value = [float(v) for v in ARRAY_RE.split(value) if len(v)]
        elif param.type == CharArrayField:
            if param.to_db is not None:
                value = param.to_db(value)
            value = [str(v) for v in ARRAY_RE.split(value) if len(v)]
        elif param.to_db is not None:
            value = param.to_db(value)
        elif param.type == None:
            continue

        setattr(job_profile, param.column, value)

    if job_profile.imt != 'sa':
        job_profile.period = None
        job_profile.damping = None
Example #4
0
 def __getitem__(self, name):
     defined_param = PARAMS.get(name)
     if (hasattr(defined_param, 'to_job')
             and defined_param.to_job is not None
             and self.params.get(name) is not None):
         return defined_param.to_job(self.params.get(name))
     return self.params.get(name)
    def is_valid(self):  # pylint: disable=R0912
        """Check type for all parameters"""
        errors = []

        for name, value in self.params.items():
            param = PARAMS.get(name)
            if param is None:
                # Ignore unknown parameters.
                continue
            else:
                if (param.type in (None, models.TextField)
                    and param.to_db is None):
                    continue
                validate_single_param(param, name, value, errors)

        return (len(errors) == 0, errors)
Example #6
0
    def is_valid(self):  # pylint: disable=R0912
        """Check type for all parameters"""
        errors = []

        for name, value in self.params.items():
            param = PARAMS.get(name)
            if param is None:
                # Ignore unknown parameters.
                continue
            else:
                if (param.type in (None, models.TextField)
                        and param.to_db is None):
                    continue
                validate_single_param(param, name, value, errors)

        return (len(errors) == 0, errors)