A machine with ID M1 has operation start time as 0 days 04:52:00
and end time as 0 days 08:54:00
. Essentially, the machine is only operating for 4 hr 2 minutes in an entire day with 1198 minutes available for maintenance (AT). The time required for maintenance is 65 minutes. I want a list of all combinations of 65 minutes from 1198 minutes available within the window 0 days 08:55:00
to 1 days 04:51:00
until it starts the service next day.
MID ST ET AT
M1 0 days 04:52:00 0 days 08:54:00 1198
What I have tried?
The code discussed in Create five minute time blocks (Pandas/Python) is only applicable for a given timestamp not newly generated timestamp.
CodePudding user response:
Pass to that function StartDate and EndDate and Interval: In your case:
from datetime import datetime, timedelta
def datetime_range(start, end, delta):
current = start
while current < end:
yield current
current = delta
start = datetime.now() pd.Timedelta(days=1)
end = start pd.Timedelta(minutes=1198)
interval = timedelta(minutes=65)
dts = [dt.strftime('%Y-%m-%d T%H:%M Z') for dt in
datetime_range(start, end, interval)]
print(dts)
print block (scopes):
def splitIntoBlocks(dts):
for i in range(len(dts)):
print ('block ' dts[i] '-' dts[i 1])
splitIntoBlocks(dts)