Exemple #1
0
        /// <summary>
        /// Laver en ny "Afstand til"
        /// </summary>
        /// <param name="type"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        /// <author>Mathias Petersen</author>
        public DistanceTo MakeNewDistanceTo(string type, int distance)
        {
            var distanceObj = new DistanceTo(type, distance);

            tempDistanceTos.Add(distanceObj);
            return(distanceObj);
        }
Exemple #2
0
 /// <summary>
 /// Sætter afstanden til en given "afstand til"
 /// </summary>
 /// <param name="distanceTo"></param>
 /// <param name="distance"></param>
 /// <author>Mathias Poulsen</author>
 public void SetDistance(DistanceTo distanceTo, int distance)
 {
     if (distanceTo.Distance != distance)
     {
         distanceTo.Distance = distance;
     }
 }
        public override bool Save()
        {
            bool fielddataOk = VerifyFields();

            if (fielddataOk)
            {
                CaseController.Instance.SetPropertyType(cboPropertyType.SelectedItem as PropertyType);
                CaseController.Instance.SetLivingArea(Convert.ToInt32(stbPropertyArea.Text));
                CaseController.Instance.SetBasementArea(Convert.ToInt32(stbPropertyBasement.Text));
                CaseController.Instance.SetBuiltYear(Convert.ToInt32(stbPropertyBuildYear.Text));
                CaseController.Instance.SetEnergyClassification(stbPropertyEnergyMark.Text);
                CaseController.Instance.SetFloors(Convert.ToInt32(stbPropertyFloors.Text));
                CaseController.Instance.SetRooms(Convert.ToInt32(stbPropertyRooms.Text));
                CaseController.Instance.SetBedrooms(Convert.ToInt32(stbPropertyBedrooms.Text));
                CaseController.Instance.SetBathrooms(Convert.ToInt32(stbPropertyBathrooms.Text));
                CaseController.Instance.SetToilets(Convert.ToInt32(stbPropertyToilets.Text));

                var shoppingDistance = Convert.ToInt32(stbDistanceToShopping.Text);
                var centerDistance   = Convert.ToInt32(stbDistanceToCenter.Text);
                var schoolDistance   = Convert.ToInt32(stbDistanceToSchool.Text);

                if (disShopping == null)
                {
                    disShopping = CaseController.Instance.MakeNewDistanceTo(
                        DistanceToSystemType.Shopping.ToString(),
                        shoppingDistance
                        );
                }
                else
                {
                    CaseController.Instance.SetDistance(disShopping, shoppingDistance);
                }

                if (disCenter == null)
                {
                    disCenter = CaseController.Instance.MakeNewDistanceTo(
                        DistanceToSystemType.Center.ToString(),
                        centerDistance
                        );
                }
                else
                {
                    CaseController.Instance.SetDistance(disCenter, centerDistance);
                }

                if (disSchool == null)
                {
                    disSchool = CaseController.Instance.MakeNewDistanceTo(
                        DistanceToSystemType.School.ToString(),
                        schoolDistance
                        );
                }
                else
                {
                    CaseController.Instance.SetDistance(disSchool, schoolDistance);
                }
            }
            return(fielddataOk);
        }
Exemple #4
0
 /// <summary>
 /// Fjerner en "Afstand til" fra casen
 /// </summary>
 /// <author>Mathias Poulsen/Mathias Petersen</author>
 public void RemoveDistanceToFromCase(DistanceTo distanceTo)
 {
     //Hvis den ikke findes i tempDistanceTos, fjern den fra kataloget
     if (!tempDistanceTos.Remove(distanceTo))
     {
         distanceToCatalog.RemoveFromCatalog(activeCase.Id, distanceTo);
     }
 }
Exemple #5
0
        public double BrandenburgDensity(double latitude, double longitude)
        {
            double density = 0;

            double d3 = DistanceTo.Brandenburg(latitude, longitude);

            density += brandenburgDistribution.ProbabilityDensityFunction(d3);
            return(density);
        }
Exemple #6
0
 internal void AddToCatalog(int caseId, DistanceTo distanceTo)
 {
     if (!distanceToDictionary.ContainsKey(caseId))
     {
         distanceToDictionary.Add(caseId, new List <DistanceTo>());
     }
     if (!distanceToDictionary[caseId].Contains(distanceTo))
     {
         distanceToDictionary[caseId].Add(distanceTo);
     }
 }
Exemple #7
0
 internal void Save(DistanceTo distanceTo, int caseId)
 {
     if (distanceTo.Id == -1)
     {
         distanceTo.Id = db.CreateDistanceTo(distanceTo, caseId);
     }
     else
     {
         db.UpdateDistanceTo(distanceTo, caseId);
     }
 }
Exemple #8
0
        public double RiverDensity(double latitude, double longitude)
        {
            double density = 0;

            double d2 = DistanceTo.River(latitude, longitude);

            if (d2 >= 0)
            {
                density += riverDistribution.ProbabilityDensityFunction(d2);
            }
            return(density);
        }
