tklab-tud / ID2T

Official ID2T repository. ID2T creates labeled IT network datasets that contain user defined synthetic attacks.
MIT License
56 stars 22 forks source link

[SOLVED] TypeError: '<=' not supported between instances of 'int' and 'str' in Percentage.py #110

Open sajho-dk opened 3 years ago

sajho-dk commented 3 years ago

Hi, I realized that there is an issue in 'validate(self, value)' of code/Attack/ParameterTypes/Percentage.py. I have corrected the issue and commented the line with the error.

from Attack.ParameterTypes.BaseType import ParameterType

class Percentage(ParameterType):

    def __init__(self):
        super(Percentage, self).__init__()
        self.name = "Percentage"

    def validate(self, value) -> (bool, int):
        #return Percentage._is_float(value)[0] and 0 <= value <= 1, value
        res = Percentage._is_float(value)
        return res[0] and 0 <= res[1] <= 1, res[1]

    @staticmethod
    def _is_float(value):
        """
        Checks whether the given value is a float.

        :param value: The value to be checked.
        :return: True if the value is a float, otherwise False. And the casted float.
        """
        try:
            value = float(value)
            return True, value
        except ValueError:
            return False, value
pepper-jk commented 2 years ago

Hi, sorry for answering so late. Must have missed your post.

Could you provide the error you received before your changes?

I'd be happy to except pull request, as long as I am sure this doesn't break anything.