示例#1
0
        /// <summary>
        /// Opens a QuizInstance of a quiz and returns it
        /// </summary>
        /// <param name="quiz">The Quiz that is to be opened</param>
        /// <param name="user">The User who opens it</param>
        internal QuizInstance OpenQuiz(Quiz quiz, User user)
        {
            QuizInstance quizInstance = new QuizInstance();

            quizInstance.Owner     = user;
            quizInstance.Quiz      = quiz;
            quizInstance.StartDate = DateTime.Now;
            quizInstance.Open      = true;
            quizInstance.Running   = false;


            var command = new SqlCommand();

            command.CommandText = @"INSERT INTO QuizInstance(UserId, QuizId, StartDate, [Open], Running) " +
                                  "VALUES (@userId, @quizId, @startDate, @open, @running); Select Scope_Identity()";

            command.Parameters.AddWithValue("@userId", user.Id);
            command.Parameters.AddWithValue("@quizId", quiz.Id);
            command.Parameters.AddWithValue("@startDate", quizInstance.StartDate);
            command.Parameters.AddWithValue("@open", quizInstance.Open);
            command.Parameters.AddWithValue("@running", quizInstance.Running);

            quizInstance.Id = repository.ExecuteStatement(command);

            //If an error occurs, return null instead
            if (quizInstance.Id == 0)
            {
                quizInstance = null;
            }

            return(quizInstance);
        }
示例#2
0
        /// <summary>
        /// Sets the text based on the quizInstance.
        /// </summary>
        public void InitializeQuizDetail(QuizInstance quizInstance)
        {
            lblTitle.Text           = quizInstance.Quiz.Title;
            lblDescription.Text     = quizInstance.Quiz.Description;
            lblRunDate.Text         = quizInstance.StartDate.ToString("yyyy-MM-dd hh:mm:ss");
            lblNoOfQuestions.Text   = "" + quizInstance.QuestionInstances.Count;
            lblNoOfContestants.Text = "" + quizInstance.Contestants.Count;

            string            contestantsWithMostCorrectText = "";
            List <Contestant> contestantsWithMostCorrect     = ContestantsWithMostCorrect(quizInstance);

            for (int i = 0; i < contestantsWithMostCorrect.Count; i++)
            {
                contestantsWithMostCorrectText += contestantsWithMostCorrect[i].Name;
                if (contestantsWithMostCorrect.Count > i + 1)
                {
                    contestantsWithMostCorrectText += "\n";
                }
            }
            lblBestContestants.Text = contestantsWithMostCorrectText;

            string questionsWithMostWrongText = "";
            List <QuestionInstance> questionsWithMostWrong = QuestionsWithMostWrong(quizInstance);

            for (int i = 0; i < questionsWithMostWrong.Count; i++)
            {
                questionsWithMostWrongText += questionsWithMostWrong[i].Header;
                if (questionsWithMostWrong.Count > i + 1)
                {
                    questionsWithMostWrongText += "\n";
                }
            }
            lblHardestQuestion.Text = questionsWithMostWrongText;
        }
示例#3
0
        /// <summary>
        /// Sets whether the QuizInstance is running or not
        /// </summary>
        /// <param name="quizInstance">QuizInstance that is to be changed. Only the "running" and "id" attributes are used</param>
        internal void RunQuiz(QuizInstance quizInstance)
        {
            var command = new SqlCommand();

            command.CommandText = @"UPDATE QuizInstance SET Running = @running WHERE Id = @id";

            command.Parameters.AddWithValue("@id", quizInstance.Id);
            command.Parameters.AddWithValue("@running", quizInstance.Running);
            //command.ExecuteNonQuery();

            using (TransactionScope scope = new TransactionScope())
            {
                if (repository.ExecuteStatement(command) < 1)
                {
                    scope.Dispose();
                    return;
                }
                if (quizInstance.Running)
                {
                    if (new DBQuestion().CreateQuestionInstances(quizInstance.Id) < 1)
                    {
                        scope.Complete();
                    }
                }
                scope.Complete();
            }
        }
