Songjun
2024-10-14 ba7116444978d7b7bea789b9372004c79bcb8942
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PalGain.Core;
using BatchService.Framework.Utility;
using sbcLabSystem.Data.Domain.Backstage;
using sbcLabSystem.Data;
using sbcLabSystem.Service.QC;
 
namespace sbcLabSystem.Service
{
    public class ZService
    {
        public ZService(int projectId, QCService i_service)
        {
            this._projectId = projectId;
            this._service = i_service;
        }
 
        private int _projectId { get; set; }
        private QCService _service { get; set; }
        public double Z_1 { get; set; }
        public double Z_2 { get; set; }
        public double Z_3 { get; set; }
        public double Z_4 { get; set; }
        public double a { get; set; }
        public double S { get; set; }
        public double AllScore { get; set; }
        public double SatisfiedScore { get; set; }
 
        public void CalcZ_Value(List<QCDistributionRegisterInfo> regInfos,
            List<Resultspercentage> scores)
        {
            var labs = regInfos.Where(p => p.ProjectId == this._projectId).ToList().Select(p => p.Id).ToList();
            var stats_temp = scores.Where(p => labs.Contains(p.QcDistributionRegisterId)).ToList();
 
            AllScore = 0.0;
            stats_temp.ForEach(score =>
            {
                switch (this._projectId)
                {
                    case 1:
                        score.SumScore = score.ABO_Score + score.RH_Score + score.KangtiFilter_Score +
                            score.KangtiIdentity_Score + score.JiaoChaPeiXing_Score;
                        break; 
                    case 2:
                        score.SumScore = score.ABO_Score + score.RH_Score + score.KangtiFilter_Score +
                             score.JiaoChaPeiXing_Score;
                        break; 
                    case 3:
                        score.SumScore = score.ABO_Score + score.RH_Score;
                        break;
                    case 4:
                        score.SumScore = score.ABO_Score + score.RH_Score + score.KangtiFilter_Score;
                        break;
                } 
            });
            var sumScoreArray = stats_temp.Select(p => p.SumScore).ToArray();
            this.a = MathNet.Numerics.Statistics.ArrayStatistics.StandardDeviation(sumScoreArray);
            this.S = MathNet.Numerics.Statistics.ArrayStatistics.Mean(sumScoreArray);
 
            LogHelper.Debug(string.Format("当前ProjectId:{0},中位数:{1},平均分:{2}",
                _projectId, this.a, this.S));
             
            this.Z_1 = this.a + this.S;
            this.Z_2 = (2 * this.a) + this.S;
            this.Z_3 = (3 * this.a) + this.S;
 
            LogHelper.Debug(string.Format("当前Z=1:{0},Z=2:{1},Z=3:{2}",
                Z_1, Z_2, Z_3));   
 
            stats_temp.ForEach(score =>
            {
                if (score.SumScore - this.S <= 0)
                {
                    score.ZValueScore = 0;
                }
                else
                {
                    score.ZValueScore = Math.Abs(score.SumScore - this.S) / this.a;
                }
                if (score.SumScore <= this.Z_2)
                {
                    score.SatisfiedScore = 0;
                }
                else if (score.SumScore >= this.Z_3)
                {
                    score.SatisfiedScore = 2;
                }
                else
                {
                    score.SatisfiedScore = 1;
                }
                _service.UpdateResultspercentage(score);
            });
        }
 
    }
}