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():
"""Function to calculate operating hours for pumps"""
op_times_all = {}
for cryo_id in cryolist:
for cryo_id in fridges:
op_times_all[cryo_id] = {}
runtimes = {}
op_times = {}
......@@ -415,7 +415,7 @@ def operatinghours_reduce():
for fridge, json_f in op_times_all.items():
# Obtain months
months = [datetime.datetime.strptime(m['x'], "%Y/%B") for
months = [datetime.strptime(m['x'], "%Y/%B") for
m in json_f['Compressor']]
# Obtain operation hours
......@@ -430,37 +430,44 @@ def operatinghours_reduce():
# Add DB entries
for idx, m in enumerate(months):
# Create dict for month
dev_dict = {A: B for A, B in zip(dev_arr, op_hours[idx])}
# Check if it already exists
d = OperationTimesMonths.query \
.filter_by(name=fridge) \
.filter_by(time=m) \
.first()
# If it exsits, update value
if d:
d.compressor = dev_dict['Compressor']
d.forepump = dev_dict['ForePump']
d.pulsetube = dev_dict['PulseTube']
d.turbopump = dev_dict['TurboPump']
# If not, create new
else:
d = OperationTimesMonths(
name=fridge,
time=m,
compressor=dev_dict['Compressor'],
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()
# Only add current month
today = datetime.now()
this_month = datetime(today.year, today.month, 1)
if m == this_month:
# Create dict for month
dev_dict = {A: B for A, B in zip(dev_arr, op_hours[idx])}
# Check if it already exists
d = OperationTimesMonths.query \
.filter_by(name=fridge) \
.filter_by(time=m) \
.first()
# If it exsits, update value
if d:
d.compressor = dev_dict['Compressor']
d.forepump = dev_dict['ForePump']
d.pulsetube = dev_dict['PulseTube']
d.turbopump = dev_dict['TurboPump']
# If not, create new
else:
d = OperationTimesMonths(
name=fridge,
time=m,
compressor=dev_dict['Compressor'],
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
def check_cooldowntime(fridge_name, log_folder=logpath):
# Read file
data = read_fridge(fridge_name, log_folder)
......@@ -575,7 +582,8 @@ def run_fridge_update(fridges):
def run_operationTime_update(fridges):
for f in fridges:
update_OPStates(f)
operatinghours_reduce()
operatinghours_reduce()
# Delete old entries
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