Пример #1
0
 public static void Add(Sensor sensor, SensorAnalyzeResult sensorAnalyzeResult)
 {
     var item = new GradingItem
                    {
                        SensorId = (int)sensor.SensorID,
                        StructId = (int)sensor.StructId,
                        FactorId = (int)sensor.FactorType,
                        Score = sensorAnalyzeResult.Score
                    };
     StructGradingPlanSet.UpdatePlan(item);
 }
Пример #2
0
        public void UpdateSensorScores(GradingItem item)
        {
            var sensorScore = this.sensorScores.FirstOrDefault(s => s.SensorId == item.SensorId);

            if (sensorScore != null)
            {
                sensorScore.SetScore(item.Score);
            }

            if (this.sensorScores.All(s => s.Completed))
            {
                this.Score = 100;
                foreach (var score in this.sensorScores)
                {
                    this.Score -= (int)((100 - score.Score) * (score.Weight / 100.0));
                }

                DbAccessor.SaveThemeScore(this.OrgStcId, this.ThemeId, this.Score, DateTime.Now);

                this.Completed = true;
            }
        }
Пример #3
0
        /// <summary>
        /// 添加评分项
        /// </summary>
        /// <param name="item">评分项</param>
        public void AddGradingItem(GradingItem item)
        {
            var factorId   = Convert.ToInt32(DbAccessor.GetSensorInfo(item.SensorId).Rows[0]["FactorId"]);
            var themeId    = Convert.ToInt32(DbAccessor.GetSafetyFactorInfo(factorId).Rows[0]["ParentId"]);
            var themeScore = this.ThemeScores.FirstOrDefault(f => f.ThemeId == themeId);

            if (themeScore != null)
            {
                themeScore.UpdateSensorScores(item);
            }

            if (this.ThemeScores.All(f => f.Completed))
            {
                var stcScore = 100;
                foreach (var score in this.ThemeScores)
                {
                    stcScore -= (int)((100 - score.Score) * (score.Weight / 100.0));
                }

                DbAccessor.SaveStructureScore(this.OrgStcId, stcScore, DateTime.Now);

                StructGradingPlanSet.CompletePlan(this);
            }
        }
Пример #4
0
        /// <summary>
        /// 更新评分计划
        /// </summary>
        /// <param name="item">评分项</param>
        public static void UpdatePlan(GradingItem item)
        {
            DataTable orgStc;

            try
            {
                orgStc = DbAccessor.GetOrgStcByStruct(item.StructId);
            }
            catch (Exception e)
            {
                Log.Error("query org-struct by grading item failed", e);
                return;
            }

            foreach (var dataRow in orgStc.AsEnumerable())
            {
                var orgStcId = Convert.ToInt32(dataRow["OrgStcId"]);
                lock (lockObj)
                {
                    if (Plans.Any(p => p.OrgStcId == orgStcId))
                    {
                        try
                        {
                            Plans.First(p => p.OrgStcId == orgStcId).AddGradingItem(item);
                            Log.DebugFormat(
                                "org-struct:{0} update score success, item:sen-{1},stc:{2},fac={3},score={4}",
                                orgStcId,
                                item.SensorId,
                                item.StructId,
                                item.FactorId,
                                item.Score);
                        }
                        catch (Exception e)
                        {
                            Log.ErrorFormat(
                                "org-struct:{0} update score error, item:sen-{1},stc:{2},fac={3},score={4}",
                                orgStcId,
                                item.SensorId,
                                item.StructId,
                                item.FactorId,
                                item.Score);
                        }
                    }
                    else
                    {
                        try
                        {
                            var plan = new StructGradingPlan(orgStcId);
                            plan.AddGradingItem(item);
                            Plans.Add(plan);
                            Log.DebugFormat(
                                "org-struct:{0} build plan success, create time:{1}",
                                plan.OrgStcId,
                                plan.CreateTime);
                        }
                        catch (Exception e)
                        {
                            Log.ErrorFormat("org-struct:{0} build plan error", e, orgStcId);
                        }
                    }
                }
            }
        }