예제 #1
0
 public void AddOrUpdate(MOE.Common.Models.MetricComment metricComment)
 {
     MOE.Common.Models.MetricComment g = (from r in db.MetricComments
                                          where r.CommentID == metricComment.CommentID
                                          select r).FirstOrDefault();
     if (g != null)
     {
         try
         {
             db.Entry(g).CurrentValues.SetValues(metricComment);
             db.SaveChanges();
         }
         catch (Exception ex)
         {
             MOE.Common.Models.Repositories.IApplicationEventRepository repository =
                 MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
             MOE.Common.Models.ApplicationEvent error = new ApplicationEvent();
             error.ApplicationName = "MOE.Common";
             error.Class           = "Models.Repository.MetricCommentRepository";
             error.Function        = "AddOrUpdate";
             error.Description     = ex.Message;
             error.SeverityLevel   = ApplicationEvent.SeverityLevels.High;
             error.Timestamp       = DateTime.Now;
             repository.Add(error);
             throw;
         }
     }
     else
     {
         db.MetricComments.Add(metricComment);
     }
 }
예제 #2
0
 public void Remove(MOE.Common.Models.MetricComment metricComment)
 {
     MOE.Common.Models.MetricComment g = (from r in db.MetricComments
                                          where r.CommentID == metricComment.CommentID
                                          select r).FirstOrDefault();
     if (g != null)
     {
         db.MetricComments.Remove(g);
         db.SaveChanges();
     }
 }
예제 #3
0
 public void Add(MOE.Common.Models.MetricComment metricComment)
 {
     MOE.Common.Models.MetricComment g = (from r in db.MetricComments
                                          where r.CommentID == metricComment.CommentID
                                          select r).FirstOrDefault();
     if (g == null)
     {
         if (metricComment.MetricTypes == null)
         {
             metricComment.MetricTypes = db.MetricTypes
                                         .Where(x => metricComment.MetricTypeIDs.Contains(x.MetricID)).ToList();
         }
         try
         {
             db.MetricComments.Add(metricComment);
             db.SaveChanges();
         }
         catch (DbEntityValidationException e)
         {
             MOE.Common.Models.Repositories.IApplicationEventRepository repository =
                 MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
             string errorMessage = string.Empty;
             foreach (var eve in e.EntityValidationErrors)
             {
                 foreach (var ve in eve.ValidationErrors)
                 {
                     errorMessage += " Property:" + ve.PropertyName + " Error:" + ve.ErrorMessage;
                 }
             }
             repository.QuickAdd("Moe.Common", "MetricCommentRepository", "Add",
                                 ApplicationEvent.SeverityLevels.Medium, errorMessage);
             throw new Exception(errorMessage);
         }
         catch (Exception ex)
         {
             MOE.Common.Models.Repositories.IApplicationEventRepository repository =
                 MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
             repository.QuickAdd("Moe.Common", "MetricCommentRepository", "Add",
                                 ApplicationEvent.SeverityLevels.Medium, ex.Message);
             throw;
         }
     }
     else
     {
         this.AddOrUpdate(metricComment);
     }
 }
예제 #4
0
        /// <summary>
        /// Adds data points to a graph with the series GreenLine, YellowLine, Redline
        /// and Points already added.
        /// </summary>
        /// <param name="chart"></param>
        /// <param name="signalPhase"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="signalId"></param>
        private void AddDataToChart(Chart chart, MOE.Common.Business.SignalPhase signalPhase, DateTime startDate,
                                    DateTime endDate, bool showVolume, bool showArrivalOnGreen)
        {
            decimal totalDetectorHits     = 0;
            decimal totalOnGreenArrivals  = 0;
            decimal percentArrivalOnGreen = 0;

            //Add the data by plan
            foreach (MOE.Common.Business.Plan plan in signalPhase.Plans.PlanList)
            {
                //check for empty pcd collection
                if (plan.CycleCollection.Count > 0)
                {
                    foreach (MOE.Common.Business.Cycle pcd in plan.CycleCollection)
                    {
                        //add the data for the green line
                        chart.Series["Change to Green"].Points.AddXY(
                            pcd.GreenEvent,
                            pcd.GreenLineY);

                        //add the data for the yellow line
                        chart.Series["Change to Yellow"].Points.AddXY(
                            pcd.YellowEvent,
                            pcd.YellowLineY);

                        //add the data for the red line
                        chart.Series["Change to Red"].Points.AddXY(
                            pcd.EndTime,
                            pcd.RedLineY);

                        //add the detector hits to the running total
                        totalDetectorHits += pcd.DetectorCollection.Count;

                        //add the detector hits to the detector activation series
                        foreach (MOE.Common.Business.DetectorDataPoint detectorPoint in pcd.DetectorCollection)
                        {
                            chart.Series["Detector Activation"].Points.AddXY(
                                detectorPoint.TimeStamp,
                                detectorPoint.YPoint);

                            //if this is an arrival on green add it to the running total
                            if (detectorPoint.YPoint > pcd.GreenLineY && detectorPoint.YPoint < pcd.RedLineY)
                            {
                                totalOnGreenArrivals++;
                            }
                        }
                    }
                }
            }

            //add the volume data to the volume series if true
            if (showVolume)
            {
                foreach (MOE.Common.Business.Volume v in signalPhase.Volume.Items)
                {
                    chart.Series["Volume Per Hour"].Points.AddXY(v.XAxis, v.YAxis);
                }
            }

            //if arrivals on green is selected add the data to the chart
            if (showArrivalOnGreen)
            {
                if (totalDetectorHits > 0)
                {
                    percentArrivalOnGreen = (totalOnGreenArrivals / totalDetectorHits) * 100;
                }
                else
                {
                    percentArrivalOnGreen = 0;
                }
                Title title = new Title();
                title.Text = Math.Round(percentArrivalOnGreen).ToString() + "% AoG";
                title.Font = new Font(FontFamily.GenericSansSerif, 20);
                chart.Titles.Add(title);


                SetPlanStrips(signalPhase.Plans.PlanList, chart, startDate);
            }

            MOE.Common.Models.Repositories.IMetricCommentRepository mcr = MOE.Common.Models.Repositories.MetricCommentRepositoryFactory.Create();

            MOE.Common.Models.MetricComment comment = mcr.GetLatestCommentForReport(signalPhase.Approach.SignalID, MetricTypeID);

            if (comment != null)
            {
                chart.Titles.Add(comment.CommentText);
                chart.Titles[1].Docking   = Docking.Bottom;
                chart.Titles[1].ForeColor = Color.Red;
            }
        }