Skip to content

Commit

Permalink
implementando base dos serviços
Browse files Browse the repository at this point in the history
  • Loading branch information
AdsonEsteves committed Nov 18, 2020
1 parent 6007388 commit 17d0cf6
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 83 deletions.
7 changes: 0 additions & 7 deletions ServerAgentsServices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@
<!-- SACIP Grouper Agent -->
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->

<service>
<name>groupStudents</name>
<description>Agrupa os alunos em grupos</description>
<entity>GrouperAgent</entity>
<scope>mas</scope>
<organization>SACIP</organization>
</service>
<service>
<name>groupStudents</name>
<description>Agrupa os alunos em grupos</description>
Expand Down
7 changes: 7 additions & 0 deletions UserAgentsServices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
<scope>mas</scope>
<organization>SACIP</organization>
</service>
<service>
<name>suggestContent</name>
<description>retorna conteúdos sugeridos para o aluno de acordo com suas características</description>
<entity>PedagogicalAgent</entity>
<scope>mas</scope>
<organization>SACIP</organization>
</service>

<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
<!-- SACIP Tracking Agent -->
Expand Down
68 changes: 40 additions & 28 deletions src/main/java/sacip/sti/agents/PedagogicalAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,25 @@ public PedagogicalAgent() {

@Override
public void provide(String service, Map in, List out) throws ServiceException {
// TODO Auto-generated method stub
// TODO Auto-generated method stub

switch (service) {
case "getAluno":
out.add(getAluno());
break;

case "suggestContent":
out.add(suggestContent());
break;

if(service.equals("getAluno"))
{
out.add(getAluno());
default:
throw new ServiceException("Serviço "+service+" não foi implementado no agente pedagógico.");
}
}

@Override
protected void lifeCycle() throws LifeCycleException, InterruptedException {

// Board.addMessageListener("PortugolSTI", this);
// for (String aluno : alunosOnline) {
try
{
// while(Board.getContextAttribute(aluno+"eventState").equals("Programando"))
// {
// ServiceWrapper serviceWrapper = require("SACIP", "storeStudentErrors"+this.instancia);

// List data = serviceWrapper.run();
// List dicas = checkDicas(data);
// if(dicas.size()>0)
// {
// sendDicas(dicas);
// }
// Thread.sleep(2000);
// }

}
catch(Exception e)
{
LOG.error("Não foi possível analisar o aluno", e);
}
// }

}

@Override
Expand All @@ -74,6 +58,34 @@ public void boardChanged(Message msg) {

}

private String suggestContent()
{
try
{
//Pegar grupo de alunos
ServiceWrapper wrapper = require("SACIP", "getStudentGroups");
wrapper.addParameter("estudante", getAluno());
List grupo = wrapper.run();

//Pedir recomendação para o recomendador
ServiceWrapper wrapper2 = require("SACIP", "getRecommendedContent");
wrapper2.addParameter("estudante", getAluno());
wrapper2.addParameter("grupo", grupo);

String recomendacoes = (String) wrapper.run().get(0);

return recomendacoes;

}
catch (Exception e)
{
LOG.error("ERRO NO PEDAGOGICAL AGENT AO SUGERIR EXERCÍCIOS", e);
e.printStackTrace();
return e.getLocalizedMessage();
}

}

private Student getAluno()
{
return this.student;
Expand Down
93 changes: 45 additions & 48 deletions src/main/java/sacip/sti/agents/RecommenderAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,71 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

import org.midas.as.agent.board.Board;
import org.midas.as.AgentServer;
import org.midas.as.agent.templates.Agent;
import org.midas.as.agent.templates.LifeCycleException;
import org.midas.as.agent.templates.ServiceException;
import org.midas.as.manager.execution.ServiceWrapper;
import org.midas.as.manager.execution.ServiceWrapperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import sacip.sti.dataentities.Student;

public class RecommenderAgent extends Agent {

private static Logger LOG = LoggerFactory.getLogger(AgentServer.class);

@Override
public void provide(String service, Map in, List out) throws ServiceException {
// TODO Auto-generated method stub
if (service.equals("getRecommendedExercises")) {
try {
String aluno = (String) in.get("aluno");
List grupo = buscarGrupos(aluno);
String exercicio = encontrarExercicio(grupo, aluno);
out.add(exercicio);
} catch (Exception e) {
throw new ServiceException("Não foi possível pegar o exercício recomendado", e);
}

switch (service)
{
case "getRecommendedContent":
out.add(getConteudosRecomendados((List<Student>)in.get("grupo"), (Student)in.get("estudante")));
break;

default:
throw new ServiceException("Serviço "+service+" não foi implementado no agente recomendador.");
}
}

@Override
protected void lifeCycle() throws LifeCycleException, InterruptedException {
// TODO Auto-generated method stub
Board.setContextAttribute("eventState", "checkErrors");
//Board.setContextAttribute("eventState", "checkErrors");
}

private String encontrarExercicio(List<String> grupo, String aluno) {

List<String> caracteristicas = new ArrayList<>();

if(!grupo.isEmpty())
private String getConteudosRecomendados(List<Student> grupo, Student aluno) {
try
{
System.out.println("Verificando semelhanças entre alunos");

caracteristicas.add("exemplo");
}
else
List<String> caracteristicas = new ArrayList<>();

if(!grupo.isEmpty())
{
System.out.println("Verificando semelhanças entre alunos");

caracteristicas.add("exemplo");
}
else
{
caracteristicas.add(aluno.getPreferenciasAsString());
}

System.out.println("buscando caracteristicas em conteudos");

//Fazer chamada ao banco

System.out.println("retornando conteudos");

String exercicio = "";

return exercicio;
}
catch (Exception e)
{
caracteristicas.add(aluno);
LOG.error("ERRO NO PEDAGOGICAL AGENT AO SUGERIR EXERCÍCIOS", e);
e.printStackTrace();
return e.getLocalizedMessage();
}

System.out.println("buscando caracteristicas em conteudos");

//Fazer chamada ao banco

System.out.println("retornando exercício");

String exercicio = "";

return exercicio;
}

private List<String> buscarGrupos(String aluno)throws InterruptedException, ExecutionException, ServiceWrapperException
{

System.out.println("Pedindo grupo para o classificador");
ServiceWrapper serviceWrapper = require("PublicAgents", "classifyStudents");
serviceWrapper.addParameter("aluno", aluno);
List resposta = serviceWrapper.run();

return resposta;
}

}

0 comments on commit 17d0cf6

Please sign in to comment.