-
Notifications
You must be signed in to change notification settings - Fork 0
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
HW21 #31
base: main
Are you sure you want to change the base?
HW21 #31
Conversation
try: | ||
with open(filename, 'r') as file: | ||
for line_number, line in enumerate(file, start=1): | ||
if 'Key TSTFEED0300|7E3E|0400' in line: |
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.
Better to avoid hardcodes - certain key string better to accept as function parameter
if 'Key TSTFEED0300|7E3E|0400' in line: | ||
match = re.search(r'Timestamp (\d{2}:\d{2}:\d{2})', line) | ||
if match: | ||
try: |
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.
No sense in this try - except - better catch all errors within analyze_heartbeat function try-except block
line_number_next, timestamp_next = timestamps[i + 1] | ||
delta = (timestamp_current - timestamp_next).total_seconds() | ||
|
||
if 31 < delta < 33: |
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.
31 and 32 better to place to the top as constants
f'at line {line_number_current} ({timestamp_current})' | ||
) | ||
elif delta >= 33: | ||
_log.error( |
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.
I have in log such line
2025-01-08 21:40:56,349 - ERROR - Critical heartbeat delay: 35.0 seconds at line 1189 (1900-01-01 04:51:17)
1900-01-01 looks as bug. Please fix it
|
||
|
||
if __name__ == '__main__': | ||
analyze_heartbeat('hblog.txt') |
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.
Here better to define as input parameters input_log_txt_filename, output_log_filename, certain Key string.
Logger creation could be organized then as separate function to accept output filename
No description provided.