Skip to content

Commit

Permalink
lambda function
Browse files Browse the repository at this point in the history
  • Loading branch information
AdsonEsteves committed Jan 1, 2021
1 parent c1bbbd0 commit 477972c
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 32 deletions.
Binary file modified board.bkp
Binary file not shown.
4 changes: 3 additions & 1 deletion src/main/java/sacip/sti/agents/GrouperAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.github.chen0040.lda.Lda;
import com.github.chen0040.lda.LdaResult;
import org.midas.as.AgentServer;
import org.midas.as.agent.board.Board;
import org.midas.as.agent.templates.Agent;
import org.midas.as.agent.templates.LifeCycleException;
import org.midas.as.agent.templates.ServiceException;
Expand Down Expand Up @@ -57,7 +58,7 @@ protected void lifeCycle() throws LifeCycleException, InterruptedException {
try
{
HashMap<Integer, List<Student>> studentGroups = findStudentGroup();

Board.setContextAttribute("StudentsGroups", studentGroups);
}
catch (Exception e) {
LOG.error("ERRO NO CICLO DE VIDA DO GROUPER", e);
Expand Down Expand Up @@ -107,6 +108,7 @@ public HashMap<Integer, List<Student>> findStudentGroup()
else
{
List<Student> grupo = new ArrayList<>();
grupo.add(estudantes.get(studentIndex));
studentGroups.put(key, grupo);
}
score+=topTopics.get(0)._2();
Expand Down
99 changes: 69 additions & 30 deletions src/main/java/sacip/sti/agents/PedagogicalAgent.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package sacip.sti.agents;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.midas.as.AgentServer;
import org.midas.as.agent.board.Board;
import org.midas.as.agent.board.BoardException;
import org.midas.as.agent.board.Message;
import org.midas.as.agent.board.MessageListener;
import org.midas.as.agent.templates.Agent;
Expand All @@ -18,7 +22,7 @@
import sacip.sti.dataentities.Content;
import sacip.sti.dataentities.Student;

public class PedagogicalAgent extends Agent implements MessageListener{
public class PedagogicalAgent extends Agent implements MessageListener {

private String instancia;
private static Logger LOG = LoggerFactory.getLogger(AgentServer.class);
Expand All @@ -32,45 +36,41 @@ public PedagogicalAgent() {
registrarConteudosDaTrilhaDoAluno();
}

private void montarAlunoExemplo()
{
private void montarAlunoExemplo() {
List<String> preferencias = new ArrayList<>();
preferencias.add("animes");
preferencias.add("filmes");
preferencias.add("jogos");
List<String> trilha = new ArrayList<String>(){{
add("2dcznTNvej");
add("Jvp1ma0QEN");
add("s19ra6yQrd");
add("tsxlrStu9a");
add("UlGW3aVSZI");
}};
this.student = new Student("Adson", "123456", "link", "masculino", 24, "Graduação", preferencias, trilha);
preferencias.add("desenhos");
preferencias.add("dc");
preferencias.add("animais");
preferencias.add("marvel");
List<String> trilha = new ArrayList<String>() {
{
add("2dcznTNvej");
add("Jvp1ma0QEN");
add("s19ra6yQrd");
add("tsxlrStu9a");
add("UlGW3aVSZI");
}
};
this.student = new Student("l4yhU9z2bx", "123456", "link", "masculino", 24, "Graduação", preferencias, trilha);
}

private void registrarConteudosDaTrilhaDoAluno()
{
try
{
private void registrarConteudosDaTrilhaDoAluno() {
try {
ServiceWrapper buscarConteudos = require("SACIP", "findContents");
buscarConteudos.addParameter("name", this.student.getTrilha().toArray(new String[this.student.getTrilha().size()]));
buscarConteudos.addParameter("name",this.student.getTrilha().toArray(new String[this.student.getTrilha().size()]));
List resultado = buscarConteudos.run();
if(resultado.get(0) instanceof List)
{
if (resultado.get(0) instanceof List) {
List<Content> trilhaConteudos = (List<Content>) resultado.get(0);
for (String nome : this.student.getTrilha()) {
for (Content content : trilhaConteudos) {
if(content.getName().equals(nome))
{
if (content.getName().equals(nome)) {
trilha.add(content);
continue;
}
}
}
}
}
catch (Exception e)
{
} catch (Exception e) {
e.printStackTrace();
LOG.error("Não conseguiu gerar a trilha", e);
}
Expand All @@ -86,9 +86,9 @@ public void provide(String service, Map in, List out) throws ServiceException {
case "suggestContent":
out.add(suggestContent());
break;

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

Expand All @@ -100,22 +100,61 @@ protected void lifeCycle() throws LifeCycleException, InterruptedException {
@Override
public void boardChanged(Message msg) {
// TODO Auto-generated method stub

}

private List<Student> getStudentGroup(Student aluno) throws BoardException
{
HashMap<Integer, List<Student>> studentGroups = (HashMap<Integer, List<Student>>) Board.getContextAttribute("StudentsGroups");

for (List<Student> group : studentGroups.values()) {
for (Student student : group) {
if(student.getName().equals(aluno.getName()))
{
return group;
}
}
}

return new ArrayList<>();
}

private String suggestContent()
{
try
{
List<Student> studentGroup = getStudentGroup(getAluno());


//Pegar grupo de alunos
ServiceWrapper servicoGetGroups = require("SACIP", "getStudentGroups");
servicoGetGroups.addParameter("estudante", getAluno());
List grupo = servicoGetGroups.run();
List<Student> grupo = (List<Student>) servicoGetGroups.run().get(0);

studentGroup.forEach(s -> {
Student student = grupo.stream().filter(g -> g.getName().equals(s.getName()))
.findAny().orElseGet(()->null);
if(student==null)
grupo.add(s);
});

// for (Student student : studentGroup) {
// boolean has = false;
// for (Student student2 : grupo) {
// if(student.getName().equals(student2.getName()))
// {
// has = true;
// break;
// }
// }
// if(!has)
// grupo.add(student);
// }

//Pedir recomendação para o recomendador
ServiceWrapper servicoGetContent = require("SACIP", "getRecommendedContent");
servicoGetContent.addParameter("estudante", getAluno());
servicoGetContent.addParameter("grupo", grupo.get(0));
servicoGetContent.addParameter("grupo", grupo);
servicoGetContent.addParameter("trilha", this.trilha);
List resultado = servicoGetContent.run();
if(resultado.isEmpty())
Expand Down
1 change: 0 additions & 1 deletion src/main/java/sacip/sti/utils/BoltCypherExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ private Session getSession() {
}

static Object convert(Value value) {
System.out.println("CONVERTENDO");
switch (value.type().name()) {
case "PATH":
return value.asList(BoltCypherExecutor::convert);
Expand Down

0 comments on commit 477972c

Please sign in to comment.