Minor refactoring. Deleted dead code. Commented unused code.

This commit is contained in:
scoobybejesus 2019-09-02 23:49:18 -04:00
parent bfa13f1aa0
commit 093224f779
7 changed files with 100 additions and 105 deletions

View File

@ -37,10 +37,10 @@ pub struct Account {
impl Account { impl Account {
pub fn is_home_currency(&self, compare: &String, raw_acct_map: &HashMap<u16, RawAccount>) -> bool { // pub fn is_home_currency(&self, compare: &String, raw_acct_map: &HashMap<u16, RawAccount>) -> bool {
let raw_acct = raw_acct_map.get(&self.raw_key).unwrap(); // let raw_acct = raw_acct_map.get(&self.raw_key).unwrap();
&raw_acct.ticker == compare // &raw_acct.ticker == compare
} // }
pub fn get_sum_of_amts_in_lots(&self) -> d128 { pub fn get_sum_of_amts_in_lots(&self) -> d128 {
let lots = self.list_of_lots.borrow(); let lots = self.list_of_lots.borrow();
@ -82,9 +82,11 @@ impl Lot {
self.movements.borrow().iter().for_each(|movement| amts += movement.amount); self.movements.borrow().iter().for_each(|movement| amts += movement.amount);
amts amts
} }
pub fn sum_of_amts_in_lot_is_zero(&self) -> bool {
d128!(0) == Self::get_sum_of_amts_in_lot(&self) // pub fn sum_of_amts_in_lot_is_zero(&self) -> bool {
} // d128!(0) == Self::get_sum_of_amts_in_lot(&self)
// }
pub fn get_sum_of_basis_in_lot(&self) -> d128 { pub fn get_sum_of_basis_in_lot(&self) -> d128 {
let mut amts = d128!(0); let mut amts = d128!(0);
self.movements.borrow().iter().for_each(|movement| amts += movement.cost_basis.get()); self.movements.borrow().iter().for_each(|movement| amts += movement.cost_basis.get());
@ -218,10 +220,10 @@ impl Movement {
} }
} }
pub fn direction(&self) -> Polarity { // pub fn direction(&self) -> Polarity {
if self.amount < d128!(0.0) { Polarity::Outgoing } // if self.amount < d128!(0.0) { Polarity::Outgoing }
else { Polarity::Incoming } // else { Polarity::Incoming }
} // }
} }
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]

View File

