コード例 #1
0
ファイル: scales.go プロジェクト: mehulsbhatt/tools-old
func test(w http.ResponseWriter, r *http.Request) {

	w.Header().Set("Content-Type", "text/html")

	//fmt.Fprint(w,  util.PrintMap(util.Map_example_right))

	// vector max values
	vMaxVal := []float64{5555.0094, 9400, 0.0094, 1.0, 110.94, 120, 0.00001233}

	scale_test := Scale_x_vm
	for _, mv := range vMaxVal {
		optScale, _, _ := BestScale(mv, scale_test)

		floatFormat, exp := practicalFormat(mv)

		funcSpanner := util.GetSpanner()

		fmt.Fprintf(w, "optimal scale for "+floatFormat+" (exp %d) is <br>", mv, exp)
		for tick, val := range optScale {
			dis1 := fmt.Sprint(tick)
			dis2 := fmt.Sprintf("%s<br>", val)

			next_idx := tick + 1
			if next_idx > len(optScale)-1 {
				next_idx = len(optScale) - 1
			}
			if util.Stof(val) <= mv && mv <= util.Stof(optScale[next_idx]) {
				dis2 = fmt.Sprintf("<b>%s</b> <br>", val)
			}
			//dis4a :=  fmt.Sprintf(" %f <=  "+floatFormat+" &&   "+floatFormat+" < %f<br>",	  util.Stof(val),mv,mv, util.Stof(optScale[next_idx]) )
			//fmt.Fprintf(w,funcSpanner(dis4a,433)	)

			fmt.Fprintf(w, funcSpanner(" ", 64))
			fmt.Fprintf(w, funcSpanner(dis1, 120))
			fmt.Fprintf(w, funcSpanner(dis2, 233))
			fmt.Fprintf(w, "<br>")

		}
		//fmt.Fprintf(w,"key %v -  pot %v <br> %v",key,pot,msg)

		fmt.Fprintf(w, "<br>")
	}

	fmt.Fprintf(w, printScale(Scale_y_vm))
	fmt.Fprintf(w, printScale(Scale_x_vm))

}
コード例 #2
0
ファイル: get_data.go プロジェクト: aarzilli/tools
func regroupFromDatastore02(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	c := appengine.NewContext(r)

	b1 := new(bytes.Buffer)
	defer func() {
		w.Header().Set("Content-Type", "text/html")
		w.Write(b1.Bytes())
	}()

	var vVSrc [][]byte
	dsObj1, err := dsu.BufGet(c, "dsu.WrapBlob__res_processed_01")
	loghttp.E(w, r, err, false)
	vVSrc = dsObj1.VVByte

	d := make(map[string]map[string]float64)

	distinctLangs := make(map[string]interface{})
	distinctPeriods := make(map[string]interface{})
	f_max := 0.0
	for i0 := 0; i0 < len(vVSrc); i0++ {
		//vVDest[i0] = []byte( b_row.Bytes() )
		s_row := string(vVSrc[i0])
		v_row := stringspb.SplitByWhitespace(s_row)

		lang := v_row[0]
		period := v_row[1]
		count := v_row[2]
		fCount := util.Stof(count)
		if fCount > f_max {
			f_max = fCount
		}

		distinctLangs[lang] = 1
		distinctPeriods[period] = 1

		if _, ok := d[period]; !ok {
			d[period] = map[string]float64{}
		}
		d[period][lang] = fCount

	}
	//fmt.Fprintf(w,"%#v\n",d2)
	//fmt.Fprintf(w,"%#v\n",f_max)

	sortedPeriods := sortmap.StringKeysToSortedArray(distinctPeriods)
	sortedLangs := sortmap.StringKeysToSortedArray(distinctLangs)

	cd := CData{}
	_ = cd

	cd.M = d
	cd.VPeriods = sortedPeriods
	cd.VLangs = sortedLangs
	cd.F_max = f_max

	SaveChartDataToDatastore(w, r, cd, "chart_data_01")

	/*
		if r.FormValue("f") == "table" {
			showAsTable(w,r,cd)
		} else {
			showAsChart(w,r,cd)
		}
	*/

}
コード例 #3
0
func showAsChart(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	cd1 := GetChartDataFromDatastore(w, r, "chart_data_01")
	cd := *cd1

	c := appengine.NewContext(r)

	optScale, _, _ := charting.BestScale(cd.F_max, charting.Scale_y_vm)
	scale_max := 0.0
	for _, val := range optScale {
		//fmt.Fprintf(w,"%v - %v \n", tick, val)
		fVal := util.Stof(val)
		if fVal > scale_max {
			scale_max = fVal
		}
	}

	p := r.FormValue("p")
	if p == "" {
		p = "static/chartbg_400x960__480x1040__12x10.png"
	}

	f, err := os.Open(p)
	loghttp.E(w, r, err, false)
	defer f.Close()

	imgRaw, whichFormat, err := image.Decode(f)
	loghttp.E(w, r, err, false, "only jpeg and png are 'activated' ")
	c.Infof("serving img format %v %T\n", whichFormat, imgRaw)

	var img *image.RGBA
	img, ok := imgRaw.(*image.RGBA)
	loghttp.E(w, r, ok, false, "chart bg must have interal format RGBA")

	for langIndex, lang := range cd.VLangs {

		gci := langIndex % len(colors.GraphColors) // graph color index

		lineCol := color.RGBA{colors.GraphColors[gci][0],
			colors.GraphColors[gci][1],
			colors.GraphColors[gci][2],
			0,
		}

		//fmt.Fprintf(w,"%v %v \n",gci,lineCol)

		drw := charting.FuncDrawLiner(lineCol, img)
		xb, yb := 40, 440
		//P0 := image.Point{xb,yb}
		//drw( P0, lineCol,img )

		x, y := xb, yb

		maxPeriods := 0
		for _, period := range cd.VPeriods {

			tmp := cd.M[period][lang] / scale_max * 400
			y = yb - int(tmp)

			drw(image.Point{x, y}, lineCol, img)
			//fmt.Fprintf(w,"%v-%v: %v => %v => %v\n",period, lang,count,int(tmp),y)
			x += 40

			maxPeriods++
			if maxPeriods > 24 {
				break
			}
		}
	}

	w.Header().Set("Content-Type", "image/png")
	png.Encode(w, img)

	charting.SaveImageToDatastore(w, r, img, "chart2")

}