Пример #1
0
    def test(self, valueToTest):
        if valueToTest is None:
            raise ValidationError("No filter provided")

        # Create the filters that we will need
        str_validate = Factory.create('string', 'string')
        int_validate = Factory.create('int', 'int')
        float_validate = Factory.create('float', 'float')
        list_validate = Factory.create('list', 'list')
        dict_validate = Factory.create('dict', 'dict')
        mode_validate = Factory.create('mode', 'mode')
        feature_validate = Factory.create('feature', 'feature')
        order_validate = Factory.create('order', 'order')
        item_type_validate = Factory.create('item_type', 'item_type')
        history_days_validate = Factory.create('history', 'history')

        result = {}
        # Verify that each individual filter is valid
        for name, fil in valueToTest.iteritems():
            # Validate name
            name = str_validate.test(name)
            if len(name) <= 0 or len(name) > 30:
                raise ValidationError('Filter name must be length 1-30')
            result[name] = {}
            # Validate the filter
            fil = dict_validate.test(fil)
            result[name]['HistoryDays'] = history_days_validate.test(
                fil.get('HistoryDays'))
            result[name]['BuyMode'] = mode_validate.test(fil.get('BuyMode'))
            result[name]['SellMode'] = mode_validate.test(fil.get('SellMode'))
            result[name]['SortBy'] = feature_validate.test(fil.get('SortBy'))
            result[name]['SortOrder'] = order_validate.test(
                fil.get('SortOrder'))
            types = list_validate.test(fil.get('Types'))
            good_types = []
            for t in types:
                t = item_type_validate.test(t)
                if t in good_types:
                    raise ValidationError(
                        'Types list cannot contain duplicates')
                good_types.append(t)
            result[name]['Types'] = good_types
            bounds = dict_validate.test(fil.get('Bounds'))
            good_bounds = {}
            for feat, dic in bounds.iteritems():
                feat = feature_validate.test(feat)
                dic = dict_validate.test(dic)
                good_bounds[feat] = {}
                min_val = dic.get('Min')
                max_val = dic.get('Max')
                if min_val is not None:
                    min_val = float_validate.test(min_val)
                    good_bounds[feat]['Min'] = min_val
                if max_val is not None:
                    max_val = float_validate.test(max_val)
                    good_bounds[feat]['Max'] = max_val
            result[name]['Bounds'] = good_bounds
        return result
Пример #2
0
    def test(self, valueToTest):
        if valueToTest is None:
            raise ValidationError("No filter provided")

        # Create the filters that we will need
        str_validate = Factory.create('string', 'string')
        int_validate = Factory.create('int', 'int')
        float_validate = Factory.create('float', 'float')
        list_validate = Factory.create('list', 'list')
        dict_validate = Factory.create('dict', 'dict')
        mode_validate = Factory.create('mode', 'mode')
        feature_validate = Factory.create('feature', 'feature')
        order_validate = Factory.create('order', 'order')
        item_type_validate = Factory.create('item_type', 'item_type')
        history_days_validate = Factory.create('history', 'history')

        result = {}
        # Verify that each individual filter is valid
        for name, fil in valueToTest.iteritems():
            # Validate name
            name = str_validate.test(name)
            if len(name) <= 0 or len(name) > 30:
                raise ValidationError('Filter name must be length 1-30')
            result[name] = {}
            # Validate the filter
            fil = dict_validate.test(fil) 
            result[name]['HistoryDays'] = history_days_validate.test(fil.get('HistoryDays'))
            result[name]['BuyMode'] = mode_validate.test(fil.get('BuyMode'))
            result[name]['SellMode'] = mode_validate.test(fil.get('SellMode'))
            result[name]['SortBy'] = feature_validate.test(fil.get('SortBy'))
            result[name]['SortOrder'] = order_validate.test(fil.get('SortOrder'))
            types = list_validate.test(fil.get('Types'))
            good_types = []
            for t in types:
                t = item_type_validate.test(t)
                if t in good_types:
                    raise ValidationError('Types list cannot contain duplicates')
                good_types.append(t)
            result[name]['Types'] = good_types
            bounds = dict_validate.test(fil.get('Bounds'))
            good_bounds = {}
            for feat, dic in bounds.iteritems():
                feat = feature_validate.test(feat)
                dic = dict_validate.test(dic)
                good_bounds[feat] = {}
                min_val = dic.get('Min')
                max_val = dic.get('Max')
                if min_val is not None:
                    min_val = float_validate.test(min_val)
                    good_bounds[feat]['Min'] = min_val
                if max_val is not None:
                    max_val = float_validate.test(max_val)
                    good_bounds[feat]['Max'] = max_val
            result[name]['Bounds'] = good_bounds
        return result
