Esempio n. 1
0
        private void ComboBoxItem_SelectionChanged(object sender, RoutedEventArgs e)
        {
            if (fallSelector.SelectedItem == null)
            {
                return;
            }

            picSelectButton.IsEnabled = false;
            if (fallSelector.SelectedItem.ToString() == "---")
            {
                selectedFallMap.Children.Clear();
                if (latText.Text != "?")
                {
                    Pushpin pushpin = new Pushpin();
                    pushpin.Name = "pushpin1";
                    double la = 0.0, lo = 0.0;
                    double.TryParse(latText.Text, out la);
                    double.TryParse(lonText.Text, out lo);
                    pushpin.Location   = new Location(la, lo);
                    pushpin.Background = System.Windows.Media.Brushes.Gainsboro;
                    selectedFallMap.Children.Add(pushpin);
                }
                // (32.082253, 34.7795), TLV => Default center
                selectedFallMap.Center = new Location(32.082253, 34.7795);
            }
            else
            {
                Fall leFall = new Fall();
                foreach (Fall f in MainWindow.GetCurrentVM().Falls)
                {
                    if (f.ToString() == fallSelector.SelectedItem.ToString())
                    {
                        leFall = f;
                    }
                }
                Pushpin pushpin = new Pushpin();
                pushpin.Name       = "pushpin" + leFall.id.ToString();
                pushpin.Location   = new Location(leFall.x, leFall.y);
                pushpin.Background = System.Windows.Media.Brushes.Orange;
                selectedFallMap.Children.Clear();
                selectedFallMap.Children.Add(pushpin);
                if (latText.Text != "?")
                {
                    pushpin      = new Pushpin();
                    pushpin.Name = "pushpin1";
                    double la = 0.0, lo = 0.0;
                    double.TryParse(latText.Text, out la);
                    double.TryParse(lonText.Text, out lo);
                    pushpin.Location   = new Location(la, lo);
                    pushpin.Background = System.Windows.Media.Brushes.Gainsboro;
                    selectedFallMap.Children.Add(pushpin);
                }
                selectedFallMap.Center = new Location(leFall.x, leFall.y);
            }
            picSelectButton.IsEnabled = true;
        }
        private void SlValue_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            slValue.IsEnabled      = false;
            accuracyText.IsEnabled = false;
            double accuracyKm = slValue.Value;
            int    pass       = MainWindow.GetCurrentVM().Falls.Where(
                f => f.isGeotagged &&
                f.actDist <= accuracyKm).Count();
            int all = MainWindow.GetCurrentVM().Falls.Where
                          (f => f.isGeotagged).Count();
            int rate = Convert.ToInt32(Math.Floor(((double)pass / all) * 100.0));

            GaugeChart.Value       = rate;
            slValue.IsEnabled      = true;
            accuracyText.IsEnabled = true;
        }
