DivingSport 板


LINE

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://webptt.com/m.aspx?n=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
1F:推 Youan: 先...先推不然人家以為我看不懂 11/03 00:31
2F:推 tsao790504: 推推! 剛好正在學python 11/03 01:53
3F:推 jal: 我以為我走錯版惹... 11/03 02:57
4F:推 tyson147258: 懂了 11/03 10:22
5F:推 Piiter: 等等來自己寫寫看 11/03 19:34







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Tech_Job站內搜尋

TOP