// Dados constantes const exerciseTheme = [ "Leitura e Escrita", "Manipulação de Entrada", "Lógica", "Matemática", "Condição", "Condição de Parada", "Laço", "Vetor"] const testCaseTypes = [ "Caso Geral", "Caso Limite", "Caso Nulo", "Caso Negativo", "Igualdade", "Tipo de Entrada"] // Aquisição de dados externos // Dados vindos do Avaliador Automático let exerciseType = [exerciseTheme[getRandomInt(0, exerciseTheme.length)], exerciseTheme[getRandomInt(0, exerciseTheme.length)]]; let testCases = [ {tag: testCaseTypes[getRandomInt(0, testCaseTypes.length)], incorrect: getRandomInt(0,2)}, {tag: testCaseTypes[getRandomInt(0, testCaseTypes.length)], incorrect: getRandomInt(0,2)}, {tag: testCaseTypes[getRandomInt(0, testCaseTypes.length)], incorrect: getRandomInt(0,2)}, {tag: testCaseTypes[getRandomInt(0, testCaseTypes.length)], incorrect: getRandomInt(0,2)}, {tag: testCaseTypes[getRandomInt(0, testCaseTypes.length)], incorrect: getRandomInt(0,2)}, {tag: testCaseTypes[getRandomInt(0, testCaseTypes.length)], incorrect: getRandomInt(0,2)}]; let allIncorrect = true; // Dados vindos da base de dados associada ao aluno let types = [ {type: exerciseTheme[0], total: 1, errors: 0}, {type: exerciseTheme[1], total: 3, errors: 0}, {type: exerciseTheme[2], total: 2, errors: 0}, {type: exerciseTheme[3], total: 1, errors: 0}, {type: exerciseTheme[4], total: 2, errors: 0}, {type: exerciseTheme[5], total: 9, errors: 2}, {type: exerciseTheme[6], total: 4, errors: 0}, {type: exerciseTheme[7], total: 1, errors: 0}]; let tags = [{tag: testCaseTypes[0], total: 15, errors: 0}, {tag: testCaseTypes[1], total: 8, errors: 1}, {tag: testCaseTypes[2], total: 5, errors: 1}, {tag: testCaseTypes[3], total: 6, errors: 0}, {tag: testCaseTypes[4], total: 7, errors: 0}, {tag: testCaseTypes[5], total: 4, errors: 0}]; let lastErrorsPerType = []; // Fila com os últimos 50 erros for (let i = 0; i<50; i++){ lastErrorsPerType.push(exerciseTheme[getRandomInt(0, exerciseTheme.length)]) } let lastErrorsPerTag = []; // Fila com os últimos 50 erros for (let i = 0; i<50; i++){ lastErrorsPerTag.push(testCaseTypes[getRandomInt(0,testCaseTypes.length)]) } // Variáveis internas let incorrect = false; let sugestions = []; let performance = []; let wrongTags = []; let wrongTagsAux = []; let lastErrorsPerTypeGraph = {}; let lastErrorsPerTagGraph = {}; // Funções auxiliares // Função que retorna um valor inteiro aleatório a partir de um intervalo definido function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min)) + min; } // Função que encontra um objeto dentro de um array a partir do valor de uma de suas chaves function findObject(array,key,value) { for(let i = 0; i < array.length; i++) { if(array[i][key] === value) { return i } } } // Funções do agente // Função que analisa o exercício em relação às tags function updateTags(testCases,tags,lastErrorsPerTag) { for (var i = 0; i < testCases.length; i++) { for (var j = 0; j < tags.length; j++) { if (testCases[i].tag === tags[j].tag) { tags[j].total += 1; if (testCases[i].incorrect) { incorrect = true; tags[j].errors += 1; lastErrorsPerTag.push(testCases[i].tag); if (lastErrorsPerTag.length > 50) { lastErrorsPerTag.shift(); } wrongTagsAux.push(testCases[i].tag); } } } } wrongTags = wrongTagsAux.filter((element, i) => wrongTagsAux.indexOf(element) === i) //wrongTags = [...new Set(wrongTagsAux)]; // CUIDADO com o set } // Função que analisa o exercício em relação aos types function updateTypes(exerciseType,types,lastErrorsPerType) { for (var i = 0; i < exerciseType.length; i++) { for (var j = 0; j < types.length; j++) { if (exerciseType[i] === types[j].type) { types[j].total += 1; if (incorrect) { types[j].errors += 1; lastErrorsPerType.push(exerciseType[i]); if (lastErrorsPerType.length > 50) { lastErrorsPerType.shift(); } } } } } } // Função que contabiliza as ocorrências dentro das fila de últimos erros function lastErrors() { lastErrorsPerType.forEach((x) => lastErrorsPerTypeGraph[x] = (lastErrorsPerTypeGraph[x] || 0)+1); lastErrorsPerTag.forEach((x) => lastErrorsPerTagGraph[x] = (lastErrorsPerTagGraph[x] || 0)+1); } // Função que adiciona o desempenho à saída function addPerformance(exerciseType,wrongTags) { let performanceText = "Desempenho\n\n"; performanceText += `Neste exercício relacionado a ${exerciseType} você `; if (incorrect) { performanceText += `errou os teste que envolvem ${wrongTags}.\n\n`; } else { performanceText += `acertou todos os teste.\n\n`; } for (let i = 0; i < exerciseType.length; i++) { let obj = findObject(types,"type",exerciseType[i]); performanceText += `Seu desempenho em exercícios com ${exerciseType[i]} é de ${(100*(1-types[obj].errors/types[obj].total)).toFixed(2)}% de sucesso\n\n`; } if (incorrect) { for (let i = 0; i < wrongTags.length; i++) { let obj = findObject(tags,"tag",wrongTags[i]); performanceText += `Seu desempenho em testes de ${wrongTags[i]} é de ${(100*(1-tags[obj].errors/tags[obj].total)).toFixed(2)}% de sucesso\n\n`; performanceText += `Dos seus últimos 50 erros ${(100*(lastErrorsPerTagGraph[wrongTags[i]]/lastErrorsPerTag.length)).toFixed(2)}% foram em testes de ${wrongTags[i]}\n\n`; } } console.log(performanceText); } // Função que adiciona a sugestão à saída function addSugestion(wrongTypes,wrongTags) { let sugestionText = "Sugestões\n\n"; if (incorrect) { sugestionText += `Levantar quais são os Casos Limites do problema a ser resolvido é fundamental para se avaliar o funcionamento adequado do programa desenvolvido, pois ao se testá-los podem ser encontrados erros que não são observados nos Casos Gerais.\n\n`; sugestionText += `[Explicação de Casos Limites]\n\n`; sugestionText += `[Exemplo de Casos Limites e Casos Gerais]\n\n`; sugestionText += `[Material ou link sobre Casos Limites]\n\n\n`; sugestionText += `O conceito de Laço é muito importante na programação, pois com ele ….\n\n`; sugestionText += `[Explicação sobre Laços]\n\n`; sugestionText += `[Exemplo do uso de Laços no iVProg]\n\n`; sugestionText += `[Material ou link sobre Laços]\n\n`; } else { sugestionText += `Parabéns!!! Seu exercício não apresentou erros.\n\n`; } console.log(sugestionText); } // Exibição dos valores recebidos console.log("\nAntes da Execução\n"); console.table(exerciseType); console.table(testCases); console.table(types); console.table(tags); //console.table(lastErrorsPerType); //console.table(lastErrorsPerTag); console.log("*****************************************************************\n"); // Execução do agente updateTags(testCases,tags,lastErrorsPerTag); updateTypes(exerciseType,types,lastErrorsPerType); lastErrors(); addPerformance(exerciseType,wrongTags); addSugestion(exerciseType,wrongTags); console.log("*****************************************************************\n"); // Reescrita do dados na base de dados associada ao aluno console.log("Após Execução\n"); console.table(types); console.table(tags); console.table(lastErrorsPerTypeGraph); console.table(lastErrorsPerTagGraph); //console.table(lastErrorsPerType); //console.table(lastErrorsPerTag); console.log("\n");