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 regInfos, List 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); }); } } }