代码实现SPC中八大判异标准逻辑

本文写的目的是备份一下当时写的逻辑。该逻辑业务大致是SPC中的八大判异标准。
八大判异标准详情请看:
https://wenku.baidu.com/view/9430b38ad05abe23482fb4daa58da0116d171f53.html[SPC中八大判异标准]
实现后样式大概为:
选中那种判异标准则在上面图表显示
该功能是在VUE中实现,图表为echar,逻辑写在js中
以下为逻辑代码(格式有点问题可以复制到编辑器中嘻嘻):
/**
*

  • @param {(measuringValue:y轴上的,productId:x轴上的)} SPCList

  • @param {平均值} avg

  • @param {一倍标准差} sd

  • @param {动态判异标准的值} abnormalSet

  • @param {是否选中前四个判异标准} checkboxs1

  • @param {是否选中后四个判异标准} checkboxs2
    */
    export function alarm(SPCList, avg, sd, abnormalSet, checkboxs1, checkboxs2) {
    const one = abnormalSet.one
    const two = abnormalSet.two
    const three = abnormalSet.three
    const four = abnormalSet.four
    const five1 = parseInt(abnormalSet.five.split(’/’)[0])
    const five2 = parseInt(abnormalSet.five.split(’/’)[1])
    const six1 = parseInt(abnormalSet.six.split(’/’)[0])
    const six2 = parseInt(abnormalSet.six.split(’/’)[1])
    const seven = abnormalSet.seven
    const eight = abnormalSet.eight
    const markPointList = []
    const a = []// 一个点远离中心线3个标准差
    let aa = 0
    let b = []// 连续7个点位于中心线一侧(box)
    let bb = 0// 连续7个点位于中心线一侧的趋势 >1:中心线上方。<1:中心线下方
    const bbb = []// 连续7个点位于中心线一侧
    let c = []// 连续6个点上升或下降(box)
    let cc = 0// 连续6个点上升或下降的趋势 >1:上升。<1:下降
    const ccc = []// 连续6个点上升或下降
    let d = []// 连续14个点交替上下变化(box)
    let dd = 0
    const ddd = []
    let e = []// 2/3的点距离中心线的距离超过2个标准差(同一侧):收集上侧的值
    const ee = []// 2/3的点距离中心线的距离超过2个标准差(同一侧):收集下侧的值
    let f = []// 4/5的点距离中心线的距离超过一个标准差(同一侧):收集上侧的值
    const ff = []// 4/5的点距离中心线的距离超过一个标准差(同一侧):收集下侧的值
    let g = []// 连续15个点排列在中心线1个标准差范围内(任一侧)(box)
    let gg = 0// 连续15个点排列在中心线1个标准差范围内(任一侧)
    const ggg = []// 连续15个点排列在中心线1个标准差范围内(任一侧)
    let h = []// 连续8个点距中心线的距离大于1个标准差(任一侧)
    let hh = 0// 连续8个点距中心线的距离大于1个标准差(任一侧)
    const hhh = []// 连续8个点距中心线的距离大于1个标准差(任一侧)
    for (let i = 0; i < SPCList.length; i++) {
    // ----------第六种---------
    // 4/5的点距离中心线的距离超过一个标准差(同一侧)
    if (checkboxs2.includes(‘6’)) {
    if (i >= six2 - 1) {
    let fff = 0
    let ffff = 0
    for (let j = 0; j < six2; j++) {
    f.push({ yAxis: SPCList[i - j].measuringValue, xAxis: SPCList[i - j].productId })
    if (SPCList[i - j].measuringValue > avg + sd) {
    fff = fff + 1
    }
    if (SPCList[i - j].measuringValue < avg - sd) {
    ffff = ffff + 1
    }
    }
    if (fff >= six1) {
    ff.push(f)
    }
    if (ffff >= six1) {
    ff.push(f)
    }
    f = []
    }
    }
    // -------------------第一种----------------------
    // 一个点远离中心线3个标准差
    if (checkboxs1.includes(‘1’) && sd !== undefined) {
    if (SPCList[i].measuringValue >= avg + 3 * sd || SPCList[i].measuringValue <= avg - 3 * sd) {
    a.push({ yAxis: SPCList[i].measuringValue, xAxis: SPCList[i].productId })
    aa = aa + 1
    }
    }
    // -------------------第二种----------------------
    // 连续7个点位于中心线一侧(等于平均线不算)
    if (checkboxs1.includes(‘2’)) {
    if (i === 0) {
    bb = SPCList[i].measuringValue > avg ? 1 : -1 // 1:中心线上方。-1:中心线下方
    } else {
    if (SPCList[i].measuringValue > avg && bb > 0) {
    if (b.length === 0 && i !== 0) { // 解决每个异常组第一个值为空
    b.push({ yAxis: SPCList[i - 1].measuringValue, xAxis: SPCList[i - 1].productId })
    }
    b.push({ yAxis: SPCList[i].measuringValue, xAxis: SPCList[i].productId })
    bb = bb + 1
    } else if (SPCList[i].measuringValue < avg && bb < 0) {
    if (b.length === 0 && i !== 0) { // 解决每个异常组第一个值为空
    b.push({ yAxis: SPCList[i - 1].measuringValue, xAxis: SPCList[i - 1].productId })
    }
    b.push({ yAxis: SPCList[i].measuringValue, xAxis: SPCList[i].productId })
    bb = bb - 1
    } else {
    if (bb >= two) { // 符合报警条件
    bbb.push(b)
    } else if (bb <= -two) {
    bbb.push(b)
    }
    if (SPCList[i].measuringValue > avg) {
    bb = 1
    } else if (SPCList[i].measuringValue < avg) {
    bb = -1
    } else if (SPCList[i].measuringValue === avg) {
    bb = 0
    }
    b = []
    }
    if (i === SPCList.length - 1) { // 最后一条
    if (bb >= two) { // 符合报警条件
    bbb.push(b)
    } else if (bb <= -two) {
    bbb.push(b)
    }
    b = []
    }
    }
    }
    // -------------------第三种----------------------
    // 连续6个点上升或下降
    if (checkboxs1.includes(‘3’)) {
    if (i === 0) {
    cc = 0 // >1:上升。<1:下降
    c.push({ yAxis: SPCList[i].measuringValue, xAxis: SPCList[i].productId })
    } else {
    if (SPCList[i].measuringValue - SPCList[i - 1].measuringValue < 0 && cc <= 0) { // 比上个数小且之前呈下降趋势
    cc = cc - 1
    c.push({ yAxis: SPCList[i].measuringValue, xAxis: SPCList[i].productId })
    } else if (SPCList[i].measuringValue - SPCList[i - 1].measuringValue < 0 && cc > 0) { // 比上个数小且之前呈上升趋势
    cc = -1
    c = []
    c.push({ yAxis: SPCList[i - 1].measuringValue, xAxis: SPCList[i - 1].productId })// 把这一组第一个数也加上
    c.push({ yAxis: SPCList[i].measuringValue, xAxis: SPCList[i].productId })
    } else if (SPCList[i].measuringValue - SPCList[i - 1].measuringValue > 0 && cc < 0) { // 比上个数大且之前呈下降趋势
    cc = 1
    c = []
    c.push({ yAxis: SPCList[i - 1].measuringValue, xAxis: SPCList[i - 1].productId })// 把这一组第一个数也加上
    c.push({ yAxis: SPCList[i].measuringValue, xAxis: SPCList[i].productId })
    } else if (SPCList[i].measuringValue - SPCList[i - 1].measuringValue > 0 && cc >= 0) { // 比上个数大且之前呈上升趋势
    cc = cc + 1
    c.push({ yAxis: SPCList[i].measuringValue, xAxis: SPCList[i].productId })
    } else {
    cc = 0
    c = []
    c.push({ yAxis: SPCList[i].measuringValue, xAxis: SPCList[i].productId })
    }
    if (c.length > three) {
    if (c.length > three + 1) { // 如果持续成上升或下降趋势,那么删除前一个元素防止重复
    ccc.pop()
    }
    ccc.push©
    }
    }
    }
    // ---------------第四种-----------
    // 连续14个点交替上下变化
    if (checkboxs1.includes(‘4’)) {
    if (i <= 1) {
    dd = 1
    d.push({ yAxis: SPCList[i].measuringValue, xAxis: SPCList[i].productId })
    } else {
    if (i === SPCList.length - 1) { // 最后一条
    if (dd >= four) { // 符合报警
    ddd.push(d)
    }
    } else {
    if ((SPCList[i].measuringValue - SPCList[i - 1].measuringValue) * (SPCList[i].measuringValue - SPCList[i + 1].measuringValue) > 0) { // 交替开始
    dd = dd + 1
    if (d.length === 0) {
    d.push({ yAxis: SPCList[i - 1].measuringValue, xAxis: SPCList[i - 1].productId })
    }
    d.push({ yAxis: SPCList[i].measuringValue, xAxis: SPCList[i].productId })
    } else {
    if (dd >= four) { // 符合报警
    ddd.push(d)
    }
    dd = 1
    d = []
    }
    }
    }
    }

    // ----------第五种---------
    // 2/3的点距离中心线的距离超过2个标准差(同一侧)
    if (checkboxs2.includes(‘5’)) {
    // (2/3)从第三组开始计算
    if (i >= five2 - 1) {
    let eee = 0
    let eeee = 0
    for (let j = 0; j < five2; j++) {
    e.push({ yAxis: SPCList[i - j].measuringValue, xAxis: SPCList[i - j].productId })
    if (SPCList[i - j].measuringValue > avg + 2 * sd) {
    eee = eee + 1
    }
    if (SPCList[i - j].measuringValue < avg - 2 * sd) {
    eeee = eeee + 1
    }
    }
    if (eee >= five1) {
    ee.push(e)
    }
    if (eeee >= five1) {
    ee.push(e)
    }
    e = []
    }
    }

    // ----------第七种---------
    // 连续15个点排列在中心线1个标准差范围内(任一侧)
    if (checkboxs2.includes(‘7’)) {
    if (SPCList[i].measuringValue > avg - sd && SPCList[i].measuringValue < avg + sd) {
    g.push({ yAxis: SPCList[i].measuringValue, xAxis: SPCList[i].productId })
    gg = gg + 1
    } else {
    if (gg >= seven) {
    ggg.push(g)
    }
    g = []
    gg = 0
    }
    if (i === SPCList.length - 1) { // 最后一条
    if (gg >= seven) {
    ggg.push(g)
    }
    }
    }

    // ----------第八种---------
    // 连续8个点距中心线的距离大于1个标准差(任一侧)
    if (checkboxs2.includes(‘8’)) {
    if (SPCList[i].measuringValue > avg + sd || SPCList[i].measuringValue < avg - sd) {
    h.push({ yAxis: SPCList[i].measuringValue, xAxis: SPCList[i].productId })
    hh = hh + 1
    } else {
    if (hh >= eight) {
    hhh.push(h)
    }
    h = []
    hh = 0
    }
    if (i === SPCList.length - 1) { // 最后一条
    if (hh >= eight) {
    hhh.push(h)
    }
    }
    }
    }
    // 把第一种报警的点表示出来
    if (checkboxs1.includes(‘1’)) {
    if (aa >= one) {
    for (let i = 0; i < a.length; i++) {
    markPointList.push({
    yAxis: a[i].yAxis,
    xAxis: a[i].xAxis,
    symbolSize: 12,
    symbol: ‘diamond’,
    itemStyle: {
    color: ‘red’
    }
    })
    }
    }
    }

// 把第二种报警的点表示出来
if (checkboxs1.includes(‘2’)) {
for (let i = 0; i < bbb.length; i++) {
for (let ii = 0; ii < bbb[i].length; ii++) {
markPointList.push({
yAxis: bbb[i][ii].yAxis,
xAxis: bbb[i][ii].xAxis,
symbolSize: 12,
symbol: ‘diamond’,
itemStyle: {
color: ‘red’
}
})
}
}
}

// 把第三种报警的点表示出来

if (checkboxs1.includes(‘3’)) {
for (let i = 0; i < ccc.length; i++) {
for (let ii = 0; ii < ccc[i].length; ii++) {
markPointList.push({
yAxis: ccc[i][ii].yAxis,
xAxis: ccc[i][ii].xAxis,
symbolSize: 12,
symbol: ‘diamond’,
itemStyle: {
color: ‘red’
}
})
}
}
}

// 把第四种报警的点表示出来
if (checkboxs1.includes(‘4’)) {
for (let i = 0; i < ddd.length; i++) {
for (let ii = 0; ii < ddd[i].length; ii++) {
markPointList.push({
yAxis: ddd[i][ii].yAxis,
xAxis: ddd[i][ii].xAxis,
symbolSize: 12,
symbol: ‘diamond’,
itemStyle: {
color: ‘red’
}
})
}
}
}

// 把第五种报警的点表示出来

if (checkboxs2.includes(‘5’)) {
for (let i = 0; i < ee.length; i++) {
for (let ii = 0; ii < ee[i].length; ii++) {
markPointList.push({
yAxis: ee[i][ii].yAxis,
xAxis: ee[i][ii].xAxis,
symbolSize: 12,
symbol: ‘diamond’,
itemStyle: {
color: ‘red’
}
})
}
}
}

// 把第六种报警的点表示出来
if (checkboxs2.includes(‘6’)) {
for (let i = 0; i < ff.length; i++) {
for (let ii = 0; ii < ff[i].length; ii++) {
markPointList.push({
yAxis: ff[i][ii].yAxis,
xAxis: ff[i][ii].xAxis,
symbolSize: 12,
symbol: ‘diamond’,
itemStyle: {
color: ‘red’
}
})
}
}
}

// 把第七种报警的点表示出来
if (checkboxs2.includes(‘7’)) {
for (let i = 0; i < ggg.length; i++) {
for (let ii = 0; ii < ggg[i].length; ii++) {
markPointList.push({
yAxis: ggg[i][ii].yAxis,
xAxis: ggg[i][ii].xAxis,
symbolSize: 12,
symbol: ‘diamond’,
itemStyle: {
color: ‘red’
}
})
}
}
}

// 把第八种报警的点表示出来
if (checkboxs2.includes(‘8’)) {
for (let i = 0; i < hhh.length; i++) {
for (let ii = 0; ii < hhh[i].length; ii++) {
markPointList.push({
yAxis: hhh[i][ii].yAxis,
xAxis: hhh[i][ii].xAxis,
symbolSize: 12,
symbol: ‘diamond’,
itemStyle: {
color: ‘red’
}
})
}
}
}
var map = {}
map.markPointList = markPointList
return map
}

该逻辑将有异常的点取出来然后在echart中渲染出来。

  • 4
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
以下是一个简单的使用Qt实现SPC控制图的代码示例: ```cpp #include <QtWidgets/QApplication> #include <QtCharts/QChartView> #include <QtCharts/QScatterSeries> #include <QtCharts/QLineSeries> #include <QtCharts/QValueAxis> QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { QApplication a(argc, argv); // 创建散点系列 QScatterSeries *series = new QScatterSeries(); // 添加数据点 series->append(1, 5); series->append(2, 7); series->append(3, 6); series->append(4, 4); series->append(5, 5); series->append(6, 8); series->append(7, 7); series->append(8, 6); series->append(9, 4); series->append(10, 5); // 创建线系列 QLineSeries *centerline = new QLineSeries(); // 添加心线数据点 centerline->append(1, 5.5); centerline->append(10, 5.5); // 创建上下限线系列 QLineSeries *upperlimit = new QLineSeries(); QLineSeries *lowerlimit = new QLineSeries(); // 添加上下限线数据点 upperlimit->append(1, 7); upperlimit->append(10, 7); lowerlimit->append(1, 4); lowerlimit->append(10, 4); // 创建图表并添加系列 QChart *chart = new QChart(); chart->addSeries(series); chart->addSeries(centerline); chart->addSeries(upperlimit); chart->addSeries(lowerlimit); // 创建X轴和Y轴 QValueAxis *axisX = new QValueAxis(); axisX->setRange(1, 10); axisX->setLabelFormat("%d"); axisX->setTitleText("Sample"); QValueAxis *axisY = new QValueAxis(); axisY->setRange(0, 10); axisY->setLabelFormat("%d"); axisY->setTitleText("Measurement"); // 添加轴到图表 chart->setAxisX(axisX, series); chart->setAxisY(axisY, series); // 创建图表视图并设置大小 QChartView *chartView = new QChartView(chart); chartView->setRenderHint(QPainter::Antialiasing); chartView->resize(800, 600); chartView->show(); return a.exec(); } ``` 这段代码使用Qt Charts模块的类来创建散点系列、线系列、轴和图表,并将它们组合在一起以生成SPC控制图。该示例只包含了少量数据点,你可以根据自己的需求进行修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值