Exemplo n.º 1
0
 /*
  * Для добавления нового инциндента создайте класс от родителя OCIncident
  * И внесите соответствующие правки в этот и следующие классы:
  * CallIncidentCmd в список и обработку параметров
  * enum RaidTypes в список
  * ModelMailTrade если нужны доп параметры (стараться не раздувать или отрефакторить и разделить контейнер для разных типов писем)
  * MailController.MailProcessStartEvent если были добавлены доп параметр
  */
 public OCIncident GetIncident(IncidentTypes type)
 {
     return(type == IncidentTypes.Raid ? new IncidentRaid()
         : type == IncidentTypes.Caravan ? new IncidentCaravan()
         : type == IncidentTypes.ChunkDrop ? new IncidentChunkDrop()
         : type == IncidentTypes.Infistation ? new IncidentInfistation()
         : type == IncidentTypes.Quest ? new IncidentQuest()
         : type == IncidentTypes.Bombing ? new IncidentBombing()
         : type == IncidentTypes.Acid ? new IncidentAcid()
         : type == IncidentTypes.EMP ? new IncidentEMP()
         : type == IncidentTypes.Pack ? new IncidentPack()
         : type == IncidentTypes.Eclipse ? new IncidentEclipse()
         : (OCIncident)null);
 }
Exemplo n.º 2
0
        protected override void Run(Prediction prediction)
        {
            List <PostGIS.Point> predictionPoints = new List <PostGIS.Point>();
            Area   predictionArea = prediction.PredictionArea;
            double areaMinX       = predictionArea.BoundingBox.MinX;
            double areaMaxX       = predictionArea.BoundingBox.MaxX;
            double areaMinY       = predictionArea.BoundingBox.MinY;
            double areaMaxY       = predictionArea.BoundingBox.MaxY;

            for (double x = areaMinX + prediction.PredictionPointSpacing / 2d; x <= areaMaxX; x += prediction.PredictionPointSpacing)  // place points in the middle of the square boxes that cover the region - we get display errors from pixel rounding if the points are exactly on the boundaries
            {
                for (double y = areaMinY + prediction.PredictionPointSpacing / 2d; y <= areaMaxY; y += prediction.PredictionPointSpacing)
                {
                    predictionPoints.Add(new PostGIS.Point(x, y, predictionArea.Shapefile.SRID));
                }
            }

            List <PostGIS.Point> incidentPoints = new List <PostGIS.Point>(Incident.Get(TrainingStart, TrainingEnd, predictionArea, IncidentTypes.ToArray()).Select(i => i.Location));

            predictionPoints.AddRange(incidentPoints);

            Console.Out.WriteLine("Filtering prediction points to prediction area");
            predictionPoints = predictionArea.Intersects(predictionPoints, prediction.PredictionPointSpacing / 2f).Select(i => predictionPoints[i]).ToList();

            NpgsqlConnection connection = DB.Connection.OpenConnection;

            try
            {
                Console.Out.WriteLine("Inserting points into prediction");
                Point.CreateTable(prediction, predictionArea.Shapefile.SRID);
                List <int> predictionPointIds = Point.Insert(connection, predictionPoints.Select(p => new Tuple <PostGIS.Point, string, DateTime>(p, PointPrediction.NullLabel, DateTime.MinValue)), prediction, predictionArea, false);

                Console.Out.WriteLine("Running overall KDE for " + IncidentTypes.Count + " incident type(s)");
                List <float>            density = GetDensityEstimate(incidentPoints, _trainingSampleSize, false, 0, 0, predictionPoints, _normalize);
                Dictionary <int, float> pointIdOverallDensity = new Dictionary <int, float>(predictionPointIds.Count);
                int pointNum = 0;
                foreach (int predictionPointId in predictionPointIds)
                {
                    pointIdOverallDensity.Add(predictionPointId, density[pointNum++]);
                }

                Dictionary <int, Dictionary <string, double> > pointIdIncidentDensity = new Dictionary <int, Dictionary <string, double> >(pointIdOverallDensity.Count);
                if (IncidentTypes.Count == 1)
                {
                    string incident = IncidentTypes.First();
                    foreach (int pointId in pointIdOverallDensity.Keys)
                    {
                        Dictionary <string, double> incidentDensity = new Dictionary <string, double>();
                        incidentDensity.Add(incident, pointIdOverallDensity[pointId]);
                        pointIdIncidentDensity.Add(pointId, incidentDensity);
                    }
                }
                else
                {
                    foreach (string incidentType in IncidentTypes)
                    {
                        Console.Out.WriteLine("Running KDE for incident \"" + incidentType + "\"");
                        incidentPoints = new List <PostGIS.Point>(Incident.Get(TrainingStart, TrainingEnd, predictionArea, incidentType).Select(i => i.Location));
                        density        = GetDensityEstimate(incidentPoints, _trainingSampleSize, false, 0, 0, predictionPoints, _normalize);
                        if (density.Count > 0)
                        {
                            pointNum = 0;
                            foreach (int predictionPointId in predictionPointIds)
                            {
                                pointIdIncidentDensity.EnsureContainsKey(predictionPointId, typeof(Dictionary <string, double>));
                                pointIdIncidentDensity[predictionPointId].Add(incidentType, density[pointNum++]);
                            }
                        }
                    }
                }

                PointPrediction.CreateTable(prediction);
                PointPrediction.Insert(GetPointPredictionValues(pointIdOverallDensity, pointIdIncidentDensity), prediction, false);

                Smooth(prediction);
            }
            finally
            {
                DB.Connection.Return(connection);
            }
        }
