Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added a continuous timer that updates during sorting #182

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

Closed
hlai1 wants to merge 1 commit into LucasPilla:master from hlai1:add-continuous-timer

Conversation

Copy link

@hlai1 hlai1 commented Dec 8, 2023

Changes

  • added a timer box on bottom right of the screen
  • timer updates as the sorting algorithm is running and shows the final value

Why (resolves #169 and #170)

  • Implementing time taken to sort #169 was about implementing the time taken to sort feature, but @LucasPilla explained in the thread of replies how it would be nice to have the time updated with each iteration, rather than just displaying it at the end

How

  • Pulled the main branch of the repo
  • Added @SunnyWan59's changes to implement a static time box in the bottom right of the screen
  • Modified main.py to update display.timeBox and display.time_taken if the display wasn't paused

Testing

  • Visually confirmed that the time box was updating for different sorting algorithms

Screenshots

Screen.Recording.2023年12月07日.at.11.33.40.PM.mov

Comment on lines +229 to +230
start_time = 0
time_taken = 0
Copy link
Contributor

@idomeisner idomeisner Dec 9, 2023
edited
Loading

Choose a reason for hiding this comment

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

I don't think start_time and time_taken need to be globals.
They are relevant only for DisplayBox, why not add them as class or instance variables?
There are several options for how to implement this.
For example, you can set start_time when starting a new sort and update time_taken when calling the update method.
You can also save only start_time and directly do something like:
self.text = str(time() - start_time)[:6] + ' seconds'

@@ -62,6 +62,21 @@ def update(self, event):
if event.key == pygame.K_BACKSPACE: self.text = self.text[:-1]
elif event.unicode.isdigit() : self.text += event.unicode

class DisplayBox(InputBox):
Copy link
Contributor

@idomeisner idomeisner Dec 9, 2023
edited
Loading

Choose a reason for hiding this comment

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

I'm not sure sure DisplayBox is a good name, all boxes display something.
Looking at the other names TextBox, SlideBox, DropdownBox, ...
Maybe TimeBox or something like that would be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
1 more reviewer

@idomeisner idomeisner idomeisner left review comments

Reviewers whose approvals may not affect merge requirements
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Implementing time taken to sort

AltStyle によって変換されたページ (->オリジナル) /