Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

HW21 #31

wants to merge 1 commit into from

Conversation

vladspirin
Copy link
Owner

No description provided.

@vladspirin vladspirin requested a review from antohaUa January 8, 2025 13:38
@vladspirin vladspirin self-assigned this Jan 8, 2025
try:
with open(filename, 'r') as file:
for line_number, line in enumerate(file, start=1):
if 'Key TSTFEED0300|7E3E|0400' in line:
Copy link
Collaborator

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:
Copy link
Collaborator

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:
Copy link
Collaborator

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(
Copy link
Collaborator

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')
Copy link
Collaborator

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

@vladspirin vladspirin added the need to improve There is a possibility of improving the code label Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need to improve There is a possibility of improving the code
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants