Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Heartbeat Analyzer for Pythonista for iOS.
# coding: utf-8
import ui
import time
tapped_time = []
def calc_bpm():
# I decided not to use the first and the last time measurement.
# So the list must have at least 4 items to calculate BPM.
if len(tapped_time) < 4:
return 0.0
else:
interval = [x-y for x, y in zip(tapped_time[2:-1], tapped_time[1:-2])]
return 60.0 * float(len(interval))/float(sum(interval))
def button_tapped(sender):
tapped_time.append(time.time())
sender.superview['label'].text = str(int(round(calc_bpm())))
view = ui.load_view('Heartbeat')
view.present('sheet')
[{"class":"View","attributes":{"background_color":"RGBA(1.000000,1.000000,1.000000,1.000000)","tint_color":"RGBA(0.000000,0.478000,1.000000,1.000000)","enabled":true,"border_color":"RGBA(0.000000,0.000000,0.000000,1.000000)","flex":""},"frame":"{{0, 0}, {320, 416}}","nodes":[{"class":"Label","attributes":{"font_size":22,"enabled":true,"text":"--","flex":"","name":"label","border_color":"RGBA(0.000000,0.000000,0.000000,1.000000)","text_color":"RGBA(0.000000,0.000000,0.000000,1.000000)","alignment":"center","uuid":"78B63916-06F6-441E-B6F8-F71C91EC1A02"},"frame":"{{85, 35}, {150, 65.5}}","nodes":[]},{"class":"Button","attributes":{"font_size":15,"enabled":true,"flex":"","font_bold":false,"name":"button1","uuid":"64F2C057-B804-4866-AA4C-04667363DB5C","border_color":"RGBA(0.000000,0.000000,0.000000,1.000000)","action":"button_tapped","title":"Button"},"frame":"{{37, 141.5}, {244.5, 166}}","nodes":[]}]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.