Spaces:
Build error
Build error
File size: 1,626 Bytes
a1da63c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
import platform
from typing import Any, Sequence
def is_linux() -> bool:
return platform.system().lower() == 'linux'
def is_macos() -> bool:
return platform.system().lower() == 'darwin'
def is_windows() -> bool:
return platform.system().lower() == 'windows'
def create_int_metavar(int_range : Sequence[int]) -> str:
return '[' + str(int_range[0]) + '..' + str(int_range[-1]) + ':' + str(calc_int_step(int_range)) + ']'
def create_float_metavar(float_range : Sequence[float]) -> str:
return '[' + str(float_range[0]) + '..' + str(float_range[-1]) + ':' + str(calc_float_step(float_range)) + ']'
def create_int_range(start : int, end : int, step : int) -> Sequence[int]:
int_range = []
current = start
while current <= end:
int_range.append(current)
current += step
return int_range
def create_float_range(start : float, end : float, step : float) -> Sequence[float]:
float_range = []
current = start
while current <= end:
float_range.append(round(current, 2))
current = round(current + step, 2)
return float_range
def calc_int_step(int_range : Sequence[int]) -> int:
return int_range[1] - int_range[0]
def calc_float_step(float_range : Sequence[float]) -> float:
return round(float_range[1] - float_range[0], 2)
def map_float(value : float, start : float, end : float, map_start : float, map_end : float) -> float:
ratio = (value - start) / (end - start)
map_value = map_start + (map_end - map_start) * ratio
return map_value
def get_first(__list__ : Any) -> Any:
return next(iter(__list__), None)
def get_last(__list__ : Any) -> Any:
return next(reversed(__list__), None)
|