Exemplo n.º 1
0
        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();
                    //}
                }
            }
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        private void SetTraceData(ref Trace newTrace, ref List <TraceColumn> columnData, FileContents fileContents, string name)
        {
            for (int i = 0; i < fileContents.NamesSplit.Length; i++)
            {
                if (fileContents.NamesSplit[i].Contains("time"))
                {
                    columnData.Add(new TraceColumn("Time", "s", i, fileContents.DataLength, fileContents.UnitsSplit[i]));
                }
                else if (fileContents.NamesSplit[i].Contains("speed"))
                {
                    columnData.Add(new TraceColumn("Speed", "km/h", i, fileContents.DataLength, fileContents.UnitsSplit[i]));
                }
                else if (fileContents.NamesSplit[i].Contains("slope"))
                {
                    columnData.Add(new TraceColumn("Gradient", "%", i, fileContents.DataLength, fileContents.UnitsSplit[i]));
                }
                else if (fileContents.NamesSplit[i].Contains("ambient-temperature"))
                {
                    columnData.Add(new TraceColumn("Temperature", "°C", i, fileContents.DataLength, fileContents.UnitsSplit[i]));
                }
                else if (fileContents.NamesSplit[i].Contains("ambient-humidity"))
                {
                    columnData.Add(new TraceColumn("RelativeHumidity", "%", i, fileContents.DataLength, fileContents.UnitsSplit[i]));
                }
            }

            for (int i = 0; i < columnData.Count; i++)
            {
                for (int j = 0; j < fileContents.DataLength; j++)
                {
                    columnData[i].Data[j] = columnData[i].Units.Convert(Convert.ToDouble(fileContents.Lines[j + fileContents.DataIndex].Split(fileContents.Delimiter)[columnData[i].Index]));
                }
            }

            List <VectorData> vectorData = new List <VectorData>();

            for (int i = 0; i < columnData.Count; i++)
            {
                vectorData.Add(new TypedVectorData <double>());
                vectorData[i].Data = columnData[i].Data.Cast <object>().ToArray();
                vectorData[i].Name = columnData[i].Name;
                vectorData[i].Unit = columnData[i].DisplayUnits;
            }
            newTrace.Vectors = vectorData.ToArray();
            newTrace.Name    = name;
        }