Created
July 3, 2019 03:04
-
-
Save CodeArtha/cefe0de9bd2ab67227ba3b3650868153 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import sys | |
| # Scripts maps a number between b0 - b1 onto the a0 - a1 scale. | |
| # Config is hardcoded for faster data input when using the same range over and over again | |
| a0 = float(0) | |
| a1 = float(500) | |
| b0 = float(61) | |
| b1 = float(538) | |
| try: | |
| if(len(sys.argv) == 1): | |
| # Use the same scales over and over again to map different values | |
| while(True): | |
| number = float(input("Enter the number you want to map: ")) | |
| mapped = ((number - b0)/(b1 - b0) * (a1 - a0)) + a0 | |
| print(mapped) | |
| elif(len(sys.argv) == 2): | |
| # Map only one value (the one given as argument) on the scales that are hardcoded above | |
| number = float(sys.argv[1]) | |
| mapped = ((number - b0)/(b1 - b0) * (a1 - a0)) + a0 | |
| print(mapped) | |
| elif(len(sys.argv) == 6): | |
| # Map the value on the scales given in argument | |
| number = float(sys.argv[1]) | |
| a0 = float(sys.argv[4]) | |
| a1 = float(sys.argv[5]) | |
| b0 = float(sys.argv[2]) | |
| b1 = float(sys.argv[3]) | |
| mapped = ((number - b0)/(b1 - b0) * (a1 - a0)) + a0 | |
| print(mapped) | |
| except: | |
| HELP_MESSAGE = """ | |
| Incorrect usage! Printing help...\n | |
| Three usages are possible: | |
| 1) No arguments are given: map.py | |
| Make an infinite loop that asks for a single value, the one to be mapped. The value is then mapped from and to scales that are defines/hardcoded in the python script. Very useful for batch processing values in the same context. | |
| 2) Give one number as argument: map.py [value] | |
| Maps just that one value on the scales that are set/hardcoded in the script. This option is the least useful. Might come in handy if you have a small amount of values to map every now and then but each time on the same intervals. | |
| 3) Provide 5 arguments: map.py [value] [from_low] [from_high] [to_low] [to_high] | |
| Maps the number [value] considered to be somewhere in the from_ interval on the to_ interval. Can be called in a loop in bash for instance for batch processing values on different intervals. | |
| """ | |
| print(HELP_MESSAGE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment