|
@@ -47,7 +47,7 @@ func ResidualAnalysisPreview(req residual_analysis_model.ResidualAnalysisReq) (r
|
|
|
startDate = req.StartDate
|
|
|
endDate = ""
|
|
|
default:
|
|
|
- startDate = utils.GetPreYear(req.DateType)
|
|
|
+ startDate = utils.GetPreYearTime(req.DateType)
|
|
|
endDate = ""
|
|
|
}
|
|
|
|
|
@@ -63,9 +63,9 @@ func ResidualAnalysisPreview(req residual_analysis_model.ResidualAnalysisReq) (r
|
|
|
baseChartInfo.ChartType = utils.CHART_TYPE_CURVE
|
|
|
|
|
|
// 原始图表信息
|
|
|
- var OriginalEdbList []*residual_analysis_model.ResidualAnalysisChartEdbInfoMapping
|
|
|
+ originalEdbList := make([]residual_analysis_model.ResidualAnalysisChartEdbInfoMapping, 0)
|
|
|
|
|
|
- OriginalEdbList, err = fillOriginalChart(req, mappingList, startDate, endDate, edbInfoMappingA, edbInfoMappingB, OriginalEdbList)
|
|
|
+ originalEdbList, err = fillOriginalChart(req, mappingList, startDate, endDate, edbInfoMappingA, edbInfoMappingB, originalEdbList)
|
|
|
if err != nil {
|
|
|
return residual_analysis_model.ResidualAnalysisResp{}, err
|
|
|
}
|
|
@@ -73,20 +73,20 @@ func ResidualAnalysisPreview(req residual_analysis_model.ResidualAnalysisReq) (r
|
|
|
|
|
|
resp.OriginalChartData = residual_analysis_model.ChartResp{
|
|
|
ChartInfo: baseChartInfo,
|
|
|
- EdbInfoList: OriginalEdbList,
|
|
|
+ EdbInfoList: originalEdbList,
|
|
|
}
|
|
|
|
|
|
- dataAList, ok := edbInfoMappingA.DataList.([]data_manage.EdbDataList)
|
|
|
+ dataAList, ok := edbInfoMappingA.DataList.([]*data_manage.EdbDataList)
|
|
|
if !ok {
|
|
|
return residual_analysis_model.ResidualAnalysisResp{}, fmt.Errorf("数据类型转换失败", nil)
|
|
|
}
|
|
|
- indexADataMap := map[string]data_manage.EdbDataList{}
|
|
|
+ indexADataMap := map[string]*data_manage.EdbDataList{}
|
|
|
for _, indexData := range dataAList {
|
|
|
indexADataMap[indexData.DataTime] = indexData
|
|
|
}
|
|
|
|
|
|
// 映射图表信息
|
|
|
- mappingEdbList, err := fillMappingChartInfo(req, edbInfoMappingA, edbInfoMappingB, OriginalEdbList, indexADataMap)
|
|
|
+ mappingEdbList, err := fillMappingChartInfo(req, edbInfoMappingA, edbInfoMappingB, originalEdbList, indexADataMap)
|
|
|
if err != nil {
|
|
|
return residual_analysis_model.ResidualAnalysisResp{}, err
|
|
|
}
|
|
@@ -113,9 +113,9 @@ func ResidualAnalysisPreview(req residual_analysis_model.ResidualAnalysisReq) (r
|
|
|
return resp, nil
|
|
|
}
|
|
|
|
|
|
-func fillResidualChartInfo(edbInfoMappingA *data_manage.ChartEdbInfoMapping, edbInfoMappingB *data_manage.ChartEdbInfoMapping, mappingEdbList []*residual_analysis_model.ResidualAnalysisChartEdbInfoMapping) ([]*residual_analysis_model.ResidualAnalysisChartEdbInfoMapping, error) {
|
|
|
+func fillResidualChartInfo(edbInfoMappingA *data_manage.ChartEdbInfoMapping, edbInfoMappingB *data_manage.ChartEdbInfoMapping, mappingEdbList []residual_analysis_model.ResidualAnalysisChartEdbInfoMapping) ([]residual_analysis_model.ResidualAnalysisChartEdbInfoMapping, error) {
|
|
|
// 计算公式 映射残差 = 因变量指标 - 映射指标
|
|
|
- var edbInfoA, edbInfoB *residual_analysis_model.ResidualAnalysisChartEdbInfoMapping
|
|
|
+ var edbInfoA, edbInfoB residual_analysis_model.ResidualAnalysisChartEdbInfoMapping
|
|
|
if mappingEdbList[0].EdbInfoId == edbInfoMappingA.EdbInfoId {
|
|
|
edbInfoA = mappingEdbList[0]
|
|
|
edbInfoB = mappingEdbList[1]
|
|
@@ -123,16 +123,16 @@ func fillResidualChartInfo(edbInfoMappingA *data_manage.ChartEdbInfoMapping, edb
|
|
|
edbInfoA = mappingEdbList[1]
|
|
|
edbInfoB = mappingEdbList[0]
|
|
|
}
|
|
|
- dataAList, ok := edbInfoA.DataList.([]data_manage.EdbDataList)
|
|
|
+ dataAList, ok := edbInfoA.DataList.([]*data_manage.EdbDataList)
|
|
|
if !ok {
|
|
|
return nil, fmt.Errorf("数据类型转换失败", nil)
|
|
|
}
|
|
|
edbData := dataAList
|
|
|
- dataBList, ok := edbInfoB.DataList.([]data_manage.EdbDataList)
|
|
|
+ dataBList, ok := edbInfoB.DataList.([]*data_manage.EdbDataList)
|
|
|
if !ok {
|
|
|
return nil, fmt.Errorf("数据类型转换失败", nil)
|
|
|
}
|
|
|
- var indexDataBMap map[string]data_manage.EdbDataList
|
|
|
+ var indexDataBMap = make(map[string]*data_manage.EdbDataList)
|
|
|
for _, data := range dataBList {
|
|
|
indexDataBMap[data.DataTime] = data
|
|
|
}
|
|
@@ -155,7 +155,7 @@ func fillResidualChartInfo(edbInfoMappingA *data_manage.ChartEdbInfoMapping, edb
|
|
|
return mappingEdbList, nil
|
|
|
}
|
|
|
|
|
|
-func fillMappingChartInfo(req residual_analysis_model.ResidualAnalysisReq, edbInfoMappingA *data_manage.ChartEdbInfoMapping, edbInfoMappingB *data_manage.ChartEdbInfoMapping, originalEdbList []*residual_analysis_model.ResidualAnalysisChartEdbInfoMapping, indexADataMap map[string]data_manage.EdbDataList) ([]*residual_analysis_model.ResidualAnalysisChartEdbInfoMapping, error) {
|
|
|
+func fillMappingChartInfo(req residual_analysis_model.ResidualAnalysisReq, edbInfoMappingA *data_manage.ChartEdbInfoMapping, edbInfoMappingB *data_manage.ChartEdbInfoMapping, originalEdbList []residual_analysis_model.ResidualAnalysisChartEdbInfoMapping, indexADataMap map[string]*data_manage.EdbDataList) ([]residual_analysis_model.ResidualAnalysisChartEdbInfoMapping, error) {
|
|
|
// 计算公式:Y=aX+b,Y为映射后的指标,X为自变量指标
|
|
|
// 正序:a=(L2-L1)/(R2-R1) b=L2-R2*a
|
|
|
// 逆序:a=(L2-L1)/(R1-R2) b=L2-R1*a
|
|
@@ -169,7 +169,7 @@ func fillMappingChartInfo(req residual_analysis_model.ResidualAnalysisReq, edbIn
|
|
|
b = req.LeftIndexMax - req.RightIndexMin*a
|
|
|
}
|
|
|
|
|
|
- dataList, ok := edbInfoMappingB.DataList.([]data_manage.EdbDataList)
|
|
|
+ dataList, ok := edbInfoMappingB.DataList.([]*data_manage.EdbDataList)
|
|
|
if !ok {
|
|
|
return nil, fmt.Errorf("数据类型转换失败", nil)
|
|
|
}
|
|
@@ -196,24 +196,29 @@ func fillMappingChartInfo(req residual_analysis_model.ResidualAnalysisReq, edbIn
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- for index, indexData := range dataList {
|
|
|
- // 计算映射值
|
|
|
- indexData.Value = a*indexData.Value + b
|
|
|
-
|
|
|
- // 从最早时间开始 补充时间为自然日
|
|
|
+ for index := 0; index < len(dataList)-1; index++ {
|
|
|
+ // 获取当前数据和下一个数据
|
|
|
beforeIndexData := dataList[index]
|
|
|
afterIndexData := dataList[index+1]
|
|
|
+
|
|
|
+ // 计算映射值
|
|
|
+ beforeIndexData.Value = a*beforeIndexData.Value + b
|
|
|
+
|
|
|
+ // 从最早时间开始,补充时间为自然日
|
|
|
if utils.IsMoreThanOneDay(beforeIndexData.DataTime, afterIndexData.DataTime) {
|
|
|
+ // 创建补充数据
|
|
|
replenishIndexData := data_manage.EdbDataList{
|
|
|
DataTime: utils.GetNextDay(beforeIndexData.DataTime),
|
|
|
DataTimestamp: time.Now().UnixMilli(),
|
|
|
Value: beforeIndexData.Value,
|
|
|
}
|
|
|
- dataList = append(dataList, replenishIndexData)
|
|
|
+
|
|
|
+ // 将补充数据插入到数据列表
|
|
|
+ dataList = append(dataList, &replenishIndexData)
|
|
|
}
|
|
|
}
|
|
|
// 根据指标A的时间key,在B的映射指标中筛选出对应的值
|
|
|
- var dataBList []data_manage.EdbDataList
|
|
|
+ var dataBList []*data_manage.EdbDataList
|
|
|
for _, indexData := range dataList {
|
|
|
if _, ok := indexADataMap[indexData.DataTime]; ok {
|
|
|
dataBList = append(dataBList, indexData)
|
|
@@ -232,9 +237,9 @@ func fillMappingChartInfo(req residual_analysis_model.ResidualAnalysisReq, edbIn
|
|
|
return mappingEdbList, nil
|
|
|
}
|
|
|
|
|
|
-func fillOriginalChart(req residual_analysis_model.ResidualAnalysisReq, mappingList []*data_manage.ChartEdbInfoMapping, startDate string, endDate string, edbInfoMappingA *data_manage.ChartEdbInfoMapping, edbInfoMappingB *data_manage.ChartEdbInfoMapping, OriginalEdbList []*residual_analysis_model.ResidualAnalysisChartEdbInfoMapping) ([]*residual_analysis_model.ResidualAnalysisChartEdbInfoMapping, error) {
|
|
|
+func fillOriginalChart(req residual_analysis_model.ResidualAnalysisReq, mappingList []*data_manage.ChartEdbInfoMapping, startDate string, endDate string, edbInfoMappingA *data_manage.ChartEdbInfoMapping, edbInfoMappingB *data_manage.ChartEdbInfoMapping, OriginalEdbList []residual_analysis_model.ResidualAnalysisChartEdbInfoMapping) ([]residual_analysis_model.ResidualAnalysisChartEdbInfoMapping, error) {
|
|
|
for _, v := range mappingList {
|
|
|
- var edbInfoMapping *residual_analysis_model.ResidualAnalysisChartEdbInfoMapping
|
|
|
+ var edbInfoMapping residual_analysis_model.ResidualAnalysisChartEdbInfoMapping
|
|
|
edbInfoMapping.EdbInfoType = 1
|
|
|
edbInfoMapping.IsOrder = false
|
|
|
edbInfoMapping.IsAxis = 1
|