Esempio n. 1
0
        private List <CycleData> ProcessCycles(List <Instance> data)
        {
            var result = new List <CycleData>();

            if (data != null)
            {
                if (data.Count > 0)
                {
                    // Filter out data that has already been processed
                    var latestData = data.FindAll(x => x.Timestamp > lastTimestamp);

                    // Insure that InstanceData list is sorted by Timestamp ASC
                    var orderedData = latestData.OrderBy(x => x.Timestamp).ToList();

                    if (configuration != null)
                    {
                        foreach (var instanceData in orderedData)
                        {
                            // Get list of new / updated CycleData objects
                            var cycleDatas = Process(instanceData);

                            // Update last timestamp for filtering
                            lastTimestamp = instanceData.Timestamp;

                            // Add new CycleData objects to returned list
                            result.AddRange(cycleDatas);
                        }
                    }
                }
            }
            else
            {
                if (storedCycle == null || storedCycle.ProductionType != CycleProductionType.STOPPED)
                {
                    storedCycle                = new CycleData();
                    storedCycle.CycleId        = Guid.NewGuid().ToString();
                    storedCycle.InstanceId     = Guid.NewGuid().ToString();
                    storedCycle.ProductionType = CycleProductionType.STOPPED;
                    storedCycle.Name           = "UNAVAILABLE";
                    storedCycle.Event          = "UNAVAILABLE";
                    storedCycle.Start          = DateTime.UtcNow;
                }

                storedCycle.Stop = DateTime.UtcNow;
                result.Add(storedCycle.Copy());
            }

            return(result);
        }
Esempio n. 2
0
        public CycleData Copy()
        {
            var result = new CycleData();

            result.CycleId        = CycleId;
            result.InstanceId     = InstanceId;
            result.Name           = Name;
            result.Event          = Event;
            result.ProductionType = ProductionType;
            result.Start          = Start;
            result.Stop           = Stop;
            result.Completed      = Completed;
            result.CycleOverrides = CycleOverrides.ToList();
            result.Overrides      = Overrides.ToList();
            return(result);
        }
Esempio n. 3
0
        private List <CycleData> Process(Instance instanceData)
        {
            var result = new List <CycleData>();

            var cc = Configuration.Get(configuration);
            var gc = GeneratedEvents.Configuration.Get(configuration);

            if (cc != null && cc.CycleEventName != null && gc != null)
            {
                // Find the CycleEventName in the Generated Events Configuration
                var cycleEvent = gc.Events.Find(x => x.Name.ToLower() == cc.CycleEventName.ToLower());
                if (cycleEvent != null)
                {
                    // Search for cycle name link in InstanceData
                    var instanceValue = instanceData.Values.Find(x => x.Id == cc.CycleNameLink);
                    if (instanceValue != null)
                    {
                        var cycleOverrides = new List <CycleOverride>();

                        // Get CycleOverride values from InstanceData
                        foreach (var ovr in cc.OverrideLinks)
                        {
                            var cycleOverride = GetOverrideFromInstanceData(ovr, instanceData);
                            if (cycleOverride != null)
                            {
                                cycleOverrides.Add(cycleOverride);
                            }
                        }

                        // Process Cycle Event using instanceData
                        var eventReturn = cycleEvent.Process(instanceData);
                        if (eventReturn != null)
                        {
                            // Get the name of the cycle
                            string cycleName = instanceValue.Value;

                            // Get the name of the cycleEvent (cycleEvent.Value)
                            string cycleEventValue = eventReturn.Value;

                            // Set cycle to stored cycleData object
                            CycleData cycle = storedCycle;
                            if (cycle != null)
                            {
                                // Update Stop Time (running total so that items such as OEE (which is based on cycles) can be updated)
                                cycle.Stop = instanceData.Timestamp;

                                if (cycle.Name != cycleName || cycle.Event != cycleEventValue || !CompareOverrideLists(cycle.CycleOverrides, cycleOverrides))
                                {
                                    cycle.Completed = true;

                                    // Add a copy of the current cycle to the list
                                    result.Add(cycle.Copy());

                                    // Check if new cycle has been started
                                    if (cycle.Name != cycleName || cycleEventValue == cc.StoppedEventValue)
                                    {
                                        // Set cycle to new instance
                                        cycle            = new CycleData();
                                        cycle.CycleId    = Guid.NewGuid().ToString();
                                        cycle.InstanceId = Guid.NewGuid().ToString();
                                        cycle.Name       = cycleName;
                                        cycle.Event      = cycleEventValue;
                                        cycle.Completed  = false;

                                        // Set Production Type
                                        var productionType = cc.ProductionTypes.Find(x => x.EventValue == cycleEventValue);
                                        if (productionType != null)
                                        {
                                            cycle.ProductionType = productionType.ProductionType;
                                        }
                                        else
                                        {
                                            cycle.ProductionType = CycleProductionType.UNCATEGORIZED;
                                        }

                                        cycle.Start          = instanceData.Timestamp;
                                        cycle.Stop           = instanceData.Timestamp;
                                        cycle.CycleOverrides = cycleOverrides.ToList();
                                    }
                                    else
                                    {
                                        // Set cycle to new Event
                                        cycle.InstanceId = Guid.NewGuid().ToString();
                                        cycle.Event      = cycleEventValue;
                                        cycle.Completed  = false;

                                        // Set Production Type
                                        var productionType = cc.ProductionTypes.Find(x => x.EventValue == cycleEventValue);
                                        if (productionType != null)
                                        {
                                            cycle.ProductionType = productionType.ProductionType;
                                        }
                                        else
                                        {
                                            cycle.ProductionType = CycleProductionType.UNCATEGORIZED;
                                        }

                                        cycle.Start          = instanceData.Timestamp;
                                        cycle.Stop           = instanceData.Timestamp;
                                        cycle.CycleOverrides = cycleOverrides.ToList();
                                    }
                                }

                                result.Add(cycle);
                            }
                            else
                            {
                                // Set cycle to new instance
                                cycle            = new CycleData();
                                cycle.CycleId    = Guid.NewGuid().ToString();
                                cycle.InstanceId = Guid.NewGuid().ToString();
                                cycle.Name       = cycleName;
                                cycle.Event      = cycleEventValue;

                                // Set Production Type
                                var productionType = cc.ProductionTypes.Find(x => x.EventValue == cycleEventValue);
                                if (productionType != null)
                                {
                                    cycle.ProductionType = productionType.ProductionType;
                                }
                                else
                                {
                                    cycle.ProductionType = CycleProductionType.UNCATEGORIZED;
                                }

                                cycle.Start          = instanceData.Timestamp;
                                cycle.Stop           = instanceData.Timestamp;
                                cycle.CycleOverrides = cycleOverrides.ToList();

                                result.Add(cycle);
                            }

                            storedCycle = cycle.Copy();
                        }
                    }
                }
            }

            return(result);
        }
