public void Dispose() { if (config != null) { config.Dispose(); config = null; } if (inputData != null) { inputData.Dispose(); inputData = null; } if (sqlContext != null) { sqlContext.Dispose(); } if (logWriter != null) { logWriter.Dispose(); logWriter = null; } if (outputTextWriter != null) { outputTextWriter.Dispose(); outputTextWriter = null; } }
public void RobotInputLocationOutsideFieldRaisesException() { string inputData = "5 3\n" + "10 1 E\n" + "RFRFRFRF\n"; InputDataHelper dataHelper = new InputDataHelper(new CommandCenter()); Exception ex = Assert.Throws <ValidationException>(() => dataHelper.ProcessInputData(inputData)); Assert.Equal("Error. Robot input location (10 1) is outside field bounds (5 3).", ex.Message); }
public void WrongRobotCommandsFormatRaisesException() { string inputData = "5 3\n" + "1 1 E\n" + "RFRFRFRF\n" + "3 2 N\n" + "FRRFLLFFR786qRFLL\n" + "0 3 W\n" + "LLFFFLFLFL"; InputDataHelper dataHelper = new InputDataHelper(new CommandCenter()); Exception ex = Assert.Throws <ValidationException>(() => dataHelper.ProcessInputData(inputData)); Assert.Equal("Wrong command instructions format: \"FRRFLLFFR786qRFLL\".\n Only L, R, F commands allowed!", ex.Message); }
public void WrongLocationParamsFormatRaisesException() { string inputData = "5 3\n" + "1 1 5\n" + "RFRFRFRF\n" + "3 2 N\n" + "FRRFLLFFRRFLL\n" + "0 3 W\n" + "LLFFFLFLFL"; InputDataHelper dataHelper = new InputDataHelper(new CommandCenter()); Exception ex = Assert.Throws <ValidationException>(() => dataHelper.ProcessInputData(inputData)); Assert.Equal("Wrong format of robot location parameters string: \"1 1 5\".\n Correct format: \"3 2 N\"", ex.Message); }
public void WrongFieldParamsFormatRaisesException() { string inputData = "5 N\n" + "1 1 E\n" + "RFRFRFRF\n" + "3 2 N\n" + "FRRFLLFFRRFLL\n" + "0 3 W\n" + "LLFFFLFLFL"; InputDataHelper dataHelper = new InputDataHelper(new CommandCenter()); Exception ex = Assert.Throws <ValidationException>(() => dataHelper.ProcessInputData(inputData)); Assert.Equal("Wrong format of field parameters string: \"5 N\".\n Example: \"5 3\"", ex.Message); }
public void BigValuesOfFieldParametersRaisesException() { string inputData = "50 51\n" + "1 1 E\n" + "RFRFRFRF\n" + "3 2 N\n" + "FRRFLLFFRRFLL\n" + "0 3 W\n" + "LLFFFLFLFL"; InputDataHelper dataHelper = new InputDataHelper(new CommandCenter()); Exception ex = Assert.Throws <ValidationException>(() => dataHelper.ProcessInputData(inputData)); Assert.Equal("Field width (50) or height (51) cannot be more than 50", ex.Message); }
public void LongStringInputRaisesException() { string inputData = "5 3\n" + "1 1 E\n" + "RFRFRFRF\n" + "3 2 N\n" + "FRRFLLFFRRFLLFRRFLLFFRRFLLFRRFLLFFRRFLLFRRFLLFFRRFLLFRRFLLFFRRFLLFRRFLLFFRRFLLFRRFLLFFRRFLLFRRFLLFFRRFLL\n" + "0 3 W\n" + "LLFFFLFLFL"; InputDataHelper dataHelper = new InputDataHelper(new CommandCenter()); Exception ex = Assert.Throws <ValidationException>(() => dataHelper.ProcessInputData(inputData)); Assert.Equal("Input data string lenght must be less that 100", ex.Message); }
public void Evaluate(out OutAttrubute outputAttribute) { outputAttribute = new OutAttrubute(); try { outputAttribute.add("log", logFileName); sqlContext = new SQLContext(logWriter.Write); config = new ConfigHelper(inputParameter.ConfigExcelFilePath, logWriter.Write); config.Initilize(); inputData = new InputDataHelper(inputParameter.InputExcelFilePath, logWriter.Write); Dictionary <string, DataTable> baseData = inputData.GetBaseData(config.GetBaseDataObjectNames()); config.SetBaseDataObjectContext(baseData); config.ValidateBaseDataObjects(); //insert data in sql config.EvaluateComputedDataObjects(sqlContext); //validate computed data types config.ValidateComputedDataObjects(); var outputfile = Path.Combine(inputParameter.LogFolder, prefix + inputParameter.OutputFileName); outputAttribute.add("csv", outputfile); outputTextWriter = new TextFileWriter(outputfile); logWriter.Write(outputfile); outputTextWriter.Write(OutputMeasure.CsvHeader); config.WriteMeasureOutput(outputTextWriter); } catch (Exception ex) { logWriter.Write(ex.Message); } }
public static PursuitGainCalculations CountCompoundSignalPursuitParameters(SpotGazeFileData fileData, FiltersConfig filterConfig) { var mncal = fileData.Spot.Min(); var mxcal = fileData.Spot.Max(); var amp = (mxcal - mncal) / 2; var srod = (mxcal + mncal) / 2; var start = fileData.Eye.FirstOrDefault(x => x == srod); var testValues = new List <double>(); var kspIndexes = new List <KeyValuePair <double, int> >(); var accuracyKspSpotValues = new List <KeyValuePair <double, double> >(); var accuracyKspDiffValues = new List <KeyValuePair <double, double> >(); double sinLongStart; double sinMidStart; double sinShortStart; double sinLongEnd; double sinMidEnd; double sinShortEnd; if (fileData.FileType == FileType.Maruniec) { // maruniec do zrobienia sinMidStart = 37 * Consts.TimeScaleFactorStandard; sinShortStart = 79 * Consts.TimeScaleFactorStandard; } else { sinLongStart = 12 * Consts.TimeScaleFactorStandard; sinLongEnd = 32 * Consts.TimeScaleFactorStandard; sinMidStart = 40 * Consts.TimeScaleFactorStandard; sinMidEnd = 68 * Consts.TimeScaleFactorStandard; sinShortStart = 77 * Consts.TimeScaleFactorStandard; sinShortEnd = 90 * Consts.TimeScaleFactorStandard; } var unifiedTimeStamps = InputDataHelper.GetTimeStampsScaled(fileData.Time, fileData.FileType); for (int i = 0; i < fileData.Spot.Length; i++) { var xSpot = fileData.Spot[i]; var sinLenght = 240D; if (unifiedTimeStamps[i] >= sinMidStart && unifiedTimeStamps[i] <= sinShortStart) { sinLenght = 120D; } else if (unifiedTimeStamps[i] >= sinShortStart) { sinLenght = 30D; } if (Math.Abs(xSpot - srod) > amp * 0.995D) { kspIndexes.Add(new KeyValuePair <double, int>(sinLenght, i)); //Accuracy var xEye = fileData.Eye[i]; var diffVal = Math.Abs(xEye - xSpot); accuracyKspDiffValues.Add(new KeyValuePair <double, double>(sinLenght, diffVal)); accuracyKspSpotValues.Add(new KeyValuePair <double, double>(sinLenght, Math.Abs(xSpot))); } } var kspEyeValues = new List <double>(); var kspSpotValues = new List <double>(); var results = new List <KeyValuePair <double, double> >(); var isPositive = true; var times = new List <double>(); var filteredControlWindows = new List <Dictionary <double, double> >(); var kspDiffValues = new List <Dictionary <double, double> >(); for (int j = 0; j < kspIndexes.Count; j++) { var sinLenght = kspIndexes[j].Key; var index = kspIndexes[j].Value; var time = InputDataHelper.GetScaledTimeFromIndex(fileData, index).GetValueOrDefault(); times.Add(time); var controlWindow = new List <double>(); var controlTimeDeltas = new List <double>(); var controlWindowLength = Convert.ToInt32(Math.Round(sinLenght / 5, 0)); if (j > 0) { controlWindow = fileData.Eye.Skip(index - (controlWindowLength / 2)).Take(controlWindowLength).ToList(); controlTimeDeltas = fileData.TimeDeltas.Skip(index - (controlWindowLength / 2)).Take(controlWindowLength).ToList(); } else { controlWindow = fileData.Eye.Skip(index).Take(controlWindowLength).ToList(); controlTimeDeltas = fileData.TimeDeltas.Skip(index).Take(controlWindowLength).ToList(); } if (filterConfig.FilterByButterworth) { controlWindow = FilterController.FilterByButterworth(filterConfig, controlWindow.ToArray()).ToList(); } var filteredWindowItems = new Dictionary <double, double>(); for (int g = 0; g < controlWindow.Count(); g++) { filteredWindowItems.Add(controlTimeDeltas[g], controlWindow[g]); } filteredControlWindows.Add(filteredWindowItems); double eyeValue; if (isPositive) { eyeValue = controlWindow.Average(); //Max(); isPositive = false; } else { eyeValue = controlWindow.Average(); //Min(); isPositive = true; } if (sinLenght == 30D) { testValues.Add(eyeValue); } //var eyeValue = fileData.Eye[index]; var spotValue = fileData.Spot[index]; var result = eyeValue / spotValue; results.Add(new KeyValuePair <double, double>(sinLenght, result)); } var longSinGain = new double?(); if (results.Where(x => x.Key == 240D).Count() > 0) { longSinGain = results.Where(x => x.Key == 240D).Select(x => x.Value).Average(); } var midSinGain = new double?(); if (results.Where(x => x.Key == 120D).Select(x => x.Value).Count() > 0) { midSinGain = results.Where(x => x.Key == 120D).Select(x => x.Value).Average(); } var shortSinGain = new double?(); if (results.Where(x => x.Key == 30D).Select(x => x.Value).Count() > 0) { shortSinGain = results.Where(x => x.Key == 30D).Select(x => x.Value).Average(); } var gainCalculations = new Dictionary <string, double?>(); if (longSinGain.HasValue) { gainCalculations.Add("Long", longSinGain.GetValueOrDefault()); } else { gainCalculations.Add("Long", null); } if (midSinGain.HasValue) { gainCalculations.Add("Mid", midSinGain.GetValueOrDefault()); } else { gainCalculations.Add("Mid", null); } if (shortSinGain.HasValue) { gainCalculations.Add("Short", shortSinGain.GetValueOrDefault()); } else { gainCalculations.Add("Short", null); } var longSinAcc = new double?(); if (accuracyKspDiffValues.Where(x => x.Key == 240D).Count() > 0 && accuracyKspSpotValues.Where(x => x.Key == 240D).Count() > 0) { var longSinW1 = accuracyKspDiffValues.Where(x => x.Key == 240D).Select(x => x.Value).Sum(); var longSinW2 = accuracyKspSpotValues.Where(x => x.Key == 240D).Select(x => x.Value).Sum(); longSinAcc = 1D - (longSinW1 / longSinW2); } var midSinAcc = new double?(); if (accuracyKspDiffValues.Where(x => x.Key == 120D).Count() > 0 && accuracyKspDiffValues.Where(x => x.Key == 120D).Count() > 0) { var midSinW1 = accuracyKspDiffValues.Where(x => x.Key == 120D).Select(x => x.Value).Sum(); var midSinW2 = accuracyKspSpotValues.Where(x => x.Key == 120D).Select(x => x.Value).Sum(); midSinAcc = 1D - (midSinW1 / midSinW2); } var shortSinAcc = new double?(); if (accuracyKspDiffValues.Where(x => x.Key == 30D).Count() > 0 && accuracyKspDiffValues.Where(x => x.Key == 30D).Count() > 0) { var shortSinW1 = accuracyKspDiffValues.Where(x => x.Key == 30D).Select(x => x.Value).Sum(); var shortSinW2 = accuracyKspSpotValues.Where(x => x.Key == 30D).Select(x => x.Value).Sum(); shortSinAcc = 1D - (shortSinW1 / shortSinW2); } else { shortSinAcc = null; } var accuracyCalculations = new Dictionary <string, double?>(); accuracyCalculations.Add("Long", longSinAcc); accuracyCalculations.Add("Mid", midSinAcc); accuracyCalculations.Add("Short", shortSinAcc); return(new PursuitGainCalculations { Gains = gainCalculations, Accuracies = accuracyCalculations, FilteredControlWindows = filteredControlWindows }); }