示例#4
0
 /// <summary>
 /// Populates the table with the data from the QuizInstance
 /// </summary>
 public void InitializeRows(QuizInstance quizInstance)
 {
     questionContestantStats.Rows.Add();
     for (int i = 0; i < quizInstance.QuestionInstances.Count; i++)
     {
         DataGridViewRow  row = (DataGridViewRow)questionContestantStats.Rows[0].Clone();
         QuestionInstance questionInstance = quizInstance.QuestionInstances[i];
         row.Cells[0].Value = questionInstance.Header;
         int i2 = 0, i3 = 1;
         foreach (Contestant contestant in quizInstance.Contestants)
         {
             if (questionInstance.WrongAnswers.Count > i2 && questionInstance.WrongAnswers[i2].Id.Equals(contestant.Id))
             {
                 row.Cells[i3].Value = "✕";
                 i2++;
             }
             else if (questionInstance.CorrectAnswer != null && questionInstance.CorrectAnswer.Id.Equals(contestant.Id))
             {
                 row.Cells[i3].Value = "✓";
             }
             else
             {
                 row.Cells[i3].Value = "◯";
             }
             i3++;
         }
         questionContestantStats.Rows.Add(row);
     }
     questionContestantStats.Rows.RemoveAt(0);
 }
示例#5
0
 // Add event handlers and event-invoking method
 private void InitializeEventHandler()
 {
     // when selected index/quiz is changed
     this.quizInstanceList.OnSelectedQuizChanged += (sender, quizInstance) =>
     {
         this.activeQuizInstance = quizInstance;
         InitializeQuizDetail();
     };
 }
示例#6
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            this.quizInstance = repository.Service.OpenQuiz(activeQuiz, repository.ActiveUser);

            lblOutput.Text = $"Quizzen {activeQuiz.Title} er åben for deltagelse";

            btnOpen.Hide();
            btnStart.Show();
        }
示例#7
0
        /// <summary>
        /// Checks if An Active quiz is open or running
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public QuizInstance GetActiveQuizInstance(int userId)
        {
            QuizInstance quizInstance = new QuizInstance();
            SqlCommand   command      = new SqlCommand();

            command.CommandText = @"WHERE UserId = " + userId + " AND ([Open] = 1 OR Running = 1)";
            command.Parameters.AddWithValue("@userId", userId);
            quizInstance = GetQuiz(command);
            return(quizInstance);
        }
示例#8
0
        /// <summary>
        /// Closes a quiz, so that it no longer is possible to add more contestants
        /// </summary>
        /// <param name="quizInstance">The instance, that is to be closed</param>
        internal void CloseQuiz(QuizInstance quizInstance)
        {
            var command = new SqlCommand();

            command.CommandText = @"UPDATE QuizInstance SET [Open] = @open WHERE Id = @id";

            command.Parameters.AddWithValue("@id", quizInstance.Id);
            command.Parameters.AddWithValue("@open", false);

            repository.ExecuteStatement(command);
        }
示例#9
0
        // Invoked by quizStatisticsListView when statistics are requested for at QuizInstance
        private void InitializeQuizStatisticsView(object sender, QuizInstance quizInstance)
        {
            // Set active quiz in quiz-question-view
            quizStatisticsView.SetActiveQuizInstance(quizInstance);
            // Hide quiz-view (sender)
            quizStatisticsListView.Hide();
            // Show quiz-question-view
            quizStatisticsView.Show();

            //ActiveQuiz();
        }
示例#10
0
        private QuizInstance GetQuiz(SqlCommand command)
        {
            QuizInstance quizInstance = new QuizInstance();

            command.CommandText = @"SELECT * FROM QuizInstance " + command.CommandText;
            quizInstance        = repository.SingleRead(command);
            if (quizInstance == null)
            {
                return(null);
            }
            quizInstance.Quiz = new DBQuiz().GetQuizById(quizInstance.QuizId);
            return(quizInstance);
        }
示例#11
0
        // Selected item is changed, fires on load and after selected item is changed
        private void listBoxQuiz_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBoxQuiz.SelectedItem is QuizInstance)
            {
                QuizInstance quizInstance = (QuizInstance)listBoxQuiz.SelectedItem;

                if (quizInstance != null && OnSelectedQuizChanged != null)
                {
                    // Invoke the event
                    this.OnSelectedQuizChanged(this, quizInstance);
                }
            }
        }
