private int CalculateReportNumber(Fall CurrentFall)
        {
            int counter = 0;
            List <FallPrediction> fallPredictions        = CurrentFallPredictionVM.FallPredictions.ToList();
            List <FallReport>     fallReports            = CurrentFallReportVM.FallReports.ToList();
            FallPrediction        currentFallPredictions = new FallPrediction();

            foreach (FallPrediction item in fallPredictions)
            {
                if (item.FallPredictionFallKey == CurrentFall.FallId)
                {
                    currentFallPredictions = item;
                }
            }

            foreach (FallReport fallReport in fallReports)
            {
                if (currentFallPredictions.FallPredictionId == fallReport.FallPredictionId)
                {
                    counter++;
                }
            }

            return(counter);
        }
        public void UpdateFallPrediction(FallPrediction ev)
        {
            var eventToUpdate = db.Predictions.SingleOrDefault(e => e.FallPredictionId == ev.FallPredictionId);

            if (eventToUpdate != null)
            {
                eventToUpdate = ev;
                db.SaveChanges();
            }
        }
Exemplo n.º 3
0
        public void UpdateFallPrediction(FallPrediction ev)
        {
            FallPrediction e = dal.GetFallPrediction(ev.FallPredictionId);

            if (e == null)
            {
                throw new Exception("not found");
            }
            else
            {
                dal.UpdateFallPrediction(ev);
            }
        }
        private FallPrediction Prediction(Fall CurrentFall)
        {
            List <FallPrediction> fallPredictions        = CurrentFallPredictionVM.FallPredictions.ToList();
            List <FallReport>     fallReports            = CurrentFallReportVM.FallReports.ToList();
            FallPrediction        currentFallPredictions = new FallPrediction();

            foreach (FallPrediction item in fallPredictions)
            {
                if (item.FallPredictionFallKey == CurrentFall.FallId)
                {
                    currentFallPredictions = item;
                }
            }
            return(currentFallPredictions);
        }
Exemplo n.º 5
0
        /// <summary>
        /// First Get GeoTagging from image path
        /// Adds Fall to the database
        /// </summary>
        /// <param name="fall">The new Fall to be add to the database</param>
        public void AddFall(Fall fall)
        {
            fall.FallLocation = GetGeoTaggingFromImage(fall.FallImage.ToString().Substring(8));
            try
            {
                fall.FallAddress = ReverseGeocode(fall.FallLocation.Latitude, fall.FallLocation.Longitude);


                //dal.AddFall(fall);
                DateTime dt = new DateTime(fall.FallTime.Year, fall.FallTime.Month, fall.FallTime.Day, fall.FallTime.Hour, fall.FallTime.Minute - fall.FallTime.Minute % 10, 0);
                List <FallPrediction> _fallPredictions = GetAllFallPredictions(fp => fp.FallPredictionFallKey == -1 && fp.FallPredictionTime == dt).ToList();
                if (_fallPredictions.Count == 0)
                {
                    throw new Exception("invalid fall time");
                }
                double   minDist = Double.MaxValue;
                DateTime minDT   = _fallPredictions[0].FallPredictionTime;
                double   currDist;
                int      _fallPredictionId = -1;
                for (int i = 0; i < _fallPredictions.Count(); i++)
                {
                    currDist = fall.GetCoordinate().GetDistanceTo(new GeoCoordinate(_fallPredictions[i].FallPredictionLocation.Latitude, _fallPredictions[i].FallPredictionLocation.Longitude));
                    if (currDist < minDist &&
                        fall.FallTime >= _fallPredictions[i].FallPredictionTime && fall.FallTime <= _fallPredictions[i].FallPredictionTime.AddMinutes(10))
                    {
                        _fallPredictionId = _fallPredictions[i].FallPredictionId;
                        minDist           = currDist;
                    }
                }
                FallPrediction temp = GetFallPrediction(_fallPredictionId);
                fall.FallPrediction = temp;
                dal.AddFall(fall);
                temp.FallPredictionFallKey = fall.FallId;
                UpdateFallPrediction(temp);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            int st = fall.FallId;
        }
Exemplo n.º 6
0
        private void GetKMeans(DateTime t)
        {
            int counter = 0;

            K               = 0;
            dateTime        = new DateTime(t.Year, t.Month, t.Day, t.Hour, t.Minute - t.Minute % 10, 0);
            fallPredictions = _ibl.GetAllFallPredictionsInCurrent10Minutes(dateTime);
            for (int i = 0; i < fallPredictions.Count(); i++)
            {
                List <FallReport> frl = _ibl.GetAllFallReports(f => f.FallPredictionId == fallPredictions[i].FallPredictionId).ToList();
                for (int j = 0; j < frl.Count(); j++)
                {
                    frl[j].FallPrediction   = null;
                    frl[j].FallPredictionId = null;
                    _ibl.UpdateFallReport(frl[j]);
                }
                _ibl.DeleteFallPrediction(fallPredictions[i].FallPredictionId);
                fallPredictions.Remove(fallPredictions[i]);
            }

            reports = _ibl.GetAllFallReports(r => r.ReportTime >= dateTime && r.ReportTime <= dateTime.AddMinutes(10)).ToList();

            for (int i = 0; i < reports.Count(); i++)
            {
                if (reports[i]._originReportId == -1)
                {
                    K += reports[i].NumOfExplosions;
                    counter++;
                    for (int j = 0; j < reports[i].NumOfExplosions; j++)
                    {
                        for (int k = 1; k <= reports[i].ReportIntensity; k++)
                        {
                            FallReport r = new FallReport();

                            r.FallReportId    = reports[i].FallReportId;
                            r.ReportLocation  = reports[i].ReportLocation;
                            r.PersonName      = reports[i].PersonName;
                            r.ReportIntensity = reports[i].ReportIntensity;
                            r.ReportAddress   = reports[i].ReportAddress;
                            r.NumOfExplosions = reports[i].NumOfExplosions;
                            r.ReportTime      = reports[i].ReportTime;
                            r._originReportId = reports[i].FallReportId;
                            reports.Add(r);
                        }
                    }
                }
            }
            if (K % counter == 0)
            {
                K = K / counter;
            }
            else
            {
                K = K / counter + 1;
            }
            for (int i = 0; i < K; i++)
            {
                FallPrediction e = new FallPrediction();
                e.FallPredictionLocation = new GPSCoordinate();
                e.FallPredictionTime     = dateTime;
                e.FallPredictionId       = -1;
                _ibl.AddFallPrediction(e);
                fallPredictions.Add(e);
            }
        }
Exemplo n.º 7
0
 public void AddFallPrediction(FallPrediction ev)
 {
     dal.AddFallPrediction(ev);
 }
 public void AddFallPrediction(FallPrediction ev)
 {
     db.Predictions.Add(ev);
     db.SaveChanges();
 }
Exemplo n.º 9
0
 public void Add(FallPrediction fallPrediction)
 {
     ibl.AddFallPrediction(fallPrediction);
 }