Skip to content

Add seconds and elapsed checks to stopwatch - #667

Merged
WasabiFan merged 5 commits into
ev3dev-stretchfrom
feature/pure-stopwatch
Dec 28, 2019
Merged

WasabiFan merged 5 commits into
ev3dev-stretchfrom
feature/pure-stopwatch

Conversation

@WasabiFan

Copy link
Copy Markdown
Member

Also did general clean-up and added documentation. Removed intermediate "value" so that accessors don't modify state.

There is one breaking change (I believe everything else is backwards-compatible): "value_hms" now returns the unstringified tuple, and a new "hms_str" returns the string version. Also changed the __str__ format to include the hms string but I don't view that as a breaking change.

Useful for #665.

Comment thread ev3dev2/stopwatch.py Resolved
Co-Authored-By: Matěj Volf <mat.volfik@gmail.com>
@mvolfik

mvolfik commented Aug 26, 2019 •

Copy link
Copy Markdown
Contributor

Wouldn't reset and start after this do the same thing? I would suggest that start would continue from the time when stop was called, or from 0 if _stopped_total_time is None, and reset would only reset _stopeed_total_time to None Better explained with code 😺 :

def start(self):
    """
    Starts the timer. If the timer is already running, does nothing.
    If the timer was previously stopped, continues with the previous elapsed time
    """
    if self._stopped_total_time is None:
        if self._start_time is None:
            self._start_time = get_ticks_ms()
    else:
        self._start_time = get_ticks_ms() - self._stopped_total_time
        self._stopped_total_time = None

Also I would either remove the start() call from reset, or name it restart.
And maybe rename is_started to is_running and implement is_started as _start_time is not None or _stopped_total_time is not None.

However, all of these are just ideas what I would find more intuitive...

@WasabiFan

Copy link
Copy Markdown
Member Author

I agree on the stop/reset semantics — I did it this way because it was backwards-compatible with what was released before. That being said, it was only released in the beta release, so if we're going to break it we should do it now. I'll look back at it tomorrow and maybe change it to be as you described.

@dwalton76 what do you think?

Comment thread ev3dev2/stopwatch.py Resolved
Co-Authored-By: Matěj Volf <mat.volfik@gmail.com>
Comment thread ev3dev2/stopwatch.py
@property
def is_started(self):
"""
True if the StopWatch has been started but not stoped (i.e., it's currently running), false otherwise.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

s/stoped/stopped/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

s/false/False/

@dwalton76 dwalton76 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The rest looks good to me

Comment thread ev3dev2/stopwatch.py
@property
def is_started(self):
"""
True if the StopWatch has been started but not stoped (i.e., it's currently running), false otherwise.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

s/false/False/

@WasabiFan

Copy link
Copy Markdown
Member Author

@dwalton76 What do you think about the questions raised by @mvolfik (about start/reset behavior)?

I think it would make sense to change the interface a bit but I'd like your opinion too.

@dwalton76

Copy link
Copy Markdown
Collaborator

I think it would be better to have a 2nd call to start raise an Exception, just because it feels like an easy mistake for the user to make. If they want to reset the timer I think they should have to explicitly call reset()

@WasabiFan

Copy link
Copy Markdown
Member Author

I guess the question of restart behavior comes down to use cases: do we expect there's a common case where someone wants to start+stop a timer then start it again from where they left off? Is that useful? I can see cases where that could be used but it seems like the majority of use cases are where you want to start the timer then wait for some amount of time to elapse while performing another action.

Comment thread ev3dev2/stopwatch.py Resolved
Comment thread ev3dev2/stopwatch.py Resolved
@WasabiFan
WasabiFan requested a review from dwalton76 December 28, 2019 05:38

@dwalton76 dwalton76 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good

@WasabiFan

Copy link
Copy Markdown
Member Author

This is a slight breaking change; this prompts a reasonable discussion. One option would be to increment the minor version (2.1.0) and bend semver, which seems attractive but I'm a bit worried about setting that precedent.

The other option would be to increment it properly and call it 3.0. I am generally OK with incrementing major versions relatively often as long as we have at least a few breaking changes included.

@dwalton76

Copy link
Copy Markdown
Collaborator

Do we have any other breaking changes? If so 3.0 sounds good, if not then 2.1.0.

@WasabiFan

Copy link
Copy Markdown
Member Author

So far, we don't. I'll merge this as-is and then I can change the planned version number as new changes come in.

@WasabiFan
WasabiFan merged commit 06604a6 into ev3dev-stretch Dec 28, 2019
@WasabiFan
WasabiFan deleted the feature/pure-stopwatch branch December 29, 2019 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants