Beispiel #1
0
        public void DrawGoodArea()
        {
            if (RK.ST.result == null)
            {
                return;
            }
            SumResult sumResult = RK.ST.result.Sum;

            cbGoodBad.Checked = sumResult.RClass == EClass.Brak;
            cbGoodBad_CheckedChanged(null, null);
            cbGoodBad.Enabled = true;
            mp1.Clear();
            SumResult.PP pp = sumResult.MaxGood;
            if (pp == null)
            {
                return;
            }
            double pos = pp.index;

            pos *= K;
            mp1.Add(new DataPoint(pos, 1.2));
            pos  = pp.index + pp.count;
            pos *= K;
            mp1.Add(new DataPoint(pos, 1.2));
        }
Beispiel #2
0
        protected override void OnUpdate()
        {
            //Create a native array to hold the intermediate sums
            int chunksInQuery = query.CalculateChunkCount();
            NativeArray <int> intermediateSums
                = new NativeArray <int>(chunksInQuery, Allocator.TempJob);

            //Schedule the first job to add all the buffer elements
            BuffersInChunks bufferJob = new BuffersInChunks();

            bufferJob.BufferType = GetArchetypeChunkBufferType <MyBufferElement>();
            bufferJob.sums       = intermediateSums;
            this.Dependency      = bufferJob.ScheduleParallel(query, this.Dependency);

            //Schedule the second job, which depends on the first
            SumResult finalSumJob = new SumResult();

            finalSumJob.sums = intermediateSums;
            NativeArray <int> finalSum = new NativeArray <int>(1, Allocator.Temp);

            finalSumJob.result = finalSum;
            this.Dependency    = finalSumJob.Schedule(this.Dependency);

            this.CompleteDependency();
            Debug.Log("Sum of all buffers: " + finalSum[0]);
            finalSum.Dispose();
        }
