diff options
Diffstat (limited to 'Pb_Api/Param')
| -rw-r--r-- | Pb_Api/Param/Color.py | 30 | ||||
| -rw-r--r-- | Pb_Api/Param/Image_Url.py | 7 | ||||
| -rw-r--r-- | Pb_Api/Param/MultiSelect.py | 56 | ||||
| -rw-r--r-- | Pb_Api/Param/NumberRange.py | 27 | ||||
| -rw-r--r-- | Pb_Api/Param/Option.py | 9 | ||||
| -rw-r--r-- | Pb_Api/Param/Options.py | 21 | ||||
| -rw-r--r-- | Pb_Api/Param/String.py | 4 | ||||
| -rw-r--r-- | Pb_Api/Param/Username.py | 7 | ||||
| -rw-r--r-- | Pb_Api/Param/__init__.py | 38 |
9 files changed, 0 insertions, 199 deletions
diff --git a/Pb_Api/Param/Color.py b/Pb_Api/Param/Color.py deleted file mode 100644 index 678a087..0000000 --- a/Pb_Api/Param/Color.py +++ /dev/null @@ -1,30 +0,0 @@ -from Pb_Api.Param.MultiSelect import Pb_Api_Param_MultiSelect -import random -class Pb_Api_Param_Color(Pb_Api_Param_MultiSelect): - def __init__(self, **kwargs): - super(Pb_Api_Param_Color, self).__init__(**kwargs) - - @classmethod - def from_rgb(cls, r,g,b): - return cls(value="rgb({},{},{})".format(r,g,b)) - - @property - def value(self): - return super(Pb_Api_Param_MultiSelect, self).get_value() - @value.setter - def value(self, value): - self._value = value - if not self._value is None: - self.is_ready = 1 - self.set_by_user = 1 - - def randomize(self): - weights_total = sum(map(lambda x: x["weight"], self.options())) + (255 * 255 * 255) - choice = random.randint(0, weights_total) - position = 0 - for elem in self.options(): - position += elem["weight"] - if position >= choice: - self.value = elem["value"] - return - self.value = "rgb({},{},{})".format( random.randint(0,255), random.randint(0,255), random.randint(0,255)) diff --git a/Pb_Api/Param/Image_Url.py b/Pb_Api/Param/Image_Url.py deleted file mode 100644 index bd22513..0000000 --- a/Pb_Api/Param/Image_Url.py +++ /dev/null @@ -1,7 +0,0 @@ -from config import TEST_URL -from Pb_Api.Param.String import Pb_Api_Param_String - -class Pb_Api_Param_Image_Url(Pb_Api_Param_String): - def __init__(self, *args, **kwargs): - super(Pb_Api_Param_Image_Url, self).__init__(*args, **kwargs) - self.default(TEST_URL) diff --git a/Pb_Api/Param/MultiSelect.py b/Pb_Api/Param/MultiSelect.py deleted file mode 100644 index 3761302..0000000 --- a/Pb_Api/Param/MultiSelect.py +++ /dev/null @@ -1,56 +0,0 @@ -import random -from Pb_Api.Param import Pb_Api_Param - -class Pb_Api_Param_MultiSelect(Pb_Api_Param): - def __init__(self, **kwargs): - self._options = [] - if 'options' in kwargs: self._options = kwargs['options'] or [] - super(Pb_Api_Param_MultiSelect, self).__init__(**kwargs) - if len(self._options): - self._validate_options() - self.default(self._choose_heaviest()) - - - def options(self): - return self._options - def _validate_options(self): - try: - int(self._options[0]['weight']) - self._options[0]['value'] - except Exception as e: - raise ValueError - - def get_value(self): - return super(Pb_Api_Param_MultiSelect, self).get_value() - def set_value(self, value): - if not any([ value == i['value'] for i in self._options ]) and value != None: - raise ValueError - super(Pb_Api_Param_MultiSelect, self).set_value(value) - value = property(get_value, set_value) - - - def randomize(self): - weights_total = sum(map(lambda x: x["weight"], self.options())) - choice = random.randint(0, weights_total) - position = 0 - for elem in self.options(): - position += elem["weight"] - if position >= choice: - self.value = elem["value"] - break - - def _choose_heaviest(self): - heaviest_idx = 0 - heaviest_weight = 0 - idx = 0 - if (len(self.options())): - for elem in self.options(): - if elem["weight"] > heaviest_weight: - heaviest_weight = elem["weight"] - heaviest_idx = idx; - idx += 1 - return self.options()[heaviest_idx]["value"] - else: - self.randomize() - def heaviest(self): - self.value = self._choose_heaviest() diff --git a/Pb_Api/Param/NumberRange.py b/Pb_Api/Param/NumberRange.py deleted file mode 100644 index fe1ece6..0000000 --- a/Pb_Api/Param/NumberRange.py +++ /dev/null @@ -1,27 +0,0 @@ -import sys -from Pb_Api.Param.MultiSelect import Pb_Api_Param_MultiSelect -import random -class Pb_Api_Param_NumberRange(Pb_Api_Param_MultiSelect): - def __init__(self, **kwargs): - super(Pb_Api_Param_NumberRange, self).__init__(**kwargs) - self.range_min = kwargs['min'] - self.range_max = kwargs['max'] - def randomize(self): - weights_total = sum(map(lambda x: x["weight"], self.options())) + self.range_max - self.range_min - choice = random.randint(0, weights_total) - position = 0 - for elem in self.options(): - position += elem["weight"] - if position >= choice: - self.value = elem["value"] - return - self.value = random.randint(self.range_min,self.range_max) - @property - def value(self): - return super(Pb_Api_Param_MultiSelect, self).get_value() - @value.setter - def value(self, value): - self._value = value - if not self._value is None: - self.is_ready = 1 - self.set_by_user = 1 diff --git a/Pb_Api/Param/Option.py b/Pb_Api/Param/Option.py deleted file mode 100644 index 2a345e7..0000000 --- a/Pb_Api/Param/Option.py +++ /dev/null @@ -1,9 +0,0 @@ -class Pb_Api_Param_Option(dict): - def __init__(self, **kwargs): - super(Pb_Api_Param_Option, self).__init__(**kwargs) - self.value = kwargs["value"] - self.weight = kwargs["weight"] - def __getattr__(self, attr): - return self.get(attr) - __setattr__= dict.__setitem__ - __delattr__= dict.__delitem__ diff --git a/Pb_Api/Param/Options.py b/Pb_Api/Param/Options.py deleted file mode 100644 index ebc6fc9..0000000 --- a/Pb_Api/Param/Options.py +++ /dev/null @@ -1,21 +0,0 @@ -from Pb_Api.Param.Option import Pb_Api_Param_Option -import sys -class Pb_Api_Param_Options: - def __init__(self, *args): - self._values = args - def __iter__(self): - return iter(self._values) - def __len__(self): - return len(self._values) - def __str__(self): - return str(self._values) - def __getitem__(self, i): - return self._values[i] - def search(self, s): - for i in self: - if str(s) in i.value: - return i - @classmethod - def from_dict(cls, *args): - options = map(lambda x: Pb_Api_Param_Option(**x), args); - return cls(*options); diff --git a/Pb_Api/Param/String.py b/Pb_Api/Param/String.py deleted file mode 100644 index 3c186f4..0000000 --- a/Pb_Api/Param/String.py +++ /dev/null @@ -1,4 +0,0 @@ -from Pb_Api.Param import Pb_Api_Param -class Pb_Api_Param_String(Pb_Api_Param): - def __init__(self, **kwargs): - super(Pb_Api_Param_String, self).__init__(**kwargs) diff --git a/Pb_Api/Param/Username.py b/Pb_Api/Param/Username.py deleted file mode 100644 index 5bd3237..0000000 --- a/Pb_Api/Param/Username.py +++ /dev/null @@ -1,7 +0,0 @@ -from config import USERNAME -from Pb_Api.Param.String import Pb_Api_Param_String - -class Pb_Api_Param_Username(Pb_Api_Param_String): - def __init__(self, **kwargs): - super(Pb_Api_Param_Username, self).__init__(**kwargs) - self.default(USERNAME) diff --git a/Pb_Api/Param/__init__.py b/Pb_Api/Param/__init__.py deleted file mode 100644 index 58b3eb0..0000000 --- a/Pb_Api/Param/__init__.py +++ /dev/null @@ -1,38 +0,0 @@ -import pprint - -class Pb_Api_Param(object): -# def __init__(self, **kwargs): - def __init__(self, required=0, set_by_user=0, value=None, name=None, **kwargs): - self._value_default = None - self.name = name - self.required = required - self.is_ready = 0 - self.value = value - self.set_by_user = set_by_user - def __str__(self): - return pprint.pformat(vars(self)) - - def get_value(self): - if self.set_by_user == 1: - return self._value - return self._value_default - def set_value(self, value): - self._value = value - if not self._value is None: - self.is_ready = 1 - self.set_by_user = 1 - value = property(get_value, set_value) - - def default(self, value): - self._value_default = value - - @property - def is_ready(self): - return self._is_ready or not self.required - @is_ready.setter - def is_ready(self, n): - self._is_ready = n - - - def randomize(self): - pass |
