Ejemplo n.º 1
0
//回填
func getFillValue(fillKey string, r *common.DataRow, k string) interface{} {
	if len(fillKey) > 0 {
		key := cache.FormatKey(fillKey, r.GetKey(fillKey), k)
		//	log.Infoln("key is ", key)
		if tv, ok := cache.Get(key); ok {
			return tv
		}
	}
	return nil
}
Ejemplo n.º 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
}
Ejemplo n.º 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
}
Ejemplo n.º 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
}