public static DjiSrtVideoLogModel GetTimeStamp(string timeStamp, ref DjiSrtVideoLogModel djiSrtVideoLogModel) { //"00:09:05,000 --> 00:09:06,000"; var timeStamps = timeStamp.Split(" --> "); djiSrtVideoLogModel.StartLog = Helpers.GetTimeSpan(timeStamps[0]); djiSrtVideoLogModel.EndLog = Helpers.GetTimeSpan(timeStamps[1]); return(djiSrtVideoLogModel); }
public static DjiSrtVideoLogModel GetCameraInfo(string cameraInfo, ref DjiSrtVideoLogModel djiSrtVideoLogModel) { //"ISO:400 Shutter:40 EV: Fnum:F2.8"; var lines = cameraInfo.Split(" "); var isoString = GetValue(lines[0]); var shutter = GetValue(lines[1]); var eV = GetValue(lines[2]); var fNum = GetValue(lines[3]); int iso = 0; int.TryParse(isoString, out iso); djiSrtVideoLogModel.ISO = iso; djiSrtVideoLogModel.Shutter = shutter; djiSrtVideoLogModel.Ev = eV; djiSrtVideoLogModel.Fnum = fNum; return(djiSrtVideoLogModel); }
public void TrimUavLogs() { int counter = 0; string line; // Read the file and display it line by line. DjiSrtVideoLogModel djiSrtVideoLogModel = new DjiSrtVideoLogModel(); List <DjiSrtVideoLogModel> djiSrtVideoLogModels = new List <DjiSrtVideoLogModel>(); using (System.IO.StreamReader file = new System.IO.StreamReader(@"H:\Code\UavLogTool\UavLogToolTest\Data\DJI_0012.SRT")) { int lineCount = 0; int id = 0; while ((line = file.ReadLine()) != null) { int idTemp; if (int.TryParse(line, out idTemp)) { djiSrtVideoLogModel = new DjiSrtVideoLogModel(); id = idTemp; lineCount++; } if (id >= 1) { switch (lineCount) { case 1: djiSrtVideoLogModel.Id = id; lineCount++; break; case 2: djiSrtVideoLogModel = SrtConverter.GetTimeStamp(line, ref djiSrtVideoLogModel); lineCount++; break; case 3: djiSrtVideoLogModel = SrtConverter.GetHomePointAndDateTime(line, ref djiSrtVideoLogModel); lineCount++; break; case 4: djiSrtVideoLogModel = SrtConverter.GetGpsPointAndBarometer(line, ref djiSrtVideoLogModel); lineCount++; break; case 5: djiSrtVideoLogModel = SrtConverter.GetCameraInfo(line, ref djiSrtVideoLogModel); djiSrtVideoLogModels.Add(djiSrtVideoLogModel); lineCount = 0; break; default: break; } } counter++; } } var filePath = Path.Combine(@"C:\Temp\", "djiSrtVideo.csv"); var noko = SrtConverter.ConvertSrtToUavLog(djiSrtVideoLogModels); var csvVideoLogs = CsvUtilities.ToCsv(",", djiSrtVideoLogModels.ToArray()); var saved = CsvUtilities.SaveCsvTofile(filePath, csvVideoLogs); }
public async Task <IActionResult> GetCsvFromSrt(IFormFile srtLog) { long size = srtLog.Length; string extension = Path.GetExtension(srtLog.FileName).ToLower(); if (size > 0) { if (!extension.Equals(".SRT", StringComparison.OrdinalIgnoreCase)) { return(BadRequest("wrong file format")); } } else { return(BadRequest("SRT File Not Found")); } string line; DjiSrtVideoLogModel djiSrtVideoLogModel = new DjiSrtVideoLogModel(); List <DjiSrtVideoLogModel> djiSrtVideoLogModels = new List <DjiSrtVideoLogModel>(); try { using (System.IO.StreamReader file = new System.IO.StreamReader(srtLog.OpenReadStream())) { int lineCount = 0; int id = 0; while ((line = file.ReadLine()) != null) { int idTemp; if (int.TryParse(line, out idTemp)) { djiSrtVideoLogModel = new DjiSrtVideoLogModel(); id = idTemp; lineCount++; } if (id >= 1) { switch (lineCount) { case 1: djiSrtVideoLogModel.Id = id; lineCount++; break; case 2: djiSrtVideoLogModel = SrtConverter.GetTimeStamp(line, ref djiSrtVideoLogModel); lineCount++; break; case 3: djiSrtVideoLogModel = SrtConverter.GetHomePointAndDateTime(line, ref djiSrtVideoLogModel); lineCount++; break; case 4: djiSrtVideoLogModel = SrtConverter.GetGpsPointAndBarometer(line, ref djiSrtVideoLogModel); lineCount++; break; case 5: djiSrtVideoLogModel = SrtConverter.GetCameraInfo(line, ref djiSrtVideoLogModel); djiSrtVideoLogModels.Add(djiSrtVideoLogModel); lineCount = 0; break; default: break; } } } if (djiSrtVideoLogModels.Any()) { var csvVideoInfoModels = CsvUtilities.ToCsv(",", djiSrtVideoLogModels); var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(srtLog.FileName); var saved = CsvUtilities.SaveCsvTofile(Path.Combine(@"C:\Temp\", $"{fileNameWithoutExtension}_resume.csv"), csvVideoInfoModels); return(Ok("Ok creating Srt to Csv")); } else { return(BadRequest("djiSrtVideoLogModels dont have any record")); } } } catch (Exception) { return(BadRequest("Problem saving Srt to csv")); } }
public static DjiSrtVideoLogModel GetGpsPointAndBarometer(string GpsPointAndBarometer, ref DjiSrtVideoLogModel djiSrtVideoLogModel) { //"GPS(9.1604,59.4049,19) BAROMETER:50.1"; var firstSpaceIndex = GpsPointAndBarometer.IndexOf(" "); var firstString = GpsPointAndBarometer.Substring(0, firstSpaceIndex); // GPS(9.1604,59.4049,19) var secondString = GpsPointAndBarometer.Substring(firstSpaceIndex + 1); // BAROMETER:50.1 var gpsLatLong = Regex.Match(firstString, @"\(([^)]*)\)").Groups[1].Value; var longitudLatitud = gpsLatLong.Split(","); djiSrtVideoLogModel.UavLongitud = longitudLatitud[0]; djiSrtVideoLogModel.UavLatitud = longitudLatitud[1]; double altitud = 0; double.TryParse(GetValue(secondString), out altitud); djiSrtVideoLogModel.UavAltitud = altitud; double barometer = 0; double.TryParse(GetValue(secondString), out barometer); djiSrtVideoLogModel.Barometer = barometer; return(djiSrtVideoLogModel); }
public static DjiSrtVideoLogModel GetHomePointAndDateTime(string homePointAndDateTime, ref DjiSrtVideoLogModel djiSrtVideoLogModel) { //"HOME(9.1534,59.4047) 2020.03.06 17:07:31"; var firstSpaceIndex = homePointAndDateTime.IndexOf(" "); var firstString = homePointAndDateTime.Substring(0, firstSpaceIndex); // HOME(9.1534,59.4047) var secondString = homePointAndDateTime.Substring(firstSpaceIndex + 1); // 2020.03.06 17:07:31 var homeLatLong = Regex.Match(firstString, @"\(([^)]*)\)").Groups[1].Value; var longitudLatitud = homeLatLong.Split(","); djiSrtVideoLogModel.HomeLongitud = longitudLatitud[0]; djiSrtVideoLogModel.HomeLatitud = longitudLatitud[1]; djiSrtVideoLogModel.DateTimeLog = Helpers.GetDateTime(secondString); return(djiSrtVideoLogModel); }