rmayormartins commited on
Commit
6803b94
·
1 Parent(s): bc94d3d

JAVA-Judge13

Browse files
Files changed (1) hide show
  1. app.py +40 -38
app.py CHANGED
@@ -3,7 +3,7 @@ import javalang
3
  from typing import Dict, List, Tuple
4
 
5
  class JavaPOOEvaluator:
6
- """Java-Judge: Evaluate POO in Java Code"""
7
  def __init__(self):
8
  self.rubric = {
9
  "classes": 20,
@@ -38,29 +38,35 @@ class JavaPOOEvaluator:
38
  else:
39
  feedback.append("⚠ Nenhuma instância de objeto criada.")
40
  except Exception as e:
41
- feedback.append("⚠ Erro ao analisar classes e objetos.")
42
 
43
  return score, feedback
44
 
45
- # Métodos de análise para outros critérios continuam iguais ao seu código anterior...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  def evaluate_code(self, code: str) -> Dict:
48
  """Avalia o código Java"""
49
- # Avaliações essenciais e bonificadas
50
  cls_score, cls_feedback = self.analyze_classes_and_objects(code)
51
  meth_score, meth_feedback = self.analyze_methods(code)
52
 
53
- enc_score, enc_feedback = self.analyze_encapsulation(code)
54
- inh_score, inh_feedback = self.analyze_inheritance(code)
55
- poly_score, poly_feedback = self.analyze_polymorphism(code)
56
- abs_score, abs_feedback = self.analyze_abstraction(code)
57
-
58
- # Pontuações
59
- essential_score = cls_score + meth_score
60
- bonus_score = enc_score + inh_score + poly_score + abs_score
61
- total_score = essential_score + bonus_score
62
- total_score = min(100, total_score)
63
-
64
  proficiency = "Necessita Melhorias"
65
  if total_score >= 90:
66
  proficiency = "Excelente"
@@ -71,25 +77,18 @@ class JavaPOOEvaluator:
71
 
72
  return {
73
  "total_score": total_score,
74
- "essential_score": essential_score,
75
- "bonus_score": bonus_score,
76
  "proficiency": proficiency,
77
  "feedback": {
78
  "classes_objetos": cls_feedback,
79
  "metodos": meth_feedback,
80
- "encapsulamento": enc_feedback,
81
- "heranca": inh_feedback,
82
- "polimorfismo": poly_feedback,
83
- "abstracao": abs_feedback
84
  }
85
  }
86
 
87
  # Interface Gradio
88
- with gr.Blocks(title="Java-Judge: Evaluate POO in Java Code") as demo:
89
  gr.Markdown("# Avaliador de POO em Java")
90
  gr.Markdown("### [Visualizar a Rubrica em PDF](rubric.pdf)")
91
- gr.Markdown("Ou confira a tabela resumida abaixo.")
92
- gr.Image("rubric_table.png", label="Tabela Resumida da Rubrica")
93
 
94
  upload = gr.File(label="Carregue arquivos Java para avaliação", file_types=[".java"], file_count="multiple")
95
  evaluate_button = gr.Button("Avaliar Código")
@@ -101,20 +100,23 @@ with gr.Blocks(title="Java-Judge: Evaluate POO in Java Code") as demo:
101
  results = []
102
 
103
  for file in files:
104
- with open(file.name, 'r', encoding='utf-8') as f:
105
- code = f.read()
106
- evaluation = evaluator.evaluate_code(code)
107
-
108
- result = f"\nArquivo: {file.name}\n"
109
- result += f"Pontuação Total: {evaluation['total_score']:.1f}/100\n"
110
- result += f"Nível: {evaluation['proficiency']}\n\n"
111
- result += "Feedback Detalhado:\n"
112
- for category, comments in evaluation['feedback'].items():
113
- result += f"\n{category.replace('_', ' ').title()}:\n"
114
- for comment in comments:
115
- result += f" {comment}\n"
116
- results.append(result)
117
-
 
 
 
118
  return "\n".join(results)
119
 
120
  evaluate_button.click(fn=evaluate_code_files, inputs=upload, outputs=output)
 
3
  from typing import Dict, List, Tuple
4
 
5
  class JavaPOOEvaluator:
6
+ """Avaliador para Programação Orientada a Objetos"""
7
  def __init__(self):
8
  self.rubric = {
9
  "classes": 20,
 
38
  else:
39
  feedback.append("⚠ Nenhuma instância de objeto criada.")
40
  except Exception as e:
41
+ feedback.append(f"⚠ Erro ao analisar classes e objetos: {e}")
42
 
43
  return score, feedback
44
 
45
+ def analyze_methods(self, code: str) -> Tuple[float, List[str]]:
46
+ """Avalia a definição e organização de métodos"""
47
+ score = 0
48
+ feedback = []
49
+
50
+ try:
51
+ tree = javalang.parse.parse(code)
52
+ methods = list(tree.filter(javalang.tree.MethodDeclaration))
53
+
54
+ if methods:
55
+ score += 15
56
+ feedback.append(f"✓ {len(methods)} método(s) declarado(s) corretamente.")
57
+ else:
58
+ feedback.append("⚠ Nenhum método declarado encontrado.")
59
+ except Exception as e:
60
+ feedback.append(f"⚠ Erro ao analisar métodos: {e}")
61
+
62
+ return score, feedback
63
 
64
  def evaluate_code(self, code: str) -> Dict:
65
  """Avalia o código Java"""
 
66
  cls_score, cls_feedback = self.analyze_classes_and_objects(code)
67
  meth_score, meth_feedback = self.analyze_methods(code)
68
 
69
+ total_score = cls_score + meth_score
 
 
 
 
 
 
 
 
 
 
70
  proficiency = "Necessita Melhorias"
71
  if total_score >= 90:
72
  proficiency = "Excelente"
 
77
 
78
  return {
79
  "total_score": total_score,
 
 
80
  "proficiency": proficiency,
81
  "feedback": {
82
  "classes_objetos": cls_feedback,
83
  "metodos": meth_feedback,
 
 
 
 
84
  }
85
  }
86
 
87
  # Interface Gradio
88
+ with gr.Blocks(title="Avaliador de POO em Java", css="#rubric_image img {max-width: 50%; height: auto; margin: 0 auto;}") as demo:
89
  gr.Markdown("# Avaliador de POO em Java")
90
  gr.Markdown("### [Visualizar a Rubrica em PDF](rubric.pdf)")
91
+ gr.Image("rubric_table.png", label="Tabela Resumida da Rubrica", elem_id="rubric_image")
 
92
 
93
  upload = gr.File(label="Carregue arquivos Java para avaliação", file_types=[".java"], file_count="multiple")
94
  evaluate_button = gr.Button("Avaliar Código")
 
100
  results = []
101
 
102
  for file in files:
103
+ try:
104
+ with open(file.name, 'r', encoding='utf-8') as f:
105
+ code = f.read()
106
+ evaluation = evaluator.evaluate_code(code)
107
+
108
+ result = f"\nArquivo: {file.name}\n"
109
+ result += f"Pontuação Total: {evaluation['total_score']:.1f}/100\n"
110
+ result += f"Nível: {evaluation['proficiency']}\n\n"
111
+ result += "Feedback Detalhado:\n"
112
+ for category, comments in evaluation['feedback'].items():
113
+ result += f"\n{category.replace('_', ' ').title()}:\n"
114
+ for comment in comments:
115
+ result += f" {comment}\n"
116
+ results.append(result)
117
+ except Exception as e:
118
+ results.append(f"Erro ao processar o arquivo {file.name}: {e}")
119
+
120
  return "\n".join(results)
121
 
122
  evaluate_button.click(fn=evaluate_code_files, inputs=upload, outputs=output)