From b2f8ba568768a5cddcd8e23f98eb35d45af4af14 Mon Sep 17 00:00:00 2001 From: wangshuai Date: Thu, 15 Apr 2021 08:40:15 +0800 Subject: [PATCH] 'commit' --- dsDataexV1.1/Config/Config.ini | 6 ++- .../GPSql/GPSqlService/GPSqlService.go | 46 +++++++++++++++++++ dsDataexV1.1/Utils/ConfigUtil/ConfigUtil.go | 11 +++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/dsDataexV1.1/Config/Config.ini b/dsDataexV1.1/Config/Config.ini index c030de94..ba8df472 100644 --- a/dsDataexV1.1/Config/Config.ini +++ b/dsDataexV1.1/Config/Config.ini @@ -34,7 +34,6 @@ replication = 1 process_no = 1 enable = 1 - [elasticsearch] nodes = http://10.10.14.61:9200,http://10.10.14.62:9200,http://10.10.14.63:9200 user = root @@ -49,6 +48,11 @@ user = root pwd = DsideaL147258369 enable = 1 +[gpsql] +is_rand_data_num = 0 +rand_range_min = 0.8 +rand_range_max = 1 + [project] project_name = dsDataex project_port = 9009 diff --git a/dsDataexV1.1/MyReport/GPSql/GPSqlService/GPSqlService.go b/dsDataexV1.1/MyReport/GPSql/GPSqlService/GPSqlService.go index 7dd8a6a7..7dc50fa8 100644 --- a/dsDataexV1.1/MyReport/GPSql/GPSqlService/GPSqlService.go +++ b/dsDataexV1.1/MyReport/GPSql/GPSqlService/GPSqlService.go @@ -2,11 +2,15 @@ package GPSqlService import ( "dsDataex/MyReport/GPSql/GPSqlDAO" + "dsDataex/Utils/ConfigUtil" "dsDataex/Utils/ES7SqlUtil" "dsDataex/Utils/GPUtil" "encoding/json" + "fmt" + "math/rand" "reflect" "strconv" + "time" ) /** @@ -208,6 +212,26 @@ func ConvEcharts(result []map[string]interface{}, queryGroup []string, queryCoun } } + // 生成0.8~1随机数, 与data相乘 + // Start + if ConfigUtil.GPSQLIsRandDataNum == 1 { + rand.Seed(time.Now().UnixNano()) + randRangeMin := int((1 - ConfigUtil.GPSQLRandRangeMin) * 100) + randRangeMax := int(ConfigUtil.GPSQLRandRangeMax * 100) + randInt := rand.Intn(randRangeMax - randRangeMin) + randFloat := float64(randInt) / 100 + + for key, value := range data { + f, _ := strconv.ParseFloat(value,64) + r := f * randFloat + val, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", r), 64) + s := strconv.FormatFloat(val,'f',-1,64) + + data[key] = s + } + } + // End + echarts.Groups = append(echarts.Groups, group) echarts.Datas = append(echarts.Datas, data) echarts.Datas2 = append(echarts.Datas2, data2) @@ -465,6 +489,28 @@ func ConvEcharts(result []map[string]interface{}, queryGroup []string, queryCoun } } + // 生成0.8~1随机数, 与data相乘 + // Start + if ConfigUtil.GPSQLIsRandDataNum == 1 { + rand.Seed(time.Now().UnixNano()) + randRangeMin := int((1 - ConfigUtil.GPSQLRandRangeMin) * 100) + randRangeMax := int(ConfigUtil.GPSQLRandRangeMax * 100) + randInt := rand.Intn(randRangeMax - randRangeMin) + randFloat := float64(randInt) / 100 + + for key, value := range datas { + for k , v := range value { + f, _ := strconv.ParseFloat(v,64) + r := f * randFloat + val, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", r), 64) + s := strconv.FormatFloat(val,'f',-1,64) + + datas[key][k] = s + } + } + } + // End + echarts.Datas = datas if total2Index > -1 { echarts.Datas2 = datas2 diff --git a/dsDataexV1.1/Utils/ConfigUtil/ConfigUtil.go b/dsDataexV1.1/Utils/ConfigUtil/ConfigUtil.go index 34f69e4d..c73c8d43 100644 --- a/dsDataexV1.1/Utils/ConfigUtil/ConfigUtil.go +++ b/dsDataexV1.1/Utils/ConfigUtil/ConfigUtil.go @@ -23,6 +23,11 @@ var ( GreenPlumDataBase string GreenPlumEnable int64 + // GP-SQL配置 + GPSQLIsRandDataNum int64 + GPSQLRandRangeMin float64 + GPSQLRandRangeMax float64 + //要发布到的主机信息 DistributeIp string DistributePort int32 @@ -128,6 +133,12 @@ func init() { // 是否启用 GreenPlumEnable = iniParser.GetInt64("greenplum", "enable") + // 是否启用随机数 + GPSQLIsRandDataNum = iniParser.GetInt64("gpsql", "is_rand_data_num") + // 随机数乘以的系数 + GPSQLRandRangeMin = iniParser.GetFloat64("gpsql", "rand_range_min") + GPSQLRandRangeMax = iniParser.GetFloat64("gpsql", "rand_range_max") + //发布的远端IP DistributeIp = iniParser.GetString("distribute", "ip") //发布的远端端口