Пример #1
0
 public FipeVehicleBrand(long id, string description, FipeVehicleTypesEnum fipeVehicleTypesEnum)
 {
     this.Id            = id;
     this.Description   = description;
     this.VehicleTypeId = fipeVehicleTypesEnum;
     this.Active        = true;
 }
Пример #2
0
        /// <summary>
        /// Get normalized Fipe table data by vehicle type and reference id.
        /// Notes:
        /// - If the reference id is parameterized with the value 0, tthe most current reference will be used, that is, the most current data from the fipe table.
        /// - The slowing in the download is caused that of the proxy of the [FIPE WebAPI], which performs momentary locks.
        /// - To avoid making requests while the proxy is still locked, the service will pause the task for a few minutes and after will perform normal.
        /// - The truck download is the fastest among them.
        /// - Downloading the three types of vehicles together [Car, Motorcycle, Truck/MicroBus] takes between 2 or 4 hours.
        /// </summary>
        /// <param name="vehicleType"></param>
        /// <param name="referenceId"></param>
        /// <returns></returns>
        public NormalizedDownloadResult GetDataFromFipeTableByVehicleType(FipeVehicleTypesEnum vehicleType, int referenceId = 0)
        {
            this._logger.LogDebug($"Starting method GetDataFromFipeTableByVehicleType. Method={nameof(this.GetDataFromFipeTableByVehicleType)}; VehicleType={vehicleType}; ReferenceId={referenceId};");

            var selectedReference = this._downloadService.GetFipeTableReference(referenceId);

            var fipeTable = new FipeDataTable(selectedReference.Id, vehicleType);

            this._downloadService.GetBrands(fipeTable);
            this._downloadService.GetModels(fipeTable);
            this._downloadService.GetYearsAndFuels(fipeTable);
            var tupleEntities = fipeTable.ModelToEntity();

            this._logger.LogDebug($"Brands and models of normalized vehicles. Method={nameof(this.GetDataFromFipeTableByVehicleType)}; VehicleType={vehicleType}; ReferenceId={referenceId};");

            var vehicles = this._downloadService.GetVehicles(fipeTable);
            var tuple    = vehicles.ModelToEntity();

            this._logger.LogDebug($"Normalized vehicles. Method={nameof(this.GetDataFromFipeTableByVehicleType)}; VehicleType={vehicleType}; ReferenceId={referenceId};");

            return(new NormalizedDownloadResult(
                       selectedReference,
                       vehicleType,
                       tupleEntities.Brands,
                       tupleEntities.Models,
                       tuple.Vehicles,
                       tuple.Prices));
        }
        public void GetDataFromFipeTableByVehicleTypeTest(FipeVehicleTypesEnum vehicleType, int referenceId)
        {
            var result    = this._normalizedDownloadService.GetDataFromFipeTableByVehicleType(vehicleType, referenceId);
            var condition = false;
            var message   = "The download of normalized FIPE data was not successful. VehicleType=";

            switch (vehicleType)
            {
            case FipeVehicleTypesEnum.Car:
                condition =
                    result.Models.Any(x => x.Description.Contains("uno", StringComparison.OrdinalIgnoreCase)) &&
                    result.Vehicles.Count(x => x.VehicleFuelTypeId == VehicleFuelTypesEnum.Ethanol) > 2 &&
                    result.Vehicles.Count(x => x.VehicleFuelTypeId == VehicleFuelTypesEnum.Diesel) > 2 &&
                    result.Vehicles.Count(x => x.VehicleFuelTypeId == VehicleFuelTypesEnum.Gas) > 2 &&
                    result.Vehicles.Count(x => x.VehicleFuelTypeId == VehicleFuelTypesEnum.Flex) > 2;
                Assert.True(condition, $"{message}{vehicleType};");
                goto default;

            case FipeVehicleTypesEnum.Motorcycle:
                condition =
                    result.Models.Any(x => x.Description.Contains("ninja", StringComparison.OrdinalIgnoreCase));
                Assert.True(condition, $"{message}{vehicleType};");
                goto default;

            case FipeVehicleTypesEnum.TruckAndMicroBus:
                condition =
                    result.Models.Any(x => x.Description.Contains("constellation", StringComparison.OrdinalIgnoreCase));
                Assert.True(condition, $"{message}{vehicleType};");
                goto default;

            default:
                Assert.True(
                    result.VehicleType == vehicleType &&
                    result.FipeReference.Id == referenceId &&
                    result.Brands.Count > 0 &&
                    result.Brands.Any(x => x.VehicleTypeId == vehicleType) &&
                    result.Models.Count > 0 &&
                    result.Vehicles.Count > 0 &&
                    result.Vehicles.Any(x => x.IsValid) &&
                    result.Prices.Any(x => x.Value > 0)
                    , $"The download of normalized FIPE data was not successful. VehicleType={vehicleType};");
                break;
            }

            int  amountValid              = result.Vehicles.Count(x => x.IsValid == true);
            int  eightyPercent            = Convert.ToInt32(result.Vehicles.Count * 0.80);
            bool greaterThanEightyPercent = amountValid > eightyPercent;

            Assert.True(greaterThanEightyPercent, "There are more than 80 percent of invalid vehicles!");
        }
Пример #4
0
 public NormalizedDownloadResult(
     FipeReference fipeReference,
     FipeVehicleTypesEnum vehicleType,
     List <FipeVehicleBrand> brands,
     List <FipeVehicleModel> models,
     List <FipeVehicleInformation> vehicles,
     List <FipeVehiclePrice> prices)
 {
     this.FipeReference = fipeReference;
     this.VehicleType   = vehicleType;
     this.Brands        = brands.AsReadOnly();
     this.Models        = models.AsReadOnly();
     this.Vehicles      = vehicles.AsReadOnly();
     this.Prices        = prices.AsReadOnly();
 }
Пример #5
0
        private NormalizedDownloadResult GetDataFipeTable(FipeVehicleTypesEnum vehicleType, int referenceId)
        {
            var downloadResult = this._normalizedDownloadService
                                 .GetDataFromFipeTableByVehicleType(vehicleType, referenceId);

            if (downloadResult.VehicleType == vehicleType &&
                downloadResult.FipeReference.Id == referenceId &&
                downloadResult.Brands.Count > 0 &&
                downloadResult.Models.Count > 0 &&
                downloadResult.Vehicles.Count > 0)
            {
                return(downloadResult);
            }
            else
            {
                throw new ArgumentNullException($"{nameof(downloadResult)}={downloadResult}");
            }
        }
Пример #6
0
 public FipeVehicleType(FipeVehicleTypesEnum fipeVehicleTypesEnum)
 {
     this.Id          = fipeVehicleTypesEnum;
     this.Description = fipeVehicleTypesEnum.ToString();
     this.Active      = true;
 }
Пример #7
0
 public FipeDataTable(int referenceId, FipeVehicleTypesEnum vehicleType)
 {
     this.ReferenceId = referenceId;
     this.VehicleType = vehicleType;
     this.Brands      = new List <Brand>();
 }