Beispiel #1
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);
        }
Beispiel #2
0
        public OfferedRentOutput processImageLatLonForOfferedRent(string imageBase64, double?latitude, double?longitude, string deviceId, string userAgent)
        {
            OfferedRentOutput offeredRentOutput = new OfferedRentOutput();
            GoogleVisionApi   googleVisionApi   = new GoogleVisionApi();
            OfferedRentInput  offeredRentInput  = new OfferedRentInput();
            ImageCategory     imageCategory;
            string            country;
            string            countryCode;

            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";

                offeredRentInput.address = new OfferedRentAddress()
                {
                    address = ConfigurationManager.AppSettings["DefaultFormatedAddress"],
                    zip     = offeredRentOutput.zip = ConfigurationManager.AppSettings["DefaultZip"],
                    town    = offeredRentOutput.town = ConfigurationManager.AppSettings["DefaultTown"],
                    street  = offeredRentOutput.street = ConfigurationManager.AppSettings["DefaultStreet"] + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second,
                    lat     = Convert.ToDouble(ConfigurationManager.AppSettings["DefaultLatitude"]),
                    lng     = Convert.ToDouble(ConfigurationManager.AppSettings["DefaultLongitude"]),
                    country = country
                };

                offeredRentOutput.minappraisalValue = Convert.ToInt64(latitude.ToString().Replace(".", String.Empty));
                offeredRentOutput.maxappraisalValue = Convert.ToInt64(longitude.ToString().Replace(".", String.Empty));
            }
            else
            {
                country     = reverseGeoCodeResult.Country;
                countryCode = "CH";

                offeredRentInput.address = new OfferedRentAddress()
                {
                    address = reverseGeoCodeResult.FormattedAddress,
                    zip     = offeredRentOutput.zip = reverseGeoCodeResult.Zip,
                    town    = offeredRentOutput.town = reverseGeoCodeResult.Town,
                    street  = offeredRentOutput.street = reverseGeoCodeResult.Street,
                    lat     = (double)latitude,
                    lng     = (double)longitude,
                    country = country
                };
            }

            if (imageCategory.CategoryCode != -1 && imageCategory.CategoryCode != -2)
            {
                getMicroRating(imageCategory.CategoryCode, offeredRentInput.address.lat ?? 0.0, offeredRentInput.address.lng ?? 0.0, countryCode);
                offeredRentInput.qualityMicro = offeredRentOutput.qualityMicro = ratingResponse.results.microRatingClass1To5 ?? 3;
                offeredRentInput.ortId        = getOrtId(countryCode, offeredRentInput.address.lat ?? 0.0, offeredRentInput.address.lng ?? 0.0, "en-US");
            }



            offeredRentOutput.country      = country;
            offeredRentOutput.CategoryCode = imageCategory.CategoryCode;

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

            case 6:
                offeredRentInput.surfaceContract = Convert.ToInt16(ConfigurationManager.AppSettings["A3SurfaceLivingDefault"]);
                offeredRentInput.categoryCode    = offeredRentOutput.CategoryCode;
                offeredRentOutput.category       = imageCategory.CategoryText; //" Condominium";
                break;

            case -1:
            case -2:
                offeredRentOutput.category = imageCategory.CategoryText;
                break;

            default:
                break;
            }

            if (imageCategory.CategoryCode != -1 && imageCategory.CategoryCode != -2)
            {
                CalculateRent(offeredRentInput, offeredRentOutput);
            }

            //Saving Property Details//
            try
            {
                RentData rentData = MapRentBuisnessDataToDatabaseModel(imageBase64, latitude, longitude, deviceId, offeredRentOutput);
                SaveRentPropertyDetails(rentData, userAgent);
            }
            catch (Exception ex)
            {
                RealEstateRepository realEstateRepository = new RealEstateRepository();
                realEstateRepository.saveException(ex.Message, Convert.ToString(ex.InnerException), ex.StackTrace);
                return(offeredRentOutput);
            }

            return(offeredRentOutput);
        }