コード例 #1
0
        public void BuildMainSpecReports(MainSpec mspec)
        {
            /*
             * 每天一条新的
             * 来的新记录,存
             * 来的相同记录, 更新,
             * 相比前面60-90天之间有超过30%, remark1
             */
            using (var context = new PumpSystemContext()) {
                var existSpec = context.MainSpecs.Where(s =>
                                                        s.Feature == mspec.Feature &&
                                                        s.Position == mspec.Position &&
                                                        s.PPGuid == mspec.PPGuid).OrderByDescending(s => s.LatestTime).FirstOrDefault();
                if (existSpec != null)
                {
                    if (mspec.LatestTime.Value.Date > existSpec.LatestTime.Value.Date)
                    {
                        context.MainSpecs.Add(mspec);
                    }
                    else
                    {
                        existSpec.LatestTime  = mspec.LatestTime;
                        existSpec.LatestValue = mspec.LatestValue;
                        if (mspec.MaxValue > existSpec.MaxValue)
                        {
                            existSpec.MaxValue = mspec.MaxValue;
                        }

                        //前一个季度 比较 设置remark1
                        var timeRangeStart  = existSpec.LatestTime - TimeSpan.FromDays(90 - 5);
                        var timeRangeEnd    = existSpec.LatestTime - TimeSpan.FromDays(90 + 5);
                        var prevSeasonSpecs =
                            context.MainSpecs.Where(s =>
                                                    s.Feature == mspec.Feature &&
                                                    s.Position == mspec.Position &&
                                                    s.PPGuid == mspec.PPGuid)
                            .Where(s => s.LatestTime >= timeRangeStart && s.LatestTime <= timeRangeEnd)
                            .ToList();
                        if (prevSeasonSpecs.Any())
                        {
                            var prevSeasonSpecMax = prevSeasonSpecs.Max(s => s.MaxValue);
                            if (existSpec.LatestValue > prevSeasonSpecMax * 1.2)
                            {
                                existSpec.Remark1 = "超过了上季度最大值的20%";
                            }
                        }
                    }
                }
                else
                {
                    context.MainSpecs.Add(mspec);
                }

                context.SaveChanges();
            }
        }
コード例 #2
0
        public void FindMainVibraSpec(PumpSystem ppSys)
        {
            var specGraphs = RuntimeRepo.RtData.Graphs.Where(g => g.Signal.Contains("Spec")).ToArray();

            //所有频谱中的最大值
            var max = specGraphs.Max(g => g.Data.Max());

            //找到最大值对应的频率是那个频谱
            var graph = specGraphs.First(g => g.Data.Max() == max);

            //找到是频谱的第几线
            var line = (double)graph.Data.IndexOf(max);

            var specWidth = double.Parse(ConfigurationManager.AppSettings["SpecWidth"]);
            var lineCount = (double)graph.Data.Count - 1;//去掉第一个0
            var f         = line * (specWidth / lineCount);

            double?speed = GetSpeed(ppSys);

            var featureF = f / (speed / 60);

            var range = 0.12D;
            var featureFRangeStart = featureF * (1 - range);
            var featureFRangeEnd   = featureF * (1 + range);
            var feature            = string.Empty;
            var featureList        = new[] { 0.5, 1, 2, 3, 4 };

            foreach (var fvalue in featureList)
            {
                if (fvalue > featureFRangeStart && fvalue < featureFRangeEnd)
                {
                    feature = fvalue + "X";
                }
            }

            var mainSpec = new MainSpec {
                PPGuid      = ppSys.Guid.ToFormatedString(),
                FirstTime   = graph.Time,
                LatestTime  = graph.Time,
                Feature     = feature,
                Position    = graph.Pos.ToString(),
                LatestValue = max,
                MaxValue    = max
            };

            MainSpecUpdated?.Invoke(mainSpec);
        }