public static void UpdateAge(this Person person, double age) { int count = person.Visits.Sum(v => v.ProfilePictures.Count); if (count == 0) { person.DateOfBirth = DateTime.UtcNow.AddYears(-(int)age); } else { int oldAge = DateHelpers.ConvertDateOfBirthToAge(person.DateOfBirth); var result = ((oldAge * count) + age) / (count + 1); person.DateOfBirth = DateTime.UtcNow.AddYears(-(int)result); } }
// Converts a recognition item entity to person data transfert object public static PersonDto ToPersonDto(this RecognitionItem recognitionItem) { var lastVisit = recognitionItem.Person?.Visits.LastOrDefault(); var age = recognitionItem.Person != null ? DateHelpers.ConvertDateOfBirthToAge(recognitionItem.Person.DateOfBirth) : recognitionItem.Face.FaceAttributes.Age; var gender = recognitionItem.Person?.Gender ?? GenderValuesHelper.Parse(recognitionItem.Face.FaceAttributes.Gender); return(new PersonDto { RecognitionId = recognitionItem.Id, FirstName = recognitionItem.Person?.FirstName, IsRecognized = recognitionItem.Person != null, PersonId = recognitionItem.Person?.PersonApiId ?? default(Guid), NbPasses = lastVisit?.NbPasses ?? 0, ReasonOfVisit = lastVisit?.Reason, Age = (int)age, Gender = gender, }); }
public double GetAverageAge() { return(Math.Round(Context.Visitors.Select(p => p.DateOfBirth) .ToList().Average(d => DateHelpers.ConvertDateOfBirthToAge(d)), 2)); }