Esempio n. 3
0
        public UpdateUserControl()
        {
            InitializeComponent();
            List <string> currentFalls = new List <string>();

            currentFalls.Add("---");
            foreach (Fall fall in MainWindow.GetCurrentVM().Falls)
            {
                if (!fall.isGeotagged)
                {
                    currentFalls.Add(fall.ToString());
                }
            }
            fallSelector.ItemsSource  = currentFalls;
            fallSelector.SelectedItem = fallSelector.Items.GetItemAt(0);
        }
        private string calcAvgActDist()
        {
            List <double> actDists = new List <double>();

            actDists = MainWindow.GetCurrentVM().Falls.Where(f => f.isGeotagged).Select(f => f.actDist).ToList();
            double avgActDist = actDists.Average();

            int n = 0;

            if (avgActDist / 10 < 1)
            {
                n = 5;
            }
            else
            {
                n = 6;
            }
            return(avgActDist.ToString().Substring(0, n) + " Km");
        }
        private int fallsPerYear(int year, bool onlyGeotagged = false)
        {
            List <DAL.Fall> falls = new List <DAL.Fall>();

            if (!onlyGeotagged)
            {
                falls = MainWindow.GetCurrentVM().Falls.Where
                            (f => f.date.ToString().Contains
                                (year.ToString())).ToList();
            }
            else
            {
                falls = MainWindow.GetCurrentVM().Falls.Where
                            (f => f.date.ToString().Contains
                                (year.ToString()) &&
                            f.isGeotagged).ToList();
            }

            return(falls.Count());
        }
        private void ActualReportButton_Click(object sender, RoutedEventArgs e)
        {
            prevFallTextBox.IsEnabled = false;
            addressBox.IsEnabled      = false;
            prevFallCheck.IsEnabled   = false;

            #region Local Variables Set Up
            float       lat = 0, lon = 0;
            int         prevMinutes   = 0;
            List <Fall> prevFalls     = new List <Fall>();
            List <Fall> fs            = new List <Fall>();
            XElement    prevFallsRoot = XElement.Load("recentFalls.xml");
            int         nextId        = 0;
            double[][]  toBeClustered;
            #endregion

            #region Validating What the User Entered
            if (addressBox.Text == null || addressBox.Text == "")
            {
                showNoAddressEntered();
                enableThings();
                return;
            }
            else if (addressBox.Text != null && addressBox.Text != "")
            {
                // With HERE Geocoder API
                string appID         = "AWOngGwwid3peeor8FB8";
                string appCode       = "Aiq7YVehgUTJxBl9eukLQg";
                string formattedAddr = addressBox.Text.Replace(", ", "%20").Replace(" ", "%20");
                string url           = string.Format("https://geocoder.api.here.com/6.2/geocode.xml?app_id={0}&app_code={1}&searchtext={2}", appID, appCode, formattedAddr);

                WebRequest  request  = WebRequest.Create(url);
                WebResponse response = request.GetResponse();
                XDocument   xdoc     = XDocument.Load(response.GetResponseStream());
                try
                {
                    XElement result = xdoc.Root.Element("Response").Element("View").Element("Result");
                    float.TryParse(result.Element("Location").Element("NavigationPosition").Element("Latitude").Value.ToString(), out lat);
                    float.TryParse(result.Element("Location").Element("NavigationPosition").Element("Longitude").Value.ToString(), out lon);
                    lat = (float)System.Math.Round(lat, 3);
                    lon = (float)System.Math.Round(lon, 3);
                }
                catch (Exception)
                {
                    showInvalidAddress();
                    enableThings();
                    return;
                }
            }
            string confirm = "Lat: " + lat.ToString()
                             + ", Lon: " + lon.ToString() + ",\nDate: "
                             + DateTime.Now.AddMinutes(-prevMinutes).ToString();

            string[] messageTitle = showConfirm(confirm);

            MessageBoxResult result1 = MessageBox.Show(messageTitle[0], messageTitle[1], MessageBoxButton.OKCancel, MessageBoxImage.Question);
            if (result1 != MessageBoxResult.OK)
            {
                enableThings();
                return;
            }
            if ((prevFallTextBox.Text == null || prevFallTextBox.Text == "") && (bool)prevFallCheck.IsChecked)
            {
                showNoPrevEntered();
                enableThings();
                return;
            }
            #endregion

            #region Case: Fall From X Minutes Ago
            else if ((bool)prevFallCheck.IsChecked && (prevFallTextBox.Text != null || prevFallTextBox.Text != ""))
            {
                int.TryParse(prevFallTextBox.Text, out prevMinutes);

                // We want to give the user a ten minutes error margin, i.e. assume that when they say
                // the fall happened x minutes ago, we include all falls between x+10 minutes ago and x-10
                // minutes ago
                List <string> prevPosDates = new List <string>();
                prevPosDates.Add(DateTime.Now.AddMinutes(prevMinutes).ToString());
                int previ = 1; int prevj = 1;
                while (previ < 11)
                {
                    prevPosDates.Add(DateTime.Now.AddMinutes(previ - prevMinutes).ToString());
                    while (prevj < 60)
                    {
                        prevPosDates.Add(DateTime.Now.AddMinutes(previ - prevMinutes).AddSeconds(prevj).ToString());
                        prevPosDates.Add(DateTime.Now.AddMinutes(previ - prevMinutes).AddSeconds(-prevj).ToString());
                        prevPosDates.Add(DateTime.Now.AddMinutes(-prevMinutes).AddSeconds(prevj).ToString());
                        prevPosDates.Add(DateTime.Now.AddMinutes(-prevMinutes).AddSeconds(-prevj).ToString());
                        prevPosDates.Add(DateTime.Now.AddMinutes(-previ - prevMinutes).AddSeconds(prevj).ToString());
                        prevPosDates.Add(DateTime.Now.AddMinutes(-previ - prevMinutes).AddSeconds(-prevj).ToString());
                        prevj++;
                    }
                    prevPosDates.Add(DateTime.Now.AddMinutes(-previ - prevMinutes).ToString());
                    prevj = 1;
                    previ++;
                }
                MessageBox.Show("prevPosDates format:\"\n\t" + prevPosDates.FirstOrDefault()
                                + "\"\nprevFallsRoot.Elements(\"Fall\")...Element(\"Date\").Value format:\"\n" +
                                prevFallsRoot.Elements("Fall").FirstOrDefault().Element("Date").Value + "\"");
                IEnumerable <XElement> falls =
                    from f2 in prevFallsRoot.Elements("Fall")
                    where prevPosDates.Contains(f2.Element("Date").Value)
                    select f2;
                toBeClustered = new double[falls.Count() + 1][];
                int k = 0;
                foreach (var fall in falls)
                {
                    double y = 0.0, x = 0.0;
                    double.TryParse(fall.Element("X").Value.ToString(), out x);
                    double.TryParse(fall.Element("Y").Value.ToString(), out y);
                    toBeClustered[k] = new double[] { y, x };
                    k++;
                }

                if (falls.Count() < 1)
                {
                    // In case this is a report refers to a "new" fall, i.e. one that has not been
                    // reported yet => one that needs a new Id for the recent falls file
                    goto NEW_FALL;
                }
                else
                {
                    if (falls.Any
                            (elem =>
                    {
                        bool t;
                        bool.TryParse(elem.Element("IsGeotagged").Value.ToString(), out t);
                        return(t);
                    }))
                    {
                        showAlreadyLocated();
                        enableThings();
                        return;
                    }
                    var f1 = falls.FirstOrDefault();
                    // We'll assign them the same Id so that - in the recent falls xml file - the Id
                    // serves as an indication of which reports should get clustered together. Only
                    // when actually entering the report into the DB will we set a correct ID.
                    var newFall1 = new XElement(
                        "Fall", new XElement("Date", DateTime.Now.AddMinutes(-prevMinutes).ToString()),
                        new XElement("Id", f1.Element("Id").Value), new XElement("X", lon),
                        new XElement("Y", lat));
                    prevFallsRoot.Add(newFall1);
                    int.TryParse(f1.Element("Id").Value.ToString(), out nextId);
                    // Recording the falls that will have to be altered after we re-calculate
                    prevFalls = MainWindow.GetCurrentVM().Falls.Where(fall => prevPosDates.Contains(fall.date.ToString())).ToList();
                }
                goto RECALC_OLD_FALLS;
            }
            // If we're dealing with a new report, that may refer to a fall from 10 minutes ago
            // that may or may not already have been reported...
            // We'll check if there have been other reports from the last 10 minutes, and if
            // yes, assign the current report the same Id.
            List <string> posDates   = new List <string>();
            var           currentRep = new Fall();
            posDates.Add(DateTime.Now.ToString());
            int i = 1; int j = 1;
            while (i < 11)
            {
                posDates.Add(DateTime.Now.AddMinutes(i).ToString());
                while (j < 60)
                {
                    posDates.Add(DateTime.Now.AddMinutes(i).AddSeconds(j).ToString());
                    posDates.Add(DateTime.Now.AddMinutes(i).AddSeconds(-j).ToString());
                    posDates.Add(DateTime.Now.AddMinutes(-i).AddSeconds(j).ToString());
                    posDates.Add(DateTime.Now.AddMinutes(-i).AddSeconds(-j).ToString());
                    j++;
                }
                posDates.Add(DateTime.Now.AddMinutes(-i).ToString());
                j = 1;
                i++;
            }
            #endregion

            #region Case New Fall Report
            List <XElement> xfs   = prevFallsRoot.Elements("Fall").Where(f3 => posDates.Contains(f3.Element("Date").Value.ToString())).ToList();
            Fall            fall1 = MainWindow.GetCurrentVM().Falls.Where(f3 => { return(posDates.Contains(f3.date.ToString())); }).OrderByDescending(f7 => f7.id).FirstOrDefault();
            foreach (var xf in xfs)
            {
                Fall  toAdd = new Fall(); DateTime toAddDate = new DateTime(0);
                float toAddX = 0.0f; float toAddY = 0.0f;
                int   toAddId =
                    MainWindow.GetCurrentVM().Falls.Where(f6 => f6.id.ToString() == xf.Element("Id").Value.ToString()).FirstOrDefault().id;
                DateTime.TryParse(xf.Element("Date").Value, out toAddDate);
                float.TryParse(xf.Element("X").Value, out toAddX);
                float.TryParse(xf.Element("Y").Value, out toAddY);
                toAdd.id = toAddId; toAdd.date = toAddDate; toAdd.x = toAddX; toAdd.y = toAddY;
                fs.Add(toAdd);
            }
            // If there where no other falls recorded in the past ten minutes
            if (fs.Count() < 1)
            {
                goto NEW_FALL;
            }
            // Otherwise, we continue:
            var f = fs.FirstOrDefault();
            // Adding the current report to the recent falls document
            var newFall = new XElement(
                "Fall", new XElement("Date", DateTime.Now.AddMinutes(-prevMinutes).ToString()),
                new XElement("Id", f.id), new XElement("X", lon),
                new XElement("Y", lat));
            prevFallsRoot.Add(newFall);
            prevFallsRoot.Save("recentFalls.xml");
            int.TryParse(f.id.ToString(), out nextId);
            // Putting the fall report in the list to be re-calculated
            currentRep.id          = nextId;
            currentRep.isGeotagged = f.isGeotagged;
            currentRep.x           = lon;
            currentRep.y           = lat;
            fs.Add(currentRep);
            toBeClustered = new double[fs.Count() + 1][];
            for (int l = 0; l < fs.Count(); l++)
            {
                toBeClustered[l] = new double[]
                { fs.ElementAtOrDefault(l).y, fs.ElementAtOrDefault(l).x };
            }
            #endregion

            #region Either It's Grouped With Other Recents Falls
            RECALC_OLD_FALLS :;
            int numOfClusters = 1;
            if (toBeClustered.Length - 1 < 8 && toBeClustered.Length - 1 > 3)
            {
                numOfClusters = 2;
            }
            else if (toBeClustered.Length - 1 > 9)
            {
                numOfClusters = 3;
            }
            // Clustering
            List <KeyValuePair <int, float[]> > newClusters = new List <KeyValuePair <int, float[]> >();
            if (fs.Count() == 2)
            {
                double dNewX = (toBeClustered[0][1] + toBeClustered[1][1]) / 2.0;
                double dNewY = (toBeClustered[0][0] + toBeClustered[1][0]) / 2.0;
                float  newX = 0.0f; float newY = 0.0f;
                float.TryParse(dNewX.ToString(), out newX);
                float.TryParse(dNewY.ToString(), out newY);
                newClusters.Add(new KeyValuePair <int, float[]>(0, new float[] { newX, newY }));
            }
            else
            {
                newClusters = KMeansClustering.ClustersAndMeans(toBeClustered, numOfClusters);
            }
            // Removing the old falls from the DB...
            foreach (Fall fall in fs)
            {
                try
                {
                    //MainWindow.GetCurrentVM().CurrentModel.db = new Model1();
                    if (MainWindow.GetCurrentVM().CurrentModel.db.falls.Where(fa => fa.id == fall.id).Count() > 0)
                    {
                        MainWindow.GetCurrentVM().CurrentModel.Remove(fall.id);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "\n\tBest regards,\n\t" + ex.Source, "Exception", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            // ... and adding the new ones
            foreach (KeyValuePair <int, float[]> kv in newClusters)
            {
                try
                {
                    MainWindow.GetCurrentVM().addFallCommand.Execute(kv.Value[0], kv.Value[1], DateTime.Now.AddMinutes(-prevMinutes));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "\n\tBest regards,\n\t" + ex.StackTrace.Split().ElementAt(0), "Exception", MessageBoxButton.OK, MessageBoxImage.Error);
                    enableThings();
                    return;
                }
            }
            showClusteredSuccess();
            enableThings();
            return;

            #endregion

            #region ... Or it's a Completely New One
            NEW_FALL :;  // A previously unreported fall
            nextId = 0;
            foreach (var f4 in prevFallsRoot.Elements("Fall"))
            {
                int temp = 0;
                int.TryParse(f4.Element("Id").Value, out temp);
                if (temp > nextId)
                {
                    nextId = temp;
                }
            }
            nextId++;
            // Adding the current report to the recent falls document
            var newFall2 = new XElement(
                "Fall", new XElement("Date", DateTime.Now.AddMinutes(-prevMinutes).ToString()),
                new XElement("Id", nextId), new XElement("X", lon),
                new XElement("Y", lat));
            prevFallsRoot.Add(newFall2);
            prevFallsRoot.Save("recentFalls.xml");
            // Adding the currently reported fall to the DB
            try
            {
                MainWindow.GetCurrentVM().addFallCommand.Execute(lat, lon, DateTime.Now.AddMinutes(-prevMinutes));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\tBest regards,\n\t" + ex.TargetSite, "Exception", MessageBoxButton.OK, MessageBoxImage.Error);
                enableThings();
                return;
            }
            showNewSuccess();
            enableThings();
            #endregion
        }
Esempio n. 7
0
        private void PicSelectButton_Click(object sender, RoutedEventArgs e)
        {
            fallSelector.IsEnabled = false;
            string oldLat = latText.Text;
            string oldLon = lonText.Text;
            float  ola = 0.0f, olo = 0.0f;

            float.TryParse(oldLat, out ola);
            float.TryParse(oldLon, out olo);
            OpenFileDialog of = new OpenFileDialog();

            //For any other formats
            of.Filter = "Image Files (*.jpg;*.jpeg)|*.BMP;*.JPG;*.JPEG;*.PNG";
            if (of.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    FileInfo   imageFile = new FileInfo(of.FileName);
                    ExifReader reader    = new ExifReader(imageFile.FullName);

                    // EXIF lat/long tags stored as [Degree, Minute, Second]
                    double[] latitudeComponents;
                    double[] longitudeComponents;

                    string latitudeRef;  // "N" or "S" ("S" will be negative latitude)
                    string longitudeRef; // "E" or "W" ("W" will be a negative longitude)


                    if (reader.GetTagValue(ExifTags.GPSLatitude, out latitudeComponents) &&
                        reader.GetTagValue(ExifTags.GPSLongitude, out longitudeComponents) &&
                        reader.GetTagValue(ExifTags.GPSLatitudeRef, out latitudeRef) &&
                        reader.GetTagValue(ExifTags.GPSLongitudeRef, out longitudeRef))
                    {
                        var latitude  = ConvertDegreeAngleToDouble(latitudeComponents[0], latitudeComponents[1], latitudeComponents[2], latitudeRef);
                        var longitude = ConvertDegreeAngleToDouble(longitudeComponents[0], longitudeComponents[1], longitudeComponents[2], longitudeRef);
                        latText.Text = string.Format(latitude.ToString(), "F3");
                        lonText.Text = string.Format(longitude.ToString(), "F3");
                        Fall leFall = new Fall();
                        foreach (Fall f in MainWindow.GetCurrentVM().Falls)
                        {
                            if (f.ToString() == fallSelector.SelectedItem.ToString())
                            {
                                leFall = f;
                            }
                        }
                        if (fallSelector.SelectedItem.ToString() != "---")
                        {
                            Pushpin pushpin = new Pushpin();
                            pushpin.Name       = "pushpin" + leFall.id.ToString();
                            pushpin.Location   = new Location(leFall.x, leFall.y);
                            pushpin.Background = System.Windows.Media.Brushes.Orange;
                            selectedFallMap.Children.Clear();
                            selectedFallMap.Children.Add(pushpin);
                        }

                        if (latText.Text != "?")
                        {
                            if (oldLat != "?")
                            {
                                Pushpin pushpin1 = new Pushpin();
                                pushpin1.Name       = "pushpin1";
                                pushpin1.Location   = new Location(ola, olo);
                                pushpin1.Background = System.Windows.Media.Brushes.Gainsboro;
                                try
                                {
                                    selectedFallMap.Children.Remove(pushpin1);
                                }
                                catch (Exception) { }
                            }
                            Pushpin pushpin = new Pushpin();
                            pushpin.Name       = "pushpin1";
                            pushpin.Location   = new Location(latitude, longitude);
                            pushpin.Background = System.Windows.Media.Brushes.Gainsboro;
                            selectedFallMap.Children.Add(pushpin);
                        }
                    }
                    geoPic.Source = new BitmapImage(new Uri(imageFile.FullName, UriKind.Absolute));
                }
                catch (Exception)
                {
                    showUnableToExtract();
                    latText.Text  = "?";
                    lonText.Text  = "?";
                    geoPic.Source = new BitmapImage(new Uri(@"Resources/demoPic.png", UriKind.Relative));
                    if (oldLat != "?")
                    {
                        Pushpin pushpin1 = new Pushpin();
                        pushpin1.Name       = "pushpin1";
                        pushpin1.Location   = new Location(ola, olo);
                        pushpin1.Background = System.Windows.Media.Brushes.Gainsboro;
                        try
                        {
                            selectedFallMap.Children.Remove(pushpin1);
                        }
                        catch (Exception) { }
                    }
                }
            }
            fallSelector.IsEnabled = true;
        }
Esempio n. 8
0
        private void ActualUpdateButton_Click(object sender, RoutedEventArgs e)
        {
            if (fallSelector.SelectedItem.ToString() == "---")
            {
                showSelectFall();
                return;
            }
            if (latText.Text == "?")
            {
                showSelectGeotaggedPic();
                return;
            }

            fallSelector.IsEnabled    = false;
            picSelectButton.IsEnabled = false;

            try
            {
                // Finding the fall we want to update
                Fall leFall = new Fall();
                foreach (Fall f in MainWindow.GetCurrentVM().Falls)
                {
                    if (f.ToString() == fallSelector.SelectedItem.ToString())
                    {
                        leFall = f;
                    }
                }
                // Setting up the variables for the new coordinates
                float NewX = 0.0f, NewY = 0.0f;
                float.TryParse(latText.Text, out NewX);
                float.TryParse(lonText.Text, out NewY);

                string confirm = "Lat1: " + leFall.x.ToString() +
                                 " -> Lat2: " + latText.Text + "\nLon1: " +
                                 leFall.y.ToString() + " -> Lon2: " + lonText.Text;

                string[] messageTitle = showConfirm(confirm, leFall.ToString());

                MessageBoxResult result1 = System.Windows.MessageBox.Show(messageTitle[0], messageTitle[1], MessageBoxButton.OKCancel, MessageBoxImage.Question);
                if (result1 != MessageBoxResult.OK)
                {
                    fallSelector.IsEnabled    = true;
                    picSelectButton.IsEnabled = true;
                    return;
                }

                // Calling the model to deal with the actual data
                MainWindow.GetCurrentVM().CurrentModel.UpdateFall(leFall.id, NewX, NewY);

                // Re-setting the source of the selector...
                List <string> currentFalls = new List <string>();
                currentFalls.Add("---");
                foreach (Fall fall in MainWindow.GetCurrentVM().Falls)
                {
                    if (fall.isGeotagged == null || !fall.isGeotagged)
                    {
                        currentFalls.Add(fall.ToString());
                    }
                }
                fallSelector.ItemsSource  = currentFalls;
                fallSelector.SelectedItem = fallSelector.Items.GetItemAt(0);
                selectedFallMap.Children.Clear();
                // ... and re-setting the demo photo and the lat and lon texts
                latText.Text  = "?";
                lonText.Text  = "?";
                geoPic.Source = new BitmapImage(new Uri(@"Resources/demoPic.png", UriKind.Relative));

                showSuccess();
            }
            catch (Exception)
            {
                showSomethingWrong();
            }

            fallSelector.IsEnabled    = true;
            picSelectButton.IsEnabled = true;
        }
        public AnalysisWindow()
        {
            InitializeComponent();
            flagImg.Source = new BitmapImage(new Uri(MainWindow.imageUri, UriKind.Relative));

            #region User Set-Up
            // Setting up the user's full name and profile picture (locally store,
            // the entry only contains the full local path to it)
            string username = MainWindow.CurrentUser.username;
            MainWindow.userVM      = new ViewModels.UserVM();
            MainWindow.CurrentUser = MainWindow.userVM.
                                     Users.Where(f => f.username.Trim()
                                                 == username.Trim()).FirstOrDefault();
            fullUserName = MainWindow.CurrentUser.firstname.Trim()
                           + " " + MainWindow.CurrentUser.lastname.Trim();
            profileNameLabel.Content = fullUserName;
            if (MainWindow.CurrentUser.photoUrl.Trim() != "not-set")
            {
                try
                {
                    profilePic.Source = new BitmapImage(
                        new Uri(MainWindow.CurrentUser.photoUrl.Trim(),
                                UriKind.Absolute));
                }
                catch (Exception e)
                {
                    if (!e.Message.StartsWith("Could not find file"))
                    {
                        UpdateUserControl.showSomethingWrong();
                    }
                }
            }
            #endregion

            #region Big Line-Series Chart Set-Up
            // Setting up the inner charts for the big chart of falls by year
            ChartValues <double> chart1 = new ChartValues <double> {
                0
            };
            // First, all falls
            for (int i = 2003; i < 2020; i++)
            {
                chart1.Add(fallsPerYear(i));
            }
            // Then only those that have been exactly located (i.e. geotagged)
            ChartValues <double> chart2 = new ChartValues <double> {
                0
            };
            for (int i = 2003; i < 2020; i++)
            {
                chart2.Add(fallsPerYear(i, true));
            }
            // Putting it all together...
            Series = new SeriesCollection
            {
                new LineSeries
                {
                    Name   = "Total",
                    Values = chart1,
                    Title  = "Total"
                },
                new LineSeries
                {
                    Name   = "Geotagged",
                    Values = chart2,
                    Title  = "Geotagged"
                },
            };
            leChart.Series = Series;
            #endregion

            // That's the label on the bottom, rightmost corner
            avgActDistLabel.Content = calcAvgActDist();

            #region Doughnut Chart Set-Up
            // Now preparing the doughnut chart of exactly located falls, separated by
            // the distance between their estiamted and their actual locations
            var fallsByActDist =
                MainWindow.GetCurrentVM().Falls.Where(
                    f => f.isGeotagged).GroupBy(
                    f => f.actDist
                    );
            // Declaring the collection...
            SeriesCollection PieCollection = new SeriesCollection();
            foreach (var fallGroup in fallsByActDist)
            {
                PieCollection.Add(
                    new PieSeries
                {
                    Title  = fallGroup.Key.ToString(),
                    Values = new ChartValues <ObservableValue>
                    {
                        new ObservableValue(fallGroup.Count())
                    },
                    DataLabels = true
                });
            }
            lePieChart.Series = PieCollection;
            #endregion

            #region Gauge Chart Set-Up
            // Finally, setting up the gauge chart for the system's accuracy rate accord-
            // ing to a user define (from the slider) desired error margin (deviation)
            double accuracyKm = slValue.Value;
            int    pass       = MainWindow.GetCurrentVM().Falls.Where(
                f => f.isGeotagged &&
                f.actDist <= accuracyKm).Count();
            int all = MainWindow.GetCurrentVM().Falls.Where
                          (f => f.isGeotagged).Count();
            int rate = Convert.ToInt32(Math.Floor(((double)pass / all) * 100.0));
            GaugeChart.Value = rate;
            #endregion
        }
        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            disableThings();

            string addr = "";
            double lat = 0.0, lon = 0.0;
            int    dev = 1;

            if ((leAddressTextBox.Text == "" || leAddressTextBox.Text == null) &&
                (bool)byAddressRadio.IsChecked)
            {
                showNoAddress();
                goto END;
            }
            else if ((bool)byAddressRadio.IsChecked)
            {
                addr = leAddressTextBox.Text;
                // With HERE Geocoder API
                string appID         = "AWOngGwwid3peeor8FB8";
                string appCode       = "Aiq7YVehgUTJxBl9eukLQg";
                string formattedAddr = addr.Replace(", ", "%20").Replace(" ", "%20");
                string url           = string.Format("https://geocoder.api.here.com/6.2/geocode.xml?app_id={0}&app_code={1}&searchtext={2}", appID, appCode, formattedAddr);

                WebRequest  request  = WebRequest.Create(url);
                WebResponse response = request.GetResponse();
                XDocument   xdoc     = XDocument.Load(response.GetResponseStream());
                try
                {
                    XElement result = xdoc.Root.Element("Response").Element("View").Element("Result");
                    float.TryParse(result.Element("Location").Element("NavigationPosition").Element("Latitude").Value.ToString(), out float latF);
                    float.TryParse(result.Element("Location").Element("NavigationPosition").Element("Longitude").Value.ToString(), out float lonF);
                    lat = (double)System.Math.Round(latF, 3);
                    lon = (double)System.Math.Round(lonF, 3);
                }
                catch (Exception)
                {
                    ReportUserControl.showInvalidAddress();
                    goto END;
                }
            }

            if (((latTextBox.Text == "" || latTextBox.Text == null) ||
                 (lonTextBox.Text == "" || lonTextBox.Text == null)) &&
                (bool)byCoordsRadio.IsChecked)
            {
                showNoCoords();
                goto END;
            }
            else if (byCoordsRadio.IsChecked.Value)
            {
                double.TryParse(latTextBox.Text, out lat);
                double.TryParse(lonTextBox.Text, out lon);
            }

            DateTime?leDate = leDatePicker.SelectedDate;

            DateTime.TryParse("1997-01-01", out DateTime minDate);
            bool noDate = (leDate == null || leDate.Value.Ticks <= minDate.Ticks);

            if (errorMarginTextBox.Text != null &&
                errorMarginTextBox.Text != "")
            {
                int.TryParse(errorMarginTextBox.Text, out dev);
            }

            List <Fall> falls = new List <Fall>();

            falls = MainWindow.GetCurrentVM().Falls.Where
                        (f =>
            {
                if (!noDate)        // If there is a date
                {
                    int year  = leDate.Value.Year;
                    int month = leDate.Value.Month;
                    int day   = leDate.Value.Day;
                    if (f.date.Day != day ||
                        f.date.Month != month ||
                        f.date.Year != year)
                    {
                        return(false);
                    }
                }
                // If only geotagged
                if (geotagCheck.IsChecked.Value &&
                    !f.isGeotagged)
                {
                    return(false);
                }
                double d = calculateActDist(f, lat, lon);
                return(d <= dev);
            }).ToList();

            fallsListBox.ItemsSource = new List <string>();
            fallsView.Children.Clear();

            // If there were no results, this is where we want to stop
            if (falls.Count() < 1)
            {
                goto END;
            }

            fallsListBox.ItemsSource = falls.OrderBy(f => f.date).Select(f => f.ToString());
            foreach (var fall in falls)
            {
                fallsView.Children.Add(
                    new Pushpin
                {
                    Name       = "pushpin" + fall.id.ToString(),
                    Location   = new Location(fall.x, fall.y),
                    Background = System.Windows.Media.Brushes.Orange
                });
            }
            fallsView.Center    = ((Pushpin)fallsView.Children[0]).Location;
            fallsView.ZoomLevel = 4 + (falls.Count() % 3) + 1;

            END :;
            enableThings();
        }