From ee79284da6abaf572f9bb1233cc78c2d51f96867 Mon Sep 17 00:00:00 2001 From: Unclear Paradigm Date: Fri, 12 Jun 2020 21:44:18 +0200 Subject: [PATCH] implement sample-rate to reduce output-file size --- src/OSCARGyroExporter/CmdArguments.cs | 6 ++++++ src/OSCARGyroExporter/OutputModel.cs | 4 ++++ src/OSCARGyroExporter/Program.cs | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/OSCARGyroExporter/CmdArguments.cs b/src/OSCARGyroExporter/CmdArguments.cs index 0e3f95d..7f51444 100644 --- a/src/OSCARGyroExporter/CmdArguments.cs +++ b/src/OSCARGyroExporter/CmdArguments.cs @@ -14,6 +14,9 @@ public class ManualCmdArguments { [Option('t', "timezoneoffset", Default=0, Required = false, HelpText = "Statischer Offset welcher zum/vom Referenzdatum addiert/subtrahiert wird")] public int TimezoneOffset { get; set; } + + [Option('s', "samplerate", Default=1, Required = false, HelpText = "Abtastrate der Eingabedatei. 1=jeder Messpunkt, 2=jeder zweite Messpunkt, 3=..., 4...")] + public int SampleRate { get; set; } } // ReSharper disable once ClassNeverInstantiated.Global @@ -27,6 +30,9 @@ public class AutomaticCmdArguments { [Option('t', "timezoneoffset", Default=0, Required = false, HelpText = "Statischer Offset welcher zum/vom Referenzdatum addiert/subtrahiert wird")] public int TimezoneOffset { get; set; } + + [Option('s', "samplerate", Default=1, Required = false, HelpText = "Abtastrate der Eingabedatei. 1=jeder Messpunkt, 2=jeder zweite Messpunkt, 3=..., 4...")] + public int SampleRate { get; set; } public string[] GetFilesInInputDirectory() => Directory.GetFiles(InputDirectory, "*.csv"); } diff --git a/src/OSCARGyroExporter/OutputModel.cs b/src/OSCARGyroExporter/OutputModel.cs index 4450e1c..1ca1036 100644 --- a/src/OSCARGyroExporter/OutputModel.cs +++ b/src/OSCARGyroExporter/OutputModel.cs @@ -31,6 +31,10 @@ public static Result Create(InputModel inputModel) { .ToString(CultureInfo.InvariantCulture) .Replace(",", "."); + if (tsString.Split(".").Length != 2) { + tsString += ".000"; + } + var model = new OutputModel( tsString, orientation.ToString(CultureInfo.InvariantCulture).Replace(",","."), diff --git a/src/OSCARGyroExporter/Program.cs b/src/OSCARGyroExporter/Program.cs index ff3f705..6769862 100644 --- a/src/OSCARGyroExporter/Program.cs +++ b/src/OSCARGyroExporter/Program.cs @@ -106,7 +106,7 @@ private static Result ReadReferenceDate() { } } - private static Result> MapToInputModels(string fileContent, DateTime referenceDateTime) { + private static Result> MapToInputModels(string fileContent, DateTime referenceDateTime, int sampleRate) { if (string.IsNullOrWhiteSpace(fileContent)) return Result.Failure>("Die angegebene Datei ist leer und entspricht nicht dem Eingabeformat"); @@ -114,7 +114,7 @@ private static Result> MapToInputModels(string fileContent, Dat var lines = fileContent.Split(detectedFileEnding); var outputList = new List>(); - foreach (var line in lines.Skip(1)) { + foreach (var line in lines.Skip(1).Where((x, i) => i % sampleRate == 0)) { var detectedColumnSeparatorChar = line.Contains(';') ? ';' : ','; var values = line.Split(detectedColumnSeparatorChar);