diff options
| author | Pepper <pepper@scannerjammer.com> | 2015-03-05 04:35:02 -0500 |
|---|---|---|
| committer | Pepper <pepper@scannerjammer.com> | 2015-03-05 04:35:02 -0500 |
| commit | e7d397472c7f6f6ba7b911ae8afff9bcb6a56b92 (patch) | |
| tree | ed4e7c9f107f9227eccfec9ccb6f21d1b851845f /Pb_Api/Params.py | |
| parent | 6b00d986288c735e0dba400a3ac02e4809279de2 (diff) | |
working better now
Diffstat (limited to 'Pb_Api/Params.py')
| -rw-r--r-- | Pb_Api/Params.py | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/Pb_Api/Params.py b/Pb_Api/Params.py index b96a9af..fff0696 100644 --- a/Pb_Api/Params.py +++ b/Pb_Api/Params.py @@ -1,41 +1,34 @@ +import pprint 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"] + #so how do we need to change these? + def param(self, name): + for p in self.params: + if p.name == name: + return p + return None + + def __str__(self): + return pprint.pformat({ "params": map(lambda x: vars(x), self.params) }) + +#do we need to add a simple __iter__ attribute to that class so that map will work, or is it already +#iterating? it is already + + + def randomize(self): for el in self.params: - if el.manually_set: + if el.set_by_user: continue el.randomize() + + def is_ready(self): - for p in self.params(): + 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() + for p in self.params: + result[p.name] = p.value return result |