Exemplo n.º 3
0
        public async Task CoralHarvesting(Stock stock, CityBuilding flowController, Laboratory laboratory, IncidentTypes incident)
        {
            int coralIncome = GetCoralIncome(flowController, laboratory, incident);

            stock.CoralAmount += coralIncome;
            await _dbContext.SaveChangesAsync();
        }
 //
 // ---------------------------------------------------------------------------
 // Insert duplicate validation.
 //
 protected override DbEntityValidationResult ValidateEntity(
     DbEntityEntry entityEntry, IDictionary <object, object> items)
 {
     if (entityEntry.Entity is ApplicationUser && entityEntry.State == EntityState.Added)
     {
         if (Users.Any(a =>
                       a.UserName == ((ApplicationUser)entityEntry.Entity).UserName ||
                       a.Email == ((ApplicationUser)entityEntry.Entity).Email ||
                       a.FullName == ((ApplicationUser)entityEntry.Entity).FullName
                       ))
         {
             // return validation error
             return(new DbEntityValidationResult(entityEntry, new List <DbValidationError>()
             {
                 new DbValidationError("User",
                                       string.Format("Duplicate User: '******' or '{1}' or '{2}'",
                                                     ((ApplicationUser)entityEntry.Entity).UserName,
                                                     ((ApplicationUser)entityEntry.Entity).Email,
                                                     ((ApplicationUser)entityEntry.Entity).FullName))
             }));
         }
     }
     if (entityEntry.Entity is Company && entityEntry.State == EntityState.Added)
     {
         if (Companies.Any(a => a.CompanyName == ((Company)entityEntry.Entity).CompanyName))
         {
             // return validation error
             return(new DbEntityValidationResult(entityEntry, new List <DbValidationError>()
             {
                 new DbValidationError("Company",
                                       string.Format("Duplicate Company: '{0}'",
                                                     ((Company)entityEntry.Entity).CompanyName))
             }));
         }
     }
     //
     if (entityEntry.Entity is IncidentType && entityEntry.State == EntityState.Added)
     {
         if (IncidentTypes.Any(a =>
                               a.IncidentTypeShortDesc == ((IncidentType)entityEntry.Entity).IncidentTypeShortDesc ||
                               a.IncidentTypeDesc == ((IncidentType)entityEntry.Entity).IncidentTypeDesc
                               ))
         {
             // return validation error
             return(new DbEntityValidationResult(entityEntry, new List <DbValidationError>()
             {
                 new DbValidationError("IncidentType",
                                       string.Format("Duplicate IncidentType: '{0}' or '{1}'",
                                                     ((IncidentType)entityEntry.Entity).IncidentTypeShortDesc,
                                                     ((IncidentType)entityEntry.Entity).IncidentTypeShortDesc))
             }));
         }
     }
     //
     if (entityEntry.Entity is NIC && entityEntry.State == EntityState.Added)
     {
         if (NICs.Any(a =>
                      a.NIC_Id == ((NIC)entityEntry.Entity).NIC_Id ||
                      a.NICDescription == ((NIC)entityEntry.Entity).NICDescription
                      ))
         {
             // return validation error
             return(new DbEntityValidationResult(entityEntry, new List <DbValidationError>()
             {
                 new DbValidationError("NIC",
                                       string.Format("Duplicate NIC: '{0}' or '{1}'",
                                                     ((NIC)entityEntry.Entity).NIC_Id,
                                                     ((NIC)entityEntry.Entity).NICDescription))
             }));
         }
     }
     if (entityEntry.Entity is NoteType && entityEntry.State == EntityState.Added)
     {
         if (NoteTypes.Any(a => a.NoteTypeDesc == ((NoteType)entityEntry.Entity).NoteTypeDesc))
         {
             // return validation error
             return(new DbEntityValidationResult(entityEntry, new List <DbValidationError>()
             {
                 new DbValidationError("NoteType", "Duplicate NoteType: '" +
                                       ((NoteType)entityEntry.Entity).NoteTypeDesc + "'")
             }));
         }
     }
     //
     return(base.ValidateEntity(entityEntry, items));
 }
        private void SetIncidentsToolTip()
        {
            if (_setIncidentsToolTip)
            {
                int numIncidents = 0;
                if (TrainingArea != null && IncidentTypes.Count > 0)
                {
                    numIncidents = Incident.Count(trainingStart.Value, trainingEnd.Value, TrainingArea, IncidentTypes.ToArray());
                }

                toolTip.SetToolTip(incidentTypes, numIncidents + " total incidents selected");
            }
        }