summaryrefslogtreecommitdiff
path: root/unused
diff options
context:
space:
mode:
Diffstat (limited to 'unused')
-rw-r--r--unused/probabilities.py21
-rw-r--r--unused/probability.py9
-rw-r--r--unused/weight.py57
3 files changed, 30 insertions, 57 deletions
diff --git a/unused/probabilities.py b/unused/probabilities.py
new file mode 100644
index 0000000..d109b18
--- /dev/null
+++ b/unused/probabilities.py
@@ -0,0 +1,21 @@
+from ricky.param.probability import Probability
+import sys
+class Probabilities:
+ 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):
+ probabilities = map(lambda x: Probability(**x), args);
+ return cls(*probabilities);
diff --git a/unused/probability.py b/unused/probability.py
new file mode 100644
index 0000000..0d27b70
--- /dev/null
+++ b/unused/probability.py
@@ -0,0 +1,9 @@
+class Probability(dict):
+ def __init__(self, **kwargs):
+ super(Probability, 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/unused/weight.py b/unused/weight.py
deleted file mode 100644
index 4bd4af4..0000000
--- a/unused/weight.py
+++ /dev/null
@@ -1,57 +0,0 @@
- weights_total = sum(
- map(lambda x: x["weight"], self.probabilities())
- ) + (255 * 255 * 255)
- choice = random.randint(0, weights_total)
- position = 0
- for elem in self.probabilities():
- position += elem["weight"]
- if position >= choice:
- self.value = elem["value"]
- return
-
- weights_total = sum(
- map(lambda x: x["weight"], self.probabilities())
- )# + self.range_max - self.range_min
- if weights_total < 100:
- weights_total = 100;
- choice = random.randint(0, weights_total)
- import sys
- sys.stderr.write("choosing %s: random_int: %s, probabilities: %s\n" % (
- self.name,
- choice,
- self.probabilities()))
- position = 0
- for elem in self.probabilities():
- position += elem["weight"]
- if position >= choice:
- self.value = elem["value"]
- return
-
-
- weights_total = sum(map(lambda x: x["weight"], self.probabilities()))
- choice = random.randint(0, weights_total)
- position = 0
- for elem in self.probabilities():
- 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()
-
- """default value is the probability with the heaviest weight"""
- self.default(self._choose_heaviest())