swad-core/swad_test_exam.h

112 lines
4.9 KiB
C
Raw Normal View History

2020-04-02 03:28:08 +02:00
// swad_test_exam.c: test exams made by users
#ifndef _SWAD_TST_EXA
#define _SWAD_TST_EXA
/*
SWAD (Shared Workspace At a Distance in Spanish),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
Copyright (C) 1999-2020 Antonio Ca<EFBFBD>as Vargas
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
2020-04-14 17:15:17 +02:00
#include "swad_test.h"
2020-04-02 03:28:08 +02:00
#include "swad_user.h"
/*****************************************************************************/
/***************************** Public constants ******************************/
/*****************************************************************************/
2020-04-22 03:15:04 +02:00
#define TstRes_MAX_BYTES_INDEXES_ONE_QST (Tst_MAX_OPTIONS_PER_QUESTION * (3 + 1))
2020-04-03 01:55:39 +02:00
2020-04-22 03:15:04 +02:00
#define TstRes_MAX_CHARS_ANSWERS_ONE_QST (128 - 1) // 127
#define TstRes_MAX_BYTES_ANSWERS_ONE_QST ((TstRes_MAX_CHARS_ANSWERS_ONE_QST + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 2047
2020-04-02 03:28:08 +02:00
2020-04-22 03:15:04 +02:00
#define TstRes_SCORE_MAX 10 // Maximum score of a test (10 in Spain). Must be unsigned! // TODO: Make this configurable by teachers
2020-04-02 03:28:08 +02:00
/*****************************************************************************/
/******************************* Public types ********************************/
/*****************************************************************************/
2020-04-22 03:15:04 +02:00
struct TstRes_Result
2020-04-02 03:28:08 +02:00
{
2020-04-22 03:15:04 +02:00
long ResCod; // Test result code
2020-04-02 03:28:08 +02:00
time_t TimeUTC[Dat_NUM_START_END_TIME];
unsigned NumQsts; // Number of questions
unsigned NumQstsNotBlank; // Number of questions not blank
2020-04-22 03:15:04 +02:00
bool Sent; // This test result has been sent or not?
2020-04-16 21:03:22 +02:00
// "Sent" means that user has clicked "Send" button after finishing
2020-04-22 03:15:04 +02:00
bool AllowTeachers; // Are teachers allowed to see this test result?
double Score; // Total score of the test result
2020-04-02 03:28:08 +02:00
struct
{
long QstCod; // Question code
2020-04-22 03:15:04 +02:00
char StrIndexes[TstRes_MAX_BYTES_INDEXES_ONE_QST + 1]; // 0 1 2 3, 3 0 2 1, etc.
char StrAnswers[TstRes_MAX_BYTES_ANSWERS_ONE_QST + 1]; // Answers selected by user
2020-04-02 03:28:08 +02:00
double Score; // Question score
bool AnswerIsNotBlank; // Answer not blank?
} Questions[TstCfg_MAX_QUESTIONS_PER_TEST];
};
/*****************************************************************************/
/***************************** Public prototypes *****************************/
/*****************************************************************************/
2020-04-22 03:15:04 +02:00
void TstRes_ResetResult (struct TstRes_Result *Result);
void TstRes_CreateExamInDB (struct TstRes_Result *Exam);
void TstRes_UpdateExamInDB (const struct TstRes_Result *Exam);
2020-04-02 03:28:08 +02:00
2020-04-22 03:15:04 +02:00
void TstRes_ShowExamAfterAssess (struct TstRes_Result *Exam);
2020-04-02 03:28:08 +02:00
2020-04-22 03:15:04 +02:00
void TstRes_ComputeScoresAndStoreExamQuestions (struct TstRes_Result *Exam,
2020-04-02 03:28:08 +02:00
bool UpdateQstScore);
2020-04-22 03:15:04 +02:00
void TstRes_ComputeChoiceAnsScore (struct TstRes_Result *Result,
2020-04-02 03:28:08 +02:00
unsigned NumQst,
struct Tst_Question *Question);
2020-04-22 03:15:04 +02:00
void TstRes_GetIndexesFromStr (const char StrIndexesOneQst[TstRes_MAX_BYTES_INDEXES_ONE_QST + 1], // 0 1 2 3, 3 0 2 1, etc.
2020-04-02 03:28:08 +02:00
unsigned Indexes[Tst_MAX_OPTIONS_PER_QUESTION]);
2020-04-22 03:15:04 +02:00
void TstRes_GetAnswersFromStr (const char StrAnswersOneQst[TstRes_MAX_BYTES_ANSWERS_ONE_QST + 1],
2020-04-02 03:28:08 +02:00
bool UsrAnswers[Tst_MAX_OPTIONS_PER_QUESTION]);
2020-04-22 03:15:04 +02:00
void TstRes_ComputeAndShowGrade (unsigned NumQsts,double Score,double MaxGrade);
double TstRes_ComputeGrade (unsigned NumQsts,double Score,double MaxGrade);
void TstRes_ShowGrade (double Grade,double MaxGrade);
2020-04-02 03:28:08 +02:00
2020-04-22 03:15:04 +02:00
void TstRes_SelUsrsToViewUsrsExams (void);
void TstRes_SelDatesToSeeMyExams (void);
void TstRes_ShowMyExams (void);
void TstRes_GetUsrsAndShowExams (void);
2020-04-02 03:28:08 +02:00
2020-04-22 03:15:04 +02:00
void TstRes_PutParamExaCod (long ExaCod);
long TstRes_GetParamExaCod (void);
2020-04-02 03:28:08 +02:00
2020-04-22 03:15:04 +02:00
void TstRes_ShowOneExam (void);
void TstRes_ShowExamAnswers (struct UsrData *UsrDat,
struct TstRes_Result *Result,
2020-04-02 03:28:08 +02:00
unsigned Visibility);
2020-04-22 03:15:04 +02:00
void TstRes_GetExamDataByExaCod (struct TstRes_Result *Result);
2020-04-02 03:28:08 +02:00
2020-04-22 03:15:04 +02:00
void TstRes_GetExamQuestionsFromDB (struct TstRes_Result *Result);
void TstRes_RemoveExamsMadeByUsrInAllCrss (long UsrCod);
void TstRes_RemoveExamsMadeByUsrInCrs (long UsrCod,long CrsCod);
void TstRes_RemoveCrsExams (long CrsCod);
2020-04-02 03:28:08 +02:00
#endif