Skip to content

Commit

Permalink
captura de dados
Browse files Browse the repository at this point in the history
  • Loading branch information
AdsonEsteves committed Mar 11, 2021
1 parent f9c89d3 commit 4d06d6b
Show file tree
Hide file tree
Showing 9 changed files with 535 additions and 97 deletions.
7 changes: 7 additions & 0 deletions UserAgentsServices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
<scope>mas</scope>
<organization>SACIP</organization>
</service>
<service>
<name>atualizarTrilha</name>
<description>atualiza a trilha do usuario com um novo conteudo</description>
<entity>PedagogicalAgent</entity>
<scope>mas</scope>
<organization>SACIP</organization>
</service>

<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
<!-- SACIP Tracking Agent -->
Expand Down
Binary file modified board.bkp
Binary file not shown.
13 changes: 13 additions & 0 deletions src/main/java/sacip/rest/RestTutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,18 @@ public String getConteudos(@RequestBody JsonNode dados){
}
}

@PostMapping("/atualizarTrilha/{agentPort}")
public String atualizarTrilha(@PathVariable String agentPort, @RequestBody JsonNode dados){
try {
ServiceWrapper wrapper = AgentServer.require("SACIP"+agentPort, "atualizarTrilha"+agentPort);
wrapper.addParameter("nomeConteudo", dados.get("nomeConteudo").asText(""));
List run = wrapper.run();
return run.get(0).toString();
} catch (Exception e) {
LOG.error("Falhou ao atualizar trilha", e);
return "Falhou ao atualizar trilha: \n"+e.getLocalizedMessage();
}
}

}

53 changes: 36 additions & 17 deletions src/main/java/sacip/sti/agents/GrouperAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ public void provide(String service, Map in, List out) throws ServiceException {
} catch (Exception e) {

}
if (service.equals("getStudentGroups")) {
try {

} catch (Exception e) {
LOG.error("ERRO NO AGENT AGRUPADOR", e);
}
}
}

