1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#![forbid(unsafe_code)]
#![deny(non_upper_case_globals)]
#![deny(non_camel_case_types)]
#![deny(non_snake_case)]
#![deny(unused_mut)]
#![deny(dead_code)]
#![deny(unused_imports)]
#![deny(missing_docs)]
#![forbid(unsafe_code)]
#[macro_use]
extern crate serde_derive;
pub mod tables;
pub fn no_decompression_limit(depth: u16) -> u16 {
let nodeco_table = tables::nodeco_table()
.expect("Error serializing the data withthe table deco_table");
let mut ndl: u16 = 0;
for row in nodeco_table.table_data.iter() {
if row.min_fsw <= depth && depth <= row.max_fsw {
ndl = row.no_stop_limit
}
}
return ndl;
}
pub fn group_letter(dive: tables::types::Dive) -> String {
let nodeco_table = tables::nodeco_table()
.expect("Error serializing the data within the deco_table");
let mut gl: String = String::from("");
for row in nodeco_table.table_data.iter() {
if row.min_fsw <= dive.depth && dive.depth <= row.max_fsw {
for value in row.values.iter() {
if value.min_time <= dive.bottom_time && dive.bottom_time <= value.max_time {
gl = String::from(&value.group_letter);
}
}
}
}
return gl;
}
pub fn repet_letter(dive_plan: tables::types::DivePlan) -> String {
let nodeco_table = tables::nodeco_table()
.expect("Error serializing the data within the deco_table");
let rgl_table = tables::rgl_table()
.expect("there was an error deserializing deco table");
let mut rl = String::new();
for row in nodeco_table.table_data.iter() {
if row.min_fsw <= dive_plan.depth && dive_plan.depth <= row.max_fsw {
for group in row.values.iter() {
if group.min_time <= dive_plan.bottom_time && dive_plan.bottom_time <= group.max_time {
for rgl_row in rgl_table.table_data.iter() {
if rgl_row.group_letter == group.group_letter && rgl_row.min_time <= dive_plan.sit && dive_plan.sit <= rgl_row.max_time {
rl = String::from(&rgl_row.repet_letter)
}
}
}
}
}
}
return rl;
}
pub fn residual_nitrogen_time(dive_plan: tables::types::DivePlan) -> u16 {
let nodeco_table = tables::nodeco_table()
.expect("Error deserializing no decompression table");
let rgl_table = tables::rgl_table()
.expect("Error deserializing repetitive group letter table");
let rnt_table = tables::rnt_table()
.expect("Error deserializing residual nitrogen time table");
let mut rnt = 0;
for row in nodeco_table.table_data.iter() {
if row.min_fsw <= dive_plan.depth && dive_plan.depth <= row.max_fsw {
for group in row.values.iter() {
if group.min_time <= dive_plan.bottom_time && dive_plan.bottom_time <= group.max_time {
for rgl_row in rgl_table.table_data.iter() {
if rgl_row.group_letter == group.group_letter && rgl_row.min_time <= dive_plan.sit && dive_plan.sit <= rgl_row.max_time {
for rnt_column in rnt_table.table_data.iter() {
if rnt_column.repet_letter == rgl_row.repet_letter {
for element in rnt_column.rnt.iter() {
if element.min_depth <= dive_plan.next_depth && dive_plan.next_depth <= element.max_depth {
rnt = element.rnt
}
}
}
}
}
}
}
}
}
}
return rnt;
}
pub fn deco_dive(dive: tables::types::Dive) -> tables::types::RowDeco {
let deco_table = tables::deco_table()
.expect("Error deserializing no decompression table");
let mut deco_profile: tables::types::RowDeco = tables::types::RowDeco {
min_time: 0,
max_time: 0,
air_tat: String::from("0"),
o2_tat: String::from("0"),
ttfs: String::from("0"),
o2cp: 0.0,
repetgroup_letter: String::from("0"),
surdo2_recommended: false,
exceptional_exposure: false,
surdo2_required: false,
strict_surdo2: false,
air_deco_stops: vec![],
o2_deco_stops: vec![],
};
for row_deco in deco_table.table_data.iter() {
if row_deco.min_fsw <= dive.depth && dive.depth <= row_deco.max_fsw {
for profile in row_deco.rows.iter() {
if profile.min_time <= dive.bottom_time && profile.max_time <= dive.bottom_time {
deco_profile = profile.clone()
}
}
}
}
return deco_profile;
}