Пример #1
0
//数据库read操作
func pid3(cmd *common.RequestData, c *online.Client) {
	if checkParamError(cmd, c, "Id", "Param") {
		return
	}
	id := cmd.GetString("Id")
	m := make(map[string]interface{})
	col, rows, err := rpc.BySqlParamName(id, m)
	if err != nil {
		log.Error(err.Error())
		writePrror("db error", cmd, c)
		return
	}
	dp := new(common.OutputParam)
	dp.RowMap = col
	dp.Rows = rows
	dp.Time = time.Now()
	writepid(c, cmd, 0, dp)
}
Пример #2
0
//时间线,单指标,单网元
//查询一段时间内指定网元,某指标的走势
func GetTimeLineData(dp *common.DataParam, t time.Time) *common.OutputParam {
	tmp := []*common.DataRow{}
	//log.Info("timeline @", dp.Id, t)
	period := 1
	if p, ok := cache.Get(cache.FormatKey("System", "Period", dp.DataKey)); ok {
		period = compute.AsInt(p)
	}
	for i := 0; i < dp.TimeRange; i++ { //取出所有的数据
		tmpTime := t.Add(time.Minute * time.Duration(-i))
		//		key := cache.FormatKey(tmpTime.Format(common.GetTimeFormat(period)), dp.DataKey, dp.LimitId[0])
		//log.Info("search key is ", key)
		if r, ok := cache.GetDataRow(dp.DataKey, tmpTime.Format(common.GetTimeFormat(period)), dp.LimitId[0]); ok {
			tmp = append(tmp, r)
			//log.Infoln("find cache", r.Row)
		}
	}
	//log.Info("result1")
	//排序
	sort.Sort(common.ByTime{tmp})
	//log.Info("result2")
	result := new(common.OutputParam)
	if len(tmp) > 0 {
		result.RowMap = make(map[string]int)
		for i, k := range dp.OutputKey {
			result.RowMap[k] = i
		}
		result.Time = t
	}
	//log.Info("result3")
	//限制输出
	//start := 0
	//if len(tmp) >= dp.DataRange {
	//	start = len(tmp) - dp.DataRange
	//}
	//for i := start; i < len(tmp); i++ {
	//	result.Rows = append(result.Rows, createRow(dp, tmp[i]))
	//}
	for _, r := range tmp {
		result.Rows = append(result.Rows, createRow(dp, r))
	}
	//log.Info("result")
	return result
}
Пример #3
0
//单时间点,单指标,多网元
//主要查多个网元指定时间的排序
func GetOrderData(dp *common.DataParam, t time.Time) *common.OutputParam {
	tmp := []*common.DataRow{}
	period := 1
	if p, ok := cache.Get(cache.FormatKey("System", "Period", dp.DataKey)); ok {
		period = compute.AsInt(p)
	}
	//	limit := []string{}
	if len(dp.LimitNodeId) > 0 { //双重限制,与LimitId同时起作用

	} else {
		for _, v := range dp.LimitId { //取出所有的数据
			//			key := cache.FormatKey(t.Format(common.GetTimeFormat(period)), dp.DataKey, v)
			if r, ok := cache.GetDataRow(dp.DataKey, t.Format(common.GetTimeFormat(period)), v); ok { //都是最新一个时间点的,都在内存
				tmp = append(tmp, r)
			}
		}
	}
	//排序
	sort.Sort(common.ByKey{tmp, dp.OrderKey})
	//限制输出
	result := new(common.OutputParam)
	if len(tmp) > 0 {
		result.RowMap = make(map[string]int)
		for i, k := range dp.OutputKey {
			result.RowMap[k] = i
		}
		result.Time = time.Now()
	}
	if dp.OrderBy == common.Desc {
		for i := len(tmp); i > 0 && i > len(tmp)-dp.DataRange; i-- {
			result.Rows = append(result.Rows, createRow(dp, tmp[i-1]))
		}
	} else {
		for i := 0; i < len(tmp) && i < dp.DataRange; i++ {
			result.Rows = append(result.Rows, createRow(dp, tmp[i]))
		}
	}
	return result
}
Пример #4
0
//单时间点,多指标,单网元
//取一个网元指定时间的多指标,主要用于查询某网元的详细指标
func GetColumnsData(dp *common.DataParam, t time.Time) *common.OutputParam {
	tmp := []*common.DataRow{}
	period := 1
	if p, ok := cache.Get(cache.FormatKey("System", "Period", dp.DataKey)); ok {
		period = compute.AsInt(p)
	}
	//key := cache.FormatKey(t.Format(common.GetTimeFormat(period)), dp.DataKey, dp.LimitId[0])
	//log.Info("id=%s", key)
	if r, ok := cache.GetDataRow(dp.DataKey, t.Format(common.GetTimeFormat(period)), dp.LimitId[0]); ok {
		tmp = append(tmp, r)
	}

	//限制输出
	result := new(common.OutputParam)
	if len(tmp) > 0 {
		result.RowMap = make(map[string]int)
		for i, k := range dp.OutputKey {
			result.RowMap[k] = i
		}
		result.Time = time.Now()
		result.Rows = append(result.Rows, createRow(dp, tmp[0]))
	}
	return result
}