-
Notifications
You must be signed in to change notification settings - Fork 0
Attune integration #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import os | ||
| import csv | ||
| import re | ||
|
|
||
| os.getcwd() | ||
| os.chdir('test_logs/') | ||
|
|
||
| log_file = 'System_2020-11-10_18-52-23.log' | ||
| #Define regexes | ||
|
|
||
| User_dictionary = { | ||
| 'test' : 'test1' | ||
| } | ||
|
Comment on lines
+12
to
+13
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On how to load this user dictionary, the normal recommendation is to load 'secret' or external data either through environment variables or external files. I would tend to prefer external files for something like this. I would use a JSON file for this. JSON data is very similar to the Python syntax, with some specific differences (like only double-quoted strings). After formatting your user dictionary as a separate JSON file (you can use websites like https://www.jsonformatter.io/) then you can load this dictionary with: This also clearly separates the code from data. We can also just never commit the json file to source control, so it never appears publicly. This approach is currently being used on the server-side of labbot. |
||
|
|
||
| event_done = re.compile('^Event:(?P<event>[^_]+)_Done') | ||
| function_in_process = re.compile('^Instrument function (?P<state>.+) executing line (?P<line>\d+)$') | ||
| event_start = re.compile('^Event:Starting_(?P<event>.+)$') | ||
|
Comment on lines
+15
to
+17
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it affects any of your regexes here, but prefer 'raw strings', e.g. by prefixing the string with an r ( If you're using Regex101 for your regex debugging, it actually hints at this; if you have it in Python regex mode, the top-string will have a little Normal strings expand escape sequences by default, e.g. they expand |
||
| user_login = re.compile('login') | ||
| bubble_error = re.compile('^Data:New Bubble Detected') | ||
| big_bubble = re.compile('BUBBLE SIZE GREATER THAN THRESHOLD!!!') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to your code, I really love that this is the actual error message. Definitely feels like a frustrated hardware engineer at some point. The triple exclamation point really sells it. |
||
| aquisition_well = re.compile('^Acquisition initiated on well (?P<well>.+) Preload') | ||
| aquisition_tube= re.compile('^Acquisition initiated$') | ||
|
|
||
|
|
||
| with open(log_file) as log: | ||
| csv_log = csv.DictReader(log, delimiter=',') | ||
| csv_log.fieldnames = [ | ||
| 'TimeStamp', | ||
| "LogType", | ||
| "User", | ||
| "Category", | ||
| "Message", | ||
| "unclearNumberString" ] | ||
|
Comment on lines
+29
to
+33
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PEP8: prefer single-quote strings ( |
||
|
|
||
| for line in csv_log: | ||
|
Comment on lines
+26
to
+35
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're going to change how this parsing works later, but this is good code! |
||
|
|
||
|
|
||
| result=event_start.match(line["Message"]) | ||
| if result != None: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a variety of reasons, prefer See https://stackoverflow.com/a/2209781 for details. |
||
| function = result.group("event") | ||
| State = "Active" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PEP8: lowercase S in state. Also, this is a very Matlab-y way to initialize variables. It is fine that you are creating |
||
|
|
||
| result=function_in_process.match(line["Message"]) | ||
| if result != None: | ||
| function = result.group("state") | ||
| lines = result.group("line") | ||
|
|
||
| result=event_done.match(line["Message"]) | ||
| if result != None: | ||
| function = result.group("event") | ||
| State = "done" | ||
|
|
||
| #result=user_login.match(line["Message"]) | ||
| #if result != None: | ||
| # User_ID = line["User"] | ||
| # User = User_Dictionary[User_ID.lower()] | ||
|
|
||
| result_well = aquisition_well.match(line["Message"]) | ||
| if result_well != None: | ||
| last_well = result_well.group("well") | ||
| print(last_well) | ||
|
|
||
|
|
||
|
|
||
|
|
||
| result_tube = aquisition_tube.match(csv_log.__next__()["Message"]) | ||
| if result_tube != None and result_well == None: | ||
| last_well = "tube" | ||
| print(last_well) | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| #result=bubble_error.match(line["Message"]) | ||
| #if result != None: | ||
| #print('Bubble Error on well', last_well, '!') | ||
|
|
||
|
|
||
| print(function, lines, State) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8: use
snake_case, e.g. no uppercase U. This is true for everything except type definitions (e.g. if this was a class).