示例#12
0
        public QuizInstance GetQuizInstanceById(int quizInstanceId, bool includeAll)
        {
            QuizInstance quizInstance = new QuizInstance();
            SqlCommand   command      = new SqlCommand();

            command.CommandText = "WHERE Id = " + quizInstanceId;
            quizInstance        = GetQuiz(command);
            if (includeAll)
            {
                quizInstance.QuestionInstances = new DBQuestionInstance().GetQuestionInstances(quizInstanceId);
                quizInstance.Contestants       = new DBContestant().GetContestants(quizInstanceId);
            }
            return(quizInstance);
        }
示例#13
0
    private void OnLevelPickerChanged(LevelID level)
    {
        QuizInstance quiz = UIParent.Data.Reports.GetQuiz(level);

        // If there is a quiz then display it
        if (quiz != null)
        {
            quizInstanceUI.DisplayQuizInstance(quiz);
        }

        // Enable/disable objects based off of whether there is a quiz for this level yet
        quizInstanceUI.AnswerUIParent.gameObject.SetActive(quiz != null);
        noQuizText.gameObject.SetActive(quiz == null);
    }
示例#14
0
    public void DisplayAnswer(QuizInstance quiz, int questionIndex)
    {
        if (questionIndex >= 0 && questionIndex < quiz.RuntimeTemplate.Questions.Length)
        {
            // Store quiz question for easy access
            QuizQuestion question    = quiz.RuntimeTemplate.Questions[questionIndex];
            QuizOption   answer      = quiz.GetAnswer(questionIndex);
            int          answerIndex = quiz.Answers[questionIndex];

            // Setup question text
            questionText.text = $"Question {questionIndex + 1}: {question.Question}";

            // Setup answer text
            answerText.text = $"\t";

            // Add text for each answer, highlighting the picked answer
            for (int i = 0; i < question.Options.Length; i++)
            {
                QuizOption option = question.Options[i];

                // Give the answer a bold white color
                if (option == answer)
                {
                    answerText.text += $"<color=white>* {option.Label}</color>";
                }
                // Use the normal label for other options
                else
                {
                    answerText.text += option.Label;
                }

                // Add endline and tab after each option except the last
                if (i < question.Options.Length - 1)
                {
                    answerText.text += "\n\t";
                }
            }

            // Compute the relative grade, and give flavor text for different grade levels
            if (question.RelativeGrade(answerIndex) > 0.6f)
            {
                gradeText.text = "<color=green>Consistent with existing research!</color>";
            }
            else
            {
                gradeText.text = "<color=red>Not consistent with existing research...</color>";
            }
        }
    }
示例#15
0
 /// <summary>
 /// Initializes the table with the data from the QuizInstance
 /// </summary>
 internal void InitializeTable(QuizInstance quizInstance)
 {
     if (this.questionContestantStats.InvokeRequired)
     {
         //A @ is used here to show that we don't mean the keyword
         InitializeTableCallBack @delegate = new InitializeTableCallBack(InitializeTable);
         this.Invoke(@delegate, new Object[] { quizInstance });
     }
     else
     {
         questionContestantStats.Rows.Clear();
         questionContestantStats.Columns.Clear();
         InitializeColoumns(quizInstance);
         InitializeRows(quizInstance);
         questionContestantStats.Refresh();
     }
 }
示例#16
0
    public void DisplayQuizInstance(QuizInstance quiz)
    {
        // Remove all existing answer uis
        foreach (QuizAnswerUI ui in currentAnswerUIs)
        {
            Destroy(ui.gameObject);
        }
        currentAnswerUIs.Clear();

        // Create an answer ui for each question in the runtime template
        for (int i = 0; i < quiz.RuntimeTemplate.Questions.Length; i++)
        {
            QuizAnswerUI ui = Instantiate(answerUIPrefab, answerUIParent);
            ui.DisplayAnswer(quiz, i);
            currentAnswerUIs.Add(ui);
        }
    }
示例#17
0
        /// <summary>
        /// Makes the columns for the table.
        /// One for each Contestant, as well as one for the QuestionInstances.
        /// </summary>
        public void InitializeColoumns(QuizInstance quizInstance)
        {
            DataGridViewColumn[] columns = new DataGridViewColumn[quizInstance.Contestants.Count + 1];

            columns[0]            = new DataGridViewTextBoxColumn();
            columns[0].HeaderText = "Spørgsmål";
            columns[0].ReadOnly   = true;

            for (int i = 1; i < columns.Length; i++)
            {
                DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
                column.HeaderText = quizInstance.Contestants[i - 1].Name;
                column.ReadOnly   = true;
                columns[i]        = column;
            }
            this.questionContestantStats.Columns.AddRange(columns);
        }
示例#18
0
 public void QuizInstanceRun()
 {
     using (TransactionScope scope = new TransactionScope())
     {
         for (int i = 0; i < 1; i++)
         {
             var quizInstance = new QuizInstance()
             {
                 Id      = 118,
                 Running = true,
                 Open    = false
             };
             DBQuiz hest = new DBQuiz();
             hest.RunQuiz(quizInstance);
         }
         scope.Dispose();
     }
 }
示例#19
0
        /// <summary>
        /// Figures out who the Contestant with the most correct answers are.
        /// Returns multiple in case of a tie.
        /// </summary>
        private List <Contestant> ContestantsWithMostCorrect(QuizInstance quizInstance)
        {
            // The two collections are parallel, so the int in one is owned by the Contestant at the
            // same location in the other.
            int[]             noOfCorrectAnswers = new int[quizInstance.Contestants.Count];
            List <Contestant> contestants        = quizInstance.Contestants;

            foreach (QuestionInstance questionInstance in quizInstance.QuestionInstances)
            {
                if (questionInstance.CorrectAnswer != null)
                {
                    bool found = false;
                    for (int i = 0; !found; i++)
                    {
                        if (questionInstance.CorrectAnswer.Id.Equals(contestants[i].Id))
                        {
                            noOfCorrectAnswers[i]++;
                            found = true;
                        }
                    }
                }
            }

            // Goes through the Contestants, seing if they have more correct, than the last one.
            // If they do, or are tied, they are added to the return-List.
            int highestNumber = 0;
            List <Contestant> contestantsWithMostCorrect = new List <Contestant>();

            for (int i = 0; i < contestants.Count; i++)
            {
                if (noOfCorrectAnswers[i] > highestNumber)
                {
                    contestantsWithMostCorrect.Clear();
                    contestantsWithMostCorrect.Add(contestants[i]);
                    highestNumber = noOfCorrectAnswers[i];
                }
                else if (noOfCorrectAnswers[i] == highestNumber && contestantsWithMostCorrect.Count < 4)
                {
                    contestantsWithMostCorrect.Add(contestants[i]);
                }
            }
            return(contestantsWithMostCorrect);
        }
示例#20
0
        /// <summary>
        /// Figures out which question most people answered wrongly.
        /// Returns multiple in case of a tie.
        /// </summary>
        private List <QuestionInstance> QuestionsWithMostWrong(QuizInstance quizInstance)
        {
            int highestNumber = 0;
            List <QuestionInstance> questionsWithMostWrong = new List <QuestionInstance>();

            foreach (QuestionInstance questionInstance in quizInstance.QuestionInstances)
            {
                if (questionInstance.WrongAnswers.Count > highestNumber)
                {
                    questionsWithMostWrong.Clear();
                    questionsWithMostWrong.Add(questionInstance);
                    highestNumber = questionInstance.WrongAnswers.Count;
                }
                else if (questionInstance.WrongAnswers.Count == highestNumber && questionsWithMostWrong.Count < 4)
                {
                    questionsWithMostWrong.Add(questionInstance);
                }
            }
            return(questionsWithMostWrong);
        }
示例#21
0
    public void SetQuiz(LevelID level, QuizInstance quiz)
    {
        Entry entry = GetEntry(level);

        // If entry already exists then set its quiz
        if (entry != null)
        {
            entry.quiz = quiz;
        }
        // If no entry yet exists then add it here
        else
        {
            Debug.Log("New quiz added to reports");
            entries.Add(new Entry
            {
                level = level,
                quiz  = quiz
            });
        }
    }
示例#22
0
        string BuildCSV(int quizID)
        {
            string CSV = "Username, Percentage \n ";

            //goes through each quiz attempt
            foreach (Quizzes attempt in this.Model.QuizAttempts)
            {
                //if the quiz attempt is of the same quiz ID, add the result
                if (attempt.quizID == quizID)
                {
                    string       JSON        = attempt.quizContent;
                    QuizInstance quizAttempt = JsonConvert.DeserializeObject <QuizInstance>(JSON);
                    //gets the percentage
                    decimal percentage = Convert.ToDecimal(quizAttempt.correctTotal) / Convert.ToDecimal(quizAttempt.questions.Length);
                    percentage *= 100;
                    //adds the result to the CSV
                    CSV += $"{quizAttempt.username},{percentage} \n ";
                }
            }
            return(CSV);
        }
示例#23
0
        public void InitializeQuizInstance(QuizInstance quizInstance)
        {
            lblOutput.Text = "";
            btnOpen.Hide();
            btnStart.Hide();
            btnStop.Hide();

            this.activeQuiz   = quizInstance.Quiz;
            this.quizInstance = quizInstance;

            quizDetail.InitializeQuizDetail(activeQuiz);


            if (quizInstance.Open)
            {
                btnStart.Show();
            }

            else if (quizInstance.Running)
            {
                btnStop.Show();
            }
        }
示例#24
0
 /// <summary>
 /// Sets whether the QuizInstance is running or not
 /// </summary>
 /// <param name="quizInstance">QuizInstance that is to be changed. Only the "running" and "id" attributes are used</param>
 public void RunQuiz(QuizInstance quizInstance)
 {
     new DBQuizInstance().RunQuiz(quizInstance);
 }
示例#25
0
 /// <summary>
 /// Closes a quiz, so that it no longer is possible to add more contestants
 /// </summary>
 /// <param name="quizInstance">The instance, that is to be closed</param>
 public void CloseQuiz(QuizInstance quizInstance)
 {
     new DBQuizInstance().CloseQuiz(quizInstance);
 }
示例#26
0
 public void CloseQuiz(QuizInstance quizInstance)
 {
     new QuizCtr().CloseQuiz(quizInstance);
 }
示例#27
0
 /// <summary>
 /// Initializes the page.
 /// </summary>
 internal void SetActiveQuizInstance(QuizInstance quizInstance)
 {
     this.activeQuizInstance = quizInstance;
     statisticTable.InitializeTable(quizInstance);
     quizInstanceDetail2.InitializeQuizDetail(quizInstance);
 }
示例#28
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        // Get the sub-properties
        SerializedProperty template = property.FindPropertyRelative(nameof(template));
        SerializedProperty answers  = property.FindPropertyRelative(nameof(answers));

        // Set out the foldout
        property.isExpanded = EditorGUIAuto.Foldout(ref position, property.isExpanded, label);

        if (property.isExpanded)
        {
            // Increase indent
            EditorGUI.indentLevel++;

            // Layout the template
            EditorGUIAuto.PropertyField(ref position, template);

            // If an object reference exists then layout the answers
            if (template.objectReferenceValue)
            {
                // Get the quiz template
                QuizTemplate quizTemplate = template.objectReferenceValue as QuizTemplate;
                CheckRuntimeTemplate(quizTemplate);

                // Use a button to regenerate quiz questions from the template
                GUI.enabled = quizTemplate.Dynamic;
                if (GUIAuto.Button(ref position, "Generate new questions"))
                {
                    runtimeTemplate = new QuizRuntimeTemplate(quizTemplate);
                }
                GUI.enabled = true;

                quizAnswersEditor.OnGUI(position, answers, runtimeTemplate.Questions);
                position.y += quizAnswersEditor.GetPropertyHeight(answers, runtimeTemplate.Questions);

                // Get a list of all the answers as integers
                int[] answersArray = Answers(property);
                resultsFoldout = EditorGUIAuto.Foldout(ref position, resultsFoldout, "Quiz Results");

                if (resultsFoldout)
                {
                    // Indent the next part and disable it
                    EditorGUI.indentLevel++;
                    GUI.enabled = false;

                    // Compute if the important questions passed, what the score is, and what the max score was
                    bool   passed      = QuizInstance.PassedImportantQuestions(runtimeTemplate, answersArray);
                    int    score       = QuizInstance.ComputeScoreInImportantCategories(runtimeTemplate, answersArray);
                    int    maxScore    = runtimeTemplate.GetMaximumPossibleScoreInImportantCategories();
                    string scoreString = $"{score} / {maxScore} - {(passed ? "Pass" : "Fail")}";

                    // Show the score on important questions
                    EditorGUIAuto.PrefixedLabelField(ref position, new GUIContent("Score on Important Questions"), scoreString);

                    // Compute if the unimportant questions passed, what the score is, and what the max score was
                    passed      = QuizInstance.PassedUnimportantQuestions(runtimeTemplate, answersArray);
                    score       = QuizInstance.ComputeScoreInUnimportantCategories(runtimeTemplate, answersArray);
                    maxScore    = runtimeTemplate.GetMaximumPossibleScoreInUnimportantCategories();
                    scoreString = $"{score} / {maxScore} - {(passed ? "Pass" : "Fail")}";

                    // Show the score on unimportant questions
                    EditorGUIAuto.PrefixedLabelField(ref position, new GUIContent("Score on Unimportant Questions"), scoreString);

                    // Show the final grade
                    EditorGUIAuto.PrefixedLabelField(ref position, new GUIContent("Final Grade"),
                                                     QuizInstance.ComputeGrade(runtimeTemplate, answersArray).ToString());

                    // Change the values back to before
                    EditorGUI.indentLevel--;
                    GUI.enabled = true;
                }
            }

            // Restore indent
            EditorGUI.indentLevel--;
        }
    }
