Skip to content

Instantly share code, notes, and snippets.

@jglee72
Created March 21, 2017 13:55
Show Gist options
  • Save jglee72/8b614e58d811e0fb69d1635a4bec0c81 to your computer and use it in GitHub Desktop.
Save jglee72/8b614e58d811e0fb69d1635a4bec0c81 to your computer and use it in GitHub Desktop.
UltCalcR2.py
# coding: utf-8
import math
import dialogs
import time
#from game_menu import MenuScene
import sound
# print fibanoci sequence up to n
##==========MODULES=======##
def fib(n):
a,b=0,1
while a < n:
print a
a,b=b,a+b
#https://gist.github.com/440fcc81233ea83af4a40dee69cd4073
# print whether n is an odd or even number.
def odd(n):
if (n%2):
print('odd number')
else:
print('even number')
# calculate payout scale for MTNW LCI-90
def payoutScale(mags,sheaveDia,cableDia):
#payout scale = pulses_per_round/((sheave dia + cable dia)) x Pi
a=mags/((sheaveDia+cableDia)*math.pi)
print 'Enter : ' , a, 'for Payout Scale'
# calculate time to go and maybe real time for lemons
def timeToLemons(metersPerMin, depth, lemonDepth):
float(metersPerMin)
float(depth)
float(lemonDepth)
timeToGo = (depth-lemonDepth)/metersPerMin
j=time.localtime()
timeHourAdd=int((timeToGo+j.tm_min)/60)
newHour=j.tm_hour+timeHourAdd
newHour-=(24 if newHour>=24 else 0)
newMin=timeToGo+j.tm_min-timeHourAdd*60
#lemonTime[0] = ('0' if newHour < 10 else '1')
lemonTime=('0' if newHour<10 else '')+str(newHour)+':'+('0' if newMin<10 else '')+str(int(newMin))
# print 'Payout',':',int(depth), '=',int(timeToGo), 'mins till lemons on surface', "(" , ('0' if newHour<10 else ''), newHour,':',('0' if newMin<10 else ''), int(newMin), ")"
callMin = newMin - int(30)
callHour = newHour
callHour -= (1 if callMin<0 else 0)
if (callHour < 0):
callHour = int(24)
callMin+=(60 if callMin<0 else 0)
callTime=('0' if callHour<10 else '' )+str(callHour)+':'+('0' if callMin<10 else '')+str(int(callMin))
# print 'Half hour callout at:',('0' if callHour<10 else '' ),callHour, ':', ('0' if callMin<10 else ''),int(callMin)
sound.play_effect('arcade:Powerup_2')
return (str(timeToGo),lemonTime,callTime)
def diveTime(timeStart,timeEnd,days):
minute0= int(timeEnd[3])-int(timeStart[3])
minute1= int(timeEnd[2])-int(timeStart[2])
hour0= int(timeEnd[1])-int(timeStart[1])
hour1= int(timeEnd[0])-int(timeStart[0])
# print hour1,hour0,':', minute1,minute0
#timeElapse = imemjEnd-timeStart
startSeconds = 0
startSeconds+=int(timeStart[0])*(10*60*60)
startSeconds+=int(timeStart[1])*(60*60)
startSeconds+=int(timeStart[2])*(10*60)
startSeconds+=int(timeStart[3])*(60)
finishSeconds=0
finishSeconds+=int(timeEnd[0])*(10*60*60)
finishSeconds+=int(timeEnd[1])*(60*60)
finishSeconds+=int(timeEnd[2])*(10*60)
finishSeconds+=int(timeEnd[3])*(60)
#print finishSeconds, startSeconds
secondsTotal=0
if (int(days) !=0):
secondsTotal= ( int(days)*24*60*60-startSeconds) + finishSeconds
else:
secondsTotal= finishSeconds-startSeconds
# print secondsTotal
print int(secondsTotal/3600.0), ':',('0' if(secondsTotal%3600/60)<10 else ''),(secondsTotal%3600/60), 'Hours Dive Time'
s_diveTime=str(int(secondsTotal/3600.0)) + ':' + str('0' if(secondsTotal%3600/60)<10 else '') + str(int(secondsTotal%3600/60))
return (s_diveTime)
##==========CALCULATORS=======##
def calcPayoutScale():
# get user data. must convert to float and translate to meters
# sheaveDia=float(dialogs.text_dialog('enter sheave diameter (inches):')) * 0.0254
# cableDia=float(dialogs.text_dialog('enter cable diameter (inches):')) * 0.0254
# mags=float(dialogs.text_dialog('enter magnet count:'))
# payoutScale(mags,sheaveDia,cableDia)
field1={'type':'number','key':'Sheave','title':'Sheave Dia: ','tint_color':'#346511'}
field2={'type':'number','key':'Cable','title':'Cable Dia : '}
field3={'type':'number','key':'Mags','title':'Number Mags: ','tint_color':'#000000'}
t=[field1,field2,field3]
answer=dialogs.form_dialog('MTNW: Payout Calculator',t,done_button_title='Do It!')
mags=float(answer['Mags'])
sheaveDia=float(answer['Sheave'])*0.0254
cableDia=float(answer['Cable'])*0.0254
payoutScale(mags,sheaveDia,cableDia)
def calcTimeToLemons():
Times=['Wait for it','I mean it','Here it Comes']
depth=0.0
while True:
field1={'type':'number','key':'Payout','title':'Payout (meters):','tint_color':'#346511','placeholder':'enter payout'}
field2={'type':'number','key':'Speed','value':'25','title':'Payout Speed (m/min) : ','placeholder':'enter winch speed'}
field3={'type':'number','key':'Lemons','title':'Lemons depth (meters)', 'value':'100','tint_color':'#a70000','placeholder':'enter lemons payout'}
field4={'type':'number','key':'MinLemons','title':'Minutes to Lemons', 'value':Times[0],'tint_color':'#a70000'}
field5={'type':'number','key':'TimeLemons','title':'Time at Lemons', 'value':Times[1],'tint_color':'#a70000'}
field6={'type':'number','key':'TimeCall','title':'Half Hour Callout', 'value':Times[2],'tint_color':'#a70000'}
s_depth=str(depth)
field7={'type':'number','key':'payout','title':'You entered:', 'value':s_depth,'tint_color':'#a70000'}
t1=[field1,field2,field3]
t2=[field7,field4,field5,field6]
s1='Input',t1
s2='Answers',t2
sect=(s1,s2)
answer=dialogs.form_dialog(title='Time to Lemons! Calculator',sections=sect,done_button_title='execute')
lemonDepth=float(answer['Lemons'])
metersPerMin =float(answer['Speed'])
depth=float(answer['Payout'])
Times=timeToLemons(metersPerMin, depth, lemonDepth)
#end of while loop
def calcDiveTime():
s_diveTime ='0'
while True:
field1={'type':'number','key':'diveStart','title':'Start Time incl 0s (24hour): ','tint_color':'#1b8c3b','placeholder':'0000'}
field2={'type':'number','key':'diveEnd','title':'End Time incl 0s (24hour): ','tint_color':'#1b8c3b','placeholder':'0000'}
field3={'type':'number','key':'diveDays','title':'Dive Days(# 00:00\'s)', 'tint_color':'#1b8c5c','value':'0'}
str_diveTime=str(s_diveTime)
field4={'type':'number','key':'diveTime','title':'Dive Time (Hrs):', 'tint_color':'#1b8c5c','value':str_diveTime}
t1=[field1,field2,field3]
t2=[field4]
s1='Input',t1
s2='Answers',t2
sect=(s1,s2)
answer=dialogs.form_dialog('Dive Time Calculator',sections=sect,done_button_title='execute')
diveStart= (answer['diveStart'])
diveEnd= (answer['diveEnd'])
diveDays= (answer['diveDays'])
s_diveTime =diveTime(diveStart,diveEnd,diveDays)
sound.play_effect('arcade:Explosion_3')
sound.play_effect('arcade:Jump_2')
sound.play_effect('arcade:Laser_4')
def fibonaci():
fibNum=float(dialogs.text_dialog('Enter a Number to Fibonaci To: '))
fib(fibNum)
############# MAIN PROGRAM #############
# show list of calculators available
calcList = ['MTNW Calculator', 'fibonaci', 'Time To Lemons','Dive Time Calculator']
calcChoice = dialogs.list_dialog('Choose a Calculator', calcList)
#show_start_menu(0)
if (calcChoice == 'MTNW Calculator'):
calcPayoutScale()
elif (calcChoice == 'fibonaci'):
fibonaci()
elif (calcChoice == 'Time To Lemons'):
calcTimeToLemons()
elif (calcChoice == 'Dive Time Calculator'):
calcDiveTime()
else:
print('No choice available')
#if __name__ == '__main__':
# main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment