Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a solution. The crux of the method is shown in the ExtractVidTimes method. The rest is just for creating the sample data</p> <pre><code> [TestFixture] public class TestyMcTest { public class Vid { public int CamId; public DateTime Start; public DateTime End; } [Test] public void Test() { var list = new List&lt;Vid&gt; { //=====Combination1======= new Vid { CamId = 1, Start = new DateTime(2000, 1, 1, 0, 0, 0), End = new DateTime(2000, 1, 1, 0, 3, 0) }, new Vid { CamId = 1, Start = new DateTime(2000, 1, 1, 0, 5, 0), End = new DateTime(2000, 1, 1, 0, 7, 0) }, //=====Combination2======= new Vid { CamId = 1, Start = new DateTime(2000, 1, 1, 0, 15, 0), End = new DateTime(2000, 1, 1, 0, 18, 0) }, //=====Combination3======= new Vid { CamId = 2, Start = new DateTime(2000, 1, 1, 0, 0, 0), End = new DateTime(2000, 1, 1, 0, 3, 0) }, //=====Combination4======= new Vid { CamId = 2, Start = new DateTime(2000, 1, 1, 0, 10, 0), End = new DateTime(2000, 1, 1, 0, 13, 0) } }; //here is your list of vids grouped by the cam id var result = ExtractVidTimes(list); } //THE METHOD private static List&lt;List&lt;Vid&gt;&gt; ExtractVidTimes(List&lt;Vid&gt; list) { //Group by cam ID var vidGroups = list.GroupBy(vid =&gt; vid.CamId).ToList(); //extract vids with aggregate times var result = vidGroups.Select(vids =&gt; { var vidTimes = new List&lt;Vid&gt;(); var finalVid = vids.OrderBy(vid=&gt; vid.Start).Aggregate((a, b) =&gt; { if (a.End.AddMinutes(5) &gt; b.Start) { a.End = b.End; return a; } vidTimes.Add(a); return b; }); vidTimes.Add(finalVid); return vidTimes; }).ToList(); //return result.SelectMany(x=&gt;x); //if you want a List&lt;vid&gt; return ed instead of a nested list return result; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload