Roc vor 1 Jahr
Ursprung
Commit
2c8c6f922e

+ 0 - 107
models/data_manage/line_feature/request/line_feature.go

@@ -1,107 +0,0 @@
-package request
-
-// SaveMultipleGraphConfigReq 多图配置请求
-type SaveMultipleGraphConfigReq struct {
-	MultipleGraphConfigId int                   `description:"配置id"`
-	EdbInfoId             int                   `description:"指标"`
-	Curve                 CurveConfig           `description:"曲线图配置"`
-	StandardDeviation     StandardDeviation     `description:"标准差配置"`
-	Percentile            Percentile            `description:"百分位配置"`
-	FrequencyDistribution FrequencyDistribution `description:"频率分布配置"`
-}
-
-// ConfigSave 数据库保存
-type ConfigSave struct {
-	Curve                 CurveConfig           `description:"曲线图配置"`
-	StandardDeviation     StandardDeviation     `description:"标准差配置"`
-	Percentile            Percentile            `description:"百分位配置"`
-	FrequencyDistribution FrequencyDistribution `description:"频率分布配置"`
-}
-
-// CurveConfig 曲线图配置
-type CurveConfig struct {
-	DateType  int     `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
-	StartDate string  `description:"自定义开始日期"`
-	EndDate   string  `description:"自定义结束日期"`
-	LeftMin   float64 `description:"图表左侧最小值"`
-	LeftMax   float64 `description:"图表左侧最大值"`
-}
-
-type StandardDeviation struct {
-	CalculateValue int `description:"滚动期数"`
-}
-
-type Percentile struct {
-	CalculateValue int    `description:"时间长度期数"`
-	CalculateUnit  string `description:"时间长度频度"`
-}
-
-type FrequencyDistribution struct {
-	//最近3月 最近6月 最近1年 最近2年 最近3年 最近5年 最近10年
-	DateType       int    `description:"日期类型:1:最近3月;2:最近6月;3:最近1年;4:最近2年;5:最近3年;6:最近5年;7:最近10年,8:自定义时间"`
-	StartDate      string `description:"自定义开始日期"`
-	EndDate        string `description:"自定义结束日期"`
-	FrequencyValue int    `description:"频段数,10/20"`
-}
-
-// LineChartInfoReq 线性拟合图表预览请求数据
-type LineChartInfoReq struct {
-	DateType       int    `description:"日期类型"`
-	StartDate      string `description:"开始日期"`
-	EndDate        string `description:"结束日期"`
-	XEdbInfoIdList []int  `description:"X轴的指标id列表"`
-	YEdbInfoIdList []int  `description:"Y轴的指标id列表"`
-	Source         int    `description:"来源,1:曲线图,8:标准差图表;9:百分位图表;10:频率分布图表;"`
-}
-
-type AddChartInfoReq struct {
-	MultipleGraphConfigId int              `description:"统一配置id,有的话就是编辑,没有则是新增"`
-	BatchAddChart         []AddChart       `description:"批量创建图的信息"`
-	ExtraConfig           LineChartInfoReq `description:"图表额外配置信息"`
-}
-
-type AddChart struct {
-	Source          int    `description:"来源,1:曲线图,8:标准差图表;9:百分位图表;10:频率分布图表;"`
-	ChartClassifyId int    `description:"分类id"`
-	ChartName       string `description:"图表名称"`
-	LeftMin         string `description:"图表左侧最小值"`
-	LeftMax         string `description:"图表左侧最大值"`
-	ChartImage      string `description:"图表截图,复制的时候才用到" json:"-"`
-}
-
-// EditChartEnInfoReq 编辑图表英文信息
-type EditChartEnInfoReq struct {
-	ChartInfoId int    `description:"图表ID"`
-	ChartNameEn string `description:"英文图表名称"`
-}
-
-// SaveMultipleGraphChartReq 多图配置的单图保存请求
-type SaveMultipleGraphChartReq struct {
-	Source                int                   `description:"来源,1:曲线图,8:标准差图表;9:百分位图表;10:频率分布图表;"`
-	ChartName             string                `description:"图表名称"`
-	ClassifyId            int                   `description:"分类id"`
-	MultipleGraphConfigId int                   `description:"配置id"`
-	EdbInfoId             int                   `description:"指标"`
-	Curve                 CurveConfig           `description:"曲线图配置"`
-	StandardDeviation     StandardDeviation     `description:"标准差配置"`
-	Percentile            Percentile            `description:"百分位配置"`
-	FrequencyDistribution FrequencyDistribution `description:"频率分布配置"`
-	IsSaveAs              bool                  `description:"是否另存为,true的话,就是另存为,不会建立与配置的关系"`
-}
-
-// SaveMultipleGraphEdbReq 多图配置的单指标保存请求
-type SaveMultipleGraphEdbReq struct {
-	EdbName    string `description:"指标名称"`
-	Frequency  string `description:"频度"`
-	Unit       string `description:"单位"`
-	ClassifyId int    `description:"分类id"`
-
-	MultipleGraphConfigId int                   `description:"配置id"`
-	Source                int                   `description:"来源,1:曲线图,8:标准差图表;9:百分位图表;10:频率分布图表;"`
-	EdbInfoId             int                   `description:"指标"`
-	Curve                 CurveConfig           `description:"曲线图配置"`
-	StandardDeviation     StandardDeviation     `description:"标准差配置"`
-	Percentile            Percentile            `description:"百分位配置"`
-	FrequencyDistribution FrequencyDistribution `description:"频率分布配置"`
-	IsSaveAs              bool                  `description:"是否另存为,true的话,就是另存为,不会建立与配置的关系"`
-}

+ 0 - 27
models/data_manage/line_feature/response/line_feature.go

@@ -1,27 +0,0 @@
-package response
-
-// FrequencyDistributionResp 频率分布图数据
-type FrequencyDistributionResp struct {
-	LeftMinValue  float64
-	LeftMaxValue  float64
-	RightMinValue float64
-	RightMaxValue float64
-	DataList      []FrequencyDistributionData
-}
-
-// FrequencyDistributionData 频率分布的值
-type FrequencyDistributionData struct {
-	Name   string      `description:"别名"`
-	NameEn string      `description:"英文别名"`
-	Unit   string      `description:"单位"`
-	UnitEn string      `description:"单位别名"`
-	Value  interface{} `description:"每个指标的值"`
-	Color  string      `description:"数据颜色"`
-	IsAxis int         `description:"1:左轴,0:右轴"`
-}
-
-// FrequencyDistributionYData 频率分布的实际数据
-type FrequencyDistributionYData struct {
-	X float64
-	Y float64
-}

+ 0 - 249
services/data/line_feature/chart_info.go

@@ -1,249 +0,0 @@
-package line_feature
-
-import (
-	"errors"
-	"github.com/shopspring/decimal"
-	"hongze/hongze_chart_lib/models"
-	"hongze/hongze_chart_lib/models/data_manage/line_feature/response"
-	"hongze/hongze_chart_lib/services/data"
-	"hongze/hongze_chart_lib/utils"
-	"time"
-)
-
-// GetStandardDeviationData 获取标准差图表的指标数据
-func GetStandardDeviationData(chartInfoId int, mappingInfo *models.ChartEdbInfoMapping, calculateValue int) (edbList []*models.ChartEdbInfoMapping, err error, errMsg string) {
-	edbList = make([]*models.ChartEdbInfoMapping, 0)
-
-	// 指标对应的所有数据
-	_, edbList, err = data.GetEdbDataMapList(chartInfoId, 1, `公历`, ``, ``, []*models.ChartEdbInfoMapping{mappingInfo})
-	if err != nil {
-		return
-	}
-
-	for k, edb := range edbList {
-		dataList := edb.DataList.([]*models.EdbDataList)
-		newDataList := make([]models.EdbDataList, 0)
-		lenData := len(dataList)
-		if lenData >= calculateValue {
-			tmpDataList := make([]float64, 0)
-			for _, tmpData := range dataList {
-				tmpDataList = append(tmpDataList, tmpData.Value)
-			}
-			for i := calculateValue; i <= lenData; i++ {
-				tmpV := utils.CalculateStandardDeviation(tmpDataList[i-calculateValue : i])
-				tmpV, _ = decimal.NewFromFloat(tmpV).Round(4).Float64()
-				newDataList = append(newDataList, models.EdbDataList{
-					EdbDataId:     i,
-					EdbInfoId:     edb.EdbInfoId,
-					DataTime:      dataList[i-1].DataTime,
-					DataTimestamp: dataList[i-1].DataTimestamp,
-					Value:         tmpV,
-				})
-			}
-		}
-
-		edb.DataList = newDataList
-		edbList[k] = edb
-	}
-
-	return
-}
-
-// GetPercentileData 获取百分位图表的指标数据
-func GetPercentileData(chartInfoId int, mappingInfo *models.ChartEdbInfoMapping, calculateValue int, calculateUnit string) (edbList []*models.ChartEdbInfoMapping, err error, errMsg string) {
-	edbList = make([]*models.ChartEdbInfoMapping, 0)
-	moveUnitDays, ok := utils.FrequencyDaysMap[calculateUnit]
-	if !ok {
-		errMsg = `错误的周期`
-		err = errors.New(errMsg)
-		return
-	}
-	calculateDay := calculateValue * moveUnitDays
-	// 指标对应的所有数据
-	_, edbList, err = data.GetEdbDataMapList(chartInfoId, 1, `公历`, ``, ``, []*models.ChartEdbInfoMapping{mappingInfo})
-	if err != nil {
-		return
-	}
-	for k, edb := range edbList {
-		dataList := edb.DataList.([]*models.EdbDataList)
-		newDataList := make([]models.EdbDataList, 0)
-
-		dataMap := make(map[time.Time]float64, 0)
-		for _, tmpData := range dataList {
-			currDateTime, _ := time.ParseInLocation(utils.FormatDate, tmpData.DataTime, time.Local)
-			dataMap[currDateTime] = tmpData.Value
-		}
-
-		//百分位:对所选指标滚动地取对应时间长度的数据值,取最大值Max,最小值Min,计算Max-Min,百分位=(现值-Min)/(Max-Min),Max=Min时不予计算。
-		for i, tmpData := range dataList {
-			currDateTime, _ := time.ParseInLocation(utils.FormatDate, tmpData.DataTime, time.Local)
-			maxVal := tmpData.Value
-			minVal := tmpData.Value
-			for i := 0; i < calculateDay; i++ {
-				preVal, ok := dataMap[currDateTime.AddDate(0, 0, -i)]
-				if ok {
-					if preVal > maxVal {
-						maxVal = preVal
-					}
-					if preVal < minVal {
-						minVal = preVal
-					}
-				}
-			}
-
-			if maxVal == minVal {
-				continue
-			}
-			tmpV := (tmpData.Value) / (maxVal - minVal) * 100
-			tmpV, _ = decimal.NewFromFloat(tmpV).Round(4).Float64()
-			//百分位=(现值-Min)/(Max-Min)
-			newDataList = append(newDataList, models.EdbDataList{
-				EdbDataId:     i,
-				EdbInfoId:     edb.EdbInfoId,
-				DataTime:      dataList[i-1].DataTime,
-				DataTimestamp: dataList[i-1].DataTimestamp,
-				Value:         tmpV,
-			})
-		}
-		edb.Unit = "%"
-		edb.UnitEn = "%"
-		edb.DataList = newDataList
-		edbList[k] = edb
-	}
-
-	return
-}
-
-// GetFrequencyDistributionData 获取频率分布的图表数据
-func GetFrequencyDistributionData(chartInfoId int, mappingInfo *models.ChartEdbInfoMapping, dateType, stepVal int, startDate, endDate string) (edbList []*models.ChartEdbInfoMapping, dataResp response.FrequencyDistributionResp, err error, errMsg string) {
-	//日期类型:1:最近3月;2:最近6月;3:最近1年;4:最近2年;5:最近3年;6:最近5年;7:最近10年,8:自定义时间
-	startDate, endDate = utils.GetDateByDateType2(dateType, startDate, endDate)
-	if startDate == `` {
-		errMsg = "错误的日期"
-		err = errors.New(errMsg)
-		return
-	}
-	XDataList := make([]float64, 0)
-	// 频度
-	Y1DataList := make([]response.FrequencyDistributionYData, 0)
-	// 累计频率
-	Y2DataList := make([]response.FrequencyDistributionYData, 0)
-	edbList = make([]*models.ChartEdbInfoMapping, 0)
-
-	// 指标对应的所有数据
-	_, edbList, err = data.GetEdbDataMapList(chartInfoId, 1, `公历`, startDate, endDate, []*models.ChartEdbInfoMapping{mappingInfo})
-	if err != nil {
-		return
-	}
-	if len(edbList) != 1 {
-		err = errors.New("指标异常")
-		return
-	}
-	startDateTime, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
-	var endDateTime time.Time
-	if endDate != `` {
-		endDateTime, _ = time.ParseInLocation(utils.FormatDate, endDate, time.Local)
-	}
-
-	edb := edbList[0]
-	dataList := edb.DataList.([]*models.EdbDataList)
-
-	if len(dataList) <= 0 {
-		return
-	}
-	maxVal := dataList[0].Value
-	minVal := dataList[0].Value
-	dataValMap := make(map[float64]int)
-	total := 0 // 数据总量
-	for _, tmpData := range dataList {
-		currDateTime, _ := time.ParseInLocation(utils.FormatDate, tmpData.DataTime, time.Local)
-		if (currDateTime.Equal(startDateTime) || currDateTime.After(startDateTime)) && (endDateTime.IsZero() || currDateTime.Before(endDateTime)) {
-			if maxVal < tmpData.Value {
-				maxVal = tmpData.Value
-			}
-			if minVal > tmpData.Value {
-				minVal = tmpData.Value
-			}
-
-			num, ok := dataValMap[tmpData.Value]
-			if ok {
-				dataValMap[tmpData.Value] = num + 1
-			} else {
-				dataValMap[tmpData.Value] = 1
-			}
-			total++
-		}
-	}
-
-	if total <= 0 {
-		errMsg = `没有数据`
-		err = errors.New(errMsg)
-		return
-	}
-
-	// 最大最小值 向上/下取整
-	minVal = utils.GetFloorNewNum(minVal, 2)
-	maxVal = utils.GetCeilNewNum(maxVal, 2)
-	//间距
-	spacing, _ := (decimal.NewFromFloat(maxVal).Sub(decimal.NewFromFloat(minVal))).Div(decimal.NewFromInt(int64(stepVal))).Float64()
-
-	distributionDataNumMap := make(map[float64]int)
-	for i := 1; i <= stepVal; i++ {
-		tmpMinVal, _ := decimal.NewFromFloat(minVal).Add((decimal.NewFromFloat(spacing)).Mul(decimal.NewFromInt(int64(i - 1)))).Float64()
-		tmpMaxVal, _ := decimal.NewFromFloat(minVal).Add((decimal.NewFromFloat(spacing)).Mul(decimal.NewFromInt(int64(i)))).Float64()
-		XDataList = append(XDataList, tmpMinVal)
-		distributionDataNumMap[tmpMinVal] = 0
-		for tmpVal, num := range dataValMap {
-			if tmpMinVal <= tmpVal && tmpVal < tmpMaxVal {
-				distributionDataNumMap[tmpMinVal] += num
-			}
-		}
-	}
-
-	tmpNum := 0
-	for _, tmpMinVal := range XDataList {
-		// 频率
-		frequencyYNum := distributionDataNumMap[tmpMinVal]
-		Y1DataList = append(Y1DataList, response.FrequencyDistributionYData{
-			X: tmpMinVal,
-			Y: float64(frequencyYNum),
-		})
-		// 累计数
-		tmpNum += frequencyYNum
-		// 累计频率
-		tmpTotalFrequency, _ := decimal.NewFromInt(int64(tmpNum)).Div(decimal.NewFromInt(int64(total))).Mul(decimal.NewFromInt(100)).Round(4).Float64()
-		Y2DataList = append(Y2DataList, response.FrequencyDistributionYData{
-			X: tmpMinVal,
-			Y: tmpTotalFrequency,
-		})
-	}
-
-	newDataList := []response.FrequencyDistributionData{
-		{
-			Name:   "频率",
-			NameEn: "Frequency",
-			Unit:   "",
-			UnitEn: "",
-			Value:  Y1DataList,
-			Color:  "#00F",
-			IsAxis: 1,
-		}, {
-			Name:   "累计频率",
-			NameEn: "Total Frequency",
-			Unit:   "%",
-			UnitEn: "%",
-			Value:  Y2DataList,
-			Color:  "#F00",
-			IsAxis: 0,
-		},
-	}
-	edbList[0].DataList = nil
-	dataResp = response.FrequencyDistributionResp{
-		LeftMinValue:  minVal,
-		LeftMaxValue:  maxVal,
-		RightMinValue: 0,
-		RightMaxValue: 100,
-		DataList:      newDataList,
-	}
-	return
-}