-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDataFormatter.cs
More file actions
76 lines (61 loc) · 2.86 KB
/
Copy pathDataFormatter.cs
File metadata and controls
76 lines (61 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
namespace DataFormatter
{
class Program
{
static void Main(string[] args)
{
//string directory = @"C:\Meine Items\Coding Ambitions\10th Semester\Exported Data\Solo Test Data\PC\";
string directory = @"C:\Meine Items\Coding Ambitions\10th Semester\Exported Data\Solo Test Data\VR\";
var filePaths = Directory.GetFiles(directory);
var dataSets = new List<DataSet>();
ImportAllDataSets();
ReformatAndWrite();
void ReformatAndWrite()
{
using StreamWriter writer = new StreamWriter(directory + "reformat.csv");
string line;
int vectorCount = dataSets[0].vectors.Count;
for (int vectorIndex = 0; vectorIndex < vectorCount; ++vectorIndex)
for (int vectorValue = 0; vectorValue < 6; ++vectorValue)
{
line = (vectorIndex + 1) + ((ValueNames)vectorValue).ToString();
foreach (DataSet dataSet in dataSets)
line += ";" + dataSet.vectors[vectorIndex].values[vectorValue].ToString(CultureInfo.InvariantCulture);
writer.WriteLine(line);
}
}
void ImportAllDataSets()
{
foreach (string path in filePaths)
{
DataSet dataSet = new DataSet();
dataSets.Add(dataSet);
int lineCount = File.ReadLines(path).Count();
using (StreamReader reader = new StreamReader(path))
{
reader.ReadLine(); // Two first lines are always redundant.
reader.ReadLine();
for (int i = 2; i < lineCount; ++i)
{
string[] values = reader.ReadLine().Split(',');
if (values.Length != 9) break; // Cuts out unnecessary lines.
var v = new Vector();
for (int j = 0; j < 6; ++j)
v.values[j] = ParseScientificNotation(values[j + 3]);
dataSet.vectors.Add(v);
}
};
}
static float ParseScientificNotation(string input) { return float.Parse(input, CultureInfo.GetCultureInfo("en-GB")); }
}
}
private class DataSet { public List<Vector> vectors = new List<Vector>(); }
private class Vector { public float[] values = new float[6]; }
private enum ValueNames { X, Y, Z, NX, NY, NZ }
}
}