Пример #3
0
 def test(self, valueToTest):
     if valueToTest is None:
         raise ValidationError("No history days provided")
     int_validate = Factory.create('int', 'int')
     days = int_validate.test(valueToTest)
     if days not in self.allowed_days:
         raise ValidationError(str(days) + " is not a valid history day amount")
     return days
Пример #4
0
    def test(self, valueToTest):
        if valueToTest is None:
            raise ValidationError("No plan provided")

        # Create the filters that we'll need
        mode_validate = Factory.create('mode', 'mode')
        history_days_validate = Factory.create('history', 'history')
        int_validate = Factory.create('int', 'int')
        dict_validate = Factory.create('dict', 'dict')
        # Filter the input as a dict
        plan = dict_validate.test(valueToTest)
        # Use the filters to get the result
        result = {}
        result['Id'] = int_validate.test(plan.get('Id'))
        result['HistoryDays'] = history_days_validate.test(plan.get('HistoryDays'))
        result['BuyMode'] = mode_validate.test(plan.get('BuyMode'))
        result['SellMode'] = mode_validate.test(plan.get('SellMode'))
        return result
Пример #5
0
 def test(self, valueToTest):
     if valueToTest is None:
         raise ValidationError("No feature provided")
     # Parse feature to string
     str_validate = Factory.create('string', 'string')
     feature = str_validate.test(valueToTest)
     # Verify that it is a valid value
     if feature not in self.features:
       raise ValidationError(feature + ' is not a valid feature')
     return feature
Пример #6
0
 def test(self, valueToTest):
     if valueToTest is None:
         raise ValidationError("No mode provided")
     # Parse mode to string
     str_validate = Factory.create('string', 'string')
     mode = str_validate.test(valueToTest)
     # Verify that it is a valid value
     if mode != 'Instant' and mode != 'Bid':
       raise ValidationError('Mode must be Instant or Bid')
     return mode
Пример #7
0
 def test(self, valueToTest):
     if valueToTest is None:
         raise ValidationError("No item type provided")
     # Parse item type to string
     str_validate = Factory.create('string', 'string')
     item_type = str_validate.test(valueToTest)
     # Verify that it is a valid value
     if item_type not in self.item_types:
       raise ValidationError(item_type + ' is not a valid item type')
     return item_type
Пример #8
0
 def test(self, valueToTest):
     if valueToTest is None:
         raise ValidationError("No order provided")
     # Parse order to string
     str_validate = Factory.create('string', 'string')
     order = str_validate.test(valueToTest)
     # Verify that it is a valid value
     if order != 'Asc' and order != 'Desc':
       raise ValidationError('Order must be Asc or Desc')
     return order
Пример #9
0
    def test(self, valueToTest):
        if valueToTest is None:
            raise ValidationError("No plan provided")

        # Create the filters that we'll need
        mode_validate = Factory.create('mode', 'mode')
        history_days_validate = Factory.create('history', 'history')
        int_validate = Factory.create('int', 'int')
        dict_validate = Factory.create('dict', 'dict')
        # Filter the input as a dict
        plan = dict_validate.test(valueToTest)
        # Use the filters to get the result
        result = {}
        result['Id'] = int_validate.test(plan.get('Id'))
        result['HistoryDays'] = history_days_validate.test(
            plan.get('HistoryDays'))
        result['BuyMode'] = mode_validate.test(plan.get('BuyMode'))
        result['SellMode'] = mode_validate.test(plan.get('SellMode'))
        return result
Пример #10
0
def _get_filter_name_from_json(jsonData):
    return ValidatorFactory.create('string',
                                   'string').test(jsonData.get('filter_name'))
Пример #11
0
def _get_filters_from_json(jsonData):
    return ValidatorFactory.create('filter', 'filter').test(jsonData)
Пример #12
0
    def _raiseError(self):
        raise BadType('', self.fieldName, self.label)

class ListValidator(BasicTypeValidator):
    label = 'list'
    def __init__(self, fieldName, forbidNone=False):
        super(ListValidator, self).__init__(fieldName, forbidNone)

    def test(self, valueToTest):
        if not super(ListValidator, self)._testForNone(valueToTest):
            if not isinstance(valueToTest, list):
                self._raiseError()
        return valueToTest

Factory.register(ListValidator)

class DictValidator(BasicTypeValidator):
    label = 'dict'
    def __init__(self, fieldName, forbidNone=False):
        super(DictValidator, self).__init__(fieldName, forbidNone)

    def test(self, valueToTest):
        if not super(DictValidator, self)._testForNone(valueToTest):
            if not isinstance(valueToTest, dict):
                self._raiseError()
        return valueToTest

Factory.register(DictValidator)

