2020-02-17 11:39:49 +00:00
|
|
|
def get_bootstraped_percent(value, total):
|
|
|
|
"""
|
|
|
|
Get percent and round to be 0, 25, 50 or 100
|
|
|
|
|
|
|
|
Useful to set progress bar width using CSS classes (e.g. w-25)
|
|
|
|
"""
|
2020-02-17 12:26:18 +00:00
|
|
|
try:
|
|
|
|
percent = value / total
|
2021-10-22 10:10:00 +00:00
|
|
|
except (TypeError, ZeroDivisionError):
|
2020-02-17 12:26:18 +00:00
|
|
|
return 0
|
2020-02-17 11:39:49 +00:00
|
|
|
|
|
|
|
bootstraped = round(percent * 4) * 100 // 4
|
|
|
|
|
|
|
|
# handle min and max boundaries
|
|
|
|
bootstraped = max(0, bootstraped)
|
|
|
|
bootstraped = min(100, bootstraped)
|
|
|
|
|
|
|
|
return bootstraped
|