Skip to content

Conversation

@jasontread
Copy link
Contributor

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

logtime.py implementation
pomodoro_timer implementation
@jasontread jasontread changed the title ADDED jread-52 Nov 16, 2022
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)
Copy link
Collaborator

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

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

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

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

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice use of constants

@bbelderbos bbelderbos merged commit 02b7765 into pybites:community Nov 17, 2022
@jasontread jasontread deleted the jread-52 branch November 18, 2022 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants