public NNResultsVisual(double width, double height, Tuple<Point, double, bool>[] values, bool shouldOutlineNonMatches)
            {
                #region Min/Max Value, Colors

                bool hasNegative = values.Any(o => o.Item2 < 0);
                double maxValue = Math.Max(Math.Abs(values.Min(o => o.Item2)), Math.Abs(values.Max(o => o.Item2)));
                if (maxValue < 1d)      // should never be greater, but leave alone if it is
                {
                    maxValue = 1d;
                }

                Color positiveColor = hasNegative ? Colors.Blue : Colors.Black;
                Color negativeColor = Colors.Red;

                #endregion
                #region XY Scale

                double radius = ((width + height) / 2) / 100;

                bool hasNegativePosition = values.Any(o => o.Item1.X < 0 || o.Item1.Y < 0);
                double maxX = Math.Max(Math.Abs(values.Min(o => o.Item1.X)), Math.Abs(values.Max(o => o.Item1.X)));
                double maxY = Math.Max(Math.Abs(values.Min(o => o.Item1.Y)), Math.Abs(values.Max(o => o.Item1.Y)));

                // If they are somewhat near 1, then cap at 1
                if (maxX > .5 && maxX < 1) maxX = 1;
                if (maxY > .5 && maxY < 1) maxY = 1;

                double offsetX = hasNegativePosition ? (width / 2) : 0;
                double offsetY = hasNegativePosition ? (height / 2) : 0;

                double scaleX = maxX > 0d ? (width - offsetX) / maxX : 1;
                double scaleY = maxY > 0d ? (height - offsetY) / maxY : 1;

                #endregion

                Pen matchPen = new Pen(Brushes.Lime, radius * .32);
                Pen otherPen = shouldOutlineNonMatches ? new Pen(new SolidColorBrush(Color.FromArgb(192, 192, 192, 192)), radius * .18) : null;

                _visual = new DrawingVisual();
                using (DrawingContext dc = _visual.RenderOpen())
                {
                    foreach (var value in values)
                    {
                        Color color = value.Item2 < 0 ? negativeColor : positiveColor;
                        double alpha = Math.Abs(value.Item2) / maxValue;
                        Color finalColor = Color.FromArgb(Convert.ToByte(alpha * 255), color.R, color.G, color.B);

                        Point point = new Point(offsetX + (value.Item1.X * scaleX), offsetY + (value.Item1.Y * scaleY));

                        Pen pen = value.Item3 ? matchPen : otherPen;

                        dc.DrawEllipse(new SolidColorBrush(finalColor), pen, point, radius, radius);
                    }
                }
            }
Beispiel #2
0
 public void ShortMinOnTwoTuple()
 {
     var sut = new Tuple<short, short>(1, 2);
       short expected = sut.AsEnumerable().Cast<short>().Min();
       short actual = sut.Min(x => (short) x);
       Assert.AreEqual(expected, actual);
 }
 public void IntegerMinOnTwoTuple()
 {
     var sut = new Tuple<int, int>(1, 2);
       int expected = sut.AsEnumerable().Cast<int>().Min();
       int actual = sut.Min(x => (int) x);
       Assert.AreEqual(expected, actual);
 }
 public void DecimalMinOnTwoTuple()
 {
     var sut = new Tuple<decimal, decimal>(1, 2);
       decimal expected = sut.AsEnumerable().Cast<decimal>().Min();
       decimal actual = sut.Min(x => (decimal) x);
       Assert.AreEqual(expected, actual);
 }
 public void DoubleMinOnTwoTuple()
 {
     var sut = new Tuple<double, double>(1, 2);
       double expected = sut.AsEnumerable().Cast<double>().Min();
       double actual = sut.Min(x => (double) x);
       Assert.AreEqual(expected, actual);
 }
Beispiel #6
0
 public void LongMinOnTwoTuple()
 {
     var sut = new Tuple<long, long>(1, 2);
       long expected = sut.AsEnumerable().Cast<long>().Min();
       long actual = sut.Min(x => (long) x);
       Assert.AreEqual(expected, actual);
 }
Beispiel #7
0
        public void ShortMinOnOneTuple()
        {
            var   sut      = new Tuple <short>(1);
            short expected = sut.AsEnumerable().Cast <short>().Min();
            short actual   = sut.Min(x => (short)x);

            Assert.AreEqual(expected, actual);
        }
Beispiel #8
0
        public void IntegerMinOnOneTuple()
        {
            var sut      = new Tuple <int>(1);
            int expected = sut.AsEnumerable().Cast <int>().Min();
            int actual   = sut.Min(x => (int)x);

            Assert.AreEqual(expected, actual);
        }
Beispiel #9
0
        public void DoubleMinOnOneTuple()
        {
            var    sut      = new Tuple <double>(1);
            double expected = sut.AsEnumerable().Cast <double>().Min();
            double actual   = sut.Min(x => (double)x);

            Assert.AreEqual(expected, actual);
        }
Beispiel #10
0
        public void LongMinOnOneTuple()
        {
            var  sut      = new Tuple <long>(1);
            long expected = sut.AsEnumerable().Cast <long>().Min();
            long actual   = sut.Min(x => (long)x);

            Assert.AreEqual(expected, actual);
        }
Beispiel #11
0
        public void DecimalMinOnOneTuple()
        {
            var     sut      = new Tuple <decimal>(1);
            decimal expected = sut.AsEnumerable().Cast <decimal>().Min();
            decimal actual   = sut.Min(x => (decimal)x);

            Assert.AreEqual(expected, actual);
        }