示例#29
0
    private void GenerateQuizInstance()
    {
        // Get the list of reviews for the current attempt of this level
        ReviewedResourceRequestList reviewsList = GameManager
                                                  .Instance
                                                  .NotebookUI
                                                  .Data
                                                  .Concepts
                                                  .GetEntryWithLatestAttempt(LevelID.Current())
                                                  .reviews;

        // If there are reviewed requests then create a quiz with additional questions
        if (reviewsList.Reviews.Count > 0)
        {
            // Filter only reviews that were granted,
            // and combine reviews that addressed and requested the same item
            ReviewedResourceRequest[] filteredReviews = reviewsList
                                                        .Reviews
                                                        .Where(ResourceRequestGeneratesQuestion)
                                                        .Distinct(new ReviewedResourceRequest.ItemComparer())
                                                        .ToArray();

            // Check to make sure there are some reviews to quiz on
            if (filteredReviews.Length > 0)
            {
                // Create an array with all the quiz questions
                QuizQuestion[] requestQuestions = new QuizQuestion[filteredReviews.Length];

                // Fill in the info for each question
                for (int i = 0; i < requestQuestions.Length; i++)
                {
                    ResourceRequest request = filteredReviews[i].Request;

                    // Set the category to the item addressed by the request
                    QuizCategory category = new QuizCategory(request.ItemAddressed, request.NeedAddressed);

                    // Generate the quiz options
                    QuizOption[] options = GenerateQuizOptions(request, category);

                    // Setup the format for the question
                    string question = $"Was the requested {request.ItemRequested.Data.Name.Get(ItemName.Type.Colloquial)} " +
                                      $"useful for improving the {request.ItemAddressed.Data.Name.Get(ItemName.Type.Colloquial)}" +
                                      $" {request.NeedAddressed} need?";

                    // Create the question
                    requestQuestions[i] = new QuizQuestion(question, category, options);
                }

                // Set the current quiz with additional request questions
                currentQuiz = new QuizInstance(template, requestQuestions);
            }
            else
            {
                currentQuiz = new QuizInstance(template);
            }
        }
        // If there are no reviwed requests
        // then create a quiz without additional questions
        else
        {
            currentQuiz = new QuizInstance(template);
        }
    }
示例#30
0
 // Feed with selected/active quiz
 public void InitializeQuizDetail(QuizInstance quizInstance)
 {
     lblTitle.Text       = quizInstance.Quiz.Title;
     lblDescription.Text = quizInstance.Quiz.Description;
     lblRunDate.Text     = quizInstance.StartDate.ToString("yyyy-MM-dd hh:mm:ss");
 }