Ejemplo n.º 1
0
// Builds a histogram from a []float64 slice :)
func HistoFromSlice(slice []float64) *plotter.Histogram {
	fmt.Println("HistoFromSlice() call - slice analytics:")
	fmt.Printf("Max: %f\n", analytics.MaxF64(slice))
	fmt.Printf("Min: %f\n", analytics.MinF64(slice))
	fmt.Printf("Avg: %f\n", analytics.AvgF64(slice))

	v := make(plotter.Values, len(slice))
	for i := range v {
		v[i] = slice[i]
	}
	h, err := plotter.NewHist(v, 150)
	if err != nil {
		panic(err)
	}
	return h
}
Ejemplo n.º 2
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))
}