Skip to content
Snippets Groups Projects
Commit 41c636bc authored by Quentin Codelupi's avatar Quentin Codelupi
Browse files

Merge branch 'features--routine_python' into 'dev'

Features  routine python

See merge request qcodelup/bi_bl_nx-cals-back!2
parents 2f75ab59 4ce1ff65
No related branches found
No related tags found
No related merge requests found
pyconf.py
pulledData/
plotOutput/
prop_pull_api/
\ No newline at end of file
This diff is collapsed.
import mysql.connector
import time
import property_pull
import mysql.connector
import requests
from property_pull import property_pull
import pytimber as pytimber
import datetime as dt
......@@ -18,6 +20,8 @@ mydb = mysql.connector.connect(
database=cfg.mysql['database']
)
API_HOST = 'http://test-nxdblm-api2.web.cern.ch/'
def start_pull(_fill_infos, _devices=None):
if _devices is None:
......@@ -29,17 +33,18 @@ def start_pull(_fill_infos, _devices=None):
for iDevice in _devices:
property_pull.property_pull(_fill_infos['fillNumber'], 'ALL', iDevice,
_fill_infos['startTime'].strftime("%Y-%m-%d %H:%M:%S.000"),
_fill_infos['endTime'].strftime("%Y-%m-%d %H:%M:%S.000"))
property_pull(_fill_infos['fillNumber'], 'ALL', iDevice,
_fill_infos['startTime'].strftime("%Y-%m-%d %H:%M:%S.000"),
_fill_infos['endTime'].strftime("%Y-%m-%d %H:%M:%S.000"),
_files_write=False)
for iMode in _fill_infos["beamModes"]:
print(iMode['mode'])
property_pull.property_pull(_fill_infos['fillNumber'], iMode['mode'], iDevice,
iMode['startTime'].strftime("%Y-%m-%d %H:%M:%S.000"),
iMode['endTime'].strftime("%Y-%m-%d %H:%M:%S.000"))
property_pull(_fill_infos['fillNumber'], iMode['mode'], iDevice,
iMode['startTime'].strftime("%Y-%m-%d %H:%M:%S.000"),
iMode['endTime'].strftime("%Y-%m-%d %H:%M:%S.000"))
'''p = Process(target=property_pull.property_pull,
'''p = Process(target=cern_nxcals_dblm_property_pull.cern_nxcals_dblm_property_pull,
args=(fill_infos['fillNumber'], iMode['mode'], 'BLMED.06L7.B1B30_TCPA.A6L7.B1',
iMode['startTime'].strftime("%y-%m-%d %H:%M:%S.000"),
iMode['endTime'].strftime("%y-%m-%d %H:%M:%S.000")))
......@@ -50,17 +55,16 @@ def start_pull(_fill_infos, _devices=None):
def routine_pull(_start_fill=None, _end_fill=None):
ldb = pytimber.LoggingDB()
gcursor = mydb.cursor()
_start_fill = None
_end_fill = None
if _start_fill is None and _end_fill is None:
res = ldb.get('HX:FILLN', dt.datetime.now())
new_fill_number = int(res['HX:FILLN'][1][0])
print(new_fill_number)
gcursor.execute('select max(name) from fill limit 1;')
last_fill_pulled = gcursor.fetchone()[0]
# gcursor.execute('select max(name) from Fill limit 1;')
# last_fill_pulled = gcursor.fetchone()[0]
response = requests.get(API_HOST + 'fill/last')
last_fill_pulled = response.json()['name']
print(last_fill_pulled)
if new_fill_number == last_fill_pulled:
......@@ -68,25 +72,19 @@ def routine_pull(_start_fill=None, _end_fill=None):
return -1
else:
new_fill_number = _end_fill
last_fll_pulled = _start_fill - 1
last_fill_pulled = _start_fill
# Select only the first 6 devices Cause: not all device works properly with NXCALS yet
gcursor.execute('select name from device limit 6')
devices_request = gcursor.fetchall()
response = requests.get(API_HOST + 'devices')
devices = []
for device in devices_request:
devices.append(device[0])
for device in response.json()['devices']:
devices.append(device['name'])
gcursor.close()
mydb.close()
# fill_number = 7444
# fill_infos = ldb.getLHCFillData(fill_number, False)
# start_pull(fill_infos, devices)
fill_number = 7472
fill_infos = ldb.getLHCFillData(fill_number, False)
start_pull(fill_infos, devices)
'''
for iFill in range(last_fill_pulled + 1, new_fill_number):
fill_infos = ldb.getLHCFillData(iFill, False)
for iFill in range(int(last_fill_pulled), int(new_fill_number)):
fill_infos = ldb.getLHCFillData(str(iFill), False)
# check if the fill is finished
if fill_infos['endTime'] is None:
......@@ -94,15 +92,11 @@ def routine_pull(_start_fill=None, _end_fill=None):
# check if data is too new
midnight_stamp = dt.datetime.now().replace(second=0, minute=0, hour=0) - dt.timedelta(days=1)
if time.mktime(midnight_stamp.timetuple()) < fill_infos['endTime']:
if midnight_stamp < fill_infos['endTime']:
continue
start_pull(fill_infos, devices)
'''
if __name__ == '__main__':
routine_pull()
routine_pull(_start_fill=7440, _end_fill=7494)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment