diff --git a/Guia3/src/alternativa.py b/Guia3/src/alternativa.py index 4dde61f..cdae2b5 100644 --- a/Guia3/src/alternativa.py +++ b/Guia3/src/alternativa.py @@ -1,4 +1,7 @@ from typing import List, Tuple, Dict class Alternativa: - pass \ No newline at end of file + def __init__(self, texto: str, correta: bool, explicacao: str = None): + self.texto = texto + self.correta = correta + self.explicacao = explicacao \ No newline at end of file diff --git a/Guia3/src/pergunta.py b/Guia3/src/pergunta.py index 5b3763d..9adaf46 100644 --- a/Guia3/src/pergunta.py +++ b/Guia3/src/pergunta.py @@ -1,4 +1,18 @@ from typing import List, Tuple, Dict +from abc import ABC, abstractmethod -class Pergunta: - pass \ No newline at end of file +class Pergunta(ABC): + def __init__(self, texto: str, explicacao_geral: str = None): + self.texto = texto + self.explicacao_geral = explicacao_geral + + @abstractmethod + def validar_resposta(self, resposta): + pass + + def get_explicacao(self): + return self.explicacao_geral + + @abstractmethod + def get_tipo(self): + pass \ No newline at end of file diff --git a/Guia3/src/perguntadiscursiva.py b/Guia3/src/perguntadiscursiva.py index f4c26af..be10e1e 100644 --- a/Guia3/src/perguntadiscursiva.py +++ b/Guia3/src/perguntadiscursiva.py @@ -1,4 +1,20 @@ from typing import List, Tuple, Dict +from .pergunta import Pergunta -class PerguntaDiscursiva: - pass \ No newline at end of file +class PerguntaDiscursiva(Pergunta): + def __init__(self, texto: str, resposta_esperada: str = None, case_sensitive: bool = False, explicacao_geral: str = None): + super().__init__(texto, explicacao_geral) + self.resposta_esperada = resposta_esperada + self.case_sensitive = case_sensitive + + def validar_resposta(self, texto: str) -> bool: + if self.resposta_esperada is None: + return False + + if self.case_sensitive: + return texto == self.resposta_esperada + + return texto.strip().lower() == self.resposta_esperada.strip().lower() + + def get_tipo(self): + return "discursiva" \ No newline at end of file diff --git a/Guia3/src/perguntamultiplaescolha.py b/Guia3/src/perguntamultiplaescolha.py index bcbe94d..715fb61 100644 --- a/Guia3/src/perguntamultiplaescolha.py +++ b/Guia3/src/perguntamultiplaescolha.py @@ -1,4 +1,21 @@ from typing import List, Tuple, Dict +from .pergunta import Pergunta -class PerguntaMultiplaEscolha: - pass \ No newline at end of file +class PerguntaMultiplaEscolha(Pergunta): + def __init__(self, texto: str, alternativas: list, explicacao_geral: str = None): + super().__init__(texto, explicacao_geral) + self.alternativas = alternativas + + def validar_resposta(self, indice: int) -> bool: + if indice < 0 or indice >= len(self.alternativas): + return False + return self.alternativas[indice].correta + + def get_alternativa_correta(self): + for alt in self.alternativas: + if alt.correta: + return alt + return None + + def get_tipo(self): + return "multipla_escolha" \ No newline at end of file diff --git a/Guia3/src/questionario.py b/Guia3/src/questionario.py index 7525582..75b6dd8 100644 --- a/Guia3/src/questionario.py +++ b/Guia3/src/questionario.py @@ -1,4 +1,14 @@ from typing import List, Tuple, Dict +from .tentativaquestionario import TentativaQuestionario + class Questionario: - pass + def __init__(self, titulo: str, perguntas=None): + self.titulo = titulo + self.perguntas = perguntas if perguntas else [] + + def adicionar_pergunta(self, pergunta): + self.perguntas.append(pergunta) + + def criar_attempt(self, usuario: str): + return TentativaQuestionario(self, usuario) \ No newline at end of file diff --git a/Guia3/src/resposta.py b/Guia3/src/resposta.py index 846d771..dbc5221 100644 --- a/Guia3/src/resposta.py +++ b/Guia3/src/resposta.py @@ -1,4 +1,12 @@ from typing import List, Tuple, Dict +from abc import ABC, abstractmethod -class Resposta: - pass \ No newline at end of file +class Resposta(ABC): + def __init__(self, pergunta): + self.pergunta = pergunta + self.esta_correta = False + self.pontuacao_obtida = 0.0 + + @abstractmethod + def calcular_pontuacao(self) -> float: + pass diff --git a/Guia3/src/respostadiscursiva.py b/Guia3/src/respostadiscursiva.py index 4ea6dbb..9e15dac 100644 --- a/Guia3/src/respostadiscursiva.py +++ b/Guia3/src/respostadiscursiva.py @@ -1,4 +1,12 @@ from typing import List, Tuple, Dict +from .resposta import Resposta -class RespostaDiscursiva: - pass \ No newline at end of file +class RespostaDiscursiva(Resposta): + def __init__(self, pergunta, texto_resposta: str): + super().__init__(pergunta) + self.texto_resposta = texto_resposta + self.esta_correta = bool(self.pergunta.validar_resposta(self.texto_resposta)) + self.pontuacao_obtida = 1.0 if self.esta_correta else 0.0 + + def calcular_pontuacao(self) -> float: + return self.pontuacao_obtida \ No newline at end of file diff --git a/Guia3/src/respostaobjetiva.py b/Guia3/src/respostaobjetiva.py index 72ed2d0..e0d4426 100644 --- a/Guia3/src/respostaobjetiva.py +++ b/Guia3/src/respostaobjetiva.py @@ -1,4 +1,13 @@ from typing import List, Tuple, Dict +from .resposta import Resposta -class RespostaObjetiva: - pass \ No newline at end of file +class RespostaObjetiva(Resposta): + def __init__(self, pergunta, indice_escolhido: int): + super().__init__(pergunta) + self.indice_escolhido = indice_escolhido + self.alternativa_selecionada = None + self.esta_correta = self.pergunta.validar_resposta(self.indice_escolhido) + self.pontuacao_obtida = 1.0 if self.esta_correta else 0.0 + + def calcular_pontuacao(self) -> float: + return self.pontuacao_obtida \ No newline at end of file diff --git a/Guia3/src/tentativaquestionario.py b/Guia3/src/tentativaquestionario.py index 9947dd1..f01da3a 100644 --- a/Guia3/src/tentativaquestionario.py +++ b/Guia3/src/tentativaquestionario.py @@ -1,4 +1,40 @@ from typing import List, Tuple, Dict +from datetime import datetime +from .respostaobjetiva import RespostaObjetiva +from .respostadiscursiva import RespostaDiscursiva class TentativaQuestionario: - pass \ No newline at end of file + def __init__(self, questionario, usuario: str): + self.questionario = questionario + self.usuario = usuario + self.data_inicio = datetime.now() + self.data_fim = None + self.respostas = [] + self._finalizado = False + + def registrar_resposta(self, indice_pergunta: int, valor): + if self._finalizado: + return + + pergunta = self.questionario.perguntas[indice_pergunta] + + if hasattr(pergunta, "alternativas"): + resposta = RespostaObjetiva(pergunta, int(valor)) + else: + resposta = RespostaDiscursiva(pergunta, str(valor)) + + resposta.calcular_pontuacao() + self.respostas.append(resposta) + + def calcular_pontuacao(self): + return sum(r.pontuacao_obtida for r in self.respostas) + + def finalizar(self): + self.data_fim = datetime.now() + self._finalizado = True + pontuacao = self.calcular_pontuacao() + feedback = f"Usuário {self.usuario} fez {pontuacao} pontos" + return pontuacao, feedback + + def is_finalizado(self): + return self._finalizado \ No newline at end of file