看板 DivingSport 關於我們 聯絡資訊
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 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 49.216.230.87 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/DivingSport/M.1604331944.A.6F4.html ※ 編輯: magicfx (49.216.230.87 臺灣), 11/02/2020 23:46:17 ※ 編輯: magicfx (49.216.230.87 臺灣), 11/02/2020 23:46:45
Youan: 先...先推不然人家以為我看不懂 11/03 00:31
tsao790504: 推推! 剛好正在學python 11/03 01:53
jal: 我以為我走錯版惹... 11/03 02:57
tyson147258: 懂了 11/03 10:22
Piiter: 等等來自己寫寫看 11/03 19:34