Skip to content

Commit

Permalink
implement sample-rate to reduce output-file size
Browse files Browse the repository at this point in the history
  • Loading branch information
unclearParadigm committed Jun 12, 2020
1 parent 520bc60 commit ee79284
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/OSCARGyroExporter/CmdArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");
}
Expand Down
4 changes: 4 additions & 0 deletions src/OSCARGyroExporter/OutputModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public static Result<OutputModel> Create(InputModel inputModel) {
.ToString(CultureInfo.InvariantCulture)
.Replace(",", ".");

if (tsString.Split(".").Length != 2) {
tsString += ".000";
}

var model = new OutputModel(
tsString,
orientation.ToString(CultureInfo.InvariantCulture).Replace(",","."),
Expand Down
4 changes: 2 additions & 2 deletions src/OSCARGyroExporter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ private static Result<DateTime> ReadReferenceDate() {
}
}

private static Result<List<InputModel>> MapToInputModels(string fileContent, DateTime referenceDateTime) {
private static Result<List<InputModel>> MapToInputModels(string fileContent, DateTime referenceDateTime, int sampleRate) {
if (string.IsNullOrWhiteSpace(fileContent))
return Result.Failure<List<InputModel>>("Die angegebene Datei ist leer und entspricht nicht dem Eingabeformat");

var detectedFileEnding = fileContent.Contains("\r\n") ? "\r\n" : "\n";
var lines = fileContent.Split(detectedFileEnding);

var outputList = new List<Result<InputModel>>();
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);

Expand Down

0 comments on commit ee79284

Please sign in to comment.