示例#1
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string eqmNo       = context.Request["eqmNo"] ?? string.Empty;
            string information = context.Request["information"] ?? string.Empty;
            string tmpStr      = context.Request["normalValue"] ?? string.Empty;

            if (string.IsNullOrEmpty(tmpStr))
            {
                context.Response.Write(Common.JsonHelper.SerializeObject(null));
                context.Response.End();
            }
            double normalValue = 0;

            normalValue = double.TryParse(tmpStr, out normalValue)?normalValue:0;
            tmpStr      = context.Request["toleranceValue"] ?? string.Empty;
            if (string.IsNullOrEmpty(tmpStr))
            {
                context.Response.Write(Common.JsonHelper.SerializeObject(null));
                context.Response.End();
            }
            double toleranceValue = 0;

            toleranceValue = double.TryParse(tmpStr, out toleranceValue) ? toleranceValue : 0;
            tmpStr         = context.Request["startTime"] ?? string.Empty;
            if (string.IsNullOrEmpty(tmpStr))
            {
                context.Response.Write(Common.JsonHelper.SerializeObject(null));
                context.Response.End();
            }
            DateTime startTime = DateTime.Now;

            startTime = DateTime.TryParse(tmpStr, out startTime) ? startTime : DateTime.Now;
            tmpStr    = context.Request["endTime"] ?? string.Empty;
            if (string.IsNullOrEmpty(tmpStr))
            {
                context.Response.Write(Common.JsonHelper.SerializeObject(null));
                context.Response.End();
            }
            DateTime endTime = DateTime.Now;

            endTime = DateTime.TryParse(tmpStr, out endTime) ? endTime : DateTime.Now;
            string partNo = context.Request["partNo"] ?? string.Empty;

            Ctrl.Bll.SpcDataAnalysisBll spcDataAnalysisBll = new Ctrl.Bll.SpcDataAnalysisBll();

            ModelView.DataAnalysisSpcView dataAnalysisSpcView = spcDataAnalysisBll.CalculateSpc(eqmNo, information, partNo, normalValue, toleranceValue, startTime, endTime);
            //ModelView.DataAnalysisSpcView dataAnalysisSpcView = spcDataAnalysisBll.CalculateSpc("DAOP 090/100", "涡旋拧紧7角度", 97.5, 50
//, new DateTime(2018, 11, 10, 23, 0, 0), new DateTime(2018, 11, 11, 23, 0, 0));
            context.Response.Write(Common.JsonHelper.SerializeObject(dataAnalysisSpcView));
            context.Response.End();
        }
示例#2
0
        /// <summary>
        /// 计算Spc
        /// </summary>
        /// <param name="eqmNo">工站编号</param>
        /// <param name="information">要计算的项目</param>
        /// <param name="partNo">型号</param>
        /// <param name="normalValue">该项目的标准值</param>
        /// <param name="tolerance">该项目的容忍度</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <returns>返回Spc统计结果</returns>
        public ModelView.DataAnalysisSpcView CalculateSpc(string eqmNo, string information, string partNo, double normalValue, double tolerance, DateTime startTime, DateTime endTime)
        {
            ModelView.DataAnalysisSpcView res = new ModelView.DataAnalysisSpcView();
            if (startTime >= endTime)
            {
                return(null);
            }
            if (string.IsNullOrEmpty(eqmNo))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(information))
            {
                return(null);
            }
            //获取样本
            List <string> tmpListStr = GetInforValueFromDb(eqmNo, information, partNo, startTime, endTime);

            if (tmpListStr == null)
            {
                return(null);
            }
            if (tmpListStr.Count <= 0)
            {
                return(null);
            }
            List <double> sample = ConvertStr2Double(tmpListStr);

            //样本校验
            if (sample == null)
            {
                return(null);
            }
            if (sample.Count <= 0)
            {
                return(null);
            }
            BasicSpcInfo basicSpcInfo = new BasicSpcInfo();
            //计算基础样本数据
            bool b = GetBasicParam(sample, normalValue, tolerance, out basicSpcInfo);

            if (!b)
            {
                return(null);
            }
            res.dotTitle     = eqmNo + "-" + information + "分析";
            res.spcTitle     = eqmNo + "-" + information + "分析";
            res.avarage      = Math.Round(basicSpcInfo.Average, 2);
            res.max          = Math.Round(basicSpcInfo.SampleMax, 2);
            res.min          = Math.Round(basicSpcInfo.SampleMin, 2);
            res.normal       = Math.Round(normalValue, 2);
            res.upLimit      = Math.Round(normalValue + tolerance / 2, 2);
            res.lowerLimit   = Math.Round(normalValue - tolerance / 2, 2);
            res.yAxisMax     = Math.Max(Math.Round(res.max + Math.Abs((res.max - res.min) * 0.2), 2), Math.Round(res.upLimit + Math.Abs((res.max - res.min) * 0.2), 2));
            res.yAxisMin     = Math.Min(Math.Round(res.min - Math.Abs((res.max - res.min) * 0.2), 2), Math.Round(res.lowerLimit - Math.Abs((res.max - res.min) * 0.2), 2));
            res.dotxAxisData = CreateSampleIndex(sample);

            List <double> sampleRound = new List <double>();

            sample.ForEach(a => sampleRound.Add(Math.Round(a, 2)));
            res.dotyAxisData = sampleRound;
            res.spcxAxisData = CreateSpcBasicData(res.min, res.max, basicSpcInfo.GroupDistance);
            res.tips         = string.Format("CP:{0}\t\tCPK:{1}", (Math.Round(basicSpcInfo.Capability, 2).ToString()), (Math.Round(basicSpcInfo.Centernal, 2).ToString()));
            List <BasicSpcInfo.Boundary> sampleGroupBoundary = CalculateBoundary(basicSpcInfo.GroupStartValue, res.max, basicSpcInfo.GroupDistance);

            if (sampleGroupBoundary == null)
            {
                return(null);
            }
            if (sampleGroupBoundary.Count <= 0)
            {
                return(null);
            }
            Dictionary <BasicSpcInfo.Boundary, int> firstStatistic = StatictisSample(sample, sampleGroupBoundary);

            if (firstStatistic == null)
            {
                return(null);
            }
            if (firstStatistic.Count <= 0)
            {
                return(null);
            }
            res.spcyAxisCountData = StatisticSampleCount(firstStatistic);
            res.spcyAxisCurveData = CalculateBasicDataNormal(res.spcxAxisData, basicSpcInfo.Average, basicSpcInfo.StandardDeviation, basicSpcInfo.GroupDistance, basicSpcInfo.SampleCount);
            return(res);
        }