예제 #1
0
func regroupFromDatastore01(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

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

	var vVSrc [][]byte

	if util_appengine.IsLocalEnviron() {
		vVSrc = bq_statified_res1
	} else {
		dsObj1, _ := dsu.BufGet(w, r, "dsu.WrapBlob__bq_res1")
		vVSrc = dsObj1.VVByte
	}

	if r.FormValue("mock") == "1" {
		dsObj1, _ := dsu.BufGet(w, r, "dsu.WrapBlob__bq_res_test")
		vVSrc = dsObj1.VVByte
	}

	var vVDest [][]byte = make([][]byte, len(vVSrc))

	for i0 := 0; i0 < len(vVSrc); i0++ {

		s_row := string(vVSrc[i0])
		v_row := util.SplitByWhitespace(s_row)
		b_row := new(bytes.Buffer)

		b_row.WriteString(fmt.Sprintf("%16.12s   ", v_row[3])) // leading spaces
		b_row.WriteString(fmt.Sprintf("%16.12s   ", v_row[5]))
		b_row.WriteString(fmt.Sprintf("%16.8s", v_row[7]))

		vVDest[i0] = []byte(b_row.Bytes())

	}

	key_combi, _ := dsu.BufPut(w, r, dsu.WrapBlob{Name: "res_processed_01", S: "[][]byte", VVByte: vVDest}, "res_processed_01")
	dsObj2, _ := dsu.BufGet(w, r, key_combi)

	printPlaintextTable(w, r, dsObj2.VVByte)

}
예제 #2
0
func regroupFromDatastore02(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

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

	var vVSrc [][]byte
	dsObj1, err := dsu.BufGet(w, r, "dsu.WrapBlob__res_processed_01")
	util_err.Err_http(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 := util.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 := util.StringKeysToSortedArray(distinctPeriods)
	sortedLangs := util.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)
		}
	*/

}