1use std::fmt::Debug;
4use std::fmt;
5use colored::*;
6
7
8#[allow(unused_imports)]
10use crate::*;
11
12#[derive(Debug, Clone)]
14pub enum ConvertRateVariable {
15 Apr,
16 Ear,
17 Epr,
18 AprContinuous,
19 EarContinuous
20}
21impl ConvertRateVariable {
22 pub fn is_apr(&self) -> bool {
23 match self {
24 ConvertRateVariable::Apr => true,
25 _ => false,
26 }
27 }
28 pub fn is_epr(&self) -> bool {
29 match self {
30 ConvertRateVariable::Epr => true,
31 _ => false,
32 }
33 }
34 pub fn is_ear(&self) -> bool {
35 match self {
36 ConvertRateVariable::Ear => true,
37 _ => false,
38 }
39 }
40 pub fn is_apr_continuous(&self) -> bool {
41 match self {
42 ConvertRateVariable::AprContinuous => true,
43 _ => false,
44 }
45 }
46 pub fn is_ear_continuous(&self) -> bool {
47 match self {
48 ConvertRateVariable::EarContinuous => true,
49 _ => false,
50 }
51 }
52}
53impl fmt::Display for ConvertRateVariable {
54 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
55 match *self {
56 ConvertRateVariable::Apr => write!(f, "Apr"),
57 ConvertRateVariable::Epr => write!(f, "Epr"),
58 ConvertRateVariable::Ear => write!(f, "Ear"),
59 ConvertRateVariable::AprContinuous => write!(f, "AprContinuous"),
60 ConvertRateVariable::EarContinuous => write!(f, "EarContinuous"),
61 }
62 }
63}
64
65pub struct ConvertRateSolution {
67 input_name: ConvertRateVariable,
68 input_rate: f64,
69 compounds_per_year: u32,
70 apr_in_percent: String,
71 epr_in_percent: String,
72 ear_in_percent: String,
73 apr: f64,
74 epr: f64,
75 ear: f64,
76 apr_formula: String,
77 epr_formula: String,
78 ear_formula: String,
79}
80impl ConvertRateSolution {
81 pub fn new(input_name: ConvertRateVariable, input_rate: f64, compounds_per_year: u32, apr_in_percent: String, epr_in_percent: String, ear_in_percent: String, apr:f64, epr:f64, ear:f64, apr_formula: &str, epr_formula: &str, ear_formula: &str) -> Self {
82 Self {
83 input_name,
84 input_rate,
85 compounds_per_year,
86 apr_in_percent,
87 epr_in_percent,
88 ear_in_percent,
89 apr,
90 epr,
91 ear,
92 apr_formula: apr_formula.to_string(),
93 epr_formula: epr_formula.to_string(),
94 ear_formula: ear_formula.to_string(),
95 }
96 }
97
98 pub fn input_rate(&self) -> f64 {
100 self.input_rate
101 }
102 pub fn apr(&self) -> f64 {
104 self.apr
105 }
106 pub fn epr(&self) -> f64 {
108 self.epr
109 }
110 pub fn ear(&self) -> f64 {
112 self.ear
113 }
114 pub fn input_name(&self) -> &ConvertRateVariable {
116 &self.input_name
117 }
118 pub fn compounds_per_year(&self) -> u32 {
120 self.compounds_per_year
121 }
122 pub fn apr_in_percent(&self) -> &String {
124 &self.apr_in_percent
125 }
126 pub fn ear_in_percent(&self) -> &String {
128 &self.ear_in_percent
129 }
130 pub fn epr_in_percent(&self) -> &String {
132 &self.epr_in_percent
133 }
134}
135
136
137impl Debug for ConvertRateSolution {
138 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
139 write!(f, "{{\n {},\n {},\n {},\n {}\n {}\n {}\n {}\n {}\n {}\n {}\n {}\n {}\n}}",
140 &format!("input_name: {}", self.input_name.to_string().magenta()),
141 &format!("input_rate: {}", self.input_rate.to_string().yellow()),
142 &format!("compounds_per_year: {:.4}", self.compounds_per_year.to_string().yellow()),
143 &format!("apr_in_percent: {:.6}%", self.apr_in_percent),
144 &format!("epr_in_percent: {:.6}%", self.epr_in_percent),
145 &format!("ear_in_percent: {:.6}%", self.ear_in_percent),
146 &format!("apr: {}", self.apr),
147 &format!("epr: {}", self.epr),
148 &format!("ear: {}", self.ear),
149 &format!("apr_formula: {}", self.apr_formula),
150 &format!("epr_formula: {}", self.epr_formula),
151 &format!("ear_formula: {}", self.ear_formula),
152 )
153 }
154}