@ -171,20 +171,18 @@ pub fn inv_costing_from_cmd_arg(arg: String) -> Result<InventoryCostingMethod, &
pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> Result<(bool, String), Box<dyn Error>> { pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> Result<(bool, String), Box<dyn Error>> {
let election: bool; match cutoff_date_arg {
let date: String;
if cutoff_date_arg.is_some() { Some(cutoff_date_arg) => {
let provided_date = NaiveDate::parse_from_str(&cutoff_date_arg, "%y-%m-%d")
let provided_date = NaiveDate::parse_from_str(&cutoff_date_arg.clone().unwrap(), "%y-%m-%d") .unwrap_or(NaiveDate::parse_from_str(&cutoff_date_arg, "%Y-%m-%d")
.unwrap_or(NaiveDate::parse_from_str(&cutoff_date_arg.clone().unwrap(), "%Y-%m-%d")
.expect("Date entered as -c command line arg has an incorrect format.")); .expect("Date entered as -c command line arg has an incorrect format."));
println!("\nUse like-kind exchange treatment through {}? [Y/n/c] ('c' to 'change') ", provided_date); println!("\nUse like-kind exchange treatment through {}? [Y/n/c] ('c' to 'change') ", provided_date);
let (election, date) = _elect_like_kind_arg(&cutoff_date_arg, provided_date)?; let (election, date) = _elect_like_kind_arg(&cutoff_date_arg, provided_date)?;
fn _elect_like_kind_arg(cutoff_date_arg: &Option<String>, provided_date: NaiveDate) -> Result<(bool, String), Box<dyn Error>> { fn _elect_like_kind_arg(cutoff_date_arg: &String, provided_date: NaiveDate) -> Result<(bool, String), Box<dyn Error>> {
let mut input = String::new(); let mut input = String::new();
let stdin = io::stdin(); let stdin = io::stdin();
@ -194,9 +192,10 @@ pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> Result<(bo
match input.trim().to_ascii_lowercase().as_str() { match input.trim().to_ascii_lowercase().as_str() {
"y" | "ye" | "yes" | "" => { "y" | "ye" | "yes" | "" => {
println!(" Using like-kind treatment through {}.\n", provided_date); println!(" Using like-kind treatment through {}.\n", provided_date);
Ok( (true, cutoff_date_arg.clone().unwrap()) ) Ok( (true, cutoff_date_arg.to_string()) )
}, },
"n" | "no" => { println!(" Proceeding without like-kind treatment.\n"); "n" | "no" => {
println!(" Proceeding without like-kind treatment.\n");
Ok( (false, "1-1-1".to_string()) ) Ok( (false, "1-1-1".to_string()) )
}, },
"c" | "change" => { "c" | "change" => {
@ -223,9 +222,9 @@ pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> Result<(bo
} }
return Ok((election, date)) return Ok((election, date))
}
} else { None => {
println!("\nContinue without like-kind exchange treatment? [Y/n] "); println!("\nContinue without like-kind exchange treatment? [Y/n] ");
let (election, date) = _no_elect_like_kind_arg()?; let (election, date) = _no_elect_like_kind_arg()?;
@ -237,7 +236,8 @@ pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> Result<(bo
stdin.lock().read_line(&mut input)?; stdin.lock().read_line(&mut input)?;
match input.trim().to_ascii_lowercase().as_str() { match input.trim().to_ascii_lowercase().as_str() {
"y" | "ye" | "yes" | "" => { println!(" Proceeding without like-kind treatment.\n"); "y" | "ye" | "yes" | "" => {
println!(" Proceeding without like-kind treatment.\n");
Ok( (false, "1-1-1".to_string()) ) Ok( (false, "1-1-1".to_string()) )
}, },
"n" | "no" => { "n" | "no" => {
@ -263,4 +263,4 @@ pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> Result<(bo
return Ok((election, date)) return Ok((election, date))
} }
} }
}

View File

@ -94,8 +94,6 @@ pub fn import_and_process_final(
&mut rdr, &mut rdr,
transactions_map, transactions_map,
action_records, action_records,
raw_acct_map,
acct_map
)?; )?;
Ok(()) Ok(())

View File

@ -259,7 +259,7 @@ pub fn create_lots_and_movements(
fn get_lifo_by_creation_date(list_of_lots: &Ref<Vec<Rc<Lot>>>) -> Vec<usize> { fn get_lifo_by_creation_date(list_of_lots: &Ref<Vec<Rc<Lot>>>) -> Vec<usize> {
let mut vec_of_indexes = [].to_vec(); let mut vec_of_indexes = [].to_vec();
for (idx, lot) in list_of_lots.iter().enumerate() { for (idx, _lot) in list_of_lots.iter().enumerate() {
vec_of_indexes.insert(0, idx) vec_of_indexes.insert(0, idx)
} }
let vec = vec_of_indexes; let vec = vec_of_indexes;
@ -277,7 +277,7 @@ pub fn create_lots_and_movements(
} }
} }
let mut vec_of_indexes = [].to_vec(); let mut vec_of_indexes = [].to_vec();
for (idx, lot) in reordered_vec.iter().enumerate() { for (idx, _lot) in reordered_vec.iter().enumerate() {
vec_of_indexes.insert(0, idx) vec_of_indexes.insert(0, idx)
} }
let vec = vec_of_indexes; let vec = vec_of_indexes;
@ -286,7 +286,7 @@ pub fn create_lots_and_movements(
fn get_fifo_by_creation_date(list_of_lots: &Ref<Vec<Rc<Lot>>>) -> Vec<usize> { fn get_fifo_by_creation_date(list_of_lots: &Ref<Vec<Rc<Lot>>>) -> Vec<usize> {
let mut vec_of_indexes = [].to_vec(); let mut vec_of_indexes = [].to_vec();
for (idx, lot) in list_of_lots.iter().enumerate() { for (idx, _lot) in list_of_lots.iter().enumerate() {
vec_of_indexes.push(idx) vec_of_indexes.push(idx)
} }
let vec = vec_of_indexes; let vec = vec_of_indexes;
@ -304,7 +304,7 @@ pub fn create_lots_and_movements(
} }
} }
let mut vec_of_indexes = [].to_vec(); let mut vec_of_indexes = [].to_vec();
for (idx, lot) in reordered_vec.iter().enumerate() { for (idx, _lot) in reordered_vec.iter().enumerate() {
vec_of_indexes.push(idx) vec_of_indexes.push(idx)
} }
let vec = vec_of_indexes; let vec = vec_of_indexes;
@ -329,7 +329,6 @@ pub fn create_lots_and_movements(
}; };
fit_into_lots( fit_into_lots(
acct.raw_key,
txn_num, txn_num,
*ar_num, *ar_num,
whole_mvmt, whole_mvmt,
@ -649,7 +648,6 @@ fn wrap_mvmt_and_push(
} }
fn fit_into_lots( fn fit_into_lots(
acct_key: u16,
txn_num: u32, txn_num: u32,
spawning_ar_key: u32, spawning_ar_key: u32,
mvmt_to_fit: Movement, mvmt_to_fit: Movement,
@ -697,7 +695,6 @@ fn fit_into_lots(
proceeds: Cell::new(d128!(0.0)), proceeds: Cell::new(d128!(0.0)),
}; };
fit_into_lots( fit_into_lots(
acct.raw_key,
txn_num, txn_num,
spawning_ar_key, spawning_ar_key,
possible_mvmt_to_fit, possible_mvmt_to_fit,
@ -771,7 +768,6 @@ fn fit_into_lots(
}; };
assert!(current_index_position < vec_of_ordered_index_values.len()); assert!(current_index_position < vec_of_ordered_index_values.len());
fit_into_lots( fit_into_lots(
acct.raw_key,
txn_num, txn_num,
spawning_ar_key, spawning_ar_key,
remainder_mvmt_to_recurse, remainder_mvmt_to_recurse,

View File

@ -117,8 +117,6 @@ pub fn import_transactions(
rdr: &mut csv::Reader<File>, rdr: &mut csv::Reader<File>,
txns_map: &mut HashMap<u32, Transaction>, txns_map: &mut HashMap<u32, Transaction>,
action_records: &mut HashMap<u32, ActionRecord>, action_records: &mut HashMap<u32, ActionRecord>,
raw_acct_map: &mut HashMap<u16, RawAccount>,
acct_map: &mut HashMap<u16, Account>,
) -> Result<(), Box<dyn Error>> { ) -> Result<(), Box<dyn Error>> {
let mut this_tx_number = 0; let mut this_tx_number = 0;
@ -138,7 +136,7 @@ pub fn import_transactions(
let mut this_tx_date: &str = ""; let mut this_tx_date: &str = "";
let mut this_proceeds: &str = ""; let mut this_proceeds: &str = "";
let mut this_memo: &str = ""; let mut this_memo: &str = "";
let mut this: String = "".to_string(); let mut this: String;
// Next, create action_records. // Next, create action_records.
let mut action_records_map_keys_vec: Vec<u32> = [].to_vec(); let mut action_records_map_keys_vec: Vec<u32> = [].to_vec();

View File

@ -8,6 +8,7 @@ pub fn round_d128_generalized(to_round: &d128, places_past_decimal: d128) -> d12
let rounded: d128 = ((to_round * d128!(10).scaleb(places_past_decimal)).quantize(d128!(1e1))) / d128!(10).scaleb(places_past_decimal); let rounded: d128 = ((to_round * d128!(10).scaleb(places_past_decimal)).quantize(d128!(1e1))) / d128!(10).scaleb(places_past_decimal);
rounded//.reduce() rounded//.reduce()
} }
pub fn round_d128_1e2(to_round: &d128) -> d128 { pub fn round_d128_1e2(to_round: &d128) -> d128 {
let rounded: d128 = ((to_round * d128!(10).scaleb(d128!(2))).quantize(d128!(1e1))) / d128!(10).scaleb(d128!(2)); let rounded: d128 = ((to_round * d128!(10).scaleb(d128!(2))).quantize(d128!(1e1))) / d128!(10).scaleb(d128!(2));
rounded//.reduce() rounded//.reduce()

View File

@ -203,16 +203,16 @@ impl ActionRecord {
else { Polarity::Incoming } else { Polarity::Incoming }
} }
pub fn is_quote_acct_for_margin_exch( // pub fn is_quote_acct_for_margin_exch(
&self, // &self,
raw_accts: &HashMap<u16, RawAccount>, // raw_accts: &HashMap<u16, RawAccount>,
acct_map: &HashMap<u16, Account> // acct_map: &HashMap<u16, Account>
) -> bool { // ) -> bool {
let acct = acct_map.get(&self.account_key).unwrap(); // let acct = acct_map.get(&self.account_key).unwrap();
let raw_acct = raw_accts.get(&acct.raw_key).unwrap(); // let raw_acct = raw_accts.get(&acct.raw_key).unwrap();
raw_acct.ticker.contains('_') // raw_acct.ticker.contains('_')
} // }
pub fn get_mvmts_in_ar( pub fn get_mvmts_in_ar(
&self, &self,
@ -220,7 +220,7 @@ impl ActionRecord {
txns_map: &HashMap<u32, Transaction>, txns_map: &HashMap<u32, Transaction>,
) -> Vec<Rc<Movement>> { ) -> Vec<Rc<Movement>> {
let polarity = Self::direction(self); // let polarity = Self::direction(self);
let txn = txns_map.get(&self.tx_key).unwrap(); let txn = txns_map.get(&self.tx_key).unwrap();
let mut movements_in_ar = [].to_vec(); let mut movements_in_ar = [].to_vec();
let acct = acct_map.get(&self.account_key).unwrap(); let acct = acct_map.get(&self.account_key).unwrap();