Пример #1
0
    def validate_parameter(param_dict=None):
        """
        this method will validate each input parameter. the validation includes type check and range check
        all appropriate errors shall be thrown within the implementation
        :return: boolean indicating success/ error value indicating error
        """

        validated = True
        error = []
        if param_dict is None or not isinstance(param_dict, dict):
            error.append('No Valid Dictionary Provided')
            return ';'.join([str(x) for x in error])

        if not Operation.check_mandatory_param(param_dict,
                                               Adjust.MANDATORY_PARAMS):
            return "mandatory information is missing"

        if "observation" in param_dict:
            observation = param_dict['observation']
            observation = re.match('^[0-9]+d[0-9]+.\d$', observation)
            if observation:
                observation = observation.group()
                x, y = observation.split("d")
                if int(x) < 0 or int(x) > 89:
                    validated = False
                    error.append(
                        'Observation degree must be integer between 0 and 89. inclusive'
                    )

                # trim leading 0
                y = y.lstrip("0")
                if float(y) < 0.0 or not float(y) < 60:
                    validated = False
                    error.append(
                        'Observation minute must be float between GE 0.0 and LT 60.0.'
                    )
                if int(x) == 0 and float(y) < 0.1:
                    validated = False
                    error.append('Observation value cannot be less than 0d0.1')
            else:
                validated = False
                error.append('Invalid Observation Value in Dictionary')
        else:
            validated = False
            error.append('Missing Observation Value in Dictionary')

        if "height" in param_dict:
            height = param_dict['height']
            try:
                height = float(height)
            except ValueError:
                error.append("Height Value Must Be A Floating Number")
                validated = False
            if height < 0:
                error.append("Height Value Must Be A Positive Floating Number")
                validated = False

        if "pressure" in param_dict:
            pressure = param_dict['pressure']
            try:
                pressure = int(pressure)
            except ValueError:
                error.append("Pressure Value Must Be A Integer")
                validated = False
            if pressure < 100:
                error.append(
                    "Pressure Value is Below the Threshold of 100 mbar")
                validated = False
            if not pressure < 1100:
                error.append("Pressure Value Exceed Threshold of 1100 mbar")
                validated = False

        if "temperature" in param_dict:
            temperature = param_dict['temperature']
            try:
                temperature = int(temperature)
            except ValueError:
                error.append("Temperature Value Must Be A Integer")
                validated = False
            if temperature < 20:
                error.append("Temperature Value is Below the Threshold of 20")
                validated = False
            if not temperature < 120:
                error.append("Temperature Value Exceed Threshold of 120")
                validated = False

        if "horizon" in param_dict:
            horizon = param_dict['horizon'].lower()
            if horizon != "natural" and horizon != "artificial":
                error.append(
                    "Not A Valid  Horizon  Value, Must be 'artificial' or 'natural'"
                )
                validated = False

        if "altitude" in param_dict:
            error.append(
                "Input Dictionary Contains Forbidden Parameter: altitude")
            validated = False

        if validated:
            return True
        else:
            return ';'.join([str(x) for x in error])
