Ejemplo n.º 1
0
        private void CalculatePrice(PriceInput priceInput, int cat, AppraisalOutput appraisalOutput)
        {
            string catText = "a3";

            /// Call Price Service
            switch (cat)
            {
            case 1:
                catText = "a1";
                break;

            case 5:
                catText = "a2";
                break;

            case 6:
                catText = "a3";
                break;

            case 21:
                catText = "a21";
                break;

            default:
                catText = "a2";
                break;
            }

            string priceUrl = String.Format("{0}/{1}/{2}", ConfigurationManager.AppSettings["Server"], ConfigurationManager.AppSettings["PriceService"], catText);
            string postData = "[" + JsonConvert.SerializeObject(priceInput) + "]";
            string result   = iaziClientsync.postApiRequest(priceUrl, postData, token);

            //PriceOutput priceOutput = Newtonsoft.Json.JsonConvert.DeserializeObject<PriceOutput>(result);
            parsePriceModelRJson(result, appraisalOutput);
        }
Ejemplo n.º 2
0
        public AppraisalOutput processDetailInput(DetailInput detailInput, string userAgent)
        {
            PriceInput      priceInput      = MapDetailInputToPriceInput(detailInput);
            AppraisalOutput appraisalOutput = new AppraisalOutput();

            CalculatePrice(priceInput, detailInput.catCode ?? 0, appraisalOutput);

            appraisalOutput.microRating = detailInput.microRating ?? 0;
            appraisalOutput.zip         = detailInput.zip;
            appraisalOutput.town        = detailInput.town;
            appraisalOutput.street      = detailInput.street;
            appraisalOutput.CatCode     = detailInput.catCode ?? 0;
            appraisalOutput.country     = detailInput.country;

            ////Saving
            try
            {
                SavePricePropertyDetails(MapPriceBuisnessDataToDatabaseModel(null, null, null, detailInput.deviceId, appraisalOutput), userAgent);
            }
            catch (Exception ex)
            {
                RealEstateRepository realEstateRepository = new RealEstateRepository();
                realEstateRepository.saveException(ex.Message, Convert.ToString(ex.InnerException), ex.StackTrace);
                return(appraisalOutput);
            }

            return(appraisalOutput);
        }
