数据分析平台 直方图接口调整

This commit is contained in:
jh_peng 2025-03-12 09:36:54 +08:00
parent 4089aa80ff
commit c017af30a7
6 changed files with 59 additions and 5 deletions

View File

@ -50,12 +50,12 @@ func (S *TestService) Histogram(c *gin.Context) {
response.FailWithMessage(msg, c) response.FailWithMessage(msg, c)
return return
} }
data, err := test_data.Histogram(&r) data, lineData, err := test_data.Histogram(&r)
if err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
response.OkWithData(gin.H{"data": data}, c) response.OkWithData(gin.H{"data": data, "line": lineData}, c)
} }
// @Tags 数据分析平台 // @Tags 数据分析平台

View File

@ -9,6 +9,18 @@ type Histogram struct {
Min string Min string
X []string X []string
Y []string Y []string
MaxY float64
MaxYX float64
}
type HistogramLine struct {
Field string
Average float64
StandardDeviation float64
N float64
Max string
Min string
X []string
Y []string
} }
type Scatter struct { type Scatter struct {

View File

@ -10,3 +10,17 @@ func GetFactorySelections() []string {
global.Oracle.Model(&model.PmcFile{}).Where("pmc02 IN ?", []string{"AB", "CPFT", "FT"}).Select("pmc03").Find(&factories) global.Oracle.Model(&model.PmcFile{}).Where("pmc02 IN ?", []string{"AB", "CPFT", "FT"}).Select("pmc03").Find(&factories)
return factories return factories
} }
func GetAllProductSelection() []string {
var products []string
global.Oracle.Model(&model.ImaFile{}).Select("Ima02").Group("Ima02").Find(&products)
productsMap := make(map[string]bool)
for _, product := range products {
productsMap[product[:6]] = true
}
products = []string{}
for product := range productsMap {
products = append(products, product)
}
return products
}

View File

@ -18,8 +18,9 @@ func QuerySelection(req *request.QuerySelection) map[string][]string {
} }
// Histogram 直方图 // Histogram 直方图
func Histogram(req *request.Histogram) ([]*model.Histogram, error) { func Histogram(req *request.Histogram) ([]*model.Histogram, []*model.HistogramLine, error) {
var fTHistogram []*model.Histogram var fTHistogram []*model.Histogram
var fTHistogramLine []*model.HistogramLine
var x, groups []string var x, groups []string
var xMax, xMin string var xMax, xMin string
@ -364,6 +365,10 @@ func Histogram(req *request.Histogram) ([]*model.Histogram, error) {
var yCounter float64 = 0 var yCounter float64 = 0
for k, v := range counter { for k, v := range counter {
if float64(v) > fTHistogram[index].MaxY {
fTHistogram[index].MaxY = float64(v)
fTHistogram[index].MaxYX = k
}
if xPointMin.LessThanOrEqual(decimal.NewFromFloat(k)) && decimal.NewFromFloat(k).LessThan(xPointMax) { if xPointMin.LessThanOrEqual(decimal.NewFromFloat(k)) && decimal.NewFromFloat(k).LessThan(xPointMax) {
yCounter += float64(v) yCounter += float64(v)
} }
@ -445,6 +450,10 @@ func Histogram(req *request.Histogram) ([]*model.Histogram, error) {
xPointMax, _ := strconv.ParseFloat(x[i+1], 64) xPointMax, _ := strconv.ParseFloat(x[i+1], 64)
var yCounter float64 = 0 var yCounter float64 = 0
for k, v := range counter { for k, v := range counter {
if float64(v) > fTHistogram[index].MaxY {
fTHistogram[index].MaxY = float64(v)
fTHistogram[index].MaxYX = k
}
if xPointMin <= k && k < xPointMax { if xPointMin <= k && k < xPointMax {
yCounter += float64(v) yCounter += float64(v)
} }
@ -459,7 +468,25 @@ func Histogram(req *request.Histogram) ([]*model.Histogram, error) {
} }
} }
} }
return fTHistogram, nil for _, histogram := range fTHistogram {
var aFTHistogramLine model.HistogramLine
for _, histogramX := range histogram.X {
aFTHistogramLine.X = append(aFTHistogramLine.X, histogramX)
}
for _, histogramX := range histogram.X {
xDecimal, _ := decimal.NewFromString(histogramX)
xFloat, _ := xDecimal.Float64()
aFTHistogramLine.Y = append(aFTHistogramLine.Y, decimal.NewFromFloat(1).
Div(decimal.NewFromFloat(histogram.StandardDeviation*math.Sqrt(2*math.Pi))).
Mul(decimal.NewFromFloat(math.Exp(-1*math.Pow(xFloat-histogram.MaxYX, 2)/(2*math.Pow(histogram.StandardDeviation, 2))))).
String())
//histogram.Average
}
aFTHistogramLine.Field = histogram.Field
aFTHistogramLine.N = histogram.MaxYX
fTHistogramLine = append(fTHistogramLine, &aFTHistogramLine)
}
return fTHistogram, fTHistogramLine, nil
} }
// Scatter 散点图 // Scatter 散点图

View File

@ -1451,7 +1451,7 @@ func ExportFT() string {
for _, ftList := range ftLists { for _, ftList := range ftLists {
ftList.Product = strings.ReplaceAll(ftList.Product, "管装", "") ftList.Product = strings.ReplaceAll(ftList.Product, "管装", "")
var warning *model.Warning var warning *model.Warning
global.PostGreSQL.Where("step LIKE ? AND product = ?", "%FT%", ftList.Product). global.PostGreSQL.Where("step LIKE ? AND product LIKE ?", "%FT%", "%"+ftList.Product+"%").
Preload("ProductionControl").Preload("PassProbabilityDiff").Preload("BinControl"). Preload("ProductionControl").Preload("PassProbabilityDiff").Preload("BinControl").
Preload("SelectionDiffControl").Preload("StackingMaterialsWarning").Preload("HistogramSelection"). Preload("SelectionDiffControl").Preload("StackingMaterialsWarning").Preload("HistogramSelection").
Preload("ScatterSelection").Find(&warning) Preload("ScatterSelection").Find(&warning)

View File

@ -10,5 +10,6 @@ func InitTestDataERPRouter(R *gin.RouterGroup) {
testDataGroup := R.Group("") testDataGroup := R.Group("")
{ {
testDataGroup.GET("import/testFile/factorySelection", testDataService.FactorySelection) testDataGroup.GET("import/testFile/factorySelection", testDataService.FactorySelection)
testDataGroup.GET("warning/productSelection", testDataService.GetAllProductSelection)
} }
} }