Exemplo n.º 1
0
        public void SaveAnswerLine(string question, string answer, int answerId)
        {
            var model = db.AnswerLine.FirstOrDefault(m => m.AnswerId == answerId && m.Question == question);

            if (model != null)
            {
                model.Answer = answer;
                db.SaveChanges();
            }
            else
            {
                AnswerLine answerLine = new AnswerLine();
                answerLine.AnswerId = answerId;
                answerLine.Answer   = answer;
                answerLine.Question = question;
                db.AnswerLine.Add(answerLine);
                db.SaveChanges();
            }
        }
Exemplo n.º 2
0
        private void colorBubbles(AnswerLine a, Bitmap source, int row)
        {
            int   i           = 0;
            float quickRadius = (float)(1.25 * base.avRadius);
            int   halfRadius  = (int)(quickRadius / 2);

            CircleF[] bubbles = new CircleF[12];
            int[]     pixels  = new int[12];

            foreach (AnswerLine b in base.xLines)
            {
                CircleF bubble = new CircleF(new Point(b.grabAverage(), a.grabAverage()), quickRadius);

                bubbles[i] = bubble;

                //Calculate the amount of colored pixels to detect colored in circles
                int totalPixel = 0;
                for (int x = b.grabAverage() - halfRadius; x <= b.grabAverage() + halfRadius; x++)
                {
                    for (int y = a.grabAverage() - halfRadius; y <= a.grabAverage() + halfRadius; y++)
                    {
                        if (Math.Pow((double)(x - b.grabAverage()), 2) + Math.Pow((double)(y - a.grabAverage()), 2) <= Math.Pow((1.25) * base.avRadius, 2))
                        {
                            totalPixel = totalPixel + (255 - source.GetPixel(x, y).R) + (255 - source.GetPixel(x, y).B) + (255 - source.GetPixel(x, y).G);
                        }
                    }
                }
                pixels[i] = (int)(totalPixel / bubble.Area);
                i         = i + 1;
            }
            while (this.colorArray[row] != pixels)
            {
                this.colorArray[row] = pixels;
            }
            while (this.centerCircles[row] != bubbles)
            {
                this.centerCircles[row] = bubbles;
            }
        }
Exemplo n.º 3
0
        public override void scoreSection(Bitmap original)
        {
            int           newRadius      = (int)(1.5 * base.avRadius);
            int           halfRadius     = newRadius / 2;
            List <Thread> startedThreads = new List <Thread>();

            for (int q = 0; q < base.yLines.Count; q++)
            {
                Bitmap   fullCopy = new Bitmap(original.Width, original.Height);
                Graphics g        = Graphics.FromImage(fullCopy);
                g.DrawImage(original, new Point(0, 0));
                g.Dispose();
                AnswerLine a       = base.yLines[q];
                Int32      meGo    = q;
                Thread     thread1 = new Thread(() => colorBubbles(a, fullCopy, meGo));
                startedThreads.Add(thread1);
                thread1.Start();
            }

            foreach (Thread t in startedThreads)
            {
                if (t.IsAlive)
                {
                    t.Join();
                }
            }
            int row = 0;

            foreach (int[] r in colorArray)
            {
                int[] answerColumn   = new int[2];
                int[] answerLocation = new int[2];
                //column 1
                bool didAnswer = false;
                int  answer1   = -1;;
                if (Math.Abs(colorArray[row][0] - colorArray[row][1]) > 70)
                {
                    didAnswer = true;
                }

                if (didAnswer)
                {
                    answer1 = returnLargest(colorArray[row][0], colorArray[row][1]);
                }
                else
                {
                    answerColumn[0]   = -1;
                    answerLocation[0] = -1;
                }
                int answer2 = -1;;
                if (Math.Abs(colorArray[row][2] - colorArray[row][3]) > 70)
                {
                    didAnswer = true;
                }

                if (didAnswer)
                {
                    answer2 = returnLargest(colorArray[row][2], colorArray[row][3]);
                }
                else
                {
                    answerColumn[1]   = -1;
                    answerLocation[1] = -1;
                }

                //score section
                if (answer1 != -1)
                {
                    if (base.test.compAnswers.Length > row)
                    {
                        answerLocation[0] = answer1;
                        if (base.test.compAnswers[row] == returnAnswer(answer1))
                        {
                            base.score      = base.score + 1;
                            answerColumn[0] = 2;
                        }
                        else
                        {
                            answerColumn[0] = 1;
                        }
                    }
                }
                else
                {
                    if (base.test.compAnswers.Length > row)
                    {
                        answerLocation[0] = 0;
                    }
                }
                if (answer2 != -1)
                {
                    if (base.test.compAnswers.Length > (row + 5))
                    {
                        answerLocation[1] = answer2 + 2;
                        if (base.test.compAnswers[row + 5] == returnAnswer(answer2))
                        {
                            base.score      = base.score + 1;
                            answerColumn[1] = 2;
                        }
                        else
                        {
                            answerColumn[1] = 1;
                        }
                    }
                }
                else
                {
                    if (base.test.compAnswers.Length > row + 5)
                    {
                        answerLocation[1] = 0;
                    }
                }

                this.scores[row]   = (answerColumn);
                this.scoreRow[row] = (answerLocation);
                row = row + 1;
            }
        }