private void LoadAgeDist() { List <AgeDist> ageDistributions = new List <AgeDist>(); var ageCategories = AgeCategories.Count; using (CommentedCsvReader reader = new CommentedCsvReader(AgeDistributionFile.GetFileName(Root.InputBaseDirectory))) { while (reader.NextLine()) { if (reader.NumberOfCurrentCells >= ageCategories + 1) { float[] ageD = new float[ageCategories]; reader.Get(out int zone, 0); for (int i = 1; i < reader.NumberOfCurrentCells; i++) { reader.Get(out ageD[i - 1], i); } ageDistributions.Add(new AgeDist { Zone = zone, Percentages = ageD }); } } } int numberOfSetZones = 0; foreach (var ageDist in ageDistributions) { if (!PDZoneMap.TryGetValue(ageDist.Zone, out List <int> pd)) { throw new XTMFRuntimeException(this, "In " + Name + " we were unable to find a planning district for the zone number '" + ageDist.Zone + "' while loading the age distribution."); } numberOfSetZones += pd.Count; } var elements = ageDistributions.Count; var first = new int[numberOfSetZones * ageCategories]; var second = new int[numberOfSetZones * ageCategories]; var d = new float[numberOfSetZones * ageCategories]; var validAgeCategory = AgeCategories.ValidIndexies().ToArray(); int soFar = 0; for (int i = 0; i < elements; i++) { var zones = PDZoneMap[ageDistributions[i].Zone]; foreach (var zone in zones) { for (int j = 0; j < ageCategories; j++) { first[soFar] = zone; second[soFar] = validAgeCategory[j]; d[soFar] = ageDistributions[i].Percentages[j]; soFar++; } } } AgeRates = SparseTwinIndex <float> .CreateTwinIndex(first, second, d); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { AgeCategories age = (AgeCategories)validationContext.ObjectInstance; if (age.AgeEnd > age.AgeStart) { return(ValidationResult.Success); } return(new ValidationResult("Le champ \"Âge de fin\" doit être supérieur au champ \"Âge de début\"")); }
/// <summary> /// Default constructor /// </summary> public MarathonResultsDesignModel() { Marathons = new[] { "2014 - Japan", "2015 - Berlin", }; Marathon = Marathons.First(); Distances = new[] { "10 км малый марафон", "42 км полный марафон" }; Distance = Distances.First(); Genders = new[] { "Любой", "Мужской", "Женский" }; Gender = Genders.First(); AgeCategories = new[] { "18 - 29", "30 - 35", "36 - 45" }; AgeCategory = AgeCategories.First(); TotalRunnersCount = 1234; FinishedRunnersCount = 1198; AverageTime = new TimeSpan(4, 2, 10); ResultsCondition = new MarathonResultsCondition { Marathon = Marathon, Distance = Distance, Gender = Gender, AgeCategory = AgeCategory }; Results = new MarathonResultsListDesignModel(); }
public void LoadData() { Loaded = true; LoadPDZoneMap(); LoadCategoryInformation(); LoadAgeDist(); LoadEmploymentDist(); LoadOccupationDist(); LoadStudentDist(); LoadJobOccupationDistribution(); LoadJobTypeDisribution(); LoadDriversLicenseDistribution(); LoadNumberOfCarsDistribution(); if (SaveDataIntoZones) { var employmentStatusIndexes = EmploymentStatus.ValidIndexArray(); var ageCategoryIndexes = AgeCategories.ValidIndexArray(); var zones = Root.ZoneSystem.ZoneArray.GetFlatData(); Parallel.For(0, zones.Length, zone => { var z = zones[zone]; float generalworker = 0; float manufacturingworker = 0; float professionalworker = 0; float salesWorker = 0; float generalJob = 0; float manufacturingJob = 0; float professionalJob = 0; float salesJob = 0; var occRates = OccupationRates[zone]; var empData = EmploymentStatusRates[zone]; if (occRates != null && empData != null) { var pop = z.Population; foreach (var age in ageCategoryIndexes) { var agePop = pop * AgeRates[zone, age]; foreach (var status in employmentStatusIndexes) { var statusPop = agePop * empData[age, status]; professionalworker += statusPop * occRates[age, status, 1]; generalworker += statusPop * occRates[age, status, 2]; salesWorker += statusPop * occRates[age, status, 3]; manufacturingworker += statusPop * occRates[age, status, 4]; } } foreach (var status in employmentStatusIndexes) { var statusJobPop = z.Employment * JobTypeRates[zone, status]; professionalJob += statusJobPop * JobOccupationRates[zone, status, 1]; generalJob += statusJobPop * JobOccupationRates[zone, status, 2]; salesJob += statusJobPop * JobOccupationRates[zone, status, 3]; manufacturingJob += statusJobPop * JobOccupationRates[zone, status, 4]; } } z.GeneralEmployment = generalJob; z.ManufacturingEmployment = manufacturingJob; z.ProfessionalEmployment = professionalJob; z.RetailEmployment = salesJob; z.WorkGeneral = generalworker; z.WorkManufacturing = manufacturingworker; z.WorkProfessional = professionalworker; z.WorkRetail = salesWorker; }); } }
public GiftCriteriaBuilder AddAgeCategory(AgeCategories ageCategory) { Age = ageCategory; return(this); }
private void LoadAgeDist() { List <AgeDist> ageDistributions = new List <AgeDist>(); var ageCategories = AgeCategories.Count; using (CsvReader reader = new CsvReader(GetFullPath(AgeDistributionFile))) { int length; if (AgeDistributionFileHeader) { // burn the header reader.LoadLine(); } while ((length = reader.LoadLine()) > ageCategories) { float[] ageD = new float[ageCategories]; reader.Get(out int zone, 0); for (int i = 1; i < length; i++) { reader.Get(out ageD[i - 1], i); } ageDistributions.Add(new AgeDist { Zone = zone, Percentages = ageD }); } } int numberOfSetZones = 0; foreach (var ageDist in ageDistributions) { if (PdZoneMap.TryGetValue(ageDist.Zone, out List <int> temp)) { numberOfSetZones += temp.Count; } } var elements = ageDistributions.Count; var first = new int[numberOfSetZones * ageCategories]; var second = new int[numberOfSetZones * ageCategories]; var d = new float[numberOfSetZones * ageCategories]; var validAgeCategory = AgeCategories.ValidIndexies().ToArray(); int soFar = 0; for (int i = 0; i < elements; i++) { if (PdZoneMap.TryGetValue(ageDistributions[i].Zone, out List <int> zones)) { foreach (var zone in zones) { for (int j = 0; j < ageCategories; j++) { first[soFar] = zone; second[soFar] = validAgeCategory[j]; d[soFar] = ageDistributions[i].Percentages[j]; soFar++; } } } } AgeRates = SparseTwinIndex <float> .CreateTwinIndex(first, second, d); }
public async Task <ActionResult <IEnumerable <ReadBookDto> > > Get([FromQuery(Name = "filter")] Filter[] filter) { //api/books?filter=[{"property":"genres","value":"Poetry"},{"property":"publicationYear","value":"1993"}] string author = null; string title = null; int? publicationYear = null; Bookbindings bookbinding = Bookbindings.NotSet; AgeCategories ageCategorie = AgeCategories.NotSet; List <Genres> genres = null; foreach (var f in filter) { switch (f.property) { case "author": author = string.IsNullOrWhiteSpace(f.value) ? null : f.value; break; case "title": title = string.IsNullOrWhiteSpace(f.value) ? null : f.value; break; case "publicationYear": publicationYear = int.TryParse(f.value, out var tmpPublicationYear) ? (int?)tmpPublicationYear : null; break; case "bookbinding": if (!string.IsNullOrWhiteSpace(f.value)) { if (Enum.TryParse(f.value, true, out Bookbindings newBookbinding)) { bookbinding = newBookbinding; } } break; case "ageCategorie": if (!string.IsNullOrWhiteSpace(f.value)) { if (Enum.TryParse(f.value, true, out AgeCategories newAgeCategorie)) { ageCategorie = newAgeCategorie; } } break; case "genres": if (!string.IsNullOrWhiteSpace(f.value)) { genres = new List <Genres>(); foreach (var v in f.value.Split(',')) { if (Enum.TryParse(v, true, out Genres genre)) { genres.Add(genre); } } } break; } } if (string.IsNullOrEmpty(author) && string.IsNullOrEmpty(title) && !publicationYear.HasValue && bookbinding == Bookbindings.NotSet && genres == null && ageCategorie == AgeCategories.NotSet) { var books = await _bookService.GetAllBooks(); var readBooks = _mapper.Map <IEnumerable <Book>, IEnumerable <ReadBookDto> >(books); return(Ok(readBooks)); } else { var criteria = GetCriteria(author, title, publicationYear, bookbinding, ageCategorie, genres); var books = _bookService.FindBooks(criteria).AsEnumerable(); var readBooks = _mapper.Map <IEnumerable <Book>, IEnumerable <ReadBookDto> >(books); return(Ok(readBooks)); } }
private static Expression <Func <Book, bool> > GetCriteria(string author, string title, int?publicationYear, Bookbindings bookbinding, AgeCategories ageCategorie, List <Genres> genres) { Expression <Func <Book, bool> > criteria = book => (string.IsNullOrEmpty(author) || book.Author.Contains(author)) && (string.IsNullOrEmpty(title) || book.Title.Contains(title)) && (!publicationYear.HasValue || book.PublicationYear.Equals(publicationYear)) && (bookbinding.HasFlag(Bookbindings.NotSet) || book.Bookbinding.HasFlag(bookbinding)) //&& (genres == null || book.Genres.Contains(genres[0])) //&& (genres == null || genres.All(g => book.Genres.Any(x => x.HasFlag(g)))) //&& (genres == null || book.Genres.All(g => genres.)) && (ageCategorie.HasFlag(AgeCategories.NotSet) || book.AgeCategorie.HasFlag(ageCategorie)); return(criteria); }