-
Notifications
You must be signed in to change notification settings - Fork 2.2k
jread-52 #852
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
jread-52 #852
Conversation
| line1 = 'ERROR 2014-07-03T23:24:31 supybot Invalid user dictionary file' | ||
| line2 = 'INFO 2015-10-03T10:12:51 supybot Shutdown initiated.' | ||
| line3 = 'INFO 2016-09-03T02:11:22 supybot Shutdown complete.' | ||
| assert convert_to_datetime(line1) == datetime(2014, 7, 3, 23, 24, 31) |
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.
You can use pytest.mark.parametrize - https://pybit.es/articles/pytest-coding-100-tests/ - no 9
| # and set the next transition time (+5 if transitioning to break, +25 if transitioning to work) | ||
| if str(datetime.now()).split('.')[0] == str(next_transition).split('.')[0]: | ||
| next_transition = datetime.now() + (break_duration if work_status == 'working' else break_frequency) | ||
| work_status = 'break' if work_status == 'working' else 'working' |
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 would put states in constants
| f'[first_break={next_transition}') | ||
|
|
||
| # Run the timer from now until the stop time designated above | ||
| while datetime.now() < stop: |
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 would put this in a function
| end = None | ||
| for line in loglines: | ||
| if SHUTDOWN_EVENT in line: | ||
| if dt := convert_to_datetime(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.
walrus, nice :)
| int(match.group(5)), int(match.group(6))) if match else None | ||
|
|
||
|
|
||
| def time_between_shutdowns(loglines): |
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.
You can use a list comprehension and built-in functions, similar function from one of our Bites:
def time_between_shutdowns(loglines):
"""TODO 2:
Extract shutdown events ("Shutdown initiated") from loglines and
calculate the timedelta between the first and last one.
Return this datetime.timedelta object.
"""
shutdown_entries = [line for line in loglines if SHUTDOWN_EVENT in line]
shutdown_times = [convert_to_datetime(event) for event in shutdown_entries]
return max(shutdown_times) - min(shutdown_times)
| DATETIME_REGEX = re.compile(r'.*(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*') | ||
| SHUTDOWN_EVENT = 'Shutdown initiated' | ||
|
|
||
| with open(os.path.join(sys.path[0], "messages.log"), "r") as f: |
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 would put this into a function
|
|
||
| from datetime import datetime | ||
|
|
||
| DATETIME_REGEX = re.compile(r'.*(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*') |
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.
nice use of constants
logtime.py implementation
pomodoro_timer implementation
ATTENTION: before clicking "Create Pull Request" please submit some meta data, thanks!
Difficulty level (1-10): 2
Estimated time spent (hours): 2.5
Completed (yes/no): yes
I stretched my coding skills (if yes what did you learn?): first lesson - learning a lot of general python knowledge
Other feedback (what can we improve?): All good