Often, we talk about operating rates and permissible downtime in SLAs, but I want to be able to quickly ask for this.
Mathematically, it's as follows.
Occupancy rate= \frac{Total time-Failure time}{Total time}
So, for example, "If the operating rate is 99%, how much suspension is allowed per month or year?" Does not come out in numbers, so let's write a program so that it can be calculated. It has a lot of second decoction, but leave it alone.
I would like to write it in Python.
One month is 30 days (24 x 60 x 60
seconds).
One year is 365 days (365 x 24 x 60 x 60
seconds).
Confirmed Python version.
$ python3 -V
Python 3.6.9
Find the following three.
Make the above available from the utilization rate, monthly permissible downtime, or annual permissible downtime.
In short, I want to make something that seeks the other element when one is given.
The permissible downtime is given in units of s
(seconds), m
(minutes), h
(hours), and d
(days), and is interpreted as seconds if omitted. Shall be.
The result is output in Markdown tabular format.
Here is the one I created.
calc.py
import datetime
year_time = 365 * 24 * 60 * 60
month_time = 30 * 24 * 60 * 60
units = {"s": "seconds", "m": "minutes", "h": "hours", "d": "days"}
def calc_from_percentage(percentage):
stop_time_per_year_raw = year_time * ((100 - percentage) / 100)
stop_time_per_month_raw = month_time * ((100 - percentage) / 100)
def format_time(time):
if time > 24 * 60 * 60:
formatted_time = f"{time / (24 * 60 * 60):.2f}Day"
elif time > 60 * 60:
formatted_time = f"{time / (60 * 60):.2f}time"
elif time > 60:
formatted_time = f"{time / 60:.2f}Minutes"
else:
formatted_time = f"{time:.2f}Seconds"
return formatted_time
stop_time_per_year = format_time(stop_time_per_year_raw)
stop_time_per_month = format_time(stop_time_per_month_raw)
return (f"{percentage}%", stop_time_per_month, stop_time_per_year)
def calc_from_month_stop_time(stop_time):
try:
seconds = int(stop_time)
except ValueError:
t = int(stop_time[:-1])
unit = units[stop_time[-1]]
seconds = datetime.timedelta(**{unit: t}).total_seconds()
percentage = 100 - ((seconds * 100) / month_time)
return calc_from_percentage(percentage)
def calc_from_year_stop_time(stop_time):
try:
seconds = int(stop_time)
except ValueError:
t = int(stop_time[:-1])
unit = units[stop_time[-1]]
seconds = datetime.timedelta(**{unit: t}).total_seconds()
percentage = 100 - ((seconds * 100) / year_time)
return calc_from_percentage(percentage)
def print_table(percentages_or_stop_times, calc_func):
print("|Occupancy rate|Monthly permissible downtime|Annual permissible downtime|")
print("|:------:|:----------------:|:----------------:|")
if isinstance(percentages_or_stop_times, list):
targets = percentages_or_stop_times
else:
targets = [percentages_or_stop_times]
for t in targets:
result = calc_func(t)
print(f"| {result[0]} | {result[1]} | {result[2]} |")
Load and launch it in Python's interactive shell.
$ python3 -i calc.py
>>>
Obtain the allowable downtime from the operating rate. If you want to give more than one, use the list.
>>> print_table(99, calc_from_percentage)
|Occupancy rate|Monthly permissible downtime|Annual permissible downtime|
|:------:|:----------------:|:----------------:|
| 99% | 7.20 hours| 3.65 days|
>>> print_table([90, 95, 99, 99.5, 99.9, 99.95, 99.99, 99.999, 99.9999], calc_from_percentage)
|Occupancy rate|Monthly permissible downtime|Annual permissible downtime|
|:------:|:----------------:|:----------------:|
| 90% | 3.00 days| 36.50 days|
| 95% | 1.50 days| 18.25th|
| 99% | 7.20 hours| 3.65 days|
| 99.5% | 3.60 hours| 1.82nd|
| 99.9% | 43.20 min| 8.76 hours|
| 99.95% | 21.60 minutes| 4.38 hours|
| 99.99% | 4.32 minutes| 52.56 minutes|
| 99.999% | 25.92 seconds| 5.26 minutes|
| 99.9999% | 2.59 seconds| 31.54 seconds|
This is the table I wanted.
Occupancy rate | Monthly permissible downtime | Annual permissible downtime |
---|---|---|
90% | 3.00 days | 36.50 days |
95% | 1.50 days | 18.25th |
99% | 7.20 hours | 3.65 days |
99.5% | 3.60 hours | 1.82nd |
99.9% | 43.20 min | 8.76 hours |
99.95% | 21.60 minutes | 4.38 hours |
99.99% | 4.32 minutes | 52.56 minutes |
99.999% | 25.92 seconds | 5.26 minutes |
99.9999% | 2.59 seconds | 31.54 seconds |
Calculated from the monthly permissible downtime.
>>> print_table("10", calc_from_month_stop_time)
|Occupancy rate|Monthly permissible downtime|Annual permissible downtime|
|:------:|:----------------:|:----------------:|
| 99.99961419753086% | 10.00 seconds| 2.03 minutes|
>>> print_table(["3d", "10m", "10s", "10"], calc_from_month_stop_time)
|Occupancy rate|Monthly permissible downtime|Annual permissible downtime|
|:------:|:----------------:|:----------------:|
| 90.0% | 3.00 days| 36.50 days|
| 99.97685185185185% | 10.00 minutes| 2.03 hours|
| 99.99961419753086% | 10.00 seconds| 2.03 minutes|
| 99.99961419753086% | 10.00 seconds| 2.03 minutes|
I wondered if the number of digits in the percentage would be good this time ...
Calculated from the annual permissible downtime.
>>> print_table("30d", calc_from_year_stop_time)
|Occupancy rate|Monthly permissible downtime|Annual permissible downtime|
|:------:|:----------------:|:----------------:|
| 91.78082191780823% | 2.47th| 30.00 days|
>>> print_table(["30d", "45m", "30s", "30"], calc_from_year_stop_time)
|Occupancy rate|Monthly permissible downtime|Annual permissible downtime|
|:------:|:----------------:|:----------------:|
| 91.78082191780823% | 2.47th| 30.00 days|
| 99.99143835616438% | 3.70 minutes| 45.00 minutes|
| 99.99990487062405% | 2.47 seconds| 30.00 seconds|
| 99.99990487062405% | 2.47 seconds| 30.00 seconds|
Like this.