Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
parser for ltq
  • Loading branch information
marinakiweler committed Jul 29, 2019
1 parent 7bec03e commit dc20899
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 27 deletions.
109 changes: 83 additions & 26 deletions MARMoSET_C/MARMoSET/InstrumentMethod.cs
Expand Up @@ -392,16 +392,22 @@ public List<string> MethodAsList(IRawDataPlus rawFile, int index, bool toLower =
public Dictionary<string, object> ltqDictListCreate(List<string> methodList)
{
var dicList = new Dictionary<string, object>();
var dic = new Dictionary<string, string>();
DataTable table = new DataTable();
var dic = new Dictionary<string, object>();
string[] split = new string[] { };
Boolean header = true;
string titel = "general";

string title = "general";
// table helper
DataTable table = new DataTable();
bool tHeader = true;
string tableTitle = "";
// Helpers for dictionary in dic
bool level2 = false;
string title2 = "";
var dicLevel2 = new Dictionary<string, string>();

foreach (string st in methodList)
{
bool splitIsHeader = false;
// split
// split at : , = , enabled/not enabled/disabled , whitespaces
if (st.Contains(":"))
{
split = Regex.Split(st.Trim(), @": ");
Expand All @@ -410,6 +416,7 @@ public List<string> MethodAsList(IRawDataPlus rawFile, int index, bool toLower =
else if (st.Contains("="))
{
split = Regex.Split(st.Trim(), @"=");
splitIsHeader = true;
}
else if (st.Contains("not enabled") || st.Contains("Not enabled"))
{
Expand All @@ -423,41 +430,91 @@ public List<string> MethodAsList(IRawDataPlus rawFile, int index, bool toLower =
replaced = replaced.Replace("disabled", "#disabled");
split = Regex.Split(replaced, "#");
}

else // for string of table
{
split = Regex.Split(st.Trim(), @"\s\s+");
}
split[0] = split[0].Trim();

if (String.Equals(split[0], "scan event details:") || String.Equals(split[0], "Scan Event Details:"))
{
splitIsHeader = false;
char[] delChar = { ':' };
title = split[0].TrimEnd(delChar);
level2 = true;
}

// header
if (split.Length == 1 && !string.IsNullOrEmpty(titel) && split[0] != "" && splitIsHeader)
if (split.Length == 1 && !string.IsNullOrEmpty(title) && split[0] != "" && splitIsHeader)
{
if (dic.Count != 0)
{
// clone dic in dicList
dicList[titel] = new Dictionary<string, string>(dic);
dicList[title] = new Dictionary<string, object>(dic);
// Clear dic
dic.Clear();
}
if (table.Rows.Count != 0)
{
// clone table in dicList
dicList[titel] = table.Copy();
dicList[tableTitle] = table.Copy();
table = new DataTable();
header = true;
tHeader = true;
}
titel = split[0].Trim();
title = split[0];
}
// line with information
if (split.Length == 1 && !splitIsHeader && split[0] != "" && !dic.ContainsKey(split[0]) && split[0].Contains('.'))
else if (split.Length == 1 && !splitIsHeader && split[0] != "" && split[0].Contains('.'))
{
split[0] = split[0].Trim();
dic.Add(split[0], "");
if (dicLevel2.Count != 0)
{
if (!dicLevel2.ContainsKey("Info"))
{
// add to Dictionary
dicLevel2.Add("Info", split[0]);
}
// clone dicLevel2 in dic
dic[title2] = new Dictionary<string, string>(dicLevel2);
// Clear dicLevel2
dicLevel2.Clear();
level2 = false;
}
else if (!dic.ContainsKey(split[0]))
{
// add to Dictionary
dic.Add("Info", split[0]);
}
}
// key : value pair
if (split.Length == 2)
// 2nd level key : value pair
else if (split.Length == 2 && level2)
{
split[1] = split[1].Trim();
if (Regex.IsMatch(split[0], @"^\d"))
{
if (dicLevel2.Count != 0)
{
// clone dicLevel2 in dic
dic[title2] = new Dictionary<string, string>(dicLevel2);
// Clear dicLevel2
dicLevel2.Clear();
}
title2 = split[1];
}
else
{
split[1] = split[1];

if (!dicLevel2.ContainsKey(split[0]))
{
// add to Dictionary
dicLevel2.Add(split[0], split[1]);
}
}
}
// usual key : value
else if (split.Length == 2)
{
// delete Whitespaces
split[0] = split[0].Trim();
split[1] = split[1].Trim();

if (!dic.ContainsKey(split[0]))
Expand All @@ -467,9 +524,10 @@ public List<string> MethodAsList(IRawDataPlus rawFile, int index, bool toLower =
}
}
// table
if (split.Length > 2)
else if (split.Length > 2)
{
if (header)
tableTitle = title;
if (tHeader)
{
int i = 0;
foreach (string col in split)
Expand All @@ -478,27 +536,26 @@ public List<string> MethodAsList(IRawDataPlus rawFile, int index, bool toLower =
string cname = "col" + i;
table.Columns.Add(cname, typeof(string));
}
header = false;
tHeader = false;
}
// Data
if (!header)
else
{
table.Rows.Add(split);
}
}
}

// catch last entries
if (dic.Count != 0)
{
// clone dic in dicList
dicList[titel] = new Dictionary<string, string>(dic);
dicList[title] = new Dictionary<string, object>(dic);
}
if (table.Rows.Count != 0)
{
// clone dic in dicList
dicList[titel] = table.Copy();

table = new DataTable();
dicList[title] = table.Copy();
}
return dicList;
}
Expand Down
2 changes: 1 addition & 1 deletion MARMoSET_C/MARMoSET/MARMoSET.csproj.user
Expand Up @@ -7,7 +7,7 @@
<StartArguments>E:\bspdaten</StartArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<StartArguments>\\KI-S0138\Abt-A%24\mkiwele\Praktikum\bspdaten\LTQ test.json</StartArguments>
<StartArguments>P:\allMARMoSET\marmoset_tests\Joh\raw_ltq testJson.json</StartArguments>
<StartWorkingDirectory>
</StartWorkingDirectory>
</PropertyGroup>
Expand Down
Binary file modified MARMoSET_C/MARMoSET/bin/x64/Debug/MARMoSET.exe
Binary file not shown.
Binary file modified MARMoSET_C/MARMoSET/bin/x64/Debug/MARMoSET.pdb
Binary file not shown.
Binary file modified MARMoSET_C/MARMoSET/bin/x64/Release/MARMoSET.exe
Binary file not shown.
Binary file modified MARMoSET_C/MARMoSET/bin/x64/Release/MARMoSET.pdb
Binary file not shown.
Binary file not shown.
Binary file modified MARMoSET_C/MARMoSET/obj/x64/Debug/MARMoSET.exe
Binary file not shown.
Binary file modified MARMoSET_C/MARMoSET/obj/x64/Debug/MARMoSET.pdb
Binary file not shown.
Binary file not shown.
Binary file modified MARMoSET_C/MARMoSET/obj/x64/Release/MARMoSET.exe
Binary file not shown.
Binary file modified MARMoSET_C/MARMoSET/obj/x64/Release/MARMoSET.pdb
Binary file not shown.

0 comments on commit dc20899

Please sign in to comment.