public ComputedResultSetFitLine ComputeLinearData(List <DeviceValue> dataPoints) { var resultSet = new ComputedResultSetFitLine(); double[] xdata = CreateXDataFromDateTimeToTotalSeconds(dataPoints); double[] ydata = CreateYDataFromDoubleValues(dataPoints); Tuple <double, double> p = Fit.Line(xdata, ydata); double intercept = p.Item1; // == 10; intercept -- No clue what this is double slope = p.Item2; // == 0.5; slope resultSet.Slope = slope; resultSet.Intercept = intercept; if (slope > 0) { resultSet.IsAscending = true; } if (slope < 0) { resultSet.IsDescending = true; } return(resultSet); }
private bool CheckResultData(AscDescEnum ascDesc, ComputedResultSetFitLine resultSetComputedLinearData) { if (ascDesc == AscDescEnum.Descending && resultSetComputedLinearData.IsDescending) { return(true); } if (ascDesc == AscDescEnum.Ascending && resultSetComputedLinearData.IsAscending) { return(true); } return(false); }
private ResultSetComputedFutureValue ComputeFutureValues(List <DeviceValue> dataPoints, AscDescEnum ascDesc, ComputedResultSetFitLine resultSetComputedLinearData, double threshold, TimeSpan timeToReachThreshold) { var resultSet = new ResultSetComputedFutureValue(); var lastValue = dataPoints.LastOrDefault(); if (lastValue != null) { var totalNumberOfSecondsInTimeSpan = timeToReachThreshold.TotalSeconds; var futureValueAtEndOfTimeSpan = totalNumberOfSecondsInTimeSpan * resultSetComputedLinearData.Slope; _logging.LogDebug($"Result of future computation. With slope {resultSetComputedLinearData.Slope} for {totalNumberOfSecondsInTimeSpan} seconds computed value is {futureValueAtEndOfTimeSpan} (threshold:{threshold})"); resultSet.FutureValueAtEndOfTimeSpan = futureValueAtEndOfTimeSpan; if (ascDesc == AscDescEnum.Ascending && futureValueAtEndOfTimeSpan >= threshold) { resultSet.TriggerTrue = true; } if (ascDesc == AscDescEnum.Descending && futureValueAtEndOfTimeSpan <= threshold) { resultSet.TriggerTrue = true; } } return(resultSet); }