Exemple #9
0
        public double SatelliteDensity(double latitude, double longitude)
        {
            double density = 0;

            double d1 = DistanceTo.Satellite(latitude, longitude);

            if (d1 >= 0)
            {
                density += satelliteDistribution.ProbabilityDensityFunction(d1);
            }
            return(density);
        }
Exemple #10
0
        /// <summary>
        /// Creates a new DistanceTo in the database.
        /// </summary>
        /// <param name="distanceTo">DistanceTo to be created.</param>
        /// <param name="caseId">CaseId connected to the DistanceTo.</param>
        /// <returns>Returns the Id of the DistanceTo created.</returns>
        /// <author>René Sørensen</author>
        public int CreateDistanceTo(DistanceTo distanceTo, int caseId)
        {
            SqlCommand cmd = new SqlCommand
            {
                CommandText = "INSERT INTO DistanceTo OUTPUT INSERTED.DistanceToId VALUES (@CaseId, @Type, @Distance); "
            };

            cmd.Parameters.Add("@CaseId", SqlDbType.Int, 4, "CaseId").Value     = caseId;
            cmd.Parameters.Add("@Type", SqlDbType.NVarChar, 50, "Type").Value   = distanceTo.Type;
            cmd.Parameters.Add("@Distance", SqlDbType.Int, 4, "Distance").Value = distanceTo.Distance;

            return((int)DBConnectionMSSQL.Instance.ExecuteScalar(cmd, -1));
        }
Exemple #11
0
        /// <summary>
        /// Updates the information from a DistanceTo, in the database.
        /// </summary>
        /// <param name="distanceTo">DistanceTo to be updated.</param>
        /// <param name="caseId">CaseId connected to the DistanceTo.</param>
        /// <author>René Sørensen</author>
        public void UpdateDistanceTo(DistanceTo distanceTo, int caseId)
        {
            int distanceToId = distanceTo.Id;

            SqlCommand cmd = new SqlCommand
            {
                CommandText = "UPDATE DistanceTo SET CaseId = (@CaseId), Type = (@Type), Distance = (@Distance) WHERE DistanceToId = (@DistanceToId)"
            };

            cmd.Parameters.Add("@DistanceToId", SqlDbType.Int, 4, "DistanceToId").Value = distanceToId;

            cmd.Parameters.Add("@CaseId", SqlDbType.Int, 4, "CaseId").Value     = caseId;
            cmd.Parameters.Add("@Type", SqlDbType.NVarChar, 50, "Type").Value   = distanceTo.Type;
            cmd.Parameters.Add("@Distance", SqlDbType.Int, 4, "Distance").Value = distanceTo.Distance;

            DBConnectionMSSQL.Instance.ExecuteNonQuery(cmd);
        }
Exemple #12
0
        public static int BinarySearchClosest <T, G>(this IList <T> array, G value, DistanceTo <T, G> distanceFunction)
        {
            if (array.Count == 0)
            {
                return(-1);
            }

            if (array.Count == 1)
            {
                return(0);
            }

            int low  = 0;
            int high = array.Count - 1;

            int lastIdx = 0;
            int diff    = int.MaxValue;

            while (low <= high)
            {
                var mid    = (low + high) / 2;
                var result = distanceFunction(array[mid], value);
                if (result == 0)
                {
                    return(mid);
                }

                var abs = Math.Abs(result);
                if (abs < diff)
                {
                    diff    = abs;
                    lastIdx = mid;
                }

                if (result > 0)
                {
                    high = mid - 1;
                }
                else
                {
                    low = mid + 1;
                }
            }

            return(lastIdx);
        }
        public NewCaseStepProperty(NewCaseDropIn baseView, Case cCase) : base(cCase)
        {
            InitializeComponent();

            foreach (var propertyType in PropertyTypeController.Instance.GetPropertyTypes())
            {
                cboPropertyType.Items.Add(propertyType);
                cboPropertyType.DisplayMember = "Description";
            }

            if (cCase != null)
            {
                cboPropertyType.SelectedItem = cCase.PropertyType;
                stbPropertyArea.Text         = cCase.LivingArea.ToString();
                stbPropertyBasement.Text     = cCase.BasementArea.ToString();
                stbPropertyBuildYear.Text    = cCase.BuiltYear.ToString();
                stbPropertyEnergyMark.Text   = cCase.EnergyClassification;
                stbPropertyFloors.Text       = cCase.Floors.ToString();
                stbPropertyRooms.Text        = cCase.Rooms.ToString();
                stbPropertyBedrooms.Text     = cCase.Bedrooms.ToString();
                stbPropertyBathrooms.Text    = cCase.Bathrooms.ToString();
                stbPropertyToilets.Text      = cCase.Toilets.ToString();

                var distances = CaseController.Instance.GetDistanceTos(cCase.Id);
                foreach (var distance in distances)
                {
                    if (distance.Type == DistanceToSystemType.Shopping.ToString())
                    {
                        disShopping = distance;
                        stbDistanceToShopping.Text = distance.Distance.ToString();
                    }
                    else if (distance.Type == DistanceToSystemType.School.ToString())
                    {
                        disSchool = distance;
                        stbDistanceToSchool.Text = distance.Distance.ToString();
                    }
                    else if (distance.Type == DistanceToSystemType.Center.ToString())
                    {
                        disCenter = distance;
                        stbDistanceToCenter.Text = distance.Distance.ToString();
                    }
                }
            }
        }
