static void Main(string[] args) { List <Generator> generators = new List <Generator>(); Random random = new Random(); for (int i = 0; i < GeneratorsQuantity; i++) { int randomInt = random.Next(MaxValue); generators.Add(delegate() { return(randomInt); }); } Averager averager = delegate(List <Generator> generatorsList) { if (generatorsList.Count == 0) { return(0); } int sum = 0; foreach (Generator generator in generatorsList) { sum += generator(); } return(sum / generatorsList.Count); }; Console.WriteLine(averager(generators)); Console.ReadKey(); }
public Line(LinePlotterWin _root, int _len, int __intMax, Color _col) { root = _root; data = new double[_len]; len = _len; inbuf = new double[32]; color = _col; drawPen = new Pen(color); _scale = 1.0; _offset = 0.0; _on = true; _acIn = false; _acOut = false; acOutOfs = 0; _intMax = __intMax; useScreen = 0; valMax = 0.0; valMaxPos = 0; valMin = 0.0; valMinPos = 0; _averager = new Averager(root.linePlotter.owner.sampleRate, __intMax, averagerCallback); averagers = Averager.getList(); newdata = false; }
public void Dispose() { Lines.Clear(); TimeLines.Values.ToList().ForEach(line => line.Dispose()); TimeLines.Clear(); Averager.Dispose(); LineMaker.Dispose(); }
public void ClearLines() { TimeLines.Values.ToList().ForEach(line => line.Clear()); TimeLines.Clear(); Averager.Clear(); LineMaker.Clear(); Lines.Clear(); }
public void TestGetPointByDistanceSimple3() { var pth = new List <List <Point> >(); var p = new List <Point>(); p.Add(new Point(-2, 4)); p.Add(new Point(0, 0)); pth.Add(p); Averager averager = new Averager(); averager.Init(pth); var testPath = averager.LinearPaths[0][0]; var result = testPath.GetPointByDistance(2.23606797749979); Assert.AreEqual(Math.Round(result.X, 1), -1); Assert.AreEqual(Math.Round(result.Y, 1), 2); }
private void buttonSelectFiles_Click(object sender, EventArgs e) { OpenFileDialog of = new OpenFileDialog(); of.InitialDirectory = Directory; of.Multiselect = true; if (of.ShowDialog(this) == DialogResult.OK) { if (of.FileNames.Length == 0) { return; } Directory = Path.GetDirectoryName(of.FileNames[0]); Averager.ProcessRanges(of.FileNames.ToList()); MessageBox.Show("Обработка завершена!"); } of.Dispose(); }
public void TestGetPointByDistanceSimple() { var pth = new List <List <Point> >(); var p = new List <Point>(); p.Add(new Point(0, 0)); p.Add(new Point(-2, -2)); pth.Add(p); Averager averager = new Averager(); averager.Init(pth); var testPath = averager.LinearPaths[0][0]; var result = testPath.GetPointByDistance(1.414213562373095); Assert.AreEqual(Math.Round(result.X, 1), -1.0); Assert.AreEqual(Math.Round(result.Y, 1), -1.0); }
public void TestInit() { var pth = new List <List <Point> >(); var p = new List <Point>(); p.Add(new Point(0, 0)); p.Add(new Point(3, 1)); pth.Add(p); p = new List <Point>(); p.Add(new Point(0, 0)); p.Add(new Point(1, 3)); pth.Add(p); Averager averager = new Averager(); averager.Init(pth); Assert.AreEqual(Math.Round(averager.LinearPaths[0][0].K, 2), 0.33); }
public void TestGetPointByDistanceSuperSimple() { var pth = new List <List <Point> >(); var p = new List <Point>(); p.Add(new Point(0, 0)); p.Add(new Point(2, 0)); pth.Add(p); Averager averager = new Averager(); averager.Init(pth); var testPath = averager.LinearPaths[0][0]; var result = testPath.GetPointByDistance(1); Assert.AreEqual(result.X, 1); Assert.AreEqual(result.Y, 0); }
public void TestGridPath() { var pth = new List <List <Point> >(); var p = new List <Point>(); p.Add(new Point(0, 0)); p.Add(new Point(4, 0)); pth.Add(p); Averager averager = new Averager(); averager.Init(pth); averager.Accuracy = 4; var testPath = averager.LinearPaths[0]; var result = averager.GridPath(testPath); Assert.AreEqual(result.Count, 4); }
/// <summary> /// Resizes the window size for gathering latency statistics. /// </summary> /// <param name="windowSize">Size of the sliding time window. Larger values consider more data points in the computations. This value cannot be zero.</param> /// <param name="granularity">The granularity used in average computations, the smaller this value, the less stable the average. This parameter must be less than 1/2 of the windowSize.</param> /// <exception cref="ArgumentOutOfRangeException">Thrown if windowSize or granularity are out of range.</exception> /// <remarks>Calling Resize() will reset any previously accumulated statistics.</remarks> public void Resize(TimeSpan windowSize, TimeSpan granularity) { if (windowSize.Ticks == 0) { throw new ArgumentOutOfRangeException("windowSize", "Window size cannot be zero."); } if (granularity.Ticks > windowSize.Ticks / 2) { throw new ArgumentOutOfRangeException("granularity", "granularity must be at most 1/2 the window size."); } _windowSize = windowSize; _granularity = granularity; _averagers = new Averager[_windowSize.Ticks / _granularity.Ticks]; for (var i = 0; i < _averagers.Length; ++i) { _averagers[i] = new Averager(); } Reset(); }
public void TestMassiveGetPointByDistanceSimple2() { var pth = new List <List <Point> >(); var p = new List <Point>(); p.Add(new Point(2, -4)); p.Add(new Point(0, 0)); p.Add(new Point(2, 4)); pth.Add(p); Averager averager = new Averager(); averager.Init(pth); var testPath = averager.LinearPaths[0]; var result = averager.GetPointByDistance(testPath, 8.944271909999159); Assert.AreEqual(Math.Round(result.X, 1), 2); Assert.AreEqual(Math.Round(result.Y, 1), 4); }
public void GetOutliers() { var averager = new Averager(); averager.Record("a", 1); averager.Record("a", 2); averager.Record("a", 3); averager.Record("a", 2); averager.Record("b", 5); averager.Record("b", 4); averager.Record("b", 5); averager.Record("b", 3); averager.Record("a", 8); var outlier = averager.GetOutliers(3).Single(); Assert.AreEqual("a", outlier.Name); Assert.AreEqual(8d, outlier.LastValue); }
public void TestGetAveragePath() { var pth = new List <List <Point> >(); var p = new List <Point>(); p.Add(new Point(0, 0)); p.Add(new Point(4, 0)); pth.Add(p); var p2 = new List <Point>(); p2.Add(new Point(0, 0)); p2.Add(new Point(0, 4)); pth.Add(p2); Averager averager = new Averager(); averager.Accuracy = 4; var result = averager.GetAveragePath(pth); //Assert.AreEqual(result.Count, 4); }
public void TestMassiveGetPointByDistanceSimple() { // тестовая фигура выглядит так: / // ___/ var pth = new List <List <Point> >(); var p = new List <Point>(); p.Add(new Point(-4, 0)); p.Add(new Point(0, 0)); p.Add(new Point(2, 4)); pth.Add(p); Averager averager = new Averager(); averager.Init(pth); var testPath = averager.LinearPaths[0]; var result = averager.GetPointByDistance(testPath, 4); Assert.AreEqual(Math.Round(result.X, 1), 0); Assert.AreEqual(Math.Round(result.Y, 1), 0); }
public void Subtract(Averager averager) { _sum -= averager._sum; _count -= averager._count; }
public void Add(KeyValuePair <DateTime, decimal> pair) { Averager.Add(pair.Value); TimeLines.Values.ToList().ForEach(line => line.Add(pair)); LineMaker.Add(new KeyValuePair <DateTime, decimal>(pair.Key, Averager.Average)); }