示例#1
0
        private async void UpdateHits(Report newReport)
        {
            Event _event = newReport.Event;
            var   hits   = _event.Hits;

            // var hits = await _dal.GetHits(h => h.Event.Id == _event.Id);

            //chsck if have real location

            /* if (hits.Count > 0 && hits.All(h => h.RealLatitude > 0))
             * {
             *   _event.Reports.Add(newReport);
             *   return;
             * }*/
            //remove the last approximate hits
            foreach (var explotion in hits.ToArray())
            {
                _dal.RemoveHit(explotion.Id);
            }
            //_event.Reports = await _dal.GetReportsAsync((report => report.Event.Id == _event.Id));
            _event.Reports.Add(newReport);
            int    averageHits            = (int)_event.Reports.Average(r => r.NumOfHits);
            KMeans kMeans                 = new KMeans(_event.Reports, averageHits);
            List <GeoCoordinate> clusters = kMeans.K_Means();

            foreach (GeoCoordinate g in clusters)
            {
                Hit h = new Hit
                {
                    ApproxLatitude  = g.Latitude,
                    ApproxLongitude = g.Longitude,
                    Event           = _event
                };
                await _dal.AddHitAsync(h);
            }
        }