rmayormartins commited on
Commit
2db7ec0
·
1 Parent(s): 3d1b7f1

JAVA-OO3331

Browse files
Files changed (1) hide show
  1. app.py +44 -22
app.py CHANGED
@@ -216,15 +216,13 @@ class JavaStructuralEvaluator:
216
  }
217
 
218
  class CompetencyEvaluator:
219
- """Avaliador baseado em competências"""
220
  def __init__(self):
221
  self.rubric = {
222
- "syntax_correctness": 50, # Corretude sintática
223
- "competencies": 50 # Competências demonstradas
224
  }
225
 
226
  def analyze_syntax_correctness(self, code: str) -> Tuple[float, List[str]]:
227
- """Analisa corretude sintática (50 pontos)"""
228
  score = 0
229
  feedback = []
230
 
@@ -244,12 +242,17 @@ class CompetencyEvaluator:
244
  if declarations:
245
  score += 5
246
  feedback.append("✓ Declarações de variáveis sintáticamente corretas")
247
- if any(d.type.name in ['int', 'double', 'String', 'boolean'] for d in declarations):
248
  score += 5
249
  feedback.append("✓ Tipos de dados usados corretamente")
250
 
251
  # 3. Expressões e Operadores (10 pontos)
252
- if list(tree.filter(javalang.tree.BinaryOperation)):
 
 
 
 
 
253
  score += 10
254
  feedback.append("✓ Expressões e operadores usados corretamente")
255
 
@@ -279,7 +282,6 @@ class CompetencyEvaluator:
279
  return score, feedback
280
 
281
  def analyze_competencies(self, code: str) -> Tuple[float, List[str]]:
282
- """Analisa competências demonstradas (50 pontos)"""
283
  score = 0
284
  feedback = []
285
 
@@ -293,35 +295,56 @@ class CompetencyEvaluator:
293
  'while': list(tree.filter(javalang.tree.WhileStatement))
294
  }
295
 
296
- appropriate_use = True
297
  for struct_type, instances in structures.items():
298
  if instances:
299
- if struct_type == 'for' and any('length' in str(inst) for inst in instances):
300
- score += 5
301
- feedback.append("✓ Uso adequado de for para iteração em arrays")
302
- elif struct_type == 'while' and any('hasNext' in str(inst) for inst in instances):
303
- score += 5
304
- feedback.append("✓ Uso adequado de while para leitura de dados")
 
 
 
 
 
 
305
  else:
306
  score += 5
307
  feedback.append(f"✓ Uso apropriado de {struct_type}")
308
 
309
  # 2. Manipulação de Dados (15 pontos)
310
- operations = list(tree.filter(javalang.tree.BinaryOperation))
311
- if operations:
312
- if any(op.operator in ['*', '/', '+', '-'] for op in operations):
 
 
 
 
 
 
 
 
313
  score += 5
314
  feedback.append("✓ Cálculos implementados corretamente")
315
- if any(op.operator in ['>', '<', '>=', '<=', '=='] for op in operations):
316
  score += 5
317
  feedback.append("✓ Comparações implementadas corretamente")
318
- if any('=' in str(op) for op in operations):
319
  score += 5
320
  feedback.append("✓ Atribuições implementadas corretamente")
321
 
322
  # 3. Clareza e Organização (10 pontos)
323
  # Verificar nomes significativos
324
- if all(len(decl.declarators[0].name) > 1 for _, decl in tree.filter(javalang.tree.LocalVariableDeclaration)):
 
 
 
 
 
 
 
 
325
  score += 5
326
  feedback.append("✓ Nomes de variáveis significativos")
327
 
@@ -332,9 +355,8 @@ class CompetencyEvaluator:
332
  feedback.append("✓ Código bem documentado")
333
 
334
  # 4. Resolução do Problema (10 pontos)
335
- # Verificar se tem entrada, processamento e saída
336
  has_input = 'Scanner' in code
337
- has_processing = bool(operations)
338
  has_output = 'System.out' in code
339
 
340
  if has_input and has_output:
 
216
  }
217
 
218
  class CompetencyEvaluator:
 
219
  def __init__(self):
