Cannot repeatedly call scripts with parameters

in perspective
Cannot repeatedly call scripts with parameters, and everytime after saving the project, the global variables of the script will be reset to zero, and the output value will also be zero


import time
total = 0
tempa = 0
oldtotal = 0
def calculate_downtime(start):    
    global total, tempa, start_time, end_time,oldtotal
    if start == False and tempa == 0:  
        start_time = time.time()  
        tempa = 1  
    elif start == True:
         tempa = 0   
    if tempa == 1:  
        end_time = time.time()  
        total = (end_time - start_time) + oldtotal
        return total/60
    elif tempa == 0:
         oldtotal = total
         return oldtotal/60

This is a script for calculating cumulative downtime, accumulating when start is 1 and stopping when start is 0

I think you should be logging events, with a timestamp, and using those to calculate the downtime. It would be simpler and more robust.

If you don't want to do that, you need to rethink the way you store data. There's a number of discussions around here about data persistence, do a quick search to find how to do it properly.

There will be multiple shutdowns every day, and the total time will be reset to zero when changing shifts at 8 am and 8 pm

Which is handled perfectly with an event history.

2 Likes