Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

309
Views
Validación de datos con función principalmente en List<T> usando .NET Core C#

Obtuve los datos como Lista < T > leyendo desde diferentes formatos, por ejemplo, CSV, Parquet, Avro, JSON.

Quiero validar los datos con la mayoría de las características, por ejemplo, la temperatura debe permanecer dentro del rango el 95% del tiempo, y el resto del valor de la columna de tiempo puede ser nulo o estar fuera de rango.

Ejemplo de expectativa de caso de uso:

 Expect_Column_Values_To_Be_Between( columnName = "temprature", minValue = 60, maxValue = 75, mostly = .95 )

La anotación de datos parece resolverlo parcialmente ( falta la mayoría de las funciones ), ya que funciona en el nivel de fila, no en toda la tabla, es decir, en el nivel de objeto.

 [Range(60, 75, ErrorMessage = "Thermostat value {0} must be between {1} and {2}.")] public int Temprature;

La referencia del paquete de Python: https://github.com/great-expectations/.great_expectations contiene validaciones de nivel de datos similares.

Ahora trato de buscar orientación sobre cómo validar los datos (ya sea por cualquier biblioteca equivalente existente en .NET o mediante la creación de nuevos métodos de extensión/clase auxiliar)

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Creó un método de extensión de muestra que valida los datos en la tabla, es decir, a nivel de objeto

 public class Room { public int RoomId { get; set; } public string Name { get; set; } public double Temprature { get; set; } }
 List<Room> rooms = new List<Room>(); rooms.Add(new Room() { RoomId = 1, Name = "Hall", Temprature = 65 }); rooms.Add(new Room() { RoomId = 2, Name = "Kitchen", Temprature = 75 }); bool result = rooms.Expect_Column_Values_To_Be_Between("Temprature", 60, 75, .95);
 public static class ValidationExtensions { public static bool Expect_Column_Values_To_Be_Between<T>(this List<T> items, string columnName, double minValue, double maxValue, double mostly = 1) { if (mostly < 0 || mostly > 1) throw new ArgumentOutOfRangeException( $"Mostly value {{{mostly}}} can not be less 0 or greater than 1"); else if (mostly == 0) return true; if (items == null || items.Count == 0) return false; int itemsInRangeCount = 0; foreach (var item in items) { PropertyInfo? propertyInfo = item.GetType().GetProperty(columnName); if (propertyInfo == null) throw new InvalidDataException($"Column not found : {columnName}"); var itemValue = Convert.ToDouble(propertyInfo.GetValue(item)); if (itemValue >= minValue && itemValue <= maxValue) itemsInRangeCount++; } return (itemsInRangeCount / items.Count) >= mostly ? true : false; } }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!