I have a data table with the following data:
LINE | SIGN | DATE
-----------------------------------------
1 | 1 | 2015-03-02 11:23:25
1 | 1 | 2015-03-02 18:24:03
1 | 1 | 2015-03-03 05:38:49
1 | 0 | 2015-03-03 08:47:02
1 | 1 | 2015-03-03 14:01:31
1 | 1 | 2015-03-03 21:11:53
1 | 1 | 2015-03-04 09:34:04
1 | 0 | 2015-03-04 15:29:27
1 | 0 | 2015-03-04 19:28:33
The data is ordered by date as you can see, my requirement is to get the Total number of minutes for a signal. Like for how many minutes the signal was 1 and for how many minutes the signal was 0.
I need a LINQ query to get the results.
At the moment what I am thinking is that I may have to do a for loop and add the number of minutes. I don't know if this is the only way:
int noOfMinutesFor1 = 0;
for (int i = 1; i < signalData.Count; i++)
{
if((signalData[i - 1].SIGN == signalData[i].SIGN == 1) || (signalData[i].SIGN == 1 && signalData[i - 1].SIGN == 0))
{
noOfMinutesFor1 += (signalData[i].SIGN - signalData[i - 1].SIGN).TotalMinutes;
}
}