/// <summary> /// Create and AggregateCalculator for a ReadProcessed service call. /// </summary> /// <param name="filter"></param> /// <param name="steppedVariable"></param> /// <returns></returns> public static AggregateCalculatorImpl CreateAggregator(NewAggregateFilter filter, bool steppedVariable) { AggregatorFactory aci = null; if (Lookup.TryGetValue(filter.AggregateType, out aci)) { AggregateCalculatorImpl retval = aci(); retval.StartTime = filter.StartTime; retval.EndTime = filter.EndTime; retval.ProcessingInterval = filter.ProcessingInterval; retval.Configuration = filter.AggregateConfiguration; retval.SteppedVariable = steppedVariable; return(retval); } return(null); }
void RunTest(AggregateType aggregate) { try { AggregateTestResultSet myResults = AggregateTestResultSet.LoadFromXMLFile( String.Format(@"{0}TestResult.xml", Enum.GetName(typeof(AggregateType), aggregate))); for (int i = 0; i < myResults.Count; i++) { AggregateTestResult testResult = myResults[i] as AggregateTestResult; Debug.WriteLine(String.Format("Test Data: {0}", testResult.TestDataName)); Debug.WriteLine(String.Format("Start time: {0}\tEnd time: {1}\tInterval: {2}", testResult.Details.StartTime.TimeOfDay, testResult.Details.EndTime.TimeOfDay, testResult.Details.ProcessingInterval)); // get expected values List<DataValue> expected = new List<DataValue>(testResult.DataValues.Count); for (int ii = 0; ii < testResult.DataValues.Count; ii++) expected.Add(testResult.DataValues[ii].GetDataValue()); // configure the aggregate calculator NewAggregateFilter filter = new NewAggregateFilter() { StartTime = testResult.Details.StartTime, EndTime = testResult.Details.EndTime, AggregateType = AggregateLookup[aggregate], AggregateConfiguration = TestData[myResults[i].TestDataName].Configuration.AggregateConfiguration, ProcessingInterval = testResult.Details.ProcessingInterval }; TestData testData = TestData[testResult.TestDataName]; AggregateCalculatorImpl calculator = Aggregators.CreateAggregator(filter, testData.Configuration.Stepped); /* calculator.Configuration = new AggregateConfiguration() { PercentDataBad = 0, PercentDataGood = 100, SteppedSlopedExtrapolation = false, TreatUncertainAsBad = true }; */ HistoryData rawHistoryData = new HistoryData(); for (int ii = 0; ii < testData.DataValues.Count; ii++) { DataValue dv = testData.DataValues[ii].GetDataValue(); rawHistoryData.DataValues.Add(dv); } HistoryData historyData = new HistoryData(); var sr = new ServiceResult(StatusCodes.Good); foreach (DataValue raw in rawHistoryData.DataValues) { IList<DataValue> released = calculator.ProcessValue(raw, sr); if (StatusCode.IsGood(sr.StatusCode) && released.Count > 0) { historyData.DataValues.AddRange(released); } } var lsr = new ServiceResult(StatusCodes.Good); historyData.DataValues.AddRange(calculator.ProcessTermination(lsr)); // obtain the actual values List<DataValue> actual = new List<DataValue>(historyData.DataValues); // compare the two value sets bool assertion = true; HelperMethods.CompareResults(expected, actual, testResult.TestDataName, assertion); Console.WriteLine("Test {0} passed", i); } } catch (Exception ex) { Debug.WriteLine(ex.StackTrace); throw; } }
/// <summary> /// Create and AggregateCalculator for a ReadProcessed service call. /// </summary> /// <param name="filter"></param> /// <param name="steppedVariable"></param> /// <returns></returns> public static AggregateCalculatorImpl CreateAggregator(NewAggregateFilter filter, bool steppedVariable) { AggregatorFactory aci = null; if (Lookup.TryGetValue(filter.AggregateType, out aci)) { AggregateCalculatorImpl retval = aci(); retval.StartTime = filter.StartTime; retval.EndTime = filter.EndTime; retval.ProcessingInterval = filter.ProcessingInterval; retval.Configuration = filter.AggregateConfiguration; retval.SteppedVariable = steppedVariable; return retval; } return null; }