Ejemplo n.º 1
0
        public static List <SubsystemClass> reorderSubs(List <LogAnalyzer> logAnalyzerData, List <SubsystemClass> subsystemList)
        {
            SubsystemClass        Subsystem;
            List <SubsystemClass> newSubsystemList   = new List <SubsystemClass>();
            List <LogAnalyzer>    newLogAnalyzerList = new List <LogAnalyzer>();
            LogAnalyzer           logAnalyzer;

            foreach (SubsystemClass subsystem in subsystemList)
            {
                logAnalyzer = logAnalyzerData.Find(x => x.SubName == subsystem.SubName);
                newLogAnalyzerList.Add(logAnalyzer);
            }

            IEnumerable <LogAnalyzer> orgData = newLogAnalyzerList.OrderByDescending(x => x.SubFailRate);    // Convert log analyzer list to IEnumerable and sort by subsystem failure rate

            newLogAnalyzerList = orgData.ToList();                                                           // Back to list

            foreach (LogAnalyzer logAnalyzerDataObject in newLogAnalyzerList)                                // Create new order subsystem list
            {
                Subsystem = new SubsystemClass(logAnalyzerDataObject.SubName, null, null);
                newSubsystemList.Add(Subsystem);
            }

            return(newSubsystemList);
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            // Subsystem evaluation:

            // Multiple functions: Logger, RunTime mode, and
            // PostProcess mode.

            // Inputs are read from .xml files.
            // All model information reside within .xml files.

            // Outputs are comma-delimited .csv files

            // Read in .xml

            List <Constraint>     constraintsList = new List <Constraint>();         // New lsit of constraints
            List <SubsystemClass> subsysList      = new List <SubsystemClass>();     // New list of subsystems
            List <StateVar>       stateVarList    = new List <StateVar>();           // New list of state variables

            OpenFileDialog ofd = new OpenFileDialog();                               // Dialog prompt to user to choose xml file location

            ofd.Filter = "XML| *.xml";                                               // Only allows xml files to be inputted
            if (ofd.ShowDialog() == DialogResult.OK)                                 // If the correct file was selected
            {
                constraintsList = readXML.XMLCon(ofd);                               // List of constraints
                subsysList      = readXML.XMLSub(ofd);                               // List of subsystems
                stateVarList    = readXML.XMLState(constraintsList, subsysList);     // List of state variables
            }

            // Done reading in .xml

            // Read-in Log

            // Implement checking for passed schedules and failed schedules

            LogData logData = new LogData(null, null, null, null, null, null, 0, 0);
            //List<LogData> logDataList = new List<LogData>();                        // New List of Log Data
            List <LogAnalyzer> LogAnalytics = new List <LogAnalyzer>();                 // New List of Log Analytics
            //var logger = new Logger();                                                // New Log class


            // Create specified subsystems and constraints for reordering
            List <SubsystemClass> subsystemList = new List <SubsystemClass>();
            SubsystemClass        subsystem     = new SubsystemClass("SubsystemNode2", null, null);

            subsystemList.Add(subsystem);
            subsystem = new SubsystemClass("SubsystemNode3", null, null);
            subsystemList.Add(subsystem);
            subsystem = new SubsystemClass("SubsystemNode4", null, null);
            subsystemList.Add(subsystem);

            List <Constraint> constraintList = new List <Constraint>();
            Constraint        constraint     = new Constraint("Constraint1", 0, null);

            constraintList.Add(constraint);
            constraint = new Constraint("Constraint2", 0, null);
            constraintList.Add(constraint);

            List <Constraint>     conOrder = new List <Constraint>();
            List <SubsystemClass> subOrder = new List <SubsystemClass>();

            // Done creating specified subsystems and constraints for reordering

            // Specify the number of failed schedules
            // Create data for each failed schedule
            // Output runTime data for every 25 failed schedules
            // Output postProcess data for every 100 failed schedules

            Console.WriteLine("Input number of failed schedules for randomized log data");      // Prompt user to input number of iterations
            string input = Console.ReadLine();                                                  // Read number of iterations
            double iters = Convert.ToDouble(input);                                             // Specify number of failed schedules
            int    i     = 0;

            Console.WriteLine("Press 1 and then press enter for RunTime mode, otherwise enter a different value "
                              + "and press enter to begin PostProcess mode.");                                      // Prompt user for mode specification
            int mode;                                                                                               // Declare mode

            if (int.TryParse(Console.ReadLine(), out mode))
            {
                for (i = 1; i <= iters; i++)
                {
                    logData = GenRandLogData.Output(constraintsList, stateVarList, subsysList, i);
                    Logger.Output(logData);

                    // Calculate and record percentage of constraint failure, their respective subsystems, etc.

                    if (mode == 1 && i % 25 == 0)      // Check if in RunTime mode && if the iteration is the 25th
                    {
                        LogAnalytics = LogAnalyzer.Analyze(LogAnalytics, Logger.Log, constraintsList, subsysList, stateVarList);
                        conOrder     = LogAnalyzer.reorderCons(LogAnalytics, constraintList);
                        subOrder     = LogAnalyzer.reorderSubs(LogAnalytics, subsystemList);
                        Logger.Log.Data.Clear();
                    }

                    else if (i % 10 == 0)             // PostProcess mode
                    {
                        LogAnalytics = LogAnalyzer.Analyze(LogAnalytics, Logger.Log, constraintsList, subsysList, stateVarList);
                        LogAnalyzer.PostProcess(LogAnalytics, subsysList);
                        conOrder = LogAnalyzer.reorderCons(LogAnalytics, constraintList);
                        subOrder = LogAnalyzer.reorderSubs(LogAnalytics, subsystemList);
                        Logger.Log.Data.Clear();
                    }
                }
            }
            // Done logging and calculating subsystem failures and constraint violations with relative data
        }
