using System.Collections.Generic;
using System.Collections;
public static void Main()
var startDate = DateTime.Now;
var data = Enumerable.Range(0, 121).Select(i => new KpiMerma
CreatedOn = startDate.AddMinutes(1),
KpiValue = Math.Round((rnd.NextDouble() * 0.2 + 0.7), 2)
var list = data.FindConsecutiveGroups<KpiMerma>((x) => x.KpiValue > 0.3, 30);
Console.WriteLine(list.Count());
foreach(var merme in list)
Console.WriteLine(merme.ToString());
public int ProductionLineId { get; set; }
public DateTime CreatedOn { get; set; }
public double KpiValue { get; set; }
public override string ToString()
return "Linea " + ProductionLineId + " Creada el " + CreatedOn.ToString("dd/MM/yyyy HH:mm:ss") + " con kpi " + KpiValue;
public static class Extensions
public static IEnumerable<IEnumerable<T>> FindConsecutiveGroups<T>(this IEnumerable<T> sequence, Predicate<T> predicate, int count)
IEnumerable<T> current = sequence;
while (current.Count() > count)
IEnumerable<T> window = current.Take(count);
if (window.Where(x => predicate(x)).Count() >= count)
current = current.Skip(1);