Beispiel #12
0
    static long Solve()
    {
        int n = int.Parse(Console.ReadLine());

        Tuple <long, long>[] cost = new Tuple <long, long>[]
        {
            new Tuple <long, long>(-1, 0),
            new Tuple <long, long>(-1, 0),
            new Tuple <long, long>(-1, 0)
        };
        for (int i = 0; i < n; i++)
        {
            var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Tuple <long, long>[] newcost = new Tuple <long, long> [3];
            for (int j = 0; j < 3; j++)
            {
                newcost[j] = new Tuple <long, long>(ab[0] + j, cost.Where(x => x.Item1 != ab[0] + j).Min(x => x.Item2) + ab[1] * j);
            }
            cost = newcost;
        }
        return(cost.Min(x => x.Item2));
    }
Beispiel #13
0
        internal static void Run()
        {
            if (string.IsNullOrEmpty(Endpoints))
            {
                throw new ArgumentException("FhirEndpoints value is empty");
            }

            endpoints = Endpoints.Split(";", StringSplitOptions.RemoveEmptyEntries).ToList();

            var globalPrefix = $"RequestedBlobRange=[{NumberOfBlobsToSkip + 1}-{MaxBlobIndexForImport}]";

            Console.WriteLine($"{globalPrefix}: Starting...");
            var blobContainerClient = GetContainer(ConnectionString, ContainerName);
            var blobs = blobContainerClient.GetBlobs().OrderBy(_ => _.Name).Where(_ => _.Name.EndsWith(".ndjson", StringComparison.OrdinalIgnoreCase)).ToList();

            Console.WriteLine($"Found ndjson blobs={blobs.Count} in {ContainerName}.");
            var take = MaxBlobIndexForImport == 0 ? blobs.Count : MaxBlobIndexForImport - NumberOfBlobsToSkip;

            blobs = blobs.Skip(NumberOfBlobsToSkip).Take(take).ToList();
            var swWrites          = Stopwatch.StartNew();
            var swReport          = Stopwatch.StartNew();
            var currentBlobRanges = new Tuple <int, int> [ReadThreads];

            BatchExtensions.ExecuteInParallelBatches(blobs, ReadThreads, BlobRangeSize, (reader, blobRangeInt) =>
            {
                var localSw               = Stopwatch.StartNew();
                var writes                = 0L;
                var blobRangeIndex        = blobRangeInt.Item1;
                var blobsInt              = blobRangeInt.Item2;
                var firstBlob             = NumberOfBlobsToSkip + (blobRangeIndex * BlobRangeSize) + 1;
                var lastBlob              = NumberOfBlobsToSkip + (blobRangeIndex * BlobRangeSize) + blobsInt.Count;
                currentBlobRanges[reader] = Tuple.Create(firstBlob, lastBlob);
                var prefix                = $"Reader={reader}.BlobRange=[{firstBlob}-{lastBlob}]";
                var incrementor           = new IndexIncrementor(endpoints.Count);
                Console.WriteLine($"{prefix}: Starting...");

                // 100 below is a compromise between processing with maximum available threads (value 1) and inefficiency in wrapping single resource in a list.
                BatchExtensions.ExecuteInParallelBatches(GetLinesInBlobRange(blobsInt, prefix), WriteThreads / ReadThreads, 100, (thread, lineBatch) =>
                {
                    Interlocked.Increment(ref writers);
                    foreach (var line in lineBatch.Item2)
                    {
                        Interlocked.Increment(ref totalWrites);
                        Interlocked.Increment(ref writes);
                        PutResource(line, incrementor);
                        if (swReport.Elapsed.TotalSeconds > ReportingPeriodSec)
                        {
                            lock (swReport)
                            {
                                if (swReport.Elapsed.TotalSeconds > ReportingPeriodSec)
                                {
                                    var currWrites = Interlocked.Read(ref totalWrites);
                                    var currReads  = Interlocked.Read(ref totalReads);
                                    var minBlob    = currentBlobRanges.Min(_ => _.Item1);
                                    var maxBlob    = currentBlobRanges.Max(_ => _.Item2);
                                    Console.WriteLine($"{globalPrefix}.WorkingBlobRange=[{minBlob}-{maxBlob}].Readers=[{Interlocked.Read(ref readers)}/{ReadThreads}].Writers=[{Interlocked.Read(ref writers)}].EndPointCalls=[{Interlocked.Read(ref epCalls)}].Waits=[{Interlocked.Read(ref waits)}]: reads={currReads} writes={currWrites} secs={(int)swWrites.Elapsed.TotalSeconds} read-speed={(int)(currReads / swReads.Elapsed.TotalSeconds)} lines/sec write-speed={(int)(currWrites / swWrites.Elapsed.TotalSeconds)} res/sec");
                                    swReport.Restart();
                                }
                            }
                        }
                    }

                    Interlocked.Decrement(ref writers);
                });
                Console.WriteLine($"{prefix}: Completed writes. Total={writes} secs={(int)localSw.Elapsed.TotalSeconds} speed={(int)(writes / localSw.Elapsed.TotalSeconds)} res/sec");
            });
            Console.WriteLine($"{globalPrefix}.Readers=[{readers}/{ReadThreads}].Writers=[{writers}].EndPointCalls=[{epCalls}].Waits=[{waits}]: total reads={totalReads} total writes={totalWrites} secs={(int)swWrites.Elapsed.TotalSeconds} read-speed={(int)(totalReads / swReads.Elapsed.TotalSeconds)} lines/sec write-speed={(int)(totalWrites / swWrites.Elapsed.TotalSeconds)} res/sec");
        }