Ejemplo n.º 3
0
        public static void PostProcess(List <LogAnalyzer> logAnalyzerData, List <SubsystemClass> subList)
        {
            int i = 0;
            int j = 0;
            int k = 0;

            List <LogAnalyzer> subOrgData   = LogAnalyzer.sortBySubFails(logAnalyzerData);
            List <LogAnalyzer> conOrgData   = LogAnalyzer.sortByConVios(logAnalyzerData);
            List <string>      stateVarList = new List <string>();

            // Output Log Data Analyzer to .csv file

            StreamWriter subOrgDataWrite = new StreamWriter(@"subsystemFailures.csv");      // Creates a new .csv file to write in

            subOrgDataWrite.Write("Failed Subsystem");                                      // Headers
            subOrgDataWrite.Write(",Subsystem Failure Rate");                               // Headers
            subOrgDataWrite.Write(",Asset Name");                                           // Headers
            subOrgDataWrite.Write(",Task Names");                                           // Headers
            subOrgDataWrite.Write(",Target Names");                                         // Headers
            subOrgDataWrite.Write(Environment.NewLine);                                     // Writes new line to the comma-delimited .csv file

            foreach (LogAnalyzer item in subOrgData)
            {
                if (item.ConName == null)
                {
                    subOrgDataWrite.Write(item.SubName);
                    subOrgDataWrite.Write("," + item.SubFailRate);
                    subOrgDataWrite.Write("," + item.AssetNames[0]);

                    if (item.TaskNames.Count > 0)
                    {
                        foreach (string item2 in item.TaskNames)
                        {
                            if (i >= 1)
                            {
                                subOrgDataWrite.Write(",,");
                            }
                            subOrgDataWrite.Write("," + item2);
                            subOrgDataWrite.Write("," + item.TarNames[i]);
                            subOrgDataWrite.Write(Environment.NewLine);
                            i++;
                        }
                        i = 0;
                    }

                    else
                    {
                        subOrgDataWrite.Write(Environment.NewLine);
                    }
                }
            }
            subOrgDataWrite.Close();                                                        // Closes the log analyzer data .csv file

            StreamWriter conOrgDataWrite = new StreamWriter(@"constraintViolations.csv");   // Creates a new .csv file to write in

            conOrgDataWrite.Write("Violated Constraint");                                   // Headers
            conOrgDataWrite.Write(",Constraint Violation Rate");                            // Headers
            conOrgDataWrite.Write(",Asset Names");                                          // Headers
            conOrgDataWrite.Write(",Violating Subsystems");                                 // Headers
            conOrgDataWrite.Write(",Violating Subsystem Rates");                            // Headers
            conOrgDataWrite.Write(",Violating State Variables");                            // Headers
            conOrgDataWrite.Write(Environment.NewLine);                                     // Writes new line to the comma-delimited .csv file

            foreach (LogAnalyzer item in conOrgData)
            {
                if (item.ConName != null)
                {
                    conOrgDataWrite.Write(item.ConName);
                    conOrgDataWrite.Write("," + item.ConVioRate);

                    if (item.ConSubNames.Count > 0)
                    {
                        foreach (string conSubName in item.ConSubNames)
                        {
                            if (i == 0)
                            {
                                conOrgDataWrite.Write("," + item.AssetNames[i]);
                                conOrgDataWrite.Write("," + item.ConSubNames[i]);
                                conOrgDataWrite.Write("," + item.ConSubRates[i]);
                                SubsystemClass subsys = subList.Find(x => x.SubName == item.ConSubNames[i]);
                                foreach (string item3 in item.VioNames)
                                {
                                    if (subsys.StateVars.Contains(item3))
                                    {
                                        if (j > 0 && stateVarList.Contains(item3) == false)
                                        {
                                            conOrgDataWrite.Write(",,,,," + item3);
                                            stateVarList.Add(item3);
                                            conOrgDataWrite.Write(Environment.NewLine);
                                        }
                                        else if (j == 0)
                                        {
                                            stateVarList.Clear();
                                            conOrgDataWrite.Write("," + item3);
                                            stateVarList.Add(item3);
                                            conOrgDataWrite.Write(Environment.NewLine);
                                        }
                                        j++;
                                    }
                                }
                                stateVarList.Clear();
                                j = 0;
                            }

                            else
                            {
                                conOrgDataWrite.Write(",," + item.AssetNames[i]);
                                conOrgDataWrite.Write("," + item.ConSubNames[i]);
                                conOrgDataWrite.Write("," + item.ConSubRates[i]);
                                SubsystemClass subsys = subList.Find(x => x.SubName == item.ConSubNames[i]);
                                foreach (string item3 in item.VioNames)
                                {
                                    if (subsys.StateVars.Contains(item3))
                                    {
                                        if (k == 0)
                                        {
                                            conOrgDataWrite.Write("," + item3);
                                            stateVarList.Add(item3);
                                            conOrgDataWrite.Write(Environment.NewLine);
                                        }
                                        else if (j > 0 && stateVarList.Contains(item3) == false)
                                        {
                                            conOrgDataWrite.Write(",,,,," + item3);
                                            stateVarList.Add(item3);
                                            conOrgDataWrite.Write(Environment.NewLine);
                                        }
                                        j++;
                                        k++;
                                    }
                                }
                                stateVarList.Clear();
                            }
                            k = 0;
                            i++;
                        }
                        i = 0;
                        j = 0;
                    }

                    else
                    {
                        conOrgDataWrite.Write(Environment.NewLine);
                    }
                }
            }
            conOrgDataWrite.Close();                                                        // Closes the logger data .csv file
        }
Ejemplo n.º 4
0
        public static List <SubsystemClass> XMLSub(OpenFileDialog ofd)           // Read in subsystem information within XML file
        {
            XDocument xDoc = XDocument.Load(ofd.FileName);                       // Opens XML file within framework and loads chosen XML file

            //LINQ query to read the xml file details
            var modelDetails = from readInfo in xDoc.Descendants("MODEL")        // Find the Model and read-in its descendant elements
                               select new
            {
                subInfo   = readInfo.Descendants("SUBSYSTEM").DescendantsAndSelf(),                         // Find all subsystems and read-in their descendant elements
                assetInfo = readInfo.DescendantsAndSelf("ASSET").DescendantsAndSelf()                       // Find all assets and read-in in their descendant elements
            };

            // Asset details retrieval
            Asset          asset  = new Asset(null, null);                  // New asset class
            SubsystemClass subSys = new SubsystemClass(null, null, null);   // New subsystem class

            List <Asset>          assetsList = new List <Asset>();          // New list of information for each asset
            List <SubsystemClass> subsysList = new List <SubsystemClass>(); // New list of information for each subsystem

            int           i         = 0;                                    // Declare counter
            string        SubName   = null;
            string        StateVar  = null;
            string        AssetName = null;
            List <string> StateVars = new List <string>();
            List <string> SubNames  = new List <string>();

            // Using foreach loop to retrieve all details by iterating through each element with the MODEL element
            foreach (var modelElem in modelDetails)
            {
                // Using foreach loop to retrieve each asset's details by iterating through each element with the ASSET element
                foreach (XElement ae in modelElem.assetInfo)
                {
                    string assetName = ae.Attribute("AssetName") != null?ae.Attribute("AssetName").Value : String.Empty;               // Extract asset name data

                    string subName = ae.Attribute("SubsystemName") != null?ae.Attribute("SubsystemName").Value : String.Empty;         // Extract subsystem name data

                    if (assetName != String.Empty)                                                                                     // If the element is an asset name
                    {
                        if (i > 0)                                                                                                     // If there is a new asset
                        {
                            asset = new Asset(AssetName, SubNames);
                            assetsList.Add(asset);                                                                                     // Add asset to asset list
                            asset    = new Asset(AssetName, SubNames);                                                                 // Populate asset class
                            SubNames = new List <string>();
                        }
                        AssetName = assetName;                                                                                         // Record asset name
                    }

                    if (subName != String.Empty)                                                                                       // If the element is a subsystem name
                    {
                        SubNames.Add(subName);                                                                                         // Record subsystem name in subsystem names list
                        i++;
                    }
                }
                asset = new Asset(AssetName, SubNames);                                                                                // Populate asset class
                assetsList.Add(asset);                                                                                                 // Add asset to asset list

                i = 0;

                // Using foreach loop to retrieve each subsystem and dependecies respective details by iterating through each element with the SUBSYSTEM element
                foreach (XElement se in modelElem.subInfo)
                {
                    string stateName = se.Attribute("key") != null?se.Attribute("key").Value : String.Empty;                   // Extract state variable data

                    string subName = se.Attribute("SubsystemName") != null?se.Attribute("SubsystemName").Value : String.Empty; // Extract subsystem name data

                    if (subName != String.Empty)                                                                               // If the element is a subsystem name
                    {
                        if (i > 0)                                                                                             // If there is a new subsystem
                        {
                            foreach (Asset item in assetsList)                                                                 // Check each asset
                            {
                                if (item.SubNames.Contains(SubName))                                                           // Find subsystem name within asset
                                {
                                    AssetName = item.AssetName;                                                                // Record asset name for subsystem class
                                }
                            }
                            subSys = new SubsystemClass(SubName, AssetName, StateVars);                     // Populate subsystem class
                            subsysList.Add(subSys);                                                         // Add subsystem class to subsystem list
                            StateVars = new List <string>();
                        }
                        SubName = subName;                                                                  // Record subsystem name for subsystem class
                        i++;
                    }


                    if (stateName != String.Empty)                                                          // If the element is a state variable
                    {
                        StateVar = stateName;
                        StateVars.Add(stateName);                                                           // Record state variable requirement for subsystem class
                    }
                }
                subSys = new SubsystemClass(SubName, AssetName, StateVars);                                 // Populate subsystem class
                subsysList.Add(subSys);                                                                     // Add subsystem class to subsystem list
            }
            return(subsysList);
        }