Best program for keeping track of Time (motor racing) - time

Short Version:
Program to:
control racing (cars) laptimes (it must not reset)
be able to use as a chronometer
b able to use as a reverse chronometer (start in X min:secs end in 00:00)
Long Version:
I need a program to control time, I need the time to go forth and back (for me to choose)
and I insert the starting time.
I also need a program to control lap times.
If anyone know any program for these stuff (racing stuff), I would apreciate it, even if there only are paid solution, I still would like to take a look at them (I staring to make a program in python and it could be good for inspiration)
After some search, I could only find this:
It's a simple clock in python TKinter..... if anyone has anything more advanced... (easier to change :) )
from Tkinter import *
import time
from Tkinter import *
import time
class StopWatch(Frame):
""" Implements a stop watch frame widget. """
def __init__(self, parent=None, **kw):
Frame.__init__(self, parent, kw)
self._start = 0.0
self._elapsedtime = 0.0
self._running = 0
self.timestr = StringVar()
self.makeWidgets()
def makeWidgets(self):
""" Make the time label. """
l = Label(self, textvariable=self.timestr)
self._setTime(self._elapsedtime)
l.pack(fill=X, expand=NO, pady=2, padx=2)
def _update(self):
""" Update the label with elapsed time. """
self._elapsedtime = time.time() - self._start
self._setTime(self._elapsedtime)
self._timer = self.after(50, self._update)
def _setTime(self, elap):
""" Set the time string to Minutes:Seconds:Hundreths """
minutes = int(elap/60)
seconds = int(elap - minutes*60.0)
hseconds = int((elap - minutes*60.0 - seconds)*100)
self.timestr.set('%02d:%02d:%02d' % (minutes, seconds, hseconds))
def Start(self):
""" Start the stopwatch, ignore if running. """
if not self._running:
self._start = time.time() - self._elapsedtime
self._update()
self._running = 1
def Stop(self):
""" Stop the stopwatch, ignore if stopped. """
if self._running:
self.after_cancel(self._timer)
self._elapsedtime = time.time() - self._start
self._setTime(self._elapsedtime)
self._running = 0
def Reset(self):
""" Reset the stopwatch. """
self._start = time.time()
self._elapsedtime = 0.0
self._setTime(self._elapsedtime)
def main():
root = Tk()
sw = StopWatch(root)
sw.pack(side=TOP)
Button(root, text='Start', command=sw.Start).pack(side=LEFT)
Button(root, text='Stop', command=sw.Stop).pack(side=LEFT)
Button(root, text='Reset', command=sw.Reset).pack(side=LEFT)
Button(root, text='Quit', command=root.quit).pack(side=LEFT)
root.mainloop()
if __name__ == '__main__':
main()

If you want to go with a packaged solution, you should try some of the apps:
for your android phone: http://www.bestandroidappsreview.com/2010/05/top-android-app-ultimate-stopwatch.html
for your iphone: http://www.apple.com/webapps/utilities/stopwatch_benku.html which is free, but if you want a more powerful stopwatch you should try LAPZERO app (see demo http://www.lapzero.com/v4/)
for your windows mobile phone: http://www.ageye.de/index.php?s=grace/about
or find one for your desktop computer platform/system on google

So what you want is a milliseconds accurate stop watch and lap timer.
Not that I have tried it but heres one I found on google http://www.xnotestopwatch.com/
I wish I could vote, cause that import tardis crack was a good one. :P

Related

pystray on MacOS to use run_detached, program crashed

