From 78a86ca1e9cfe336ffd26658cfda2d5013608b8c Mon Sep 17 00:00:00 2001 From: Husky Date: Fri, 31 May 2019 22:36:43 +0200 Subject: [PATCH 1/3] =?UTF-8?q?CSV=20factoriy=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CSVParser/AcceptedCSVFormats.cs | 9 +++++++++ CSVParser/CsvParserFactory.cs | 25 +++++++++++++++++++++++++ SanSystem/UCInliner.cs | 7 ++++--- 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 CSVParser/AcceptedCSVFormats.cs create mode 100644 CSVParser/CsvParserFactory.cs diff --git a/CSVParser/AcceptedCSVFormats.cs b/CSVParser/AcceptedCSVFormats.cs new file mode 100644 index 0000000..2a6bc39 --- /dev/null +++ b/CSVParser/AcceptedCSVFormats.cs @@ -0,0 +1,9 @@ +namespace CSVParser +{ + public enum AcceptedCSVFormats + { + UVRELINING, + BLUELIGHT + + } +} \ No newline at end of file diff --git a/CSVParser/CsvParserFactory.cs b/CSVParser/CsvParserFactory.cs new file mode 100644 index 0000000..dee5ce2 --- /dev/null +++ b/CSVParser/CsvParserFactory.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SanShared; + +namespace CSVParser +{ + public static class CsvParserFactory + { + public static IReadCSVData ReadCSVFile(AcceptedCSVFormats csvFormat, string csvFile) + { + switch (csvFormat) + { + case AcceptedCSVFormats.UVRELINING: + return new UVRelining(csvFile); + case AcceptedCSVFormats.BLUELIGHT: + return new BlueLight(csvFile); + default: + throw new ArgumentOutOfRangeException(nameof(csvFormat)); + } + } + } +} diff --git a/SanSystem/UCInliner.cs b/SanSystem/UCInliner.cs index 7ebecfd..cff90c1 100644 --- a/SanSystem/UCInliner.cs +++ b/SanSystem/UCInliner.cs @@ -286,9 +286,10 @@ namespace SanSystem IEnumerable files = Directory.EnumerateFiles(myPath, "*.csv", SearchOption.AllDirectories); - //List struktures = HelpFunktion.ParseCSVFile(files.Last()); - UVRelining uv = new UVRelining(files.Last()); - List struktures = uv.ReadCSVStrukture(); + + IReadCSVData csvFile = null; + csvFile = CsvParserFactory.ReadCSVFile(AcceptedCSVFormats.UVRELINING, files.Last()); + List struktures = csvFile.ReadCSVStrukture(); inliner.AnfangAushaertung = struktures.Select(x => x.Zeitstempel).Min(); inliner.EndeAushaertung = struktures.Select(x => x.Zeitstempel).Max(); From 95ea4a34988a477a1b46a52949e207320cc18eb4 Mon Sep 17 00:00:00 2001 From: Husky Date: Fri, 31 May 2019 22:38:47 +0200 Subject: [PATCH 2/3] WIP: BlueLight angefangen --- CSVParser/BlueLight.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/CSVParser/BlueLight.cs b/CSVParser/BlueLight.cs index a30abf7..6be70c1 100644 --- a/CSVParser/BlueLight.cs +++ b/CSVParser/BlueLight.cs @@ -15,7 +15,22 @@ namespace CSVParser public override List ReadCSVStrukture() { - return null; + List result = new List(); + DateTime zeit; + double temperatur; + double druck; + int geschwindigkeit; + + foreach (string partial in Input) + { + string[] parts = partial.Split(','); + string datum = parts[1]; + string uhrzeit = parts[2]; + + if(!DateTime.TryParse(datum + " "+uhrzeit,out zeit)) + throw new Exception("Konnte die datum uhrzeit nicht konventieren"); + } + return result; } } } From c568cb3bb67cb99da085e8dbe3330353663ef84e Mon Sep 17 00:00:00 2001 From: Husky Date: Fri, 12 Jul 2019 08:34:43 +0200 Subject: [PATCH 3/3] Parser weitergeschrieben --- CSVParser/BlueLight.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CSVParser/BlueLight.cs b/CSVParser/BlueLight.cs index 6be70c1..49355ac 100644 --- a/CSVParser/BlueLight.cs +++ b/CSVParser/BlueLight.cs @@ -23,12 +23,25 @@ namespace CSVParser foreach (string partial in Input) { + UVcsvStrukture strukture = new UVcsvStrukture(); string[] parts = partial.Split(','); string datum = parts[1]; string uhrzeit = parts[2]; + if(!DateTime.TryParse(datum + " "+uhrzeit,out zeit)) throw new Exception("Konnte die datum uhrzeit nicht konventieren"); + + double.TryParse(parts[3].Replace('.', ','), out temperatur); + int.TryParse(parts[4], out geschwindigkeit); + double.TryParse(parts[5].Replace('.', ','), out druck); + + strukture.Zeitstempel = zeit; + strukture.Druck = druck; + strukture.Geschwindigkeit = geschwindigkeit; + strukture.Temperatur = temperatur; + + result.Add(strukture); } return result; }