Exemple #14
0
        public static int BinarySearchLower <T, G>(this IList <T> array, G value, DistanceTo <T, G> distanceFunction)
        {
            var idx = BinarySearchClosest(array, value, distanceFunction);

            if (idx < 0)
            {
                return(idx);
            }
            var distance = distanceFunction(array[idx], value);

            if (distance > 0)
            {
                return(0 == idx ? idx : idx - 1);
            }
            else
            {
                return(idx);
            }
        }
Exemple #15
0
        /// <summary>
        /// Returns a dictionary containing all the DistanceTos in the database.
        /// </summary>
        /// <returns>Returns a dictionary containing all the DistanceTos in the database, with CaseId as key and a list of DistanceTos containing that CaseId</returns>
        /// <author>René Sørensen</author>
        public Dictionary <int, List <DistanceTo> > ReadDistanceTos()
        {
            Dictionary <int, List <DistanceTo> > distanceToDictionary = new Dictionary <int, List <DistanceTo> >();
            SqlCommand cmd = new SqlCommand
            {
                CommandText = "SELECT * FROM DistanceTo;",
            };

            SqlDataReader reader = null;

            try
            {
                reader = DBConnectionMSSQL.Instance.ExecuteReader(cmd);
                while (reader.Read())
                {
                    int    distanceToId = (int)reader["DistanceToId"];
                    int    caseId       = (int)reader["CaseId"];
                    string type         = (string)reader["Type"];
                    int    distance     = (int)reader["Distance"];

                    var distanceTo = new DistanceTo(distanceToId, type, distance);
                    if (!distanceToDictionary.ContainsKey(caseId))
                    {
                        distanceToDictionary.Add(caseId, new List <DistanceTo>());
                    }
                    distanceToDictionary[caseId].Add(distanceTo);
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return(distanceToDictionary);
        }
Exemple #16
0
        public double CalculateDensity(double latitude, double longitude)
        {
            double density = 0;

            double d1 = DistanceTo.Satellite(latitude, longitude);
            double d2 = DistanceTo.River(latitude, longitude);
            double d3 = DistanceTo.Brandenburg(latitude, longitude);

            if (d1 >= 0)
            {
                density += satelliteDistribution.ProbabilityDensityFunction(d1);
            }

            if (d2 >= 0)
            {
                density += riverDistribution.ProbabilityDensityFunction(d2);
            }

            density += brandenburgDistribution.ProbabilityDensityFunction(d3);
            return(density);
        }
Exemple #17
0
        /// <summary>
        /// Returns all the ads from the database, with a given CaseId.
        /// </summary>
        /// <param name="caseId">Id of the case</param>
        /// <returns>Returns a List of all the ads, having a CaseId given by the parameter</returns>
        /// <author>René Sørensen</author>
        public List <DistanceTo> ReadDistanceTos(int caseId)
        {
            var        distanceToList = new List <DistanceTo>();
            SqlCommand cmd            = new SqlCommand
            {
                CommandText = "SELECT * FROM DistanceTo WHERE CaseId = (@CaseId);",
            };

            cmd.Parameters.Add("@CaseId", SqlDbType.Int, 4, "CaseId").Value = caseId;

            SqlDataReader reader = null;

            try
            {
                reader = DBConnectionMSSQL.Instance.ExecuteReader(cmd);
                while (reader.Read())
                {
                    int    distanceToId = (int)reader["DistanceToId"];
                    string type         = (string)reader["Type"];
                    int    distance     = (int)reader["Distance"];

                    var distanceTo = new DistanceTo(distanceToId, type, distance);
                    distanceToList.Add(distanceTo);
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return(distanceToList);
        }
Exemple #18
0
 internal void RemoveFromCatalog(int caseId, DistanceTo distanceTo)
 {
     distanceToDictionary[caseId].Remove(distanceTo);
 }
Exemple #19
0
 /// <summary>
 /// Tilføjer en "Afstand til" til casen
 /// </summary>
 /// <param name="distanceTo"></param>
 /// <author>Mathias Poulsen</author>
 private void AddDistanceToCase(DistanceTo distanceTo)
 {
     distanceToCatalog.AddToCatalog(activeCase.Id, distanceTo);
 }
Exemple #20
0
 /// <summary>
 /// Sætter afstanden på DistanceTo
 /// </summary>
 /// <author>Mathias Petersen</author>
 public void SetDistanceTo(DistanceTo distanceTo, int distance)
 {
     distanceTo.Distance = distance;
 }