#![forbid(unsafe_code)]
#![deny(non_snake_case)]
#![deny(non_camel_case_types)]
#![deny(non_upper_case_globals)]
#![deny(unused_imports)]
#![deny(unused_mut)]
#![deny(missing_docs)]
#![deny(dead_code)]
#[macro_use]
extern crate serde_derive;
pub mod airtables;
#[derive(Serialize, Deserialize, Copy, Clone, Debug)]
pub struct Dive {
pub depth: u16,
pub bottom_time: u16,
}
#[derive(Serialize, Deserialize, Copy, Clone, Debug)]
pub struct DivePlan {
pub depth: u16,
pub bottom_time: u16,
pub surface_interval_time: u16,
pub next_dive_depth: u16,
}
impl Dive {
pub fn new(depth: u16, bottom_time: u16) -> Self {
Self {
depth,
bottom_time,
}
}
pub fn no_decompression_limit(self) -> u16 {
let mut ndl: u16 = 0;
if self.depth > 190 {
return ndl;
}
let nodeco_table = airtables::nodeco_table()
.expect("Error serializing the data within the table nodeco_table");
for row in nodeco_table.table_data.iter() {
if row.min_fsw <= self.depth && self.depth <= row.max_fsw {
ndl = row.no_stop_limit
}
}
return ndl;
}
pub fn group_letter(self) -> String {
let mut gl: String = String::from("");
let nodeco_table = airtables::nodeco_table()
.expect("Error serializing the data within the deco_table");
for row in nodeco_table.table_data.iter() {
if row.min_fsw <= self.depth && self.depth <= row.max_fsw {
for value in row.values.iter() {
if value.min_time <= self.bottom_time && self.bottom_time <= value.max_time {
gl = String::from(&value.group_letter);
}
}
}
}
if gl == String::from("") && self.depth > 0 && self.depth <= 10 && self.bottom_time > 462 {
gl = String::from("F")
} else if gl == String::from("") && self.depth > 10 && self.depth <= 15 && self.bottom_time > 449 {
gl = String::from("I")
} else if gl == String::from("") && self.depth > 15 && self.depth <= 20 && self.bottom_time > 461 {
gl = String::from("L")
}
if gl == String::from("") && self.depth <= 190 {
gl = String::from("this dive is out of the time range for no-decompression air dives")
} else if gl == String::from("") && self.depth > 190 {
gl = String::from("this dive is out of the depth range for no-decompression air dives")
}
return gl;
}
pub fn deco_dive(self) -> airtables::RowDeco {
let deco_table = airtables::deco_table()
.expect("Error deserializing no decompression table");
let mut deco_profile: airtables::RowDeco = airtables::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 <= self.depth && self.depth <= row_deco.max_fsw {
for profile in row_deco.rows.iter() {
if profile.min_time <= self.bottom_time && profile.max_time <= self.bottom_time {
deco_profile = profile.clone()
}
}
}
}
return deco_profile;
}
}
impl DivePlan {
pub fn new(depth: u16, bottom_time: u16, surface_interval_time: u16, next_dive_depth: u16) -> Self {
Self {
depth,
bottom_time,
surface_interval_time,
next_dive_depth,
}
}
pub fn from_dive(dive: Dive, surface_interval_time: u16, next_dive_depth: u16) -> Self {
Self {
depth: dive.depth,
bottom_time: dive.bottom_time,
surface_interval_time,
next_dive_depth,
}
}
pub fn no_decompression_limit(self) -> u16 {
let mut ndl: u16 = 0;
if self.depth > 190 {
return ndl;
}
let nodeco_table = airtables::nodeco_table()
.expect("Error serializing the data withthe table deco_table");
for row in nodeco_table.table_data.iter() {
if row.min_fsw <= self.depth && self.depth <= row.max_fsw {
ndl = row.no_stop_limit
}
}
return ndl;
}
pub fn group_letter(self) -> String {
let mut gl: String = String::from("");
let nodeco_table = airtables::nodeco_table()
.expect("Error serializing the data within the deco_table");
for row in nodeco_table.table_data.iter() {
if row.min_fsw <= self.depth && self.depth <= row.max_fsw {
for value in row.values.iter() {
if value.min_time <= self.bottom_time && self.bottom_time <= value.max_time {
gl = String::from(&value.group_letter);
}
}
}
}
if gl == String::from("") && self.depth > 0 && self.depth <= 10 && self.bottom_time > 462 {
gl = String::from("F")
} else if gl == String::from("") && self.depth > 10 && self.depth <= 15 && self.bottom_time > 449 {
gl = String::from("I")
} else if gl == String::from("") && self.depth > 15 && self.depth <= 20 && self.bottom_time > 461 {
gl = String::from("L")
}
if gl == String::from("") && self.depth <= 190 {
gl = String::from("this dive is out of the time range for no-decompression air dives")
} else if gl == String::from("") && self.depth > 190 {
gl = String::from("this dive is out of the depth range for no-decompression air dives")
}
return gl;
}
pub fn repet_letter(self) -> String {
let nodeco_table = airtables::nodeco_table()
.expect("Error serializing the data within the deco_table");
let rgl_table = airtables::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 <= self.depth && self.depth <= row.max_fsw {
for group in row.values.iter() {
if group.min_time <= self.bottom_time && self.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 <= self.surface_interval_time && self.surface_interval_time <= rgl_row.max_time {
rl = String::from(&rgl_row.repet_letter)
}
}
}
}
}
}
return rl;
}
pub fn residual_nitrogen_time(self) -> u16 {
let nodeco_table = airtables::nodeco_table()
.expect("Error deserializing no decompression table");
let rgl_table = airtables::rgl_table()
.expect("Error deserializing repetitive group letter table");
let rnt_table = airtables::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 <= self.depth && self.depth <= row.max_fsw {
for group in row.values.iter() {
if group.min_time <= self.bottom_time && self.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 <= self.surface_interval_time && self.surface_interval_time <= 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 <= self.next_dive_depth && self.next_dive_depth <= element.max_depth {
rnt = element.rnt
}
}
}
}
}
}
}
}
}
}
return rnt;
}
}