class IntegerValidator(BasicTypeValidator):
Пример #13
0
        # Create the filters that we'll need
        mode_validate = Factory.create('mode', 'mode')
        history_days_validate = Factory.create('history', 'history')
        int_validate = Factory.create('int', 'int')
        dict_validate = Factory.create('dict', 'dict')
        # Filter the input as a dict
        plan = dict_validate.test(valueToTest)
        # Use the filters to get the result
        result = {}
        result['Id'] = int_validate.test(plan.get('Id'))
        result['HistoryDays'] = history_days_validate.test(plan.get('HistoryDays'))
        result['BuyMode'] = mode_validate.test(plan.get('BuyMode'))
        result['SellMode'] = mode_validate.test(plan.get('SellMode'))
        return result

Factory.register(PlanValidator)


class FilterValidator(BasicTypeValidator):
    label = 'filter'

    def __init__(self, fieldName, forbidNone=False):
        super(FilterValidator, self).__init__(fieldName, forbidNone)

    def test(self, valueToTest):
        if valueToTest is None:
            raise ValidationError("No filter provided")

        # Create the filters that we will need
        str_validate = Factory.create('string', 'string')
        int_validate = Factory.create('int', 'int')
Пример #14
0
def _get_plan_from_json(jsonData):
    return ValidatorFactory.create('plan', 'plan').test(jsonData)
Пример #15
0
def _get_filter_name_from_json(jsonData):
    return ValidatorFactory.create('string', 'string').test(jsonData.get('filter_name'))
Пример #16
0
def _get_filters_from_json(jsonData):
    return ValidatorFactory.create('filter', 'filter').test(jsonData)
Пример #17
0

class ListValidator(BasicTypeValidator):
    label = 'list'

    def __init__(self, fieldName, forbidNone=False):
        super(ListValidator, self).__init__(fieldName, forbidNone)

    def test(self, valueToTest):
        if not super(ListValidator, self)._testForNone(valueToTest):
            if not isinstance(valueToTest, list):
                self._raiseError()
        return valueToTest


Factory.register(ListValidator)


class DictValidator(BasicTypeValidator):
    label = 'dict'

    def __init__(self, fieldName, forbidNone=False):
        super(DictValidator, self).__init__(fieldName, forbidNone)

    def test(self, valueToTest):
        if not super(DictValidator, self)._testForNone(valueToTest):
            if not isinstance(valueToTest, dict):
                self._raiseError()
        return valueToTest

Пример #18
0
    def __init__(self, fieldName, forbidNone=False):
        super(ModeValidator, self).__init__(fieldName, forbidNone)

    def test(self, valueToTest):
        if valueToTest is None:
            raise ValidationError("No mode provided")
        # Parse mode to string
        str_validate = Factory.create('string', 'string')
        mode = str_validate.test(valueToTest)
        # Verify that it is a valid value
        if mode != 'Instant' and mode != 'Bid':
          raise ValidationError('Mode must be Instant or Bid')
        return mode

Factory.register(ModeValidator)


class FeatureValidator(BasicTypeValidator):
    label = 'feature'

    def __init__(self, fieldName, forbidNone=False):
        super(FeatureValidator, self).__init__(fieldName, forbidNone)
        self.features = ['ItemID', 'ItemType', 'ItemRarity', 'ItemLevel', 'NumBuyOrders',
          'NumSellOrders', 'BuyPrice', 'SellPrice', 'ZScoreBuyPrice', 'ZScoreSellPrice',
          'MeanBuyPrice', 'MeanSellPrice', 'VarBuyPrice', 'VarSellPrice', 'MedianBuyPrice',
          'MedianSellPrice', 'SlopeBuyPrice', 'SlopeSellPrice', 'CurrentFlipProfit',
          'MeanProfit', 'VarProfit', 'MedianProfit', 'OurBuyPrice', 'NumConsidered']

    def test(self, valueToTest):
        if valueToTest is None:
Пример #19
0
def _get_plan_from_json(jsonData):
    return ValidatorFactory.create('plan', 'plan').test(jsonData)
Пример #20
0
        history_days_validate = Factory.create('history', 'history')
        int_validate = Factory.create('int', 'int')
        dict_validate = Factory.create('dict', 'dict')
        # Filter the input as a dict
        plan = dict_validate.test(valueToTest)
        # Use the filters to get the result
        result = {}
        result['Id'] = int_validate.test(plan.get('Id'))
        result['HistoryDays'] = history_days_validate.test(
            plan.get('HistoryDays'))
        result['BuyMode'] = mode_validate.test(plan.get('BuyMode'))
        result['SellMode'] = mode_validate.test(plan.get('SellMode'))
        return result


Factory.register(PlanValidator)


class FilterValidator(BasicTypeValidator):
    label = 'filter'

    def __init__(self, fieldName, forbidNone=False):
        super(FilterValidator, self).__init__(fieldName, forbidNone)

    def test(self, valueToTest):
        if valueToTest is None:
            raise ValidationError("No filter provided")

        # Create the filters that we will need
        str_validate = Factory.create('string', 'string')
        int_validate = Factory.create('int', 'int')