I am trying to use pystray to create a icon on tasktray, it is working on windows but now I am building one for Mac. I need the program minimize to tasktray on run on background. so I need to use icon.run_detached() instead of icon.run().
However, it keep crashing the app and I read the documents seems that I need to give some darwin_nsapplication = AppKit.NSApplication.sharedApplication() to the code but I really don't know how to implement this. here is my code.
import tkinter as tk
import time
import pystray
from tkinter import *
from tkinter import messagebox
from PIL import Image
import AppKit
`class Gui():
def __init__(self):
self.window = tk.Tk()
self.darwin_nsapplication = AppKit.NSApplication.sharedApplication()
self.image = Image.open("./images/noname.png")
self.menu = (
pystray.MenuItem('Show', self.show_window),
pystray.MenuItem('Quit', self.quit_window)
)
# Declaration of variables
self.hour=StringVar()
self.minute=StringVar()
self.second=StringVar()
# setting the default value as 0
self.hour.set("00")
self.minute.set("00")
self.second.set("00")
# Use of Entry class to take input from the user
hourEntry= Entry(self.window, width=3, font=("Arial",18,""),
textvariable=self.hour)
hourEntry.place(x=80,y=20)
minuteEntry= Entry(self.window, width=3, font=("Arial",18,""),
textvariable=self.minute)
minuteEntry.place(x=130,y=20)
secondEntry= Entry(self.window, width=3, font=("Arial",18,""),
textvariable=self.second)
secondEntry.place(x=180,y=20)
# button widget
btn = Button(self.window, text='Set Time Countdown', bd='5',
command= self.submit)
btn.place(x = 70,y = 120)
def submit(self):
try:
# the input provided by the user is
# stored in here :temp
temp = int(self.hour.get())*3600 + int(self.minute.get())*60 + int(self.second.get())
except:
print("Please input the right value")
while temp >-1:
# divmod(firstvalue = temp//60, secondvalue = temp%60)
mins,secs = divmod(temp,60)
# Converting the input entered in mins or secs to hours,
# mins ,secs(input = 110 min --> 120*60 = 6600 => 1hr :
# 50min: 0sec)
hours=0
if mins >60:
# divmod(firstvalue = temp//60, secondvalue
# = temp%60)
hours, mins = divmod(mins, 60)
# using format () method to store the value up to
# two decimal places
self.hour.set("{0:2d}".format(hours))
self.minute.set("{0:2d}".format(mins))
self.second.set("{0:2d}".format(secs))
# updating the GUI window after decrementing the
# temp value every time
self.window.update()
time.sleep(1)
# when temp value = 0; then a messagebox pop's up
# with a message:"Time's up"
if (temp == 0):
messagebox.showinfo("Time Countdown", "Time's up ")
# after every one sec the value of temp will be decremented
# by one
temp -= 1
def quit_window(self):
self.icon.stop()
self.window.destroy()
def show_window(self):
self.icon.stop()
self.window.protocol('WM_DELETE_WINDOW', self.withdraw_window)
self.window.after(0, self.window.deiconify)
def withdraw_window(self):
self.window.withdraw()
self.icon = pystray.Icon("name", self.image, "title", self.menu)
self.icon.run_detached()
if __name__ in '__main__':
app = Gui()
app.window.protocol('WM_DELETE_WINDOW', app.withdraw_window)
app.window.mainloop()`
I tried to add darwin_nsapplication to icon like self.icon = pystray.Icon("name", self.image, "title", self.menu,self.darwin_nsapplication)
But it is said 6 arguments are given, 2-5 are needed.

PYQT After Timeline Animation

I have a lottery program which is written by python(PYQT5). Now,I got the lucky number in the back first and roll the label. I want to paste the answer finally. Like code.
r_list = [0,1,2,3,4,5,6,7,8,9] #random list
animation(label,r_list,ans) #GUI showing
#GUI showing (label,random list,final text)
def animation(label,r_list,ans):
show_timmer = 5 #time of animation(sec)
#animation
timeline = QtCore.QTimeLine(show_timmer * 1000, self) #time of timeline
timeline.setFrameRange(label.geometry().top(), label.geometry().width()) #range of anumation
timeline.setLoopCount(1) #action times
timeline.frameChanged.connect(lambda: self.__set_frame_func(label,r_list)) #animation action
timeline.start() #anumation start
#finally:paste the answer
#anumation action:rolling label
def set_frame_func(label,r_list):
msg = r_list[random.randint(0,len(r_list)-1)] #random text
label.setText(msg) #change the text
return
Accroding to the code, I try in vain to finish the code.
#finally:paste the answer
while True:
if timeline.state() == 0:
label.setText(ans)
break
#finally:paste the answer
time.sleep(show_timmer)
label.setText(ans)
#finally:paste the answer
start = time.time()
while True:
if time.time() - start >= show_timmer:
break
label.setText(ans)
All the ways will crash the computer. Which case I can reference?
I'm poor at English. I'm sorry if I offend.

How to measure execution time for prediction per image (keras)

