[心得] 用 python 解释 PADI RDP 潜水计划表

楼主: magicfx (去南半球度假)   2020-11-02 23:45:38
PADI RDP表
https://elearning.padi.com/company0/tools/RDP_Table%20Met.pdf
因为自然语言讲起来比较囉嗦,如果用程式语言根据RDP的数据和算法来实作
其实看的懂得人 反而会觉得更清楚
在此利用 python 来示范怎么实作 RDP 和其应用(解习题)
==
利用线上的 python interpreter 去跑,只需要开浏览器,什么都不用安装
https://www.programiz.com/python-programming/online-compiler/
想要看什么资料就直接print出来就好
连GUI都不用去设计,很快就可以让程式运作起来得到我们想要的答案
==
程式 = 资料 + 算法
我们先思考怎么去将RDP上的资料表示
因为RDP就是一种 look-up table,所以自然而然在 python 会用dictionary
去实作
而我们可以列出几个dic:
padi_table1
surface_table
padi_table2
max_bottom_times
然后再根据RDP上面的数据去输入key:value
==
接下来我们来思考需要 def 哪些运算
get_depth_group的挑战是
输入一个深度
找出集合中和他最接近但是不小于的数字
def get_depth_group(depth):
depths = sorted(padi_table_1.keys())
last_dep = 0
for d in depths:
if last_dep < depth <= d:
return d
last_dep = d
print(last_dep)
print("depth group is " + str(get_depth_group(30)))
也就是如果想知道如果我一开始想下 30 公尺,那应该要查表上的哪个深度
我们把中间比较的过程也print出来,则output会是
10
12
14
16
18
20
22
25
depth group is 30
==
max_bottom_times = {10: 219, 12: 147, 14: 98, 16: 72, 18: 56, 20: 45, 22: 37, 25: 29, 30: 20, 35: 14, 40: 9}
def max_bottom_time(depth):
dep_group = get_depth_group(depth)
return max_bottom_times[dep_group]
max_bottom_times => 我们想要知道每一个深度的最大滞底时间
超过这个时间就要进deco了
(在表格上是涂黑)
先建立起 max_bottom_times的 dictionary
print(max_bottom_time(28))
结果是 20
==
def get_nearest_time_frame(dive_time, depth):
times = sorted([int(x) for x in padi_table_1[depth].keys()])
last_time = 0
for t in times:
if last_time < dive_time <= t:
return t
last_time = t
确定深度,往下找那一列的时间,然后一样找不小于的时间
print( get_nearest_time_frame(18, 30))
output: 19
==
def get_end_pres(time, depth):
depth = get_depth_group(depth)
time = str(get_nearest_time_frame(time, depth))
pressure = padi_table_1[depth][time]
return pressure
print(get_end_pres(18, 30))
output: M
得到结束时的压力等级是M
==
# 给定下潜前后的压力等级,计算需要的 SI 区间
def get_interval(pressure_i, pressure_e):
interval = surface_table[pressure_i][pressure_e]
return interval
print(get_interval(‘M’,’B’))
output: ['01:26', '02:14’]
所以我就知道如果要从压力等级 M 变成 B
SI 要介于 01:26 - 02:13 (时:分)
==
# 把时间区间的时:分格式转成秒,方便电脑比较时间长短
def time2secs(str_time):
hour_seconds = int(str_time.split(':')[0])*60*60
min_seconds = int(str_time.split(':')[1])*60
return hour_seconds + min_seconds
print(time2secs("02:13”))
output: 7980 也就是说 2小时13分 = 7980 秒
就是利用 split的method去利用中间的冒号把小时跟分钟分开
然后小时乘上 60*60
分钟乘上 60
最后加总就变成秒
==
# 如果知道起始的压力等级和水面休息时间,计算休息后的新压力等级
def pressure_after_time(start_p, surf_time):
surf_time *= 60
if surf_time >= 3*60*60:
return 'A'
intervals = surface_table[start_p]
for x in intervals.keys():
interval = intervals[x]
if time2secs(interval[0]) <= surf_time <= time2secs(interval[1]):
return x
print(pressure_after_time(“M", 60))
output: D
也就是原本是M,休息60分钟后,压力等级变成D
==
如果下一潜想要下某个深度待某个时间,则压力等级至少要是多少才不会超过 NDL
这时候你就要去看该深度的 ABT (actual bottom time) 刚好大过这个时间
def min_d2_start_pressure(d2_depth, d2_time):
closest_depth = get_depth_group(d2_depth)
max_times = padi_table_2[closest_depth]
for x in sorted(max_times.keys(), reverse=True):
abt = max_times[x][1]
if d2_time > abt:
continue
else:
return x
print(min_d2_start_pressure(14, 50))
output: M
==
#如果知道下潜之前的压力等级,然后预计下一潜要潜的深度和时间,那么SI至少要多久?
def min_surface(d1_end_p, d2_depth, d2_time):
d2_start_p = min_d2_start_pressure(d2_depth, d2_time)
if d1_end_p < d2_start_p:
return 0
else:
surface_interval = get_interval(d1_end_p, d2_start_p)
get_min_minutes = time2secs(surface_interval[0]) / 60
return get_min_minutes
print(min_surface(“M”,14, 60)
output: 15.0
也就是休息15分钟后,压力等级会从M变成J,而J的压力等级下14m的 ABT最多可以61,刚好超过60
==
#如果知道SI过后的新压力等级,然后下一潜想下的深度和时间,求下一潜结束后的新压力等级
def repeat_dive_end_pressure(si_p_end, d2_depth, d2_time):
closest_depth = get_depth_group(d2_depth)
bottom_time_adjustment = padi_table_2[closest_depth][si_p_end][0]
adjusted_time = d2_time + bottom_time_adjustment
return get_end_pres(adjusted_time, closest_depth)
print(repeat_dive_end_pressure(“J", 20, 15))
output: R
也就是SI后压力等级J,下20公尺15分钟,这时候加上RNT 25分钟变成40分钟的TBT
然后切换回表1
查看下20公尺 40分钟后,压力等级会是R
作者: Youan (阿干)   2020-11-03 00:31:00
先...先推不然人家以为我看不懂
作者: tsao790504 (tsao)   2020-11-03 01:53:00
推推! 刚好正在学python
作者: jal (北海岸一日游)   2020-11-03 02:57:00
我以为我走错版惹...
作者: tyson147258 (siblagg846)   2020-11-03 10:22:00
懂了
作者: Piiter (Piiter)   2020-11-03 19:34:00
等等来自己写写看

Links booklink

Contact Us: admin [ a t ] ucptt.com