220
  self.rubric = {
221
+ "syntax_correctness": 50,
222
+ "competencies": 50
223
  }
224
 
225
  def analyze_syntax_correctness(self, code: str) -> Tuple[float, List[str]]:
 
226
  score = 0
227
  feedback = []
228
 
 
242
  if declarations:
243
  score += 5
244
  feedback.append("✓ Declarações de variáveis sintáticamente corretas")
245
+ if any(hasattr(d, 'type') and d.type.name in ['int', 'double', 'String', 'boolean'] for d in declarations):
246
  score += 5
247
  feedback.append("✓ Tipos de dados usados corretamente")
248
 
249
  # 3. Expressões e Operadores (10 pontos)
250
+ binary_operations = []
251
+ for path, node in tree.filter(javalang.tree.BinaryOperation):
252
+ if hasattr(node, 'operator'):
253
+ binary_operations.append(node)
254
+
255
+ if binary_operations:
256
  score += 10
257
  feedback.append("✓ Expressões e operadores usados corretamente")
258
 
 
282
  return score, feedback
283
 
284
  def analyze_competencies(self, code: str) -> Tuple[float, List[str]]:
 
285
  score = 0
286
  feedback = []
287
 
 
295
  'while': list(tree.filter(javalang.tree.WhileStatement))
296
  }
297
 
 
298
  for struct_type, instances in structures.items():
299
  if instances:
300
+ if struct_type == 'for':
301
+ for path, node in tree.filter(javalang.tree.ForStatement):
302
+ if any('length' in str(getattr(node, attr, '')) for attr in dir(node)):
303
+ score += 5
304
+ feedback.append("✓ Uso adequado de for para iteração em arrays")
305
+ break
306
+ elif struct_type == 'while':
307
+ for path, node in tree.filter(javalang.tree.WhileStatement):
308
+ if any('hasNext' in str(getattr(node, attr, '')) for attr in dir(node)):
309
+ score += 5
310
+ feedback.append("✓ Uso adequado de while para leitura de dados")
311
+ break
312
  else:
313
  score += 5
314
  feedback.append(f"✓ Uso apropriado de {struct_type}")
315
 
316
  # 2. Manipulação de Dados (15 pontos)
317
+ binary_operations = []
318
+ for path, node in tree.filter(javalang.tree.BinaryOperation):
319
+ if hasattr(node, 'operator'):
320
+ binary_operations.append(node)
321
+
322
+ if binary_operations:
323
+ arithmetic_ops = [op for op in binary_operations if hasattr(op, 'operator') and op.operator in ['*', '/', '+', '-']]
324
+ comparison_ops = [op for op in binary_operations if hasattr(op, 'operator') and op.operator in ['>', '<', '>=', '<=', '==']]
325
+ assignment_ops = [op for op in binary_operations if hasattr(op, 'operator') and '=' in op.operator]
326
+
327
+ if arithmetic_ops:
328
  score += 5
329
  feedback.append("✓ Cálculos implementados corretamente")
330
+ if comparison_ops:
331
  score += 5
332
  feedback.append("✓ Comparações implementadas corretamente")
333
+ if assignment_ops:
334
  score += 5
335
  feedback.append("✓ Atribuições implementadas corretamente")
336
 
337
  # 3. Clareza e Organização (10 pontos)
338
  # Verificar nomes significativos
339
+ has_meaningful_names = True
340
+ for path, node in tree.filter(javalang.tree.LocalVariableDeclaration):
341
+ if hasattr(node, 'declarators') and node.declarators:
342
+ for declarator in node.declarators:
343
+ if hasattr(declarator, 'name') and len(declarator.name) <= 1:
344
+ has_meaningful_names = False
345
+ break
346
+
347
+ if has_meaningful_names:
348
  score += 5
349
  feedback.append("✓ Nomes de variáveis significativos")
350
 
 
355
  feedback.append("✓ Código bem documentado")
356
 
357
  # 4. Resolução do Problema (10 pontos)
 
358
  has_input = 'Scanner' in code
359
+ has_processing = bool(binary_operations)
360
  has_output = 'System.out' in code
361
 
362
  if has_input and has_output: