private void SetTestProcedureData(ref TestProcedure newTestProcedure, string name, string traceName) { TestProcedure templateTestProcedure = ExtendedEntityManager.DeserializeEntity <TestProcedure>(Properties.Resources.TestProcedure); newTestProcedure.Blocks = templateTestProcedure.Blocks; (newTestProcedure.Blocks[0] as DriveUnitBlock).TraceNames = new string[] { traceName }; newTestProcedure.Name = name; }
private void CreateEntities() { if (_filePaths != null && _filePaths.Count > 0) { List <string> traceNames = new List <string>(); List <string> testProcedureNames = new List <string>(); List <string> shiftTableNames = new List <string>(); List <string> shiftListNames = new List <string>(); foreach (string filePath in _filePaths) { Trace newTrace = new Trace(); TestProcedure newTestProcedure = new TestProcedure(); ShiftTable newShiftTable = new ShiftTable();; ShiftList newShiftList = new ShiftList(); string baseName = GetNameFromPath(filePath); FileContents fileContents = GetFileContents(filePath); List <TraceColumn> columnData = new List <TraceColumn>(); string predictedTraceName = ExtendedEntityManager.PredictEntityName <Trace>(baseName + " Trace", traceNames); string predictedTestProcedureName = ExtendedEntityManager.PredictEntityName <TestProcedure>(baseName + " Test Procedure", testProcedureNames); string predictedShiftTableName = ExtendedEntityManager.PredictEntityName <ShiftTable>(baseName + " Shift Table", shiftTableNames); string predictedShiftListName = ExtendedEntityManager.PredictEntityName <ShiftList>(baseName + " Shift List", shiftListNames); traceNames.Add(predictedTraceName); testProcedureNames.Add(predictedTestProcedureName); shiftTableNames.Add(predictedShiftTableName); shiftListNames.Add(predictedShiftListName); SetTraceData(ref newTrace, ref columnData, fileContents, predictedTraceName); SetTestProcedureData(ref newTestProcedure, predictedTestProcedureName, predictedTraceName); SetShiftTableData(ref newShiftTable, columnData, fileContents, predictedShiftTableName, predictedTraceName); SetShiftListData(ref newShiftList, predictedShiftListName, predictedTestProcedureName, predictedShiftTableName); MEF.EntityManagerView.Traces.Value.Create(ExtendedEntityManager.GetEntityURI <Trace>(), newTrace.Properties); MEF.EntityManagerView.TestProcedures.Value.Create(ExtendedEntityManager.GetEntityURI <TestProcedure>(), newTestProcedure.Properties); MEF.EntityManagerView.ShiftTables.Value.Create(ExtendedEntityManager.GetEntityURI <ShiftTable>(), newShiftTable.Properties); MEF.EntityManagerView.ShiftLists.Value.Create(ExtendedEntityManager.GetEntityURI <ShiftList>(), newShiftList.Properties); ShowDialog(predictedTraceName, predictedTestProcedureName, predictedShiftTableName, predictedShiftListName); //if (filePath == _filePaths.Last()) //{ // Thread newThread = new Thread(x => ShowImportedTrace(predictedTraceName)) { IsBackground = true }; // newThread.Start(); //} } } }
private void SetShiftTableData(ref ShiftTable newShiftTable, List <TraceColumn> columnData, FileContents fileContents, string name, string traceName) { ShiftTable templateShiftTableAutomatic = ExtendedEntityManager.DeserializeEntity <ShiftTable>(Properties.Resources.ShiftTableA); ShiftTable templateShiftTableManual = ExtendedEntityManager.DeserializeEntity <ShiftTable>(Properties.Resources.ShiftTableM); int gearIndex = -1; bool isAutomatic = true; for (int i = 0; i < fileContents.NamesSplit.Length; i++) { if (fileContents.NamesSplit[i].Contains("gear")) { gearIndex = i; } } if (gearIndex >= 0) { for (int i = fileContents.DataIndex; i < fileContents.DataLength + fileContents.DataIndex; i++) { string thisGear = fileContents.Lines[i].Split(fileContents.Delimiter)[gearIndex]; if (CaseInsensitiveContains(thisGear, "MANUAL")) { isAutomatic = false; break; } if (CaseInsensitiveContains(thisGear, "AUTOMATIC")) { isAutomatic = true; break; } } } double[] timeData = columnData.FirstOrDefault(x => x.Name == "Time").Data; if (isAutomatic) { double[] speedData = columnData.FirstOrDefault(x => x.Name == "Speed").Data; int start = -1; int end = speedData.Length - 1; for (int i = 0; i < speedData.Length; i++) { if (speedData[i] != 0 && start < 0) { start = i - 1; } if (speedData[i] != 0) { end = i + 1; } } if (start >= 5) { start = start - 5; } else if (start < 0) { start = 0; } if (end > speedData.Length - 1) { end = speedData.Length - 1; } newShiftTable.MaximumGear = templateShiftTableAutomatic.MaximumGear; newShiftTable.TransmissionType = templateShiftTableAutomatic.TransmissionType; newShiftTable.Vectors = templateShiftTableAutomatic.Vectors; newShiftTable.Vectors[0].Data = (new double[] { start, end }).Cast <object>().ToArray(); } else { List <double> time = new List <double>(); List <string> gear = new List <string>(); List <bool> declutch = new List <bool>(); List <string> message = new List <string>(); for (int i = fileContents.DataIndex; i < fileContents.DataLength + fileContents.DataIndex; i++) { string thisGear = fileContents.Lines[i].Split(fileContents.Delimiter)[gearIndex]; if (thisGear != String.Empty) { thisGear = thisGear.Split('-').Last(); if (TypeCast.IsInt(thisGear)) { time.Add(timeData[i - fileContents.DataIndex]); gear.Add(thisGear); declutch.Add(false); message.Add(String.Empty); } } } newShiftTable.MaximumGear = TypeCast.ToInt(gear.Max()); newShiftTable.TransmissionType = templateShiftTableManual.TransmissionType; newShiftTable.Vectors = templateShiftTableManual.Vectors; newShiftTable.Vectors[0].Data = time.Cast <object>().ToArray(); newShiftTable.Vectors[1].Data = gear.Cast <object>().ToArray(); newShiftTable.Vectors[2].Data = declutch.Cast <object>().ToArray(); newShiftTable.Vectors[3].Data = message.Cast <object>().ToArray(); } newShiftTable.TraceName = traceName; newShiftTable.Name = name; }