Пример #2
0
    def validate_parameter(param_dict=None):
        validated = True
        error = []

        if not Operation.check_mandatory_param(param_dict,
                                               Correct.MANDATORY_PARAMS):
            return "mandatory information is missing"

        if 'correctedDistance' in param_dict or 'correctedAzimuth' in param_dict:
            return "Input Dictionary Contains Forbidden Parameter: correctAzimuth/correctedDistance"

        lat = param_dict['lat']
        longitude = param_dict['long']
        altitude = param_dict['altitude']
        assumed_lat = param_dict['assumedLat']
        assumed_long = param_dict['assumedLong']

        # validate lat
        if not isinstance(lat, basestring):
            validated = False
            error.append('Latitude Must be A String Value')
        else:
            lat = re.match('^[-]?[0-9]+d[0-9]{1,2}.\d$', lat)
            if lat:
                lat = lat.group()
                x, y = lat.split("d")
                if int(x) < -89 or int(x) > 89:
                    validated = False
                    error.append('Latitude Out of Range: -90.0 < lat < 90.0')

                # trim leading 0
                y = y.lstrip("0")
                if float(y) < 0.0 or not float(y) < 60:
                    validated = False
                    error.append(
                        'Latitude Minute Out of Range: 0 <= lat < 60.0')
            else:
                validated = False
                error.append('Incorrect Latitude Format: xdyy.y')

        # validate assumedLat
        if not isinstance(assumed_lat, basestring):
            validated = False
            error.append('Assumed Latitude Must be A String Value')
        else:
            assumed_lat = re.match('^[-]?[0-9]+d[0-9]{1,2}.\d$', assumed_lat)
            if assumed_lat:
                assumed_lat = assumed_lat.group()
                x, y = assumed_lat.split("d")
                if int(x) < -89 or int(x) > 89:
                    validated = False
                    error.append(
                        'Assumed Latitude Out of Range: -90.0 < assumedLat < 90.0'
                    )

                # trim leading 0
                y = y.lstrip("0")
                if float(y) < 0.0 or not float(y) < 60:
                    validated = False
                    error.append(
                        'Assumed Latitude Minute Out of Range: 0 <= assumedLat < 60.0'
                    )
            else:
                validated = False
                error.append('Incorrect Assumed Latitude Format: xdyy.y')

        # validate long
        if not isinstance(longitude, basestring):
            validated = False
            error.append('Longitude Must be A String Value')
        else:
            longitude = re.match('^[-]?[0-9]+d[0-9]{1,2}.\d$', longitude)
            if longitude:
                longitude = longitude.group()
                x, y = longitude.split("d")
                if int(x) < 0 or int(x) > 359:
                    validated = False
                    error.append('Longitude Out of Range: 0.0 <= long < 360.0')

                # trim leading 0
                y = y.lstrip("0")
                if float(y) < 0.0 or not float(y) < 60:
                    validated = False
                    error.append(
                        'Longitude Minute Out of Range: 0 <= long < 60.0')
            else:
                validated = False
                error.append('Incorrect Longitude Format: xdyy.y')

        # validate assumedLong
        if not isinstance(assumed_long, basestring):
            validated = False
            error.append('Assumed Longitude Must be A String Value')
        else:
            assumed_long = re.match('^[-]?[0-9]+d[0-9]{1,2}.\d$', assumed_long)
            if assumed_long:
                assumed_long = assumed_long.group()
                x, y = assumed_long.split("d")
                if int(x) < 0 or int(x) > 359:
                    validated = False
                    error.append(
                        'Assumed Longitude Out of Range: 0.0 <= assumedLong < 360.0'
                    )

                # trim leading 0
                y = y.lstrip("0")
                if float(y) < 0.0 or not float(y) < 60:
                    validated = False
                    error.append(
                        'Assumed Longitude Minute Out of Range: 0 <= assumedLong < 60.0'
                    )
            else:
                validated = False
                error.append('Incorrect Assumed Longitude Format: xdyy.y')

        # validate altitude
        if not isinstance(altitude, basestring):
            validated = False
            error.append('Altitude Must be A String Value')
        else:
            altitude = re.match('^[-]?[0-9]+d[0-9]{1,2}.\d$', altitude)
            if altitude:
                altitude = altitude.group()
                x, y = altitude.split("d")
                if int(x) < 0 or int(x) > 89:
                    validated = False
                    error.append(
                        'Altitude Out of Range: 0.0 < altitude < 90.0')

                # trim leading 0
                y = y.lstrip("0")
                if float(y) < 0.0 or not float(y) < 60:
                    validated = False
                    error.append(
                        'Altitude Minute Out of Range: 0 <= altitude < 60.0')

                if int(x) == 0 and float(y) < 0.1:
                    validated = False
                    error.append('Altitude value cannot be less than 0d0.1')
            else:
                validated = False
                error.append('Incorrect Altitude Format: xdyy.y')

        if validated:
            return True
        else:
            return error
Пример #3
0
 def validate_parameter(param_dict=None):
     validated = True
     error = []
     
     if not Operation.check_mandatory_param(param_dict, Predict.MANDATORY_PARAMS):
         return "mandatory information is missing"
     
     if "lat" in param_dict or "long" in param_dict:
         validated = False
         error.append('[lat] or [long] key cannot be in Dictionary')
     
     if "body" not in param_dict:
         validated = False
         error.append('Missing Star Name in Dictionary')
     else:
         if not isinstance(param_dict['body'], basestring):
             validated = False
             error.append('Invalid Star Name')
         else:
             star_name = param_dict['body'].lower().capitalize()
             if star_name not in STARS:
                 validated = False
                 error.append('Star Not Found on Star List')
         
     if "date" in param_dict:
         input_date = param_dict['date']
         if not isinstance(input_date, basestring):
             validated = False
             error.append('Invalid Date Value')
         else:
             input_date = re.match('^2[0-9]{3}-[0-9]{2}-[0-9]{2}$', input_date)
             if input_date:
                 input_date = input_date.group()
                 (year, month, day) = input_date.split('-')
                 year = int(year)
                 month = int(month)
                 day = int(day)
                 if year < 2001:
                     validated = False
                     error.append('Date Out of Range: Date Must be at least 2001')
                 else:
                     try:
                         date(year, month, day)
                     except ValueError:
                         validated = False
                         error.append('Invalid Date')
             else:
                 validated = False
                 error.append('Incorrect Date Format: Must be yyyy-mm-dd')
         
     if "time" in param_dict:
         input_time = param_dict['time']
         if not isinstance(input_time, basestring):
             validated = False
             error.append('Invalid Time Value')
         else:
             input_time = re.match('^[0-9]{2}:[0-9]{2}:[0-9]{2}$', input_time)
             if input_time:
                 input_time = input_time.group()
                 (hour, minute, second) = input_time.split(':')
                 hour = int(hour)
                 minute = int(minute)
                 second = int(second)
                 if hour > 23 or minute > 59 or second > 59:
                     validated = False
                     error.append('Invalid Time')
             else:
                 validated = False
                 error.append('Incorrect Time Format: Must be hh:mm:ss')
     
     if validated:
         return True
     else:
         return error