diff options
| author | Pepper <pepper@scannerjammer.com> | 2015-03-04 15:57:53 -0500 |
|---|---|---|
| committer | Pepper <pepper@scannerjammer.com> | 2015-03-04 15:57:53 -0500 |
| commit | 021842ec42b991e7a641ae26862d77b324ea05db (patch) | |
| tree | 81194a75da0ff1279af7346d6e50cd424c33bacb /Pb_Api/Params.py | |
| parent | 513526efe79ff90be5b23459253dd5f553ec73d6 (diff) | |
started oop code
Diffstat (limited to 'Pb_Api/Params.py')
| -rw-r--r-- | Pb_Api/Params.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Pb_Api/Params.py b/Pb_Api/Params.py new file mode 100644 index 0000000..b96a9af --- /dev/null +++ b/Pb_Api/Params.py @@ -0,0 +1,41 @@ +class Pb_Api_Params(object): + def _weighted_choice(self, param): + weights_total = sum(map(lambda x: x["weight"], param)) + choice = random.randint(0, weights_total) + position = 0 + for elem in param: + position += elem["weight"] + if position >= choice: + return elem["value"] + def _default_choice(self, param): + heaviest_idx = 0 + heaviest_weight = 0 + idx = 0 + for elem in param: + if elem["weight"] > heaviest_weight: + heaviest_weight = elem["weight"] + heaviest_idx = idx; + idx += 1 + return param[heaviest_idx]["value"] + def randomize(self): + for el in self.params: + if el.manually_set: + continue + el.randomize() + def is_ready(self): + for p in self.params(): + if not p.is_ready(): + return 0 + return 1 + def params(self): + return self._params + def param(self, name): + for p in self.params(): + if p.name() == name: + return p + return None + def as_hash(self): + result = {} + for p in self.params(): + result[p.name()] = p.value() + return result |
