Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds remap function to converters.py #8

Merged
merged 1 commit into from Mar 3, 2020
Merged

Conversation

kdschlosser
Copy link
Contributor

maps a int/float within a given range to the value within a new range.

great example is an AVR that uses dB's
min = -80dB
max = 10dB

and you want to convert a percentage (0-100) to the dB for that percentage

from __future__ import print_function
from python_utils.converters import remap

print(remap(46.0, 0.0, 100.0, -80.0, 10.0))

the output is

-38.6

It handles negative and positive integers and floats of any combination. There is handling of the new range being 0 (0 gets returned) and also the old range being 0 (minimum of the new range is returned)

maps a int/float within a given range to the value within a new range.

great example is an AVR that uses dB's
min = -80dB
max = 10dB

and you want to convert a percentage (0-100) to the dB for that percentage

```python
print(remap(46.0, 0.0, 100.0, -80.0, 10.0)
```
the output is
```python
-38.6
```
@coveralls
Copy link

Coverage Status

Coverage remained the same at ?% when pulling 1cd155c on kdschlosser:remap into 6afba59 on WoLpH:develop.

@wolph wolph merged commit 1cd155c into wolph:develop Mar 3, 2020
@wolph
Copy link
Owner

wolph commented Mar 3, 2020

Thanks for the addition. I've made a new release :)

@kdschlosser kdschlosser deleted the remap branch March 3, 2020 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants