コード例 #1
0
        private ComputedResultSetFitLine CreateLinearDataSet(List <DeviceValue> dataPoints, int numberOfLastMeasurements)
        {
            var lastDataPoints = dataPoints.OrderBy(x => x.DateTimeOfMeasurment).Take(numberOfLastMeasurements).ToList();
            var fitLineHandler = new FitLineHandler();

            return(fitLineHandler.ComputeLinearData(lastDataPoints));
        }
コード例 #2
0
        public bool TriggerTrue(List <DeviceValue> dataPoints, AscDescEnum ascDesc, double?threshold = null, TimeSpan?timeToReachThreshold = null)
        {
            if (dataPoints != null && dataPoints.Count > 1)
            {
                _logging.LogDebug($"Wait for lock in DataCurveComputation for device:{dataPoints.First().DeviceId}");

                //Do computations to find if we have ascending or descending curve. Start by locking the methode to avoid multiple results
                lock (_lock)
                {
                    _logging.LogDebug($"computing the curve for device:{dataPoints.First().DeviceId}");

                    var fitLineHandler = new FitLineHandler();
                    var resultSetComputedLinearData = fitLineHandler.ComputeLinearData(dataPoints);

                    var culture = CultureInfo.CreateSpecificCulture("en-US");
                    _logging.LogDebug($"result of computing IsDescending: {resultSetComputedLinearData.IsDescending.ToString()} IsAscending:{resultSetComputedLinearData.IsAscending.ToString()} Slope:{resultSetComputedLinearData.Slope.ToString("#.###", culture)}");

                    var resultsetLastValues = ComputeLastValues(dataPoints, ascDesc);

                    if (threshold.HasValue && timeToReachThreshold.HasValue)
                    {
                        //Hente ut siste verdi
                        var resultSetComputedFutureLine = ComputeFutureValues(dataPoints, ascDesc, resultSetComputedLinearData, threshold.Value, timeToReachThreshold.Value);
                        _logging.LogDebug($"ascDec Descending{ascDesc == AscDescEnum.Descending} resultSetComputedFutureLine.TriggerTrue: {resultSetComputedFutureLine.TriggerTrue} resultSetComputedLinearData.IsDescending: {resultSetComputedLinearData.IsDescending } resultSetComputedLinearData.IsAscending: {resultSetComputedLinearData.IsAscending }  resultsetLastValues.LastSlope: {resultsetLastValues.LastSlope} resultsetLastValues.LastValueHighest: {resultsetLastValues.LastValueHighest } resultsetLastValues.LastValueLowest: {resultsetLastValues.LastValueLowest} ");
                        if (ascDesc == AscDescEnum.Ascending && resultSetComputedFutureLine.TriggerTrue && resultSetComputedLinearData.IsAscending && resultsetLastValues.LastSlope > 0 && resultsetLastValues.LastValueHighest)
                        {
                            return(true);
                        }
                        if (ascDesc == AscDescEnum.Descending && resultSetComputedFutureLine.TriggerTrue && resultSetComputedLinearData.IsDescending && resultsetLastValues.LastSlope < 0 && resultsetLastValues.LastValueLowest)
                        {
                            return(true);
                        }
                    }

                    else
                    {
                        //Only test curves
                        _logging.LogDebug($"ascDec Descending{ascDesc == AscDescEnum.Descending}  resultSetComputedLinearData.IsDescending: {resultSetComputedLinearData.IsDescending } resultSetComputedLinearData.IsAscending: {resultSetComputedLinearData.IsAscending }  resultsetLastValues.LastSlope: {resultsetLastValues.LastSlope} resultsetLastValues.LastValueHighest: {resultsetLastValues.LastValueHighest } resultsetLastValues.LastValueLowest: {resultsetLastValues.LastValueLowest} ");
                        if (ascDesc == AscDescEnum.Ascending && resultSetComputedLinearData.IsAscending && resultsetLastValues.LastSlope > 0 && resultsetLastValues.LastValueHighest)
                        {
                            return(true);
                        }
                        if (ascDesc == AscDescEnum.Descending && resultSetComputedLinearData.IsDescending && resultsetLastValues.LastSlope < 0 && resultsetLastValues.LastValueLowest)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }