public void GetUavLogFromVideoTimeStampTest() { List <UavLog> uavLogs = new List <UavLog>(); var path = @"Data\200122_12-28-09_1.csv"; // "," dateTime: "2020/01/22 12:25:55.734" using (TextFieldParser csvParser = new TextFieldParser(path)) { csvParser.CommentTokens = new string[] { "#" }; csvParser.SetDelimiters(new string[] { "," }); csvParser.HasFieldsEnclosedInQuotes = true; string[] headers = csvParser.ReadFields(); var djiHeaderDictionary = CsvUtilities.GetHeaderDictionary(headers); if (djiHeaderDictionary.Any()) { int rowNumber = 1; while (csvParser.PeekChars(1) != null) { rowNumber++; string[] fields = csvParser.ReadFields(); uavLogs.Add(CsvUtilities.GetUavLog(fields, djiHeaderDictionary, rowNumber)); } } string csv = String.Join(",", uavLogs); } var sortUavList = uavLogs; sortUavList.Sort((x, y) => DateTime.Compare(x.DateTime, y.DateTime)); //var noko = Helpers.GetfirstLog(uavLogs); TimeSpan timeSpanp = Helpers.GetTimeSpan("12:36.15"); var sortedUavLogs = Helpers.FilterUavlosAndSort(uavLogs); var videoLenght = Helpers.GetVideoLenghtInMilliseconds(sortedUavLogs); var videoLengh = Helpers.ConvertMilisecondsToHMSmm(videoLenght); if (timeSpanp.TotalMilliseconds < videoLenght) { var photolog = Helpers.GetUavLogFromVideoTimeStamp(timeSpanp, uavLogs); } else { } }
public void TrimUavLogs() { List <UavLog> uavLogs = new List <UavLog>(); var path = @"Data\200122_12-28-09_1.csv"; // "," dateTime: "2020/01/22 12:25:55.734" using (TextFieldParser csvParser = new TextFieldParser(path)) { csvParser.CommentTokens = new string[] { "#" }; csvParser.SetDelimiters(new string[] { "," }); csvParser.HasFieldsEnclosedInQuotes = true; string[] headers = csvParser.ReadFields(); var djiHeaderDictionary = CsvUtilities.GetHeaderDictionary(headers); if (djiHeaderDictionary.Any()) { int rowNumber = 1; while (csvParser.PeekChars(1) != null) { rowNumber++; string[] fields = csvParser.ReadFields(); uavLogs.Add(CsvUtilities.GetUavLog(fields, djiHeaderDictionary, rowNumber)); } } string csv = String.Join(",", uavLogs); } var sortUavList = uavLogs; sortUavList.Sort((x, y) => DateTime.Compare(x.DateTime, y.DateTime)); //var noko = Helpers.GetfirstLog(uavLogs); TimeSpan startTimeSpan = Helpers.GetTimeSpan("01:00.15"); TimeSpan endTimeStamp = Helpers.GetTimeSpan("01:36.15"); var newUavlogs = Helpers.TrimUavLogs(sortUavList, startTimeSpan, endTimeStamp); var filePath = Path.Combine(@"C:\Temp\", "sort_test.csv"); var csvVideoLogs = CsvUtilities.ToCsv(",", newUavlogs); var saved = CsvUtilities.SaveCsvTofile(filePath, csvVideoLogs); }
public async Task <IActionResult> TrimCsvLog(IFormFile uavLogsCsv, string startTime, string endTime) { long csvFilLength = uavLogsCsv.Length; string csvFileExtension = Path.GetExtension(uavLogsCsv.FileName).ToLower(); if (csvFilLength > 0) { if (csvFileExtension != ".csv") { return(BadRequest("wrong CSV file format")); } } else { return(BadRequest("CSV File Not Found")); } List <UavLog> uavLogs = new List <UavLog>(); using (TextFieldParser csvParser = new TextFieldParser(uavLogsCsv.OpenReadStream())) { csvParser.SetDelimiters(new string[] { "," }); csvParser.HasFieldsEnclosedInQuotes = true; string[] headers = csvParser.ReadFields(); var djiHeaderDictionary = CsvUtilities.GetHeaderDictionary(headers); if (djiHeaderDictionary.Any()) { int rowNumber = 1; while (csvParser.PeekChars(1) != null) { rowNumber++; string[] fields = csvParser.ReadFields(); uavLogs.Add(CsvUtilities.GetUavLog(fields, djiHeaderDictionary, rowNumber)); } } string csv = String.Join(",", uavLogs); } var sortUavList = uavLogs; sortUavList.Sort((x, y) => DateTime.Compare(x.DateTime, y.DateTime)); //var newUavlogs = Helpers.TrimUavLogs(sortUavList, "01:00:22", "01:36:22"); TimeSpan startTimeSpan = Helpers.GetTimeSpan(startTime); TimeSpan endTimeSpan = Helpers.GetTimeSpan(endTime); if (startTimeSpan == TimeSpan.Zero) { return(BadRequest($"cant get video start time from string '{startTime}'")); } if (endTimeSpan == TimeSpan.Zero) { return(BadRequest($"cant get video end time from string '{endTime}'")); } var newUavlogs = Helpers.TrimUavLogs(sortUavList, startTimeSpan, endTimeSpan); var videoInfoModels = Helpers.GetVideoInfoModels(newUavlogs); if (videoInfoModels != null) { var csvVideoInfoModels = CsvUtilities.ToCsv(",", videoInfoModels); var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(uavLogsCsv.FileName); var saved = CsvUtilities.SaveCsvTofile(Path.Combine(@"C:\Temp\", $"{fileNameWithoutExtension}_resume.csv"), csvVideoInfoModels); // convert string to stream byte[] byteArray = Encoding.UTF8.GetBytes(string.Concat(csvVideoInfoModels)); var stream = new MemoryStream(byteArray); return(File(stream, "application/octet-stream", $"{ fileNameWithoutExtension}_resume.csv")); } return(BadRequest("No file Created")); }