public ActionResult SaveCrimeType(CrimeType crimeType) { context.CrimeTypes.Add(crimeType); context.SaveChanges(); return(RedirectToAction("CrimeTypes")); }
// <inheritdoc> public IQueryable <Incident> getAllForCrimeType(CrimeType type) { return(this.repository.Query <Incident>() .Where(x => x.CrimeType.Equals(type.ToString())) .OrderBy(x => x.DateCreated) .AsQueryable()); }
/// <summary> /// Initializes a new instance of the <see cref="T:com.kiranpatel.crimecluster.framework.MarkovModel"/> class. /// </summary> /// <param name="type">crime type this markov model instance is for.</param> /// <param name="logger">Logger.</param> public MarkovModel(CrimeType type, ILogger logger) { this.crimeType = type; this.modelGenerated = false; this.currentState = 0; this.logger = logger; }
// <inheritdoc> public void AddIncident(Incident incident) { if (incident == null) { this.logger.warn($"Adding incident was null"); return; } CrimeType type = CrimeType.Default; if (!Enum.TryParse(incident.CrimeType, out type)) { this.logger.warn($"Incident {incident.ID} has an invalid crime type {incident.CrimeType}"); return; } this.logger.debug($"Adding Incident { incident.ID.ToString() } to cache."); if (this.incidentCache.ContainsKey(type)) { this.incidentCache[type].Add(incident); } else { this.logger.warn($"Attempted to add incident with no model generated: {type}"); } this.GenerateModel(type); }
public static string ImageSource(CrimeType type) { switch (type) { case Models.CrimeType.Homicide: return("Images/h_on.png"); case Models.CrimeType.Robbery: return("Images/ro_on.png"); case Models.CrimeType.Assault: return("Images/a_on.png"); case Models.CrimeType.Burglary: return("Images/b_on.png"); case Models.CrimeType.Rape: return("Images/ra_on.png"); case Models.CrimeType.Theft: return("Images/t_on.png"); case Models.CrimeType.Prostition: return("Images/p_on.png"); case Models.CrimeType.TheftFromAuto: return("Images/ta_on.png"); case Models.CrimeType.StolenVehicle: return("Images/vt_on.png"); case Models.CrimeType.VehicleRecovery: return("Images/rv_on.png"); case Models.CrimeType.Gun: return("Images/g_on.png"); case Models.CrimeType.CriminalMischief: return("Images/m_on.png"); case Models.CrimeType.DUI: return("Images/d_on.png"); case Models.CrimeType.Narcotics: return("Images/n_on.png"); case Models.CrimeType.Other: return("Images/o_on.png"); case Models.CrimeType.OtherSexAssault: return("Images/s_on.png"); case Models.CrimeType.Nothing: return("Images/unknown_on.png"); default: return("Images/o_on.png"); } }
public ActionResult DeleteConfirmed(int id) { CrimeType crimetype = db.CrimeTypes.Find(id); db.CrimeTypes.Remove(crimetype); db.SaveChanges(); return(RedirectToAction("Index")); }
public static void AddNewCrimeType(CrimeType _model) { var _list = GetCrimeTypes(); _model.CrimeTypeId = _list.Items.Count > 0 ? _list.Items.LastOrDefault().CrimeTypeId + 1 : 1; _list.Items.Add(_model); SaveChanges(_list); }
public static void UpdateCrimeType(CrimeType _model) { var _list = GetCrimeTypes(); var edited = _list.Items.FirstOrDefault(x => x.CrimeTypeId == _model.CrimeTypeId); edited = _model; SaveChanges(_list); }
public async Task <ActionResult> DeleteConfirmed(int id) { CrimeType crimeType = await db.CrimeTypes.FindAsync(id); db.CrimeTypes.Remove(crimeType); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
// // GET: /CrimeType/Delete/5 public ActionResult Delete(int id = 0) { CrimeType crimetype = db.CrimeTypes.Find(id); if (crimetype == null) { return(HttpNotFound()); } return(View(crimetype)); }
public ActionResult Edit(CrimeType crimetype) { if (ModelState.IsValid) { db.Entry(crimetype).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(crimetype)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name")] CrimeType crimeType) { if (ModelState.IsValid) { db.Entry(crimeType).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(crimeType)); }
public static bool RemovePlayerCrime(string socialClubID, CrimeType _crime) { var edited = currentCrimes.Items.FirstOrDefault(x => x.OwnerSocialClubName == socialClubID); if (edited == null) { return(false); } return(edited.Crimes.Remove(_crime)); }
public ActionResult Create(CrimeType crimetype) { if (ModelState.IsValid) { db.CrimeTypes.Add(crimetype); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(crimetype)); }
public async Task <ActionResult> Create([Bind(Include = "Id,Name")] CrimeType crimeType) { if (ModelState.IsValid) { db.CrimeTypes.Add(crimeType); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(crimeType)); }
/// <summary> /// Gets the description for the enum. /// </summary> /// <returns>The description.</returns> /// <param name="value">Crime Type.</param> public static String GetDescription(this CrimeType value) { var info = value.GetType().GetField(value.ToString()); var attributes = (DescriptionAttribute[])info.GetCustomAttributes(typeof(DescriptionAttribute), false); if (attributes == null || attributes.Length <= 0) { return(value.ToString()); } return(attributes[0].Description); }
// <inheritdoc> public double Evaluate(DateTime testStart, DateTime testEnd, double Radius) { this.logger.info("Evaluating the Model."); IList <Incident> testSet = this.incidentService.getForDateRange(testStart, testEnd).OrderBy(x => x.DateCreated).ToList(); IKdTreeWrapper <double, string> kdTree = this.generateKdTree(testSet); double correct = 0; double error = 0; double countDone = 0; double countToDo = testSet.Count; foreach (var currentIncident in testSet) { CrimeType currentType = default(CrimeType); if (!Enum.TryParse(currentIncident.CrimeType, out currentType)) { this.logger.debug($"Could not parse crime type {currentIncident.CrimeType}"); continue; } if (!this.mixedMarkovModel.IsGenerated(currentType)) { this.logger.debug($"model was not generated for {currentType}"); continue; } var predictedPoint = this.mixedMarkovModel.Predict(currentType); if (predictedPoint == null) { this.logger.debug($"predicted point was null for {currentIncident.ID}"); continue; } var nearest = kdTree.GetNearestNeighbours(predictedPoint); if (this.distanceMeasure.measure(nearest, predictedPoint) <= Radius) { this.logger.debug($"Match found between predicted { predictedPoint[0] } , { predictedPoint[1] } and Incident { nearest }"); correct++; } else { error++; } this.mixedMarkovModel.AddIncident(currentIncident); this.progressCheck(++countDone, countToDo); } return(correct / (correct + error)); }
public Crime(CrimeType crimeType, Tile [] tiles, List <Criminal> criminals, List <Villain> villains, float crimeProgressNeeded) { this.crimeType = crimeType; this.criminals = criminals; this.villains = villains; this.tiles = tiles; this.crimeProgressNeeded = crimeProgressNeeded; crimeStarted = false; crimeComplete = false; crimeCurrentProgress = 0f; progressMultiplier = 1f; }
public static void AddCrimeToPlayer(CrimeType _crime, string socialClubID) { Crime edited = currentCrimes.Items.FirstOrDefault(x => x.OwnerSocialClubName == socialClubID); if (edited == null) { edited = new Crime(); edited.OwnerSocialClubName = socialClubID; currentCrimes.Items.Add(edited); } edited.Crimes.Add(_crime); edited.CrimesBefore++; SaveChanges(); }
// GET: CrimeTypes/Delete/5 public async Task <ActionResult> Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CrimeType crimeType = await db.CrimeTypes.FindAsync(id); if (crimeType == null) { return(HttpNotFound()); } return(View(crimeType)); }
/// <summary> /// Generates a Markov Model for the passed Crime Type and sets them to the internal dictionary or updates an existing entry with a cache. /// </summary> /// <param name="currentEnum">Current enum to generate the Markov Model for.</param> private void GenerateModel(CrimeType currentEnum) { this.logger.debug($"Generating Markov Model for {currentEnum.ToString()}"); HashSet <Incident> currentIncidents; if (this.incidentCache.ContainsKey(currentEnum)) { currentIncidents = this.incidentCache[currentEnum]; } else { currentIncidents = this.incidentService.getAllForCrimeType(currentEnum) .Where(x => x.DateCreated >= this.start && x.DateCreated <= this.end) .ToHashSet(); this.incidentCache[currentEnum] = currentIncidents; } double[][] dataSet = currentIncidents .Select(x => new double[] { x.Location.Latitude.Value, x.Location.Longitude.Value }) .ToArray(); this.logger.debug($"Clustering Data for {currentEnum.ToString()}"); var rawClusters = this.clusteringService.Learn(dataSet); var clusters = new List <Cluster>(); for (int i = 0; i < rawClusters.Count; i++) { clusters.Add(new Cluster(i, rawClusters[i])); } this.logger.debug($"Generating Transition matrix for {currentEnum.GetDescription()}"); var model = new MarkovModel(currentEnum, this.logger); model.generateTransitionMatrix(currentIncidents, clusters); if (this.modelLookup.ContainsKey(currentEnum)) { this.modelLookup[currentEnum] = model; } else { this.modelLookup.Add(currentEnum, model); } }
public CrimeDetailPage(CustomPin pin) { _pin = pin; _type = pin.CrimeType; InitializeComponent(); Appearing += (object sender, EventArgs e) => { SetupMessaging(); }; Disappearing += (object sender, EventArgs e) => { TeardownMessaging(); }; GetCrimeDetails(); }
public CrimeDetailPage(CrimeReport report) { _pin = new CustomPin(); _pin.Id = report.DCN; _type = report.Type; InitializeComponent(); Appearing += (object sender, EventArgs e) => { SetupMessaging(); }; Disappearing += (object sender, EventArgs e) => { TeardownMessaging(); }; GetCrimeDetails(); }
public CrimeDetailPage(string dcn, CrimeType crimeType) { _pin = new CustomPin(); _pin.Id = dcn; _type = crimeType; InitializeComponent(); Appearing += (object sender, EventArgs e) => { SetupMessaging(); }; Disappearing += (object sender, EventArgs e) => { TeardownMessaging(); }; GetCrimeDetails(); }
public JsonResult Filter(String crimeType) { if (String.IsNullOrEmpty(crimeType)) { this.logger.warn($"{nameof(crimeType)} was null or empty"); return(new JsonResult()); } int parsedType = 0; if (!int.TryParse(crimeType, out parsedType)) { this.logger.warn($"{nameof(crimeType)} could not be parsed into an integer"); return(new JsonResult()); } if (!this.crimeTypes.ContainsKey(parsedType)) { this.logger.warn($"{nameof(this.crimeTypes)} does not contain {nameof(parsedType)}"); return(new JsonResult()); } CrimeType descType = this.crimeTypes[parsedType]; var start = Convert.ToDateTime(configService.Get(ConfigurationKey.TestStartDate, "01/01/2016")); var end = Convert.ToDateTime(configService.Get(ConfigurationKey.TestEndDate, "31/12/2016")); var relatedIncidents = this.incidentService .getAllForCrimeType(descType) .Where(x => x.DateCreated >= start && x.DateCreated <= end); List <LocationModel> locations = relatedIncidents .Select(x => new LocationModel(x.Location.Latitude.ToString(), x.Location.Longitude.ToString())) .ToList(); JsonResult result = new JsonResult(); result.Data = this.serialisationService.serialise <List <LocationModel> >(locations); return(result); }
public void DataFill(FullCrimeReport report, CrimeType type) { Device.BeginInvokeOnMainThread(() => { Indicator.IsRunning = false; MainLayout.Children.Remove(Indicator); }); CrimeView.UpdateData(report, type); // Was a single person arrested for this? if (report.FullArrestDetails.Length == 1) { SingleArrestView.UpdateData(report.FullArrestDetails[0]); } else { foreach (var arrest in report.FullArrestDetails) { Device.BeginInvokeOnMainThread(() => { MultipleArrestsView view = new MultipleArrestsView(); view.UpdateData(arrest); MultipleNotice.IsVisible = true; MultipleArrestContent.Children.Add(view); MultipleArrestContent.IsVisible = true; }); } } // Add a news card for each piece of news found foreach (var news in report.News) { Device.BeginInvokeOnMainThread(() => { var newsCard = new NewsCard(news); NewsView.Children.Add(newsCard); }); } }
// <inheritdoc> public double[] Predict(CrimeType type) { this.logger.debug($"Predicting on type {type.ToString()}"); if (!this.modelLookup.ContainsKey(type)) { string message = $"{type.ToString()} not in lookup"; var e = new InvalidOperationException(message); this.logger.error(message, e); throw e; } this.modelLookup[type].predict(); var predictionPoint = this.modelLookup[type].getPredictionPoint(); if (predictionPoint != null && predictionPoint.Count() < 2) { this.logger.debug($"Generated Prediction Point, Lat: {predictionPoint[0]}, Long: {predictionPoint[1]}"); } return(predictionPoint); }
public MapLegend(CrimeType type) { InitializeComponent(); _type = type; }
// <inheritdoc> public bool IsGenerated(CrimeType type) { return(this.modelLookup.ContainsKey(type)); }