示例#1
0
        public void Gerar()
        {
            foreach (Agendamento agendamento in db.Agendamento.Where(ag => ag.Ativo).ToList())
            {
                if (PermitiGerar(agendamento))
                {
                    var acesso = db.AcessoBaseRh.FirstOrDefault();

                    //Deve conter informações para acesso na base RH e deve ter os atributos da árvore configurados
                    if (acesso != null && db.ConfiguracaoAtributo.Count(config => config.ConfiguracaoArvoreID == agendamento.ConfiguracaoArvoreID) > 0)
                    {
                        //Toda vez que integrar deve excluir a tabela e gerar novamente para buscar as novas informações
                        var configuracaoArvore = db.ConfiguracaoArvore.FirstOrDefault(config => config.ID == agendamento.ConfiguracaoArvoreID);
                        TabelaTemporaria.Excluir(configuracaoArvore.ID);
                        configuracaoArvore.Tabela          = TabelaTemporaria.Gerar(configuracaoArvore.Sql, configuracaoArvore.ID, acesso.RetornaStringConexao());
                        db.Entry(configuracaoArvore).State = EntityState.Modified;
                        db.SaveChanges();

                        RodarArvore(agendamento.ConfiguracaoArvoreID);
                        agendamento.UltimaExecucao  = DateTime.Now;
                        db.Entry(agendamento).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
            }
        }
示例#2
0
        private void RodarArvore(int configuracaoArvoreId)
        {
            var    atributos          = db.ConfiguracaoAtributo.Where(config => config.ConfiguracaoArvoreID == configuracaoArvoreId).ToList();
            string classeMeta         = atributos[0].ClasseMeta;
            var    configuracaoArvore = db.ConfiguracaoArvore.FirstOrDefault(configArvore => configArvore.ID == configuracaoArvoreId);

            //Gerar a árvore
            List <Atributo> atrs = new List <Atributo>();

            foreach (var atr in atributos)
            {
                atrs.Add(new Atributo {
                    Nome = atr.Nome, TipoAtributo = atr.Tipo, Legenda = atr.Legenda
                });
            }

            TabelaTemporaria.PreencherAtributos(atrs, configuracaoArvoreId);

            C45 c45 = new C45();

            if (configuracaoArvore.Poda > 0)
            {
                c45.Poda = configuracaoArvore.Poda;
            }
            c45.Calcular(classeMeta, atrs);

            ArvoreGerada arvoreGerada = new ArvoreGerada();

            arvoreGerada.ConfiguracaoArvoreID = configuracaoArvoreId;
            arvoreGerada.ClasseMeta           = atributos.FirstOrDefault(x => x.Nome.Equals(classeMeta)).Legenda;
            arvoreGerada.JSON           = new JavaScriptSerializer().Serialize(c45.arvore.GerarJSON());
            arvoreGerada.UsuarioGeracao = "Agendamento";
            arvoreGerada.DataGeracao    = DateTime.Now;
            var xml = new System.Xml.Serialization.XmlSerializer(c45.arvore.GetType());

            using (StringWriter textWriter = new StringWriter())
            {
                xml.Serialize(textWriter, c45.arvore);
                arvoreGerada.XML = textWriter.ToString();
            }
            var doc = new GeradorPMML().Gerar(atrs, classeMeta, c45.arvore, c45.PercentuaisClasseMeta);

            xml = new System.Xml.Serialization.XmlSerializer(doc.GetType());
            using (StringWriter textWriter = new StringWriter())
            {
                xml.Serialize(textWriter, doc);
                arvoreGerada.XmlPmml = textWriter.ToString();
            }

            if (atributos.Count(x => x.Tipo == Tipo.Mineração_de_Texto) > 0)
            {
                arvoreGerada.JsonNuvemPalavras = new JavaScriptSerializer().Serialize(TabelaTemporaria.RetornaNuvemPalavras(atributos.FirstOrDefault(x => x.Tipo == Tipo.Mineração_de_Texto).Nivel));
            }

            db.ArvoreGerada.Add(arvoreGerada);
            db.SaveChanges();
        }
        public ActionResult DeleteConfirmed(int id)
        {
            if (db.ArvoreGerada.Count(arvore => arvore.ConfiguracaoArvoreID == id) > 0)
            {
                ModelState.AddModelError("", "Já existem arvores geradas para essa configuração. Exclusão não permitida.");
            }
            else
            {
                ConfiguracaoArvore configuracaoArvore = db.ConfiguracaoArvore.Find(id);
                TabelaTemporaria.Excluir(configuracaoArvore.ID);
                db.ConfiguracaoAtributo.RemoveRange(db.ConfiguracaoAtributo.Where(atr => atr.ConfiguracaoArvoreID == id));
                db.Agendamento.RemoveRange(db.Agendamento.Where(atr => atr.ConfiguracaoArvoreID == id));
                db.ConfiguracaoArvore.Remove(configuracaoArvore);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View("Delete", db.ConfiguracaoArvore.Find(id)));
        }
        public ActionResult Create(ConfiguracaoArvore configuracaoArvore)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (db.AcessoBaseRh.Count() <= 0)
                    {
                        ModelState.AddModelError("", "Não foi realizado cadastro da conexão com a Base RH. Favor verificar.");
                    }
                    else
                    {
                        var acesso = db.AcessoBaseRh.FirstOrDefault();

                        if (!TabelaTemporaria.VerificarComando(configuracaoArvore.Sql, acesso.RetornaStringConexao()))
                        {
                            ModelState.AddModelError("", "Comando SQL possui problemas. Favor verificar.");
                        }
                        else
                        {
                            db.ConfiguracaoArvore.Add(configuracaoArvore);
                            db.SaveChanges();

                            configuracaoArvore.Tabela          = TabelaTemporaria.Gerar(configuracaoArvore.Sql, configuracaoArvore.ID, acesso.RetornaStringConexao());
                            db.Entry(configuracaoArvore).State = EntityState.Modified;
                            db.SaveChanges();

                            return(RedirectToAction("Index"));
                        }
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }

            return(View(configuracaoArvore));
        }
示例#5
0
        public ActionResult Index(IList <MineradorRH.Models.ConfiguracaoAtributo> atributos)
        {
            string classeMeta = atributos[0].ClasseMeta;

            if (string.IsNullOrEmpty(classeMeta))
            {
                ModelState.AddModelError("", "Um atributo deve ser classe meta.");
                return(View(atributos));
            }

            if (atributos.Count(x => x.Tipo == Tipo.Mineração_de_Texto) > 1)
            {
                ModelState.AddModelError("", "Árvore pode possuir apenas um atributo do tipo Mineração de texto.");
                return(View(atributos));
            }

            if (ModelState.IsValid)
            {
                foreach (var atributo in atributos.Where(atr => atr.ID > 0))
                {
                    db.Entry(atributo).State = EntityState.Modified;
                }

                foreach (var atributo in atributos.Where(atr => atr.ID <= 0))
                {
                    db.ConfiguracaoAtributo.Add(atributo);
                }

                db.SaveChanges();

                int arvoreID           = atributos[0].ConfiguracaoArvoreID;
                var configuracaoArvore = db.ConfiguracaoArvore.FirstOrDefault(configArvore => configArvore.ID == arvoreID);

                //Gerar a árvore
                List <Atributo> atrs = new List <Atributo>();
                foreach (var atr in atributos)
                {
                    atrs.Add(new Atributo {
                        Nome = atr.Nome, TipoAtributo = atr.Tipo, Legenda = atr.Legenda, Nivel = atr.Nivel
                    });
                }

                TabelaTemporaria.PreencherAtributos(atrs, arvoreID);

                C45 c45 = new C45();
                if (configuracaoArvore.Poda > 0)
                {
                    c45.Poda = configuracaoArvore.Poda;
                }
                c45.Calcular(classeMeta, atrs);

                ArvoreGerada arvoreGerada = new ArvoreGerada();
                arvoreGerada.ConfiguracaoArvoreID = arvoreID;
                arvoreGerada.ClasseMeta           = atributos.FirstOrDefault(x => x.Nome.Equals(classeMeta)).Legenda;
                arvoreGerada.JSON           = new JavaScriptSerializer().Serialize(c45.arvore.GerarJSON());
                arvoreGerada.UsuarioGeracao = User.Identity.Name;
                arvoreGerada.DataGeracao    = DateTime.Now;
                var xml = new System.Xml.Serialization.XmlSerializer(c45.arvore.GetType());
                using (StringWriter textWriter = new StringWriter())
                {
                    xml.Serialize(textWriter, c45.arvore);
                    arvoreGerada.XML = textWriter.ToString();
                }
                var doc = new GeradorPMML().Gerar(atrs, classeMeta, c45.arvore, c45.PercentuaisClasseMeta);
                xml = new System.Xml.Serialization.XmlSerializer(doc.GetType());
                using (StringWriter textWriter = new StringWriter())
                {
                    xml.Serialize(textWriter, doc);
                    arvoreGerada.XmlPmml = textWriter.ToString();
                }

                if (atributos.Count(x => x.Tipo == Tipo.Mineração_de_Texto) > 0)
                {
                    arvoreGerada.JsonNuvemPalavras = new JavaScriptSerializer().Serialize(TabelaTemporaria.RetornaNuvemPalavras(atributos.FirstOrDefault(x => x.Tipo == Tipo.Mineração_de_Texto).Nivel));
                }

                db.ArvoreGerada.Add(arvoreGerada);
                db.SaveChanges();

                return(View("Grafico", arvoreGerada));
            }

            return(View(atributos));
        }