Ejemplo n.º 3
0
        private void parsePriceModelRJson(string resultJson, AppraisalOutput appraisalOutput)
        {
            dynamic jsonPriceResult = Newtonsoft.Json.JsonConvert.DeserializeObject(resultJson);

            if (jsonPriceResult.status.Value == "OK" && jsonPriceResult.data[0].result.status.Value == 0)
            {
                appraisalOutput.appraisalValue = jsonPriceResult.data[0].result.value.Value;

                Random rnd       = new Random();
                double randomHi  = 13 / 100.0; //rnd.Next(10, 15) / 100.0;
                double randomLow = 17 / 100.0; //rnd.Next(15, 20) / 100.0;

                if (reverseGeoCodeResult == null || reverseGeoCodeResult.Country == "Switzerland")
                {
                    appraisalOutput.minappraisalValue = Convert.ToInt64(appraisalOutput.appraisalValue - (appraisalOutput.appraisalValue * randomLow));
                    appraisalOutput.maxappraisalValue = Convert.ToInt64(appraisalOutput.appraisalValue + (appraisalOutput.appraisalValue * randomHi));
                }

                for (int i = 0; i < jsonPriceResult.data[0].parameterInfo.Count; i++)
                {
                    dynamic component = jsonPriceResult.data[0].parameterInfo[i];
                    string  compName  = component.name;
                    // check if this entry in address_components has a type of country
                    switch (compName)
                    {
                    case "roomNb":
                        appraisalOutput.roomNb = (component.value > 0) ? component.value : component.replacedValue;
                        break;

                    case "surfaceLiving":
                        appraisalOutput.surfaceLiving = (component.value > 0) ? component.value : component.replacedValue;
                        break;

                    case "surfaceGround":
                        appraisalOutput.landSurface = (component.value > 0) ? component.value : component.replacedValue;
                        break;

                    case "bathNb":
                        appraisalOutput.bathNb = (component.value > 0) ? component.value : component.replacedValue;
                        break;

                    case "buildYear":
                        appraisalOutput.buildYear = (component.value > 0) ? component.value : component.replacedValue;
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private PriceData MapPriceBuisnessDataToDatabaseModel(string imageBase64, double?latitude, double?longitude, string deviceId, AppraisalOutput appraisalOutput)
        {
            PriceData priceData = new PriceData();

            /* Process Image Data */
            if (imageBase64 != null)
            {
                priceData.realestateData.Image = imageBase64;

                if (appraisalOutput.CatCode != -2)
                {
                    using (var ms = new MemoryStream(Convert.FromBase64String(imageBase64)))
                    {
                        System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
                        priceData.realestateData.ImageSize   = ms.Length / 1024;
                        priceData.realestateData.ImageWidth  = img.Width;
                        priceData.realestateData.ImageHeight = img.Height;
                    }
                }
            }

            if (latitude != null)
            {
                priceData.realestateData.Latitude = (decimal)latitude;
            }

            if (longitude != null)
            {
                priceData.realestateData.Longitude = (decimal)longitude;
            }

            priceData.realestateData.DeviceId = deviceId;

            /* Store Address */
            priceData.realestateData.AddressZip    = appraisalOutput.zip;
            priceData.realestateData.AddressTown   = appraisalOutput.town;
            priceData.realestateData.AddressStreet = appraisalOutput.street;
            priceData.realestateData.Country       = appraisalOutput.country;
            priceData.realestateData.CatCode       = appraisalOutput.CatCode;

            /* Store all calculated values */
            priceData.realestateData.SurfaceLiving = appraisalOutput.surfaceLiving;
            priceData.realestateData.LandSurface   = appraisalOutput.landSurface;

            if (appraisalOutput.microRating != null)
            {
                priceData.realestateData.MicroRating = (decimal)appraisalOutput.microRating;
            }

            if (appraisalOutput.roomNb != null)
            {
                priceData.realestateData.RoomNb = (decimal)appraisalOutput.roomNb;
            }

            priceData.realestateData.BathNb    = appraisalOutput.bathNb;
            priceData.realestateData.BuildYear = appraisalOutput.buildYear;

            //realEstateAppraise.RealEstateId =  new Guid();
            priceData.realestateAppraise.AppraisalValue    = appraisalOutput.appraisalValue;
            priceData.realestateAppraise.MinAppraisalValue = appraisalOutput.minappraisalValue;
            priceData.realestateAppraise.MaxAppraisalValue = appraisalOutput.maxappraisalValue;

            return(priceData);
        }
Ejemplo n.º 5
0
        public AppraisalOutput processImageLatLon(string imageBase64, double?latitude, double?longitude, string deviceId, string userAgent)
        {
            AppraisalOutput appraisalOutput = new AppraisalOutput();
            GoogleVisionApi googleVisionApi = new GoogleVisionApi();
            PriceInput      priceInput      = new PriceInput();
            ImageCategory   imageCategory;
            string          country;
            string          countryCode;
            double?         lat;
            double?         lng;

            try
            {
                imageCategory = googleVisionApi.fetchCategoryForImage(imageBase64);
            }
            catch (Exception)
            {
                // imageBase64 = getImageAndConvertbase64();
                // imageCategory = googleVisionApi.fetchCategoryForImage(imageBase64);
                imageCategory = new ImageCategory();
                imageCategory.CategoryCode = -2;
                imageCategory.CategoryText = "Invalid Image";
            }

            getAddressForLatLong(latitude ?? 0.0, longitude ?? 0.0);

            if (reverseGeoCodeResult.Country != "Switzerland")
            {
                country     = "Switzerland";
                countryCode = "CH";

                priceInput.zip  = appraisalOutput.zip = ConfigurationManager.AppSettings["DefaultZip"];
                priceInput.town = appraisalOutput.town = ConfigurationManager.AppSettings["DefaultTown"];
                //if country is not switzerland then attach time to street .
                priceInput.street = appraisalOutput.street = ConfigurationManager.AppSettings["DefaultStreet"] + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second;

                appraisalOutput.minappraisalValue = Convert.ToInt64(latitude.ToString().Replace(".", String.Empty));
                appraisalOutput.maxappraisalValue = Convert.ToInt64(longitude.ToString().Replace(".", String.Empty));
                lat = Convert.ToDouble(ConfigurationManager.AppSettings["DefaultLatitude"]);
                lng = Convert.ToDouble(ConfigurationManager.AppSettings["DefaultLongitude"]);
            }
            else
            {
                country     = reverseGeoCodeResult.Country;
                countryCode = "CH";

                priceInput.zip    = appraisalOutput.zip = reverseGeoCodeResult.Zip;
                priceInput.town   = appraisalOutput.town = reverseGeoCodeResult.Town;
                priceInput.street = appraisalOutput.street = reverseGeoCodeResult.Street;
                lat = (double)latitude;
                lng = (double)longitude;
            }

            if (imageCategory.CategoryCode != -1 && imageCategory.CategoryCode != -2)
            {
                getMicroRating(imageCategory.CategoryCode, lat ?? 0.0, lng ?? 0.0, countryCode);
                priceInput.qualityMicro = appraisalOutput.microRating = ratingResponse.results.microRatingClass1To5 ?? 3;
            }


            appraisalOutput.country = country;
            appraisalOutput.CatCode = imageCategory.CategoryCode;

            switch (imageCategory.CategoryCode)
            {
            case 5:
                priceInput.surfaceLiving = Convert.ToInt16(ConfigurationManager.AppSettings["A2SurfaceLivingDefault"]); //set default for A2 for Surface
                appraisalOutput.category = imageCategory.CategoryText;                                                  //" Single family House";
                break;

            case 6:
                priceInput.surfaceLiving = Convert.ToInt16(ConfigurationManager.AppSettings["A3SurfaceLivingDefault"]);;
                appraisalOutput.category = imageCategory.CategoryText;      //" Condominium";
                break;

            case -1:
            case -2:
                appraisalOutput.category = imageCategory.CategoryText;      //Set the first two labels that are returned by Google
                break;

            default:
                break;
            }


            if (imageCategory.CategoryCode != -1 && imageCategory.CategoryCode != -2)
            {
                CalculatePrice(priceInput, imageCategory.CategoryCode, appraisalOutput);
            }

            //Saving Property Details//
            try
            {
                PriceData priceData = MapPriceBuisnessDataToDatabaseModel(imageBase64, latitude, longitude, deviceId, appraisalOutput);
                SavePricePropertyDetails(priceData, userAgent);
            }
            catch (Exception ex)
            {
                RealEstateRepository realEstateRepository = new RealEstateRepository();
                realEstateRepository.saveException(ex.Message, Convert.ToString(ex.InnerException), ex.StackTrace);
                return(appraisalOutput);
            }


            return(appraisalOutput);
        }