User avatar
Trigo
Posts: 106
Joined: Fri Jun 17, 2016 7:52 pm

Chronometer for multiple athletes

Thu Apr 23, 2020 11:42 am

Hi all, hope you're doing well over the pandemic! I am surrounding a stopwatch for multiple athletes... Let's say that i have 5 athletes and only one track to them. They don't start at the same time. They could start with a 5 sec gap between them. How do i know the exact time from each one? I have a source code from a GitHub developer. That code only starts and stops the watch and gives the delta between starting and stopping! Is everyone helping? Hopping on that!! I would like to add a class of athlete +1 and give them a time (delta)! I want all the deltas for that particular athlete. They are five! The training task for one of, needs him to pass every 200 meters at 33 seconds! It's 2000 meters, he needs to pass it 10 times at that clock range!

#Imagine each number is a person. Everytime you press the same number it gives you the deltatime between pressing!!!!

Code: Select all

#!/usr/bin/env python3



from __future__ import print_function, division
import datetime
import os
import signal
from termcolor import colored, cprint


class Stopwatch(object):
    def __init__(self):
        self.time = datetime.datetime.now()
        self.state = False
        self.seconds = 0
        cprint('Lets start running! ', 'green')
        self.print_out_and_log()

    def switch(self):
        if self.state:
            diff = datetime.datetime.now() - self.time
            self.seconds += diff.total_seconds()
            self.time = datetime.datetime.now()
        else:
            self.time = datetime.datetime.now()
        self.state = not self.state
        self.print_out_and_log()
        
        

    def print_out_and_log(self):
        timestr = self.time.strftime('%H:%M:%S')
        statestr = 'Running' if self.state else 'Paused'
        stateclr = 'green' if self.state else 'red'
        statemsg = "%s at %s." % (statestr, timestr)
        elapsemsg = "Elapsed time: %s" % self.elapsed_str() 
        print_msg = '%s %s' % (colored(statemsg, stateclr), elapsemsg)
        print ('Ctrl+C to exit')
        print(print_msg)
  
    def elapsed_str(self):
        hours = self.seconds // 3600
        minutes = (self.seconds - 3600*hours) // 60
        seconds = (self.seconds % 60) // 1
        rest = self.seconds - 3600*hours - 60*minutes - seconds
        milli = round(rest*100.0)
        return '%02i:%02i:%02i:%02i' % (hours, minutes, seconds, milli)

 [b]def ath (self):
        if command = 1:
            print [/b]
    
    def stop(self):
        if self.state:
            self.switch()
        else:
            self.print_out_and_log()


def main():

    sw = Stopwatch()
    try:
        while True:
            if sw.state:
                input('Press Enter to pause ...')
            else:
                input('Press Enter to start ...')
            sw.switch()
    except (KeyboardInterrupt, EOFError):
        pass
    finally:
        print()
        sw.stop()
        

if __name__ == '__main__':
    main()
Beat psychologically with a stick :?:

User avatar
Trigo
Posts: 106
Joined: Fri Jun 17, 2016 7:52 pm

Re: Chronometer for multiple athletes

Fri Apr 24, 2020 11:20 am

I was reading about time.perf_counter! I'm a newbie... Anyone?
Beat psychologically with a stick :?:

Return to “Python”