diff --git a/src/main/java/sacip/sti/agents/InterfaceAgent.java b/src/main/java/sacip/sti/agents/InterfaceAgent.java index bc6d229..48b1930 100644 --- a/src/main/java/sacip/sti/agents/InterfaceAgent.java +++ b/src/main/java/sacip/sti/agents/InterfaceAgent.java @@ -4,6 +4,8 @@ import java.util.Map; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import org.midas.as.AgentServer; import org.midas.as.agent.board.Message; @@ -76,11 +78,15 @@ public String editarConta(String name) { @PostMapping("/conteudos") @ResponseBody - public String criaNovoConteudo(@RequestBody Content conteudo) { + public String criaNovoConteudo(@RequestBody JsonNode conteudo) { try { ServiceWrapper wrapper = AgentServer.require("SACIP", "createContent"); - wrapper.addParameter("conteudo", conteudo); + String contxt= conteudo.get("conteudo").toString(); + Content content = new ObjectMapper().readValue(contxt, Content.class); + wrapper.addParameter("conteudo", content); + wrapper.addParameter("conteudoRelacionado", conteudo.get("conteudoRelacionado").asText(null)); + wrapper.addParameter("valorRelacao", conteudo.get("valorRelacao").asInt(0)); List run = wrapper.run(); return run.toString(); } catch (Exception e) { diff --git a/src/main/java/sacip/sti/agents/PedagogicalAgent.java b/src/main/java/sacip/sti/agents/PedagogicalAgent.java index c2b3510..f5c5054 100644 --- a/src/main/java/sacip/sti/agents/PedagogicalAgent.java +++ b/src/main/java/sacip/sti/agents/PedagogicalAgent.java @@ -15,22 +15,62 @@ import org.slf4j.LoggerFactory; import sacip.Launcher; +import sacip.sti.dataentities.Content; import sacip.sti.dataentities.Student; public class PedagogicalAgent extends Agent implements MessageListener{ - List alunosOnline = new ArrayList<>(); private String instancia; private static Logger LOG = LoggerFactory.getLogger(AgentServer.class); private Student student; + List trilha = new ArrayList<>(); public PedagogicalAgent() { super(); this.instancia = Launcher.instancia; + montarAlunoExemplo(); + registrarConteudosDaTrilhaDoAluno(); + } + + private void montarAlunoExemplo() + { List preferencias = new ArrayList<>(); preferencias.add("Animação"); preferencias.add("Filmes"); this.student = new Student("Adson", "123456", "link", "masculino", 24, "bacharelado", preferencias); + List trilha = new ArrayList(){{ + add("JogoDaVelha"); + add("DesenhandoThor"); + }}; + this.student.setTrilha(trilha); + } + + private void registrarConteudosDaTrilhaDoAluno() + { + try + { + ServiceWrapper buscarConteudos = require("SACIP", "findContents"); + buscarConteudos.addParameter("name", this.student.getTrilha().toArray()); + List resultado = buscarConteudos.run(); + if(resultado.get(0) instanceof List) + { + List trilhaConteudos = (List) resultado.get(0); + for (String nome : this.student.getTrilha()) { + for (Content content : trilhaConteudos) { + if(content.getName().equals(nome)) + { + trilha.add(content); + continue; + } + } + } + } + } + catch (Exception e) + { + e.printStackTrace(); + LOG.error("Não conseguiu gerar a trilha", e); + } } @Override @@ -73,6 +113,7 @@ private String suggestContent() ServiceWrapper servicoGetContent = require("SACIP", "getRecommendedContent"); servicoGetContent.addParameter("estudante", getAluno()); servicoGetContent.addParameter("grupo", grupo); + servicoGetContent.addParameter("trilha", this.trilha); List resultado = servicoGetContent.run(); if(resultado.isEmpty()) { @@ -97,4 +138,12 @@ private Student getAluno() return this.student; } + public List getTrilha() { + return this.trilha; + } + + public void setTrilha(List trilha) { + this.trilha = trilha; + } + } diff --git a/src/main/java/sacip/sti/agents/RecommenderAgent.java b/src/main/java/sacip/sti/agents/RecommenderAgent.java index c68f965..44163d1 100644 --- a/src/main/java/sacip/sti/agents/RecommenderAgent.java +++ b/src/main/java/sacip/sti/agents/RecommenderAgent.java @@ -27,7 +27,7 @@ public void provide(String service, Map in, List out) throws ServiceException { switch (service) { case "getRecommendedContent": - out.add(getConteudosRecomendados((List)in.get("grupo"), (Student)in.get("estudante"))); + out.add(getConteudosRecomendados((List)in.get("grupo"), (Student)in.get("estudante"), (List)in.get("trilha"))); break; default: @@ -40,7 +40,7 @@ protected void lifeCycle() throws LifeCycleException, InterruptedException { //Board.setContextAttribute("eventState", "checkErrors"); } - private String getConteudosRecomendados(List grupo, Student aluno) { + private String getConteudosRecomendados(List grupo, Student aluno, List trilha) { List preferenciasAluno = aluno.getPreferencias(); try @@ -57,7 +57,20 @@ private String getConteudosRecomendados(List grupo, Student aluno) { { caracteristicas.addAll(preferenciasAluno); } - + + //Verificar os tópicos e níveis que o aluno utilizou + + //Fazer chamada ao banco buscando os conteúdos desses níveis + + //Verificar se há algum tópico faltante em um dos níveis feitos do aluno (guardar níveis completados?) + + //recomendar os tópicos de níveis mais baixos. + + //pegar os conteúdos desse tópico + + //filtrar pelos seguintes + + //Fazer chamada ao banco ServiceWrapper wrapper = require("SACIP", "getContentByTags"); wrapper.addParameter("tags", caracteristicas); @@ -83,8 +96,12 @@ public int compare(Content o1, Content o2) { }; for (Content content : conteudos) { + if(!content.getComplexity().equals(aluno.getNivelEducacional())) + { + content.pontos-=100; + } content.pontos += calculateTagPoints(content.getTags(), preferenciasAluno); - content.pontos += calculateDistancePoints(aluno.getTrilha(), content); + content.pontos += calculateDistancePoints(trilha, content); sortedContent.add(content); } @@ -116,15 +133,26 @@ private int calculateTagPoints(List tagsConteudo, List preferenc return pontos; } - private int calculateDistancePoints(List trilha, Content conteudo) + private int calculateDistancePoints(List trilha, Content conteudo) { int pontos = 0; ListIterator li = trilha.listIterator(trilha.size()); while(li.hasPrevious()) { - String contTrilha = (String) li.previous(); + Content contTrilha = (Content) li.previous(); } return pontos; } + + private int dificuldadeMedia(List trilha) + { + int media = 0; + + for (Content content : trilha) { + media+=content.getDifficulty(); + } + + return media/trilha.size(); + } } diff --git a/src/main/java/sacip/sti/components/DBConnection.java b/src/main/java/sacip/sti/components/DBConnection.java index 98dc8c8..4aa7b3c 100644 --- a/src/main/java/sacip/sti/components/DBConnection.java +++ b/src/main/java/sacip/sti/components/DBConnection.java @@ -74,10 +74,10 @@ public void provide(String service, Map in, List out) throws ServiceException { break; case "createContent": - out.add(createContent((Content)in.get("conteudo"))); + out.add(createContent((Content)in.get("conteudo"), (String)in.get("conteudoRelacionado"), (int)in.get("valorRelacao"))); break; - case "findContent": + case "findContents": out.add(getContents(in)); break; @@ -116,6 +116,7 @@ private Content instanceContent(Map in) { try { return new Content((String)in.get("name"), + ((Long)in.get("level")).intValue(), (String)in.get("topic"), ((Long)in.get("difficulty")).intValue(), (String)in.get("complexity"), @@ -277,13 +278,26 @@ private Object getUsers(Map attributes) { try { //Cria query necessária - StringBuilder query = new StringBuilder("MATCH (n:USER {"); + StringBuilder query = new StringBuilder("MATCH (n:USER)"); for (Map.Entry entry : attributes.entrySet()) { - query.append(entry.getKey()+": $"+entry.getKey()); - query.append(", "); + query.append("\nWHERE n."); + query.append(entry.getKey()); + query.append(" IN ["); + if(entry.getValue() instanceof String[]) + { + String[] attrs = (String[]) entry.getValue(); + for (String attr : attrs) { + query.append("'"+attr+"',"); + } + query.deleteCharAt(query.length()-1); + } + else + { + query.append("'"+entry.getValue()+"'"); + } + query.append("]"); } - query.delete(query.length()-2, query.length()-1); - query.append("}) RETURN n"); + query.append("\nRETURN n"); //realisa a busca var result = cypher.readquery(query.toString(), attributes); @@ -357,30 +371,56 @@ private String deleteUser(String name) } } - private String createContent(Content content) + private String createContent(Content content, String relatedName, int relationValue) { try { - var result = cypher.writequery("CREATE (c:CONTENT " - +"{" - +"name: $name," - +"topic: $topic," - +"difficulty: $difficulty," - +"complexity: $complexity," - +"exercise: $exercise," - +"taxonomy: $taxonomy," - +"tags: $tags," - +"link: $link" - +"})", - Map.of("name", content.getName(), - "topic", content.getTopic(), - "difficulty", content.getDifficulty(), - "complexity", content.getComplexity(), - "exercise", content.getExercise(), - "taxonomy", content.getTaxonomy(), - "tags", content.getTags(), - "link", content.getLink() - )); + StringBuilder query = new StringBuilder(); + + if(relatedName!=null) + query.append("MATCH (n:CONTENT {name: $relatedName})\n"); + + query.append("CREATE (c:CONTENT " + +"{" + +"name: $name," + +"level: $level," + +"topic: $topic," + +"difficulty: $difficulty," + +"complexity: $complexity," + +"exercise: $exercise," + +"taxonomy: $taxonomy," + +"tags: $tags," + +"link: $link" + +"})"); + + + HashMap map = new HashMap<>(); + map.putAll(Map.of("name", content.getName(), + "level", content.getLevel(), + "topic", content.getTopic(), + "difficulty", content.getDifficulty(), + "complexity", content.getComplexity(), + "exercise", content.getExercise(), + "taxonomy", content.getTaxonomy(), + "tags", content.getTags(), + "link", content.getLink() + )); + + if(relatedName!=null) + { + if(relationValue>0) + { + query.append("-[:RELATED {dPoints: $relationValue}]->(n)"); + } + else + { + query.append("<-[:RELATED {dPoints: $relationValue}]-(n)"); + } + map.put("relatedName", relatedName); + map.put("relationValue", relationValue); + } + + var result = cypher.writequery(query.toString(),map); return result.toString(); } catch (Exception e) @@ -394,13 +434,26 @@ private Object getContents(Map attributes) { try { //Cria query necessária - StringBuilder query = new StringBuilder("MATCH (n:CONTENT {"); + StringBuilder query = new StringBuilder("MATCH (n:CONTENT)"); for (Map.Entry entry : attributes.entrySet()) { - query.append(entry.getKey()+": $"+entry.getKey()); - query.append(", "); + query.append("\nWHERE n."); + query.append(entry.getKey()); + query.append(" IN ["); + if(entry.getValue() instanceof String[]) + { + String[] attrs = (String[]) entry.getValue(); + for (String attr : attrs) { + query.append("'"+attr+"',"); + } + query.deleteCharAt(query.length()-1); + } + else + { + query.append("'"+entry.getValue()+"'"); + } + query.append("]"); } - query.delete(query.length()-2, query.length()-1); - query.append("}) RETURN n"); + query.append("\nRETURN n"); //realisa a busca var result = cypher.readquery(query.toString(), attributes); diff --git a/src/main/java/sacip/sti/dataentities/Content.java b/src/main/java/sacip/sti/dataentities/Content.java index 812d300..43cf0e1 100644 --- a/src/main/java/sacip/sti/dataentities/Content.java +++ b/src/main/java/sacip/sti/dataentities/Content.java @@ -14,6 +14,7 @@ public class Content extends MidasBean{ private String taxonomy; private List tags; private String link; + private int level; public int pontos = 0; @@ -21,7 +22,8 @@ public Content() { super(); } - public Content(String name, String topic, int difficulty, String complexity, boolean exercise, String taxonomy, List tags, String link) { + + public Content(String name, int level, String topic, int difficulty, String complexity, boolean exercise, String taxonomy, List tags, String link) { this.name = name; this.topic = topic; this.difficulty = difficulty; @@ -30,6 +32,7 @@ public Content(String name, String topic, int difficulty, String complexity, boo this.taxonomy = taxonomy; this.tags = tags; this.link = link; + this.level = level; } public String getName() { @@ -114,10 +117,19 @@ public void setLink(String link) { this.link = link; } + public int getLevel() { + return this.level; + } + + public void setLevel(int level) { + this.level = level; + } + @Override public String toString() { return "{" + " name:'" + getName() + "'" + + ", level:'" + getLevel() + "'" + ", topic:'" + getTopic() + "'" + ", difficulty:" + getDifficulty() + "" + ", complexity:'" + getComplexity() + "'" +