I hope I explain this well. I have a List of "Records". Each record has a DateTime property. What I want to do is create another List that contains the records that are "X" seconds apart. I was trying to use a lambda to do this but can't figure it out. Could some one assist please. See Demo code.
public MainWindow()
{
InitializeComponent();
List<MyRecords> MyRecordsList = new List<MyRecords>();
List<MyGroupedRecords> MyGroupedRecordsList = new List<MyGroupedRecords>();
int groupRecordsThatAreSecondsApart = 3;
MyRecords myRecord = new MyRecords() { Name = "A", RecordDate = new DateTime(2018, 2, 8, 0, 1, 0) };
MyRecordsList.Add(myRecord);
myRecord = new MyRecords() { Name = "B", RecordDate = new DateTime(2018, 2, 8, 0, 1, 1) };
MyRecordsList.Add(myRecord);
myRecord = new MyRecords() { Name = "C", RecordDate = new DateTime(2018, 2, 8, 0, 1, 19) };
MyRecordsList.Add(myRecord);
myRecord = new MyRecords() { Name = "C", RecordDate = new DateTime(2018, 2, 8, 0, 1, 4) };
MyRecordsList.Add(myRecord);
myRecord = new MyRecords() { Name = "W", RecordDate = new DateTime(2018, 2, 8, 2, 1, 10) };
MyRecordsList.Add(myRecord);
myRecord = new MyRecords() { Name = "X", RecordDate = new DateTime(2018, 2, 8, 3, 16, 31) };
MyRecordsList.Add(myRecord);
myRecord = new MyRecords() { Name = "Y", RecordDate = new DateTime(2018, 2, 8, 2, 1, 11) };
MyRecordsList.Add(myRecord);
myRecord = new MyRecords() { Name = "Z", RecordDate = new DateTime(2018, 2, 8, 2, 1, 14) };
MyRecordsList.Add(myRecord);
}
class MyRecords
{
public string Name { get; set; }
public DateTime RecordDate { get; set; }
}
class MyGroupedRecords
{
public DateTime StartDate { get; set; }
public List<MyRecords> GroupedRecordsList { get; set; }
}
I was trying to use something like this but can't figure it out:
List<GroupedSamples> groupedSamples = tag.SamplesCollection
.GroupBy(r => r.StartTime)
.Select(gg => new GroupedSamples
{
TimeStamp = gg.Key,
Samples = gg.OrderBy(r => r.StartTime).ToList(),
Count = gg.Count()
})
.ToList();
>` and all you need to do is filter the duplicate lists. where they all have the same id as another list
– Franck Feb 08 '18 at 18:21