SA may be right, though I would want to see your data in more detail first.
I would also suggest that some of this is very, very unnecessary:
String mth = row.Cells[1].Value.ToString() + "/";
String dy = row.Cells[2].Value.ToString() + " ";
String hr = row.Cells[3].Value.ToString() + ":";
String min = row.Cells[4].Value.ToString();
if (mth.Length == 1)
{
mth = "0" + mth;
}
if (dy.Length == 1)
{
dy = "0" + dy;
}
if (hr.Length == 1)
{
hr = "0" + hr;
}
if (min.Length == 1)
{
min = "0" + min;
}
string dts = yr + mth + dy + hr + min;
dt[i] = Convert.ToDateTime(dts);
Could be replaced with:
dt[i] = new DateTime(yr,
row.Cells[1].Value,
row.Cells[2].Value,
row.Cells[3].Value,
row.Cells[4].Value);
I think you need to look at how you are handling all this: I particularly dislike the +5 and -5 your code is sprinkled with - I know why you are doing it, but it is hard to understand and maintain.
Don't use
List<object>
- be specific, it helps to avoid problems and means you don't have to cast it before you can use it!
To be honest, I would set up a class (call it DatedValues)to hold row data with a constructor taking a DataGridViewRow and with a ContainsInformaion property getter. If true, I would add the row, otherwise I would discard it. The class would have (say) a DateTime property, and a List of values. Then use a list of the with-information DatedValues instead of your
List<Object>
- it will make your code a lot clearer!
"Thanks OriginalGriff for your response.
Setting up a class sounds like a better way to do this. I initially planned on having only one value column and started this way but later decided to add more value columns.
I still cannot figure out how I isolate the non-zero blocks in my data. The hardest part for me is to take care of minimum separation between two non-zero blocks. I can send you my original data, targetted result and the rules... but I could not find a way to attach any file here"
Your "two hours since a non-zero" condition shouldn't be too major a problem: once you have the log time as a DateTime, you can set a "always include if before this" DateTime by using the DateTime.AddHours or DateTime.AddMinutes methods. Remember, you can do direct comparisons between two DateTime objects:
DateTime now = DateTime.Now;
DateTime then = now.AddMinutes(120);
...
if (myRecord.Timestamp <= then)
{
...
}