@Override
Expand All @@ -57,7 +50,7 @@ protected void lifeCycle() throws LifeCycleException, InterruptedException {
{
try
{
HashMap<Integer, List<Student>> studentGroups = findStudentGroup();
HashMap<String, List<Student>> studentGroups = findStudentGroup();
Board.setContextAttribute("StudentsGroups", studentGroups);
}
catch (Exception e) {
Expand All @@ -73,34 +66,38 @@ public static void main(String[] args) {
agent.findStudentGroup();
}

public HashMap<Integer, List<Student>> findStudentGroup()
public HashMap<String, List<Student>> findStudentGroup()
{
List<Student> estudantes = getUsers();
HashMap<Integer, List<Student>> studentGroups = new HashMap<>();
HashMap<String, List<Student>> studentGroups = new HashMap<>();
double score = 0.0;
int mean = 5;
int mean = 10;
// List<String> docs = Arrays.asList("carros animes youtube História", "comédia animes História Livros", "monstros cultura comédia Tecnologia", "Livros", "mitologia animes", "Livros matemática");
List<String> docs = new ArrayList<>();

for (Student estudante : estudantes)
{
docs.add(estudante.getPreferencias().toString().replaceAll("[,\\[\\]]", ""));
docs.add(estudante.getPreferencias().toString().replaceAll("[,\\[\\]]", "")+" "+estudante.getNivelEducacional()+" "+estudante.getGenero()+" "+grupoIdade(estudante.getIdade()));
//System.out.println(estudante.getPreferencias().toString().replaceAll("[,\\[\\]]", "")+" "+estudante.getNivelEducacional());
//docs.add(estudante.getPreferencias().toString().replaceAll("[,\\[\\]]", ""));
}
while(score<0.5)
//while(score<0.5)
{
studentGroups.clear();
Lda method = new Lda();
method.setTopicCount((estudantes.size()/mean)+1);
method.setMaxVocabularySize(20000);
method.setRemoveNumber(false);

LdaResult result = method.fit(docs);

for(Doc doc : result.documents())
{
List<TupleTwo<Integer, Double>> topTopics = doc.topTopics(1);
int key = topTopics.get(0)._1();
String key = result.topicSummary(topTopics.get(0)._1());
int studentIndex = doc.getDocIndex();

if(studentGroups.containsKey(topTopics.get(0)._1()))
if(studentGroups.containsKey(key))
{
studentGroups.get(key).add(estudantes.get(studentIndex));
}
Expand All @@ -111,15 +108,37 @@ public HashMap<Integer, List<Student>> findStudentGroup()
studentGroups.put(key, grupo);
}
score+=topTopics.get(0)._2();
//System.out.println("Doc: {"+doc.getDocIndex()+"}"+" TOP TOPIC: {"+topTopics.get(0)._1()+"}"+" SCORE: {"+topTopics.get(0)._2()+"}");
//System.out.println("Doc: {"+doc.getDocIndex()+"}"+" TOP TOPIC: {"+result.topicSummary(topTopics.get(0)._1())+"}"+" SCORE: {"+topTopics.get(0)._2()+"}");
}
score=score/docs.size();
mean++;
}
//System.out.println("Finalizou: "+studentGroups);
System.out.println("Finalizou: "+score+ " Media:"+mean + " Grupos: " +studentGroups.size());

return studentGroups;
}

private String grupoIdade(int idade)
{
if(idade<13)
{
return "menor13";
}
else if(idade<18)
{
return "13menor18";
}
else if(idade < 24)
{
return "18menor24";
}
else if(idade < 30)
{
return "24menor30";
}
return "maior30";
}

private List<Student> findStudentSimilars(Student alunoRequisitado)
{
List<Student> estudantes = getUsers();
Expand Down
98 changes: 73 additions & 25 deletions src/main/java/sacip/sti/agents/PedagogicalAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import java.util.Map;
import java.util.Map.Entry;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;

import org.midas.as.AgentServer;
import org.midas.as.agent.board.Board;
Expand All @@ -23,6 +26,7 @@
import sacip.Launcher;
import sacip.sti.dataentities.Content;
import sacip.sti.dataentities.Student;
import sacip.sti.evaluation.DataHolder;

public class PedagogicalAgent extends Agent implements MessageListener {

Expand Down Expand Up @@ -63,24 +67,34 @@ private void montarAlunoExemplo() {
}

private void registrarConteudosDaTrilhaDoAluno() {
try {
ServiceWrapper buscarConteudos = require("SACIP", "findContents");
buscarConteudos.addParameter("name",this.student.getTrilha().toArray(new String[this.student.getTrilha().size()]));
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;
if(student.getTrilha()!=null)
{
List<String> modifiedList = new ArrayList<>();
try {
ServiceWrapper buscarConteudos = require("SACIP", "findContents");
buscarConteudos.addParameter("name",this.student.getTrilha().toArray(new String[this.student.getTrilha().size()]));
List resultado = buscarConteudos.run();
if (resultado.get(0) instanceof List) {
List<Content> trilhaConteudos = (List<Content>) resultado.get(0);
trilha.clear();
for (String nome : this.student.getTrilha()) {
for (Content content : trilhaConteudos) {
if (content.getName().equals(nome)) {
trilha.add(content);
modifiedList.add(nome);
continue;
}
}
}
}
student.setTrilha(modifiedList);
} catch (Exception e) {
e.printStackTrace();
LOG.error("Não conseguiu gerar a trilha", e);
}
} catch (Exception e) {
e.printStackTrace();
LOG.error("Não conseguiu gerar a trilha", e);
}
else{
student.setTrilha(new ArrayList<String>());
}
}

Expand All @@ -95,6 +109,10 @@ public void provide(String service, Map in, List out) throws ServiceException {
out.add(new ObjectMapper().valueToTree(trilha));
break;

case "atualizarTrilha":
out.add(atualizarTrilha((String)in.get("nomeConteudo")));
break;

case "suggestContent":
out.add(suggestContent());
break;
Expand Down Expand Up @@ -132,15 +150,40 @@ public void boardChanged(Message msg) {

}

private Object atualizarTrilha(String nomeConteudo)
{
if(nomeConteudo.equals(""))
{
return new ServiceException("nome de conteudo invalido");
}

getAluno().addNovoPassoTrilha(nomeConteudo);
registrarConteudosDaTrilhaDoAluno();

try {
ServiceWrapper wrapper = require("SACIP", "editStudentListAttr");
wrapper.addParameter("name", getAluno().getName());
wrapper.addParameter("attrName", "trilha");
wrapper.addParameter("newValue", new TextNode(nomeConteudo));
return wrapper.run().get(0);
} catch (Exception e) {
LOG.error("ERRO NO TRACKING AGENT AO ENVIAR DADOS de "+trilha, e);
e.printStackTrace();
return e.getLocalizedMessage();
}
}

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

for (List<Student> group : studentGroups.values()) {
for (Student student : group) {
for (Entry<String, List<Student>> group : studentGroups.entrySet()) {
for (Student student : group.getValue()) {
if(student.getName().equals(aluno.getName()))
{
return group;
System.out.println("TOPICOS: "+group.getKey());
DataHolder.getInstance().setTopic(group.getKey());
return group.getValue();
}
}
}
Expand All @@ -152,21 +195,26 @@ private String suggestContent()
{
try
{
List<Student> studentGroup = getStudentGroup(getAluno());

List<Student> studentGroup = getStudentGroup(getAluno());

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

// List<Student> grupo = (List<Student>) servicoGetGroups.run().get(0);
List<Student> grupo = new ArrayList<>();

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


//Pedir recomendação para o recomendador
ServiceWrapper servicoGetContent = require("SACIP", "getRecommendedContent");
servicoGetContent.addParameter("estudante", getAluno());
Expand Down
Loading

0 comments on commit 4d06d6b

Please sign in to comment.