I have a simple model created with Keras and I need to measure the execution time for prediction per image. Right now I just do this:
start = time.clock()
my_model.predict(images_test)
end = time.clock()
print("Time per image: {} ".format((end-start)/len(images_test)))
But I noticed that the calculated time is bigger when len(images_test) is smaller. For example when len(images_test) = 32 I get: 0.06 and when len(images_test) = 1024 I get: 0.006
Is there a "right" way to do this ?
if use TF it seems no Asynchronous problem
but if use pytorch it has Asynchronous problem.
in TF:
start = time.clock()
result = my_model.predict(images_test)
end = time.clock()
in pytorch:
torch.cuda.synchronize()
start = time.clock()
my_model.predict(images_test)
torch.cuda.synchronize()
end = time.clock()
But i think you can do 10 times Loop model_predict
and print time_list
(computer need load keras model so first time load slower than other times )
in TF:
pred_time_list=[]
for i in range(10):
start = time.clock()
result = my_model.predict(images_test)
end = time.clock()
pred_time_list.append(end-start)
print(pred_time_list)
(print the pred_time_list and you may find out why the times incorrect)
Reference:
[1]
https://discuss.pytorch.org/t/doing-qr-decomposition-on-gpu-is-much-slower-than-on-cpu/21213/6
[2]
https://discuss.pytorch.org/t/is-there-any-code-torch-backends-cudnn-benchmark-torch-cuda-synchronize-similar-in-tensorflow/51484/2

Q: Resample bitstamp bars in pyalgotrade

I'm working with an algo on the bitstamp client that works better with 30-min bars, rather than seeing each trade as a bar.
Is there a "right" way to resample those bars into 30-min intervals on the fly?
I can do it no problem with the bitcoincharts broker, but I need the execution from the bitstampbroker, so I was hoping to do it with one.
This should help:
from pyalgotrade.bitstamp import barfeed
from pyalgotrade.bitstamp import broker
from pyalgotrade import strategy
class Strategy(strategy.BaseStrategy):
def __init__(self, feed, brk):
super(Strategy, self).__init__(feed, brk)
self._instrument = "BTC"
self._bid = None
self._ask = None
self._resampledBF = self.resampleBarFeed(60, self.onResampledBars)
# Subscribe to order book update events to get bid/ask prices to trade.
feed.getOrderBookUpdateEvent().subscribe(self._onOrderBookUpdate)
def _onOrderBookUpdate(self, orderBookUpdate):
bid = orderBookUpdate.getBidPrices()[0]
ask = orderBookUpdate.getAskPrices()[0]
if bid != self._bid or ask != self._ask:
self._bid = bid
self._ask = ask
self.info("Order book updated. Best bid: %s. Best ask: %s" % (self._bid, self._ask))
def onResampledBars(self, dt, bars):
bar = bars[self._instrument]
self.info("Resampled - Price: %s. Volume: %s." % (bar.getClose(), bar.getVolume()))
def onBars(self, bars):
bar = bars[self._instrument]
self.info("Price: %s. Volume: %s." % (bar.getClose(), bar.getVolume()))
def main():
barFeed = barfeed.LiveTradeFeed()
brk = broker.PaperTradingBroker(1000, barFeed)
strat = Strategy(barFeed, brk)
strat.run()
if __name__ == "__main__":
main()

Implementing a simple CPU meter

I'd like to implement a real time plot of my CPU and GPU load.
I already have a script that retrieve the data and echo it in a terminal.
What I want to do now is to plot this information to see the evolution with time.
I don't know if I need python for instance, and in this case using which module?
Is there any other alternative?
Does someone have any experience doing real time plotting?
Éric.
here is what I did so far
#! /usr/bin/python
import pylab
import time
t = 0
dt = .25
old = None
if __name__ == "__main__":
pylab.ion()
#pylab.xlabel('this is x!')
#pylab.ylabel('this is y!')
#pylab.title('My First Plot')
while True:
with open('/proc/stat') as stat:
new = map(float, stat.readline().strip().split()[1:])
if old is not None:
diff = [n - o for n, o in zip(new, old)]
idle = diff[3] / sum(diff)
pylab.clf()
pylab.plot(t,int(255 * (1 - idle)),'-b', label='cpu')
#print t,int(255 * (1 - idle))
pylab.draw()
old = new
time.sleep(dt)
t = t + dt
Well, something happens when I execute it but nothing is displayed.
Any suggestion?
Thank you,
Éric.

Resources