I want to write a simple program to ease my life at work, but I'm not too familiar with C# so I'm trying to read the documentation and some examples, but I don't find the documentation too good, and can't find any examples to feed off.
I have a CSV file (wireless temperature sensor that sometimes loses connection or sends multiple readouts in quick succession) and I want to compare two DateTimes (TimeSpan) from 2 subsequent rows, and depending on result remove that row, or add another in between these. If TimeSpan between 2 DateTimes is less than 10 minutes, delete that row. If it's longer than 10 minutes create a new row with time that is 10 minutes after the first one. All readouts are between themselves in multiples of 10 minutes.
Example file:
[DelimitedRecord(","), IgnoreFirst(1)] public class CSVDataFields{ [FieldQuoted('"')] [FieldConverter(ConverterKind.Date, "MM/dd/yyyy h:mm tt")] public DateTime Date; [FieldQuoted('"')] public float Value; } "Date","Value" "03/19/2019 3:10 PM","20.5" "03/19/2019 3:10 PM","20.5" "03/19/2019 3:10 PM","20.4" "03/19/2019 3:20 PM","20.2" "03/19/2019 3:50 PM","20.0" "03/19/2019 4:00 PM","19.8" So the first check is [0] and [1], it's less than 10, so delete that row, [0] and [2] less than 10 - delete, [0] and [3] it's ok,
[3] and [4] is longer than 10 minutes, create a new row with time([3] + 10) and value average (20.2, 20.0),
new [4] and [5] is longer than 10 minutes, create a new row with time ([4] + 10) and value average (20.1, 20.0), and so on.
In the example on FileHelpers.net there is only this example. Here you can only access 1 row at a time I think, while I need to have access to 2 rows at the same time.
private void DetectDupes(ref CSVDataFields[] csv){ foreach(CSVDataFields csvData in csv){ } } I've also not gotten that far as how to save the new file with the modified rows.
create a new row with time([3] + 10). Why+ 10? What's the rationale behind that? Is10arbitrary? Would it be more desirable to find a mean date/time between the two entries? Or are you looking to create a sequence separated by10?