Commit e020241b authored by Christian Schneider's avatar Christian Schneider
Browse files

Added function to reduce operation hours

parent 7d007ba1
...@@ -304,7 +304,7 @@ def operatinghours_reduce(): ...@@ -304,7 +304,7 @@ def operatinghours_reduce():
"""Function to calculate operating hours for pumps""" """Function to calculate operating hours for pumps"""
op_times_all = {} op_times_all = {}
for cryo_id in cryolist: for cryo_id in fridges:
op_times_all[cryo_id] = {} op_times_all[cryo_id] = {}
runtimes = {} runtimes = {}
op_times = {} op_times = {}
...@@ -415,7 +415,7 @@ def operatinghours_reduce(): ...@@ -415,7 +415,7 @@ def operatinghours_reduce():
for fridge, json_f in op_times_all.items(): for fridge, json_f in op_times_all.items():
# Obtain months # Obtain months
months = [datetime.datetime.strptime(m['x'], "%Y/%B") for months = [datetime.strptime(m['x'], "%Y/%B") for
m in json_f['Compressor']] m in json_f['Compressor']]
# Obtain operation hours # Obtain operation hours
...@@ -430,37 +430,44 @@ def operatinghours_reduce(): ...@@ -430,37 +430,44 @@ def operatinghours_reduce():
# Add DB entries # Add DB entries
for idx, m in enumerate(months): for idx, m in enumerate(months):
# Create dict for month
dev_dict = {A: B for A, B in zip(dev_arr, op_hours[idx])} # Only add current month
today = datetime.now()
# Check if it already exists this_month = datetime(today.year, today.month, 1)
d = OperationTimesMonths.query \
.filter_by(name=fridge) \ if m == this_month:
.filter_by(time=m) \ # Create dict for month
.first() dev_dict = {A: B for A, B in zip(dev_arr, op_hours[idx])}
# If it exsits, update value # Check if it already exists
if d: d = OperationTimesMonths.query \
d.compressor = dev_dict['Compressor'] .filter_by(name=fridge) \
d.forepump = dev_dict['ForePump'] .filter_by(time=m) \
d.pulsetube = dev_dict['PulseTube'] .first()
d.turbopump = dev_dict['TurboPump']
# If it exsits, update value
# If not, create new if d:
else: d.compressor = dev_dict['Compressor']
d = OperationTimesMonths( d.forepump = dev_dict['ForePump']
name=fridge, d.pulsetube = dev_dict['PulseTube']
time=m, d.turbopump = dev_dict['TurboPump']
compressor=dev_dict['Compressor'],
forepump=dev_dict['ForePump'], # If not, create new
pulsetube=dev_dict['PulseTube'], else:
turbopump=dev_dict['TurboPump'], d = OperationTimesMonths(
) name=fridge,
db_cryo.session.add(d) time=m,
db_cryo.session.commit() compressor=dev_dict['Compressor'],
db_cryo.session.close() forepump=dev_dict['ForePump'],
pulsetube=dev_dict['PulseTube'],
turbopump=dev_dict['TurboPump'],
)
db_cryo.session.add(d)
db_cryo.session.commit()
db_cryo.session.close()
return op_times_all return op_times_all
def check_cooldowntime(fridge_name, log_folder=logpath): def check_cooldowntime(fridge_name, log_folder=logpath):
# Read file # Read file
data = read_fridge(fridge_name, log_folder) data = read_fridge(fridge_name, log_folder)
...@@ -575,7 +582,8 @@ def run_fridge_update(fridges): ...@@ -575,7 +582,8 @@ def run_fridge_update(fridges):
def run_operationTime_update(fridges): def run_operationTime_update(fridges):
for f in fridges: for f in fridges:
update_OPStates(f) update_OPStates(f)
operatinghours_reduce()
operatinghours_reduce()
# Delete old entries # Delete old entries
db_cryo.session.execute( db_cryo.session.execute(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment