Skip to content

Commit

Permalink
Conteúdos com níveis
Browse files Browse the repository at this point in the history
  • Loading branch information
AdsonEsteves committed Dec 10, 2020
1 parent e282676 commit 3972808
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 43 deletions.
10 changes: 8 additions & 2 deletions src/main/java/sacip/sti/agents/InterfaceAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
51 changes: 50 additions & 1 deletion src/main/java/sacip/sti/agents/PedagogicalAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> alunosOnline = new ArrayList<>();
private String instancia;
private static Logger LOG = LoggerFactory.getLogger(AgentServer.class);
private Student student;
List<Content> trilha = new ArrayList<>();

public PedagogicalAgent() {
super();
this.instancia = Launcher.instancia;
montarAlunoExemplo();
registrarConteudosDaTrilhaDoAluno();
}

private void montarAlunoExemplo()
{
List<String> preferencias = new ArrayList<>();
preferencias.add("Animação");
preferencias.add("Filmes");
this.student = new Student("Adson", "123456", "link", "masculino", 24, "bacharelado", preferencias);
List<String> trilha = new ArrayList<String>(){{
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<Content> trilhaConteudos = (List<Content>) 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
Expand Down Expand Up @@ -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())
{
Expand All @@ -97,4 +138,12 @@ private Student getAluno()
return this.student;
}

public List<Content> getTrilha() {
return this.trilha;
}

public void setTrilha(List<Content> trilha) {
this.trilha = trilha;
}

}
40 changes: 34 additions & 6 deletions src/main/java/sacip/sti/agents/RecommenderAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void provide(String service, Map in, List out) throws ServiceException {
switch (service)
{
case "getRecommendedContent":
out.add(getConteudosRecomendados((List<Student>)in.get("grupo"), (Student)in.get("estudante")));
out.add(getConteudosRecomendados((List<Student>)in.get("grupo"), (Student)in.get("estudante"), (List<Content>)in.get("trilha")));
break;

default:
Expand All @@ -40,7 +40,7 @@ protected void lifeCycle() throws LifeCycleException, InterruptedException {
//Board.setContextAttribute("eventState", "checkErrors");
}

private String getConteudosRecomendados(List<Student> grupo, Student aluno) {
private String getConteudosRecomendados(List<Student> grupo, Student aluno, List<Content> trilha) {

List<String> preferenciasAluno = aluno.getPreferencias();
try
Expand All @@ -57,7 +57,20 @@ private String getConteudosRecomendados(List<Student> 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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -116,15 +133,26 @@ private int calculateTagPoints(List<String> tagsConteudo, List<String> preferenc
return pontos;
}

private int calculateDistancePoints(List<String> trilha, Content conteudo)
private int calculateDistancePoints(List<Content> 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<Content> trilha)
{
int media = 0;

for (Content content : trilha) {
media+=content.getDifficulty();
}

return media/trilha.size();
}
}
119 changes: 86 additions & 33 deletions src/main/java/sacip/sti/components/DBConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -277,13 +278,26 @@ private Object getUsers(Map<String, Object> attributes) {
try
{
//Cria query necessária
StringBuilder query = new StringBuilder("MATCH (n:USER {");
StringBuilder query = new StringBuilder("MATCH (n:USER)");
for (Map.Entry<String, Object> 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);
Expand Down Expand Up @@ -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<String, Object> 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)
Expand All @@ -394,13 +434,26 @@ private Object getContents(Map<String, Object> attributes)
{
try {
//Cria query necessária
StringBuilder query = new StringBuilder("MATCH (n:CONTENT {");
StringBuilder query = new StringBuilder("MATCH (n:CONTENT)");
for (Map.Entry<String, Object> 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);
Expand Down
Loading

0 comments on commit 3972808

Please sign in to comment.