Created
July 11, 2018 17:54
-
-
Save seanwittmeyer/6684ba0c616207058e827c5ab2b6d272 to your computer and use it in GitHub Desktop.
range choice python component by jonah hawk for the udan project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Provides a scripting component. | |
Inputs: | |
min: Minimum value for the range | |
max: Maximum value for the range | |
count: the length of the list of number, including the min and max values. | |
i: index choice of the list | |
Output: | |
a: The a output variable""" | |
__author__ = "jonah.hawk" | |
__version__ = "2018.05.18" | |
import math | |
import decimal | |
if not min: | |
min = 0 | |
if not max: | |
max = 1.00 | |
if not count: | |
count = 10 | |
if not i: | |
i = 0 | |
if min == max: | |
max = min + 0.001 | |
min = decimal.Decimal(min) | |
max = decimal.Decimal(max) | |
count = decimal.Decimal(count) | |
def drange(x, y, jump): | |
while x < y: | |
yield float(x) | |
x += decimal.Decimal(jump) | |
theRange = [] | |
stepFloat = (max-min)/(count-1) | |
step = round(stepFloat, 3) | |
print(step) | |
theRange = list(drange(min, max, step)) | |
ind = int(i) | |
if max not in theRange: | |
theRange.append(float(max)) | |
print(theRange) | |
if i >= len(theRange): | |
ind = (len(theRange) -1) | |
S = step | |
R = theRange | |
I = theRange[ind] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment