aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster
diff options
context:
space:
mode:
authorSelene ToyKeeper2018-08-23 01:45:02 -0600
committerSelene ToyKeeper2018-08-23 01:45:02 -0600
commit303ec3fced6e47a402db290ed62d59aa5c73f6e1 (patch)
treea3ccb413596700b40c1655ffb7c647e02b9ded9c /spaghetti-monster
parentmerged trunk, including zeroflow's fixes and my related changes (diff)
downloadanduril-303ec3fced6e47a402db290ed62d59aa5c73f6e1.tar.gz
anduril-303ec3fced6e47a402db290ed62d59aa5c73f6e1.tar.bz2
anduril-303ec3fced6e47a402db290ed62d59aa5c73f6e1.zip
added a stepped ramp calculator for Anduril,
because people keep asking
Diffstat (limited to 'spaghetti-monster')
-rwxr-xr-xspaghetti-monster/anduril/steps.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/spaghetti-monster/anduril/steps.py b/spaghetti-monster/anduril/steps.py
new file mode 100755
index 0000000..9056ea3
--- /dev/null
+++ b/spaghetti-monster/anduril/steps.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+
+"""steps.py: Calculate the stepped ramp levels used by Anduril.
+Usage: steps.py floor ceiling num_steps
+For example:
+ > ./steps.py 1 150 3
+ 1: 1
+ 2: 75
+ 3: 150
+"""
+
+def main(args):
+ floor, ceil, steps = [int(x) for x in args[:3]]
+ for i in range(steps):
+ guess = floor + (i * (float(ceil-floor)/(steps-1)))
+ this = nearest_level(guess, floor, ceil, steps)
+ #print('%i: %i (guess: %i)' % (i+1, this, guess))
+ print('%i: %i' % (i+1, this))
+
+
+def nearest_level(target, floor, ceil, steps):
+ """Copied/adapted from anduril.c"""
+ # bounds check
+ # using int16_t here saves us a bunch of logic elsewhere,
+ # by allowing us to correct for numbers < 0 or > 255 in one central place
+ mode_min = floor;
+ mode_max = ceil;
+
+ if (target < mode_min): return mode_min;
+ if (target > mode_max): return mode_max;
+ # the rest isn't relevant for smooth ramping
+ #if (! ramp_style): return target;
+
+ ramp_range = ceil - floor;
+ ramp_discrete_step_size = ramp_range / (steps-1);
+ this_level = floor;
+
+ for i in range(steps):
+ this_level = floor + (i * int(ramp_range) / (steps-1));
+ diff = int(target - this_level);
+ if (diff < 0): diff = -diff;
+ if (diff <= (ramp_discrete_step_size>>1)):
+ return this_level;
+
+ return this_level;
+
+
+if __name__ == "__main__":
+ import sys
+ main(sys.argv[1:])
+
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.