Esempio n. 4
0
 public CycleData Copy()
 {
     var result = new CycleData();
     result.CycleId = CycleId;
     result.InstanceId = InstanceId;
     result.Name = Name;
     result.Event = Event;
     result.ProductionType = ProductionType;
     result.Start = Start;
     result.Stop = Stop;
     result.Completed = Completed;
     result.CycleOverrides = CycleOverrides.ToList();
     result.Overrides = Overrides.ToList();
     return result;
 }
Esempio n. 5
0
        private List<CycleData> ProcessCycles(List<Instance> data)
        {
            var result = new List<CycleData>();

            if (data != null)
            {
                if (data.Count > 0)
                {
                    // Filter out data that has already been processed
                    var latestData = data.FindAll(x => x.Timestamp > lastTimestamp);

                    // Insure that InstanceData list is sorted by Timestamp ASC
                    var orderedData = latestData.OrderBy(x => x.Timestamp).ToList();

                    if (configuration != null)
                    {
                        foreach (var instanceData in orderedData)
                        {
                            // Get list of new / updated CycleData objects
                            var cycleDatas = Process(instanceData);

                            // Update last timestamp for filtering
                            lastTimestamp = instanceData.Timestamp;

                            // Add new CycleData objects to returned list
                            result.AddRange(cycleDatas);
                        }
                    }
                }
            }
            else
            {
                if (storedCycle == null || storedCycle.ProductionType != CycleProductionType.STOPPED)
                {
                    storedCycle = new CycleData();
                    storedCycle.CycleId = Guid.NewGuid().ToString();
                    storedCycle.InstanceId = Guid.NewGuid().ToString();
                    storedCycle.ProductionType = CycleProductionType.STOPPED;
                    storedCycle.Name = "UNAVAILABLE";
                    storedCycle.Event = "UNAVAILABLE";
                    storedCycle.Start = DateTime.UtcNow;
                }

                storedCycle.Stop = DateTime.UtcNow;
                result.Add(storedCycle.Copy());
            }

            return result;
        }
Esempio n. 6
0
        private List<CycleData> Process(Instance instanceData)
        {
            var result = new List<CycleData>();

            var cc = Configuration.Get(configuration);
            var gc = GeneratedEvents.Configuration.Get(configuration);

            if (cc != null && cc.CycleEventName != null && gc != null)
            {
                // Find the CycleEventName in the Generated Events Configuration
                var cycleEvent = gc.Events.Find(x => x.Name.ToLower() == cc.CycleEventName.ToLower());
                if (cycleEvent != null)
                {
                    // Search for cycle name link in InstanceData
                    var instanceValue = instanceData.Values.Find(x => x.Id == cc.CycleNameLink);
                    if (instanceValue != null)
                    {
                        var cycleOverrides = new List<CycleOverride>();

                        // Get CycleOverride values from InstanceData
                        foreach (var ovr in cc.OverrideLinks)
                        {
                            var cycleOverride = GetOverrideFromInstanceData(ovr, instanceData);
                            if (cycleOverride != null) cycleOverrides.Add(cycleOverride);
                        }

                        // Process Cycle Event using instanceData
                        var eventReturn = cycleEvent.Process(instanceData);
                        if (eventReturn != null)
                        {
                            // Get the name of the cycle
                            string cycleName = instanceValue.Value;

                            // Get the name of the cycleEvent (cycleEvent.Value)
                            string cycleEventValue = eventReturn.Value;

                            // Set cycle to stored cycleData object
                            CycleData cycle = storedCycle;
                            if (cycle != null)
                            {
                                // Update Stop Time (running total so that items such as OEE (which is based on cycles) can be updated)
                                cycle.Stop = instanceData.Timestamp;

                                if (cycle.Name != cycleName || cycle.Event != cycleEventValue || !CompareOverrideLists(cycle.CycleOverrides, cycleOverrides))
                                {
                                    cycle.Completed = true;

                                    // Add a copy of the current cycle to the list
                                    result.Add(cycle.Copy());

                                    // Check if new cycle has been started
                                    if (cycle.Name != cycleName || cycleEventValue == cc.StoppedEventValue)
                                    {
                                        // Set cycle to new instance
                                        cycle = new CycleData();
                                        cycle.CycleId = Guid.NewGuid().ToString();
                                        cycle.InstanceId = Guid.NewGuid().ToString();
                                        cycle.Name = cycleName;
                                        cycle.Event = cycleEventValue;
                                        cycle.Completed = false;

                                        // Set Production Type
                                        var productionType = cc.ProductionTypes.Find(x => x.EventValue == cycleEventValue);
                                        if (productionType != null) cycle.ProductionType = productionType.ProductionType;
                                        else cycle.ProductionType = CycleProductionType.UNCATEGORIZED;

                                        cycle.Start = instanceData.Timestamp;
                                        cycle.Stop = instanceData.Timestamp;
                                        cycle.CycleOverrides = cycleOverrides.ToList();
                                    }
                                    else
                                    {
                                        // Set cycle to new Event
                                        cycle.InstanceId = Guid.NewGuid().ToString();
                                        cycle.Event = cycleEventValue;
                                        cycle.Completed = false;

                                        // Set Production Type
                                        var productionType = cc.ProductionTypes.Find(x => x.EventValue == cycleEventValue);
                                        if (productionType != null) cycle.ProductionType = productionType.ProductionType;
                                        else cycle.ProductionType = CycleProductionType.UNCATEGORIZED;

                                        cycle.Start = instanceData.Timestamp;
                                        cycle.Stop = instanceData.Timestamp;
                                        cycle.CycleOverrides = cycleOverrides.ToList();
                                    }
                                }

                                result.Add(cycle);
                            }
                            else
                            {
                                // Set cycle to new instance
                                cycle = new CycleData();
                                cycle.CycleId = Guid.NewGuid().ToString();
                                cycle.InstanceId = Guid.NewGuid().ToString();
                                cycle.Name = cycleName;
                                cycle.Event = cycleEventValue;

                                // Set Production Type
                                var productionType = cc.ProductionTypes.Find(x => x.EventValue == cycleEventValue);
                                if (productionType != null) cycle.ProductionType = productionType.ProductionType;
                                else cycle.ProductionType = CycleProductionType.UNCATEGORIZED;

                                cycle.Start = instanceData.Timestamp;
                                cycle.Stop = instanceData.Timestamp;
                                cycle.CycleOverrides = cycleOverrides.ToList();

                                result.Add(cycle);
                            }

                            storedCycle = cycle.Copy();
                        }
                    }
                }
            }

            return result;
        }