func main() { JsonObj := []byte(`{"Age":22, "Retirement_age":65, "Terminal_age":90, "Effective_tax_rate":0.3, "Returns_tax_rate":0.3, "N": 20000, "Non_Taxable_contribution":17500, "Taxable_contribution": 0, "Non_Taxable_balance":0, "Taxable_balance": 0, "Yearly_social_security_income":0, "Asset_volatility": 0.15, "Expected_rate_of_return": 0.07, "Inflation_rate":0.035}`) rc := retcalc.NewRetCalcFromJSON(JsonObj) a := rc.RunIncomes() fmt.Println(analytics.HistoCumulative(a, 200)) }
func TestConstructors(t *testing.T) { JsonObj := []byte(`{"Age":22, "Retirement_age":65, "Terminal_age":90, "Effective_tax_rate":0.3, "Returns_tax_rate":0.3, "N": 20000, "Non_Taxable_contribution":17500, "Taxable_contribution": 0, "Non_Taxable_balance":0, "Taxable_balance": 0, "Yearly_social_security_income":0, "Asset_volatility": 0.15, "Expected_rate_of_return": 0.07, "Inflation_rate":0.035}`) rc, err := retcalc.NewRetCalcFromJSON(JsonObj) if err != nil { t.Error(err) } fmt.Println(rc.IncomeOnPath(0)) }
func RecalcFromWebInput(w http.ResponseWriter, r *http.Request) error { defer r.Body.Close() body, _ := ioutil.ReadAll(r.Body) myRetCalc := retcalc.NewRetCalcFromJSON(body) fmt.Println() fmt.Println("POST request recieved - RecalcFromWebInput()") fmt.Printf("Recived: %s\n", string(body)) fmt.Println() incs := myRetCalc.RunIncomes() fmt.Println("RunIncomes() analystics:") fmt.Printf("Max: %f\n", analytics.MaxF64(incs)) fmt.Printf("Min: %f\n", analytics.MinF64(incs)) fmt.Printf("Avg: %f\n", analytics.AvgF64(incs)) myRetCalc.ShowRetCalc() //return json.NewEncoder(w).Encode(retcalc.HistoFromSlice(myRetCalc.RunIncomes())) return json.NewEncoder(w).Encode(analytics.HistoCumulative(myRetCalc.RunIncomes(), 250)) }