Beispiel #3
0
        public static ListNode Run(ListNode l1, ListNode l2)
        {
            SumResult firstResult = Sum(l1, l2);

            ListNode sum  = new ListNode(firstResult.Digit);
            int      rest = firstResult.Rest;

            ListNode it1 = l1.next;
            ListNode it2 = l2.next;

            ListNode currentListNode = sum;

            while (it1 != null || it2 != null)
            {
                var currentSumResult = Sum(it1, it2, rest);

                rest = currentSumResult.Rest;
                currentListNode.next = new ListNode(currentSumResult.Digit);

                currentListNode = currentListNode.next;
                it1             = it1?.next;
                it2             = it2?.next;
            }

            if (rest != 0)
            {
                currentListNode.next = new ListNode(rest);
            }

            return(sum);
        }
        public async Task <IActionResult> GetSum()
        {
            try
            {
                SumResult sumResult = null;
                Task      t         = new Task(() =>
                {
                    sumResult = _randomPairsServiceProvider.GetSum();
                });

                t.Start();
                await t;

                if (sumResult != null)
                {
                    return(Ok(sumResult));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Beispiel #5
0
        private SumResult SumFollowUpRecursive(Node a, Node b)
        {
            SumResult resultRight = null;

            if (a.Next != null)
            {
                resultRight = SumFollowUpRecursive(a.Next, b.Next);
            }

            SumResult result = new SumResult();

            int val = a.X + b.X;

            if (resultRight != null)
            {
                val += resultRight.Carrier;
            }

            result.Carrier = val / 10;
            result.Node    = new Node(val % 10);

            if (resultRight != null)
            {
                result.Node.Next = resultRight.Node;
            }

            return(result);
        }
Beispiel #6
0
        public Node SumFollowUp(Node a, Node b)
        {
            int countA = Count(a);
            int countB = Count(b);

            if (countA > countB)
            {
                PadZeroLeft(b, countA - countB);
            }
            else
            {
                PadZeroLeft(a, countB - countA);
            }

            SumResult sumResult = SumFollowUpRecursive(a.Next, b.Next);

            Node result = Node.BuildSentinel();

            result.Next = sumResult.Node;

            if (sumResult.Carrier > 0)
            {
                Node first = result.Next;
                result.Next      = new Node(sumResult.Carrier);
                result.Next.Next = first;
            }

            return(result);
        }
Beispiel #7
0
 internal void Draw(SumResult _sumResult)
 {
     Clear();
     for (int i = 0; i < _sumResult.MClass.Count(); i++)
     {
         mp.Add(1).Color = Classer.GetColor(_sumResult.MClass[i]);
     }
 }
        public IActionResult Index([FromRoute] int firstNumber, [FromRoute] int secondNumber)
        {
            var result = new SumResult()
            {
                FirstNumber  = firstNumber,
                SecondNumber = secondNumber,
                Sum          = (firstNumber + secondNumber)
            };

            return(Ok(result));
        }
Beispiel #9
0
        internal void Draw()
        {
            SumResult sumResult = RK.ST.result.Sum;

            Clear();
            for (int i = 0; i < sumResult.MClass.Count(); i++)
            {
                double pos = i;
                pos *= K;
                pos += 0.5 * K;
                DataPoint p = new DataPoint(pos, 1);
                p.Color = Classer.GetColor(sumResult.MClass[i]);
                mp.Add(p);
            }
        }
Beispiel #10
0
        private string CalculateSum(string firstNum, string secondNum)
        {
            int       maxLength = firstNum.Length > secondNum.Length ? firstNum.Length : secondNum.Length;
            string    result    = "";
            SumResult sumResult = new SumResult();

            for (int i = 0; i < maxLength; i++)
            {
                char firstChar  = GetCharAt(firstNum, i);
                char secondChar = GetCharAt(secondNum, i);
                sumResult = SumChar(firstChar, secondChar, sumResult.Overflow);
                result   += sumResult.Ch;
            }
            return(FormatResult(result));
        }
        //Schedules the two jobs with a dependency between them
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            //Create a native array to hold the intermediate sums
            int entitiesInQuery = query.CalculateEntityCount();
            NativeArray <int> intermediateSums
                = new NativeArray <int>(entitiesInQuery, Allocator.TempJob);

            //Schedule the first job to add all the buffer elements
            BuffersByEntity bufferJob = new BuffersByEntity();

            bufferJob.sums = intermediateSums;
            JobHandle intermediateJob = bufferJob.Schedule(this, inputDeps);

            //Schedule the second job, which depends on the first
            SumResult finalSumJob = new SumResult();

            finalSumJob.sums = intermediateSums;
            return(finalSumJob.Schedule(intermediateJob));
        }
Beispiel #12
0
        /*
         * PUBLIC METHODS
         */

        // Calculate the sum of the 10 oldest numbers that haven't summed yet.
        // If not enough 10 numbers, calculate whatever available and return.
        public SumResult GetSum()
        {
            int       sum       = 0;
            SumResult sumResult = null;

            try
            {
                lock (_pairsListLock)
                {
                    if (RandomPairsList != null)
                    {
                        int count = 0;
                        for (int i = 0; i < RandomPairsList.Count && count < SUM_AMOUNT; i++)
                        {
                            if (RandomPairsList[i].TTL > 0 && !RandomPairsList[i].IsSummed)
                            {
                                RandomPairsList[i].IsSummed = true;
                                sum += RandomPairsList[i].Value;
                                count++;
                            }
                        }
                    }
                }

                // If the sum is actually calculated
                if (sum > 0)
                {
                    int sumCount = InsertSumValueAscending(sum);
                    sumResult = new SumResult()
                    {
                        NewSumValue = sum,
                        SumCount    = sumCount
                    };
                }
            }
            catch (Exception ex)
            {
                // TODO: log error
            }

            return(sumResult);
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            //Create a native array to hold the intermediate sums
            int chunksInQuery = query.CalculateChunkCount();
            NativeArray <int> intermediateSums
                = new NativeArray <int>(chunksInQuery, Allocator.TempJob);

            //Schedule the first job to add all the buffer elements
            BuffersInChunks bufferJob = new BuffersInChunks();

            bufferJob.BufferType = GetArchetypeChunkBufferType <MyBufferElement>();
            bufferJob.sums       = intermediateSums;
            JobHandle intermediateJob = bufferJob.Schedule(query, inputDeps);

            //Schedule the second job, which depends on the first
            SumResult finalSumJob = new SumResult();

            finalSumJob.sums = intermediateSums;
            return(finalSumJob.Schedule(intermediateJob));
        }
Beispiel #14
0
        internal void Draw()
        {
            Clear();
            if (RK.ST.result == null)
            {
                return;
            }
            uTube.Value = RK.ST.result.IdTube.ToString();
            SumResult sumResult = RK.ST.result.Sum;

            for (int i = 0; i < sumResult.MClass.Count(); i++)
            {
                double pos = i;
                pos *= K;
                pos += 0.5 * K;
                DataPoint p = new DataPoint(pos, 1);
                p.Color = Classer.GetColor(sumResult.MClass[i]);
                mp.Add(p);
            }
            uSelectResult1.RClass = sumResult.RClass;
            //uSelectResult1.Enabled = true;
        }
Beispiel #15
0
        public void DrawGoodArea()
        {
            if (RK.ST.result == null)
            {
                return;
            }
            SumResult sumResult = RK.ST.result.Sum;

            uSelectResult1.Enabled = true;
            uSelectResult1.RClass  = sumResult.RClass;
            mp1.Clear();
            SumResult.PP pp = sumResult.MaxGood;
            if (pp == null)
            {
                return;
            }
            double pos = pp.index;

            pos *= K;
            mp1.Add(new DataPoint(pos, 1.2));
            pos  = pp.index + pp.count;
            pos *= K;
            mp1.Add(new DataPoint(pos, 1.2));
        }