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

[add] check data before start pulling

parent 3407da85
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<option name="myName" value="Project Default" /> <option name="myName" value="Project Default" />
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true"> <inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<Languages> <Languages>
<language minSize="146" name="Python" /> <language minSize="213" name="Python" />
</Languages> </Languages>
</inspection_tool> </inspection_tool>
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true"> <inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
......
import mysql.connector import mysql.connector
import time
import property_pull import property_pull
import pytimber as pytimber import pytimber as pytimber
...@@ -22,19 +23,19 @@ def start_pull(_fill_infos, _devices=None): ...@@ -22,19 +23,19 @@ def start_pull(_fill_infos, _devices=None):
if _devices is None: if _devices is None:
_devices = ['BLMED.06L7.B1B30_TCPA.A6L7.B1'] _devices = ['BLMED.06L7.B1B30_TCPA.A6L7.B1']
print(fill_infos) print(_fill_infos)
if _fill_infos["endTime"] is None: if _fill_infos["endTime"] is None:
return -1 return -1
for iDevice in _devices: for iDevice in _devices:
property_pull.property_pull(fill_infos['fillNumber'], 'ALL', iDevice, property_pull.property_pull(_fill_infos['fillNumber'], 'ALL', iDevice,
fill_infos['startTime'].strftime("%Y-%m-%d %H:%M:%S.000"), _fill_infos['startTime'].strftime("%Y-%m-%d %H:%M:%S.000"),
fill_infos['endTime'].strftime("%Y-%m-%d %H:%M:%S.000")) _fill_infos['endTime'].strftime("%Y-%m-%d %H:%M:%S.000"))
for iMode in fill_infos["beamModes"]: for iMode in _fill_infos["beamModes"]:
print(iMode['mode']) print(iMode['mode'])
property_pull.property_pull(fill_infos['fillNumber'], iMode['mode'], iDevice, property_pull.property_pull(_fill_infos['fillNumber'], iMode['mode'], iDevice,
iMode['startTime'].strftime("%Y-%m-%d %H:%M:%S.000"), iMode['startTime'].strftime("%Y-%m-%d %H:%M:%S.000"),
iMode['endTime'].strftime("%Y-%m-%d %H:%M:%S.000")) iMode['endTime'].strftime("%Y-%m-%d %H:%M:%S.000"))
...@@ -47,16 +48,29 @@ def start_pull(_fill_infos, _devices=None): ...@@ -47,16 +48,29 @@ def start_pull(_fill_infos, _devices=None):
''' '''
if __name__ == '__main__': def routine_pull(_start_fill=None, _end_fill=None):
ldb = pytimber.LoggingDB() ldb = pytimber.LoggingDB()
# res = ldb.get('HX:FILLN', datetime.datetime.now())
# fillNumber = int(res['HX:FILLN'][1][0])
fill_number = 7493
fill_infos = ldb.getLHCFillData(fill_number, False)
gcursor = mydb.cursor() 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]
print(last_fill_pulled)
if new_fill_number == last_fill_pulled:
print('already pulled last fill')
return -1
else:
new_fill_number = _end_fill
last_fll_pulled = _start_fill - 1
# Select only the first 6 devices Cause: not all device works properly with NXCALS yet
gcursor.execute('select name from device limit 6') gcursor.execute('select name from device limit 6')
devices_request = gcursor.fetchall() devices_request = gcursor.fetchall()
devices = [] devices = []
...@@ -66,6 +80,29 @@ if __name__ == '__main__': ...@@ -66,6 +80,29 @@ if __name__ == '__main__':
gcursor.close() gcursor.close()
mydb.close() mydb.close()
print(devices) fill_number = 7472
fill_infos = ldb.getLHCFillData(fill_number, False)
start_pull(fill_infos, devices) start_pull(fill_infos, devices)
'''
for iFill in range(last_fill_pulled + 1, new_fill_number):
fill_infos = ldb.getLHCFillData(iFill, False)
# check if the fill is finished
if fill_infos['endTime'] is None:
break
# 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']:
continue
start_pull(fill_infos, devices)
'''
if __name__ == '__main__':
routine_pull()
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