Ejemplo n.º 1
0
        public void Status_ShouldBeToBeInspected_WhenNextInspectionDueDateIsInLessThanTwoWeeks()
        {
            var nextInspectionDueDate = DateTime.Now.AddDays(13);
            var defibrillator         = new Defibrillator(1, nextInspectionDueDate);

            defibrillator.Status.Should().Be(DefibrillatorStatus.TO_BE_INSPECTED);
        }
Ejemplo n.º 2
0
        private async void Lv_OnItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            Defibrillator def = new Defibrillator();

            def = e.SelectedItem as Defibrillator;
            await Navigation.PushAsync(new AddAED(def));
        }
Ejemplo n.º 3
0
        public void Status_ShouldBeNotInspected_WhenNextInspectionDueDateIsInThePast()
        {
            var nextInspectionDueDate = DateTime.Now.AddDays(-1);
            var defibrillator         = new Defibrillator(1, nextInspectionDueDate);

            defibrillator.Status.Should().Be(DefibrillatorStatus.NOT_INSPECTED);
        }
Ejemplo n.º 4
0
    static void Main(string[] args)
    {
        string   LON          = Console.ReadLine();
        string   LAT          = Console.ReadLine();
        Location userLocation = new Location();

        userLocation.longitude = double.Parse(LON.Replace(',', '.'));
        userLocation.latitude  = double.Parse(LAT.Replace(',', '.'));

        double bestDistance = double.MaxValue;
        int    bestIndex    = -1;

        int N = int.Parse(Console.ReadLine());

        Defibrillator[] defibrillators = new Defibrillator[N];

        for (int i = 0; i < N; i++)
        {
            string DEFIB = Console.ReadLine();
            defibrillators[i] = GetDefibrillator(DEFIB);
            double _tempDistance = GetDistance(userLocation, defibrillators[i].Position);

            if (_tempDistance < bestDistance)
            {
                bestDistance = _tempDistance;
                bestIndex    = i;
            }
        }

        // Write an action using Console.WriteLine()
        // To debug: Console.Error.WriteLine("Debug messages...");

        Console.WriteLine(defibrillators[bestIndex].ToString());
    }
Ejemplo n.º 5
0
        public void Inspect_ShouldMoveNextInspectionDueDateInOneMonth()
        {
            var defibrillator = new Defibrillator(1, A_DATE);

            defibrillator.Inspect();

            defibrillator.NextInspectionDueDate.Should().Be(DateTime.Now.AddMonths(1).Date);
        }
Ejemplo n.º 6
0
	/// <summary>
	/// Calculate the distance between the <paramref name="defib"/> and 
	/// <paramref name="longitude"/> with <paramref name="latitude"/>.
	/// </summary>
	/// <param name="defib">The defibrillator.</param>
	/// <param name="longitude">The longitude.</param>
	/// <param name="latitude">The latitude.</param>
	static double CalculateDistance(Defibrillator defib, double longitude, double latitude)
	{
		// determine variables to calculate the distance.
		double x, y;
		x = (longitude - defib.Longitude)
		    * Math.Cos( (latitude + defib.Latitude) / 2 );
		y = (latitude - defib.Latitude);
		return	Math.Sqrt( x * x + y * y ) * 6371;
	}
Ejemplo n.º 7
0
        public double GetDistanceFromUser(Defibrillator defibrillator)
        {
            Location a = defibrillator.Location;
            Location b = UserLocation;

            double xDistance = (b.Longitude - a.Longitude) * Math.Cos((a.Latitude + b.Latitude) / 2);
            double yDistance = b.Latitude - a.Latitude;

            double xSquaredPlusYSquared = Math.Pow(xDistance, 2) + Math.Pow(yDistance, 2);

            return(Math.Sqrt(xSquaredPlusYSquared) * 6371);
        }
Ejemplo n.º 8
0
        public void LoadData()
        {
            int defibrillatorsCount = int.Parse(Console.ReadLine());

            this.instruments = new List <Defibrillator>(defibrillatorsCount);

            for (int i = 0; i < defibrillatorsCount; i++)
            {
                var instrument = Defibrillator.Read();
                if (ReferenceEquals(null, instrument))
                {
                    continue;
                }

                this.instruments.Add(instrument);
            }
        }
Ejemplo n.º 9
0
        public AddAED(Defibrillator def)
        {
            InitializeComponent();
            var client2 = new HttpClient();

            PreviousName = def.Name;
            var url    = "https://newmobtech.azurewebsites.net/api/AED/GetID?name=" + def.Name;
            var result = client2.GetStringAsync(url);

            id                = Int32.Parse(result.Result);
            Changed           = true;
            aedName.Text      = def.Name;
            aedDesc.Text      = def.Description;
            lon.Text          = def.Longitude.ToString();
            lat.Text          = def.Latitude.ToString();
            PhotoImage.Source = "https://mobtechdef.blob.core.windows.net/mobtechcontainer/" + def.Photograph;
        }
Ejemplo n.º 10
0
    /*
     *               INPUT:
     *      Line 1: User's longitude (in degrees)
     *      Line 2: User's latitude (in degrees)
     *      Line 3: The number N of defibrillators located in the streets of Montpellier
     *      N lignes suivantes : N lines describing each defibrilator
     *
     *  A number identifying the defibrillator
     *  Name
     *  Address
     *  Contact Phone number
     *  Longitude (degrees)
     *  Latitude (degrees)
     *
     * These fields are separated by a semicolon ;
     *
     *      OUTPUT:
     *      The name of the defibrillator located the closest to the user’s position.
     */
    public static void Defibrillators()
    {
        string longitudeOfUser = Console.ReadLine();
        string latitudeOfUser  = Console.ReadLine();

        Location userLocation = new Location(longitudeOfUser, latitudeOfUser);

        int numberOfDefibrillators = int.Parse(Console.ReadLine());

        List <Defibrillator> defibrillators = new List <Defibrillator>();

        for (int i = 0; i < numberOfDefibrillators; i++)
        {
            string[] defibrillatorDetails = Console.ReadLine().Split(';');
            Console.Error.WriteLine(defibrillatorDetails);

            Defibrillator defibrillator = new Defibrillator
            {
                Id       = int.Parse(defibrillatorDetails[0]),
                Name     = defibrillatorDetails[1],
                Address  = defibrillatorDetails[2],
                Phone    = defibrillatorDetails[3],
                Location = new Location(defibrillatorDetails[4], defibrillatorDetails[5])
            };

            defibrillators.Add(defibrillator);
        }

        Dictionary <int, double> defibrillatorDistances = new Dictionary <int, double>();

        LocationDistances locationDistances = new LocationDistances(userLocation);

        foreach (Defibrillator defibrillator in defibrillators)
        {
            defibrillatorDistances.Add(defibrillator.Id, locationDistances.GetDistanceFromUser(defibrillator));
        }

        int closestDefibrillatorId = defibrillatorDistances.OrderBy(dd => dd.Value).First().Key;

        Defibrillator closestDefibrillator = defibrillators.First(d => d.Id == closestDefibrillatorId);

        Console.WriteLine(closestDefibrillator.Name);
    }
    static void Main(string[] args)
    {
        Usr user = new Usr();
        user.Longitude = ConvertToRadians(Double.Parse(Console.ReadLine().Replace(',', '.')));
        user.Latitude = ConvertToRadians(Double.Parse(Console.ReadLine().Replace(',', '.')));
        int Nb_defibrilator = int.Parse(Console.ReadLine());

        List<DefPositionFromUsr> defibrilators = new List<DefPositionFromUsr>();

        for (int i = 0; i < Nb_defibrilator; i++)
        {
            Defibrillator def = new Defibrillator(Console.ReadLine());
            defibrilators.Add(new DefPositionFromUsr(def, user));
        }

        defibrilators.Sort();

        // Write an action using Console.WriteLine()
        // To debug: Console.Error.WriteLine("Debug messages...");

        Console.WriteLine(defibrilators.First().Def.Name);
    }
Ejemplo n.º 12
0
        private async void SaveAED(object sender, EventArgs e)
        {
            var account = CloudStorageAccount.Parse(
                "DefaultEndpointsProtocol=https;AccountName=mobtechdef;AccountKey=q6g5XNLUjRzXETkx9KMUXg+erf7ELKsW0PhmvasP0rS+ZFhUHTjZQCJ/oCng05CR7hgvBbwpyYpRPbr/5gVcXA==;EndpointSuffix=core.windows.net");
            var client    = account.CreateCloudBlobClient();
            var container = client.GetContainerReference("mobtechcontainer");
            var blockBlob = container.GetBlockBlobReference(PreviousName + ".png");
            var def       = new Defibrillator();

            blockBlob = container.GetBlockBlobReference(aedName.Text + ".png");
            await UploadImage(blockBlob);

            def.Name        = aedName.Text.ToString();
            def.Description = aedDesc.Text.ToString();
            def.Latitude    = (float)Convert.ToDouble(lat.Text.ToString());
            def.Longitude   = (float)Convert.ToDouble(lon.Text.ToString());
            def.Photograph  = aedName.Text.ToString() + ".png";
            var client2 = new HttpClient();

            if (Changed)
            {
                UpdatedAED newAed = new UpdatedAED();
                newAed.Name        = def.Name;
                newAed.Description = def.Description;
                newAed.Latitude    = def.Latitude;
                newAed.Longitude   = def.Longitude;
                newAed.Photograph  = def.Photograph;
                newAed.SearchedID  = id;
                var json2    = JsonConvert.SerializeObject(newAed);
                var content2 = new StringContent(json2, Encoding.UTF8, "application/json");
                var result2  = await client2.PostAsync("https://newmobtech.azurewebsites.net/api/AED/Update", content2);

                if (result2.IsSuccessStatusCode)
                {
                    await DisplayAlert("Message", "Success", "OK");

                    await Navigation.PushAsync(new HomePage());
                }
                else
                {
                    await DisplayAlert("Message", "Something went wrong!", "OK");

                    await Navigation.PushAsync(new HomePage());
                }
            }
            else
            {
                var json    = JsonConvert.SerializeObject(def);
                var content = new StringContent(json, Encoding.UTF8, "application/json");
                var result  = await client2.PostAsync("https://newmobtech.azurewebsites.net/api/AED/Add", content);

                if (result.IsSuccessStatusCode)
                {
                    await DisplayAlert("Message", "Success", "OK");
                }
                else
                {
                    await DisplayAlert("Message", "Something went wrong!", "OK");
                }
            }
        }
 private double GetDistanceFromUser(Defibrillator def, Usr user)
 {
     double x = (def.Longitude - user.Longitude) * Math.Cos((user.Latitude + def.Latitude) / 2);
     double y = def.Latitude - user.Latitude;
     return Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) * 6371;
 }
 public DefPositionFromUsr(Defibrillator d, Usr user)
 {
     this.Def = d;
     this.Distance = GetDistanceFromUser(d, user);
 }