Exemplo n.º 1
0
 public DataCollectorResult(DateTime endTime, bool successful, IToolSpecification toolSpecification, IReadOnlyList <IToolMeasurementData> measurementData, IReferenceSample referenceSample = null)
     : base(endTime, successful)
 {
     Specification   = toolSpecification;
     Reference       = referenceSample;
     MeasurementData = measurementData;
 }
Exemplo n.º 2
0
        public bool GatherData(IToolSpecification specification, IEnumerable <string> measurementDataFileNames, IReferenceSample reference = null)
        {
            if (!IsInitialized)
            {
                _parameters.Logger.LogError("Not initialized yet.");
                return(false);
            }

            List <IToolMeasurementData> measurementDatas = new List <IToolMeasurementData>();

            foreach (string name in measurementDataFileNames)
            {
                measurementDatas.Add((IToolMeasurementData)_parameters.MeasurementDataRepository.Get(name));
            }

            var localResultreadyevent = ResultReadyEvent;

            localResultreadyevent?.Invoke(this, new ResultEventArgs(new DataCollectorResult(_parameters.DateTimeProvider.GetDateTime(), true, specification, measurementDatas, reference)));

            return(true);
        }
Exemplo n.º 3
0
        private void Evaluate(QueueElement element)
        {
            IDataCollectorResult collectedData = element.DataCollectorResult;

            IToolSpecification specification = collectedData.Specification;
            IReadOnlyList <IToolMeasurementData> measurementDatas = collectedData.MeasurementData;
            IReferenceSample referenceSample = collectedData.Reference;

            if (specification == null)
            {
                _parameters.Logger.LogMethodError("Received specification is null.");
                return;
            }

            if (measurementDatas == null)
            {
                _parameters.Logger.LogMethodError("Received measurement data is null.");
                return;
            }

            _parameters.Logger.LogMethodInfo($"Started to evaluate received collectordata: Specification name: {specification.Name}");
            _parameters.Logger.LogMethodInfo($"Reference name: {referenceSample?.Name ?? "No reference received"}.");
            _parameters.Logger.LogMethodInfo($"Measurement datas: {string.Join(",", measurementDatas.Select(p => p.Name))}");

            List <IQuantityEvaluationResult> quantityResultList = new List <IQuantityEvaluationResult>();

            // go through all quantity specifications:
            foreach (IQuantitySpecification quantitySpec in specification.QuantitySpecifications)
            {
                List <IConditionEvaluationResult> conditionResultList = new List <IConditionEvaluationResult>(quantitySpec.Conditions.Count);

                // go through all conditions in one quantity specification
                foreach (ICondition condition in quantitySpec.Conditions)
                {
                    try
                    {
                        // skip condition if condition is null:
                        //if (condition == null)
                        //{
                        //    _parameters.Logger.LogMethodError("Received condition is null");
                        //    continue;
                        //}

                        _parameters.MessageControl.AddMessage(_parameters.Logger.LogMethodInfo($"{quantitySpec.Quantity.Name}-{condition.Name} Evaluation started."));

                        // skip condition if not enabled:
                        if (!condition.Enabled)
                        {
                            _parameters.MessageControl.AddMessage(_parameters.Logger.LogMethodInfo($"{quantitySpec.Quantity.Name}-{condition.Name} is not enabled -> condition check skipped."));
                            continue;
                        }

                        // get the calculation:
                        ICalculation calculation = _parameters.CalculationContainer.GetCalculation(condition.CalculationTypeHandler.CalculationType);

                        // find measurement data associated with the condition name from the matcher:
                        IEnumerable <string>     coherentMeasurementDataNames = _parameters.Matcher.GetMeasDataNames(condition.Name);
                        List <IMeasurementSerie> coherentMeasurementData      = new List <IMeasurementSerie>();
                        foreach (var item in measurementDatas)
                        {
                            coherentMeasurementData.AddRange(item.Results.Where(p => coherentMeasurementDataNames.Contains(p.Name)));
                        }

                        if (coherentMeasurementData.Count == 0)
                        {
                            _parameters.MessageControl.AddMessage(_parameters.Logger.LogMethodError($"{quantitySpec.Quantity.Name}-{condition.Name} No coherent measurement data was found in measurement data files. Searched names: {string.Join(",", coherentMeasurementDataNames)}"), MessageSeverityLevels.Error);
                            continue;
                        }

                        // if more result were found with the same name -> they will be linked together, unless their name is different the coherent measurement datas will be summarized into one measurement data
                        List <INumericMeasurementPoint> measPointList = new List <INumericMeasurementPoint>();
                        foreach (IMeasurementSerie serie in coherentMeasurementData)
                        {
                            measPointList.AddRange(serie.MeasuredPoints);
                        }
                        IMeasurementSerie jointCalculationInputData = new MeasurementSerie(coherentMeasurementData[0].Name, measPointList, coherentMeasurementData[0].Dimension);

                        _parameters.MessageControl.AddMessage(_parameters.Logger.LogMethodInfo($"{coherentMeasurementData.Count} measurement data(s) were created (joint together)."));

                        // find reference associated with the specification
                        string          referenceName  = _parameters.Matcher.GetReferenceName(condition.Name);
                        IReferenceValue referenceValue = referenceSample?.ReferenceValues?.FirstOrDefault(p => string.Equals(p.Name, referenceName));

                        // perform calculation:
                        IResult calcResult = calculation.Calculate(jointCalculationInputData, condition, referenceValue);

                        if (!calcResult.Successful)
                        {
                            _parameters.MessageControl.AddMessage(_parameters.Logger.LogMethodError($"{quantitySpec.Quantity.Name}-{condition.Name} Calculation {calculation.CalculationType} was not successful."), MessageSeverityLevels.Error);
                            continue;
                        }

                        IConditionEvaluationResult conditionEvaluationResult = condition.EvaluateCondition(calcResult, _parameters.DateTimeProvider.GetDateTime(), referenceValue);

                        conditionResultList.Add(conditionEvaluationResult);

                        #region logging
                        if (_parameters.Logger.IsTraceEnabled)
                        {
                            _parameters.Logger.LogMethodTrace("The evaluation result:");
                            _parameters.Logger.LogMethodTrace($"   End time: {conditionEvaluationResult.CreationTime}");
                            _parameters.Logger.LogMethodTrace($"   The calculation was {(conditionEvaluationResult.Successful ? "" : "NOT")} successful.");
                            _parameters.Logger.LogMethodTrace($"   Calculation input data name {jointCalculationInputData.Name} number of measurement points: {jointCalculationInputData.MeasuredPoints.Count}");
                            _parameters.Logger.LogMethodTrace($"   ReferenceValue: {referenceValue}");
                            _parameters.Logger.LogMethodTrace($"   Condition: {condition}");
                            _parameters.Logger.LogMethodTrace($"   The result is {(conditionEvaluationResult.ConditionIsMet ? "" : "NOT")} acceptable.");
                        }
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        _parameters.Logger.LogMethodError($"Exception occured: {ex}");
                    }
                }

                quantityResultList.Add(new QuantityEvaluationResult(conditionResultList, quantitySpec.Quantity));
            }

            IEvaluationResult evaluationResult = new EvaluationResult(_parameters.DateTimeProvider.GetDateTime(), true, quantityResultList, specification.ToolName, specification.Name);

            var resultreadyevent = ResultReadyEvent;
            resultreadyevent?.Invoke(this, new ResultEventArgs(evaluationResult));

            _parameters.MessageControl.AddMessage(_parameters.Logger.LogMethodError("Calculation Finished"));
        }
Exemplo n.º 4
0
 public int CompareTo(IToolSpecification other)
 {
     throw new NotImplementedException();
 }