static void IndexPrices(Acco acco, IEnumerable<Price> prices) { if (!prices.Any()) return; client.Bulk(bulk => { foreach (var price in prices) { bulk.Index<Price>(index => index .Parent(acco.Id.ToString(CultureInfo.InvariantCulture)) .Object(price)); } return bulk; }).AssertValid(); }
public static List<Price> GeneratePrices(Acco acco, Dictionary<DateTime, TempAvailability> accoAvailabilities) { //Debug.WriteLine("GeneratePrices"); List<Price> prices = new List<Price>(); IEnumerable<string> availableCareTypes = CareTypeCodesDistribution.Pick(); if (!acco.CountryCanHaveAllInclusive) availableCareTypes = availableCareTypes.Where(ct => ct != "AI"); if (!availableCareTypes.Any()) { availableCareTypes = new[] { "AI" }; } var careTypes = GenerateCareTypes(availableCareTypes, acco.AccoBaseCareTypePricePerDay); int numOfFlightTimes = FlightTimesDistribution.Pick(); DateTime endDate = DateTime.Today.AddYears(1); for (var date = DateTime.Today.AddDays(2); date <= endDate; date = date.AddDays(1)) { TempAvailability accoAvailability; if (!accoAvailabilities.TryGetValue(date, out accoAvailability)) continue; foreach (var duration in accoAvailability.DurationDays) { List<TempFlightInfo> flights = new List<TempFlightInfo>(); if (acco.CountryHasFlight) { TempAvailability flightAvailability; if (!acco.CityFlightAvailabilities.TryGetValue(date, out flightAvailability)) continue; if (!flightAvailability.DurationDays.Contains(duration)) continue; for (int i = 0; i < numOfFlightTimes; i++) { var fee = FlightFeesDistribution.Pick(); var flight = new TempFlightInfo { Price = acco.CountryFlightPriceBase + fee }; foreach (var careType in careTypes) { var pricePerPerson = acco.CountryBasePrice + flight.Price + careType.PricePerDay * duration; prices.Add(new Price { Id = priceId++, CareType = careType.Code, DepartureDate = date, DurationDays = duration, PricePerPerson = pricePerPerson, TransportType = "VL", TransportFrom = "AMS" }); } } } if (!acco.CountryHasFlight || acco.AccoFlightOptional) { foreach (var careType in careTypes) { var pricePerPerson = acco.CountryBasePrice + +careType.PricePerDay * duration; prices.Add(new Price { Id = priceId++, CareType = careType.Code, DepartureDate = date, DurationDays = duration, PricePerPerson = pricePerPerson, TransportType = "EV" }); } } } } return prices; }
/// <summary> /// Generates Accos. /// We generate 42 countries and use a formula and some randomness to create accos in that country. /// </summary> /// <returns></returns> public static IEnumerable<Acco> GenerateAccos(int numOfCountries) { int accoNr = 1; for (int country = 1; country <= numOfCountries; country++) { using (new Timed(string.Format("Generation country {0}/{1}", country, numOfCountries))) { var countryHasFlight = CountryFlightDistribution.Pick(); var countryFlightPriceBase = CountryFlightPriceDistanceDistribution.Pick(); // some countries are just more expensive (this is not per day) var countryPriceBase = RandomUtils.CreateMemberInNormalDistribution(0, 140, 8); var countryCanHaveAllInclusive = RandomUtils.RandomBool(0.8); int avgNumOfCities = 12 * country; int minNumOfCities = (int)Math.Floor(avgNumOfCities * 0.7); // deviation of 30% max int maxNumOfCities = (int)Math.Ceiling(avgNumOfCities * 1.3); // deviation of 30% max int avgNumOfAccosThisCountry = 60 * country; int minNumOfAccosThisCountry = (int)Math.Floor(avgNumOfAccosThisCountry * 0.9); // deviation of 10% max int maxNumOfAccosThisCountry = (int)Math.Ceiling(avgNumOfAccosThisCountry * 1.1); // deviation of 10% max int numOfCities = RandomUtils.MinMax(minNumOfCities, maxNumOfCities); int numOfAccosThisCountry = RandomUtils.MinMax(minNumOfAccosThisCountry, maxNumOfAccosThisCountry); int numAccoPerCity = (int)Math.Ceiling(numOfAccosThisCountry / (double)numOfCities); int minNumOfAccos = (int)Math.Floor(numAccoPerCity * 0.8); // deviation of 20% max int maxNumOfAccos = (int)Math.Ceiling(numAccoPerCity * 1.2); // deviation of 20% max var highSeasons = GetHighSeasons(); var cityFlightAvailability = GenerateFlightAvailabilities(highSeasons); double citySameAirportChance = CitySameAirportDistribution.Pick(); int basePricePerDay = RandomUtils.CreateMemberInNormalDistribution(5, 150, 20, 50); // http://www.wolframalpha.com/input/?i=normal%2C+mean%3D50%2C+sd%3D20 int baseCareTypePricePerDay = RandomUtils.CreateMemberInNormalDistribution(5, 50, 5, 20); for (int city = 1; city <= numOfCities; city++) { var locationCode = createLocationCode(country, city); if (RandomUtils.RandomBool(citySameAirportChance)) { // 80% kans dat deze stad dezelfde luchthaven gebruikt als de vorige stad. cityFlightAvailability = GenerateFlightAvailabilities(highSeasons); } int numOfAccos = RandomUtils.MinMax(minNumOfAccos, maxNumOfAccos); for (int i = 0; i < numOfAccos; i++) { bool accoFlightOptional = AccoFlightOptionalDistribution.Pick(); // some accos are more expensive var accoPriceBasePerDay = basePricePerDay + RandomUtils.CreateMemberInNormalDistribution(0, 20, 2, 6); var accoBaseCareTypePricePerDay = baseCareTypePricePerDay + RandomUtils.CreateMemberInNormalDistribution(0, 10, 1.5, 5); var acco = new Acco { Id = accoNr, Name = "Acco " + locationCode + " " + accoNr, LocationCode = locationCode, Description = GetRandomDescription(), CountryHasFlight = countryHasFlight, CountryFlightPriceBase = countryFlightPriceBase, CountryCanHaveAllInclusive = countryCanHaveAllInclusive, CountryBasePrice = countryPriceBase, AccoFlightOptional = accoFlightOptional, AccoBaseCareTypePricePerDay = accoBaseCareTypePricePerDay, AccoBasePricePerDay = accoPriceBasePerDay, CityFlightAvailabilities = cityFlightAvailability, HighSeasons = highSeasons }; yield return acco; accoNr++; } } } } }
static void IndexAcco(Acco acco) { client.Index(acco).AssertValid(); }