Example #1
0
func calcScheduleResult(schedule_int_info map[string]int, schedule_string_info map[string]string) {
	predict1_json := make(map[string]interface{})
	predict2_json := make(map[string]interface{})

	sql1 := "select predict1_result,count(*) as predict1_cnt from `pk_asia_pan_log` where schedule_date = ? and schedule_no=? group by predict1_result"
	res_map, _ := myinit.Engine.Query(sql1, schedule_string_info["schedule_date"], schedule_string_info["schedule_no"])

	for _, row := range res_map {
		json_key := ""
		json_val := ""
		for colName, colValue := range row {

			value := common.BytesToString(colValue)
			fmt.Println("colName")
			fmt.Println(colName)
			fmt.Println("value")
			fmt.Println(value)
			if colName == "predict1_result" {
				json_key = value
			}
			if colName == "predict1_cnt" {
				json_val = value
			}
		}
		predict1_json[json_key] = json_val

	}

	sql2 := "select predict2_result,count(*) as predict2_cnt from `pk_asia_pan_log` where schedule_date = ? and schedule_no=? group by predict2_result"
	res2_map, _ := myinit.Engine.Query(sql2, schedule_string_info["schedule_date"], schedule_string_info["schedule_no"])

	for _, row2 := range res2_map {
		json_key2 := ""
		json_val2 := ""
		for colName2, colValue2 := range row2 {

			value2 := common.BytesToString(colValue2)
			if colName2 == "predict2_result" {
				json_key2 = value2
			}
			if colName2 == "predict2_cnt" {
				json_val2 = value2
			}
		}
		predict2_json[json_key2] = json_val2

	}

	//		predict1_string, _ := json.Marshal(predict1_json)
	//		fmt.Println(string(predict1_string))

	//		predict2_string, _ := json.Marshal(predict2_json)
	//		fmt.Println(string(predict2_string))

	predict_json := make(map[string]interface{})
	predict_json["predict1"] = predict1_json
	predict_json["predict2"] = predict2_json

	predict_json_string, _ := json.Marshal(predict_json)

	exist_schedule := new(myinit.Schedule)
	exist_schedule.ScheduleAlResult = string(predict_json_string)
	update_affected, update_err :=
		myinit.Engine.Cols("schedule_al_result").
			Where("schedule_fenxi_id=? AND schedule_date = ? and schedule_no=? ", schedule_int_info["schedule_fenxi_id"], schedule_string_info["schedule_date"], schedule_string_info["schedule_no"]).Update(exist_schedule)

	fmt.Println(update_affected)
	fmt.Println(update_err)
}