예제 #1
0
    def get_gevts_templates(self, gevts_templates):
        gevts_templantes_executar = {}
        if type(gevts_templates) is list:
            for gevt_template in gevts_templates:
                separacao = gevt_template.split('#')
                gevt_path = InOut.ajuste_path(separacao[0])
                gevt_file_name = (gevt_path.split(InOut.barra())[-1]).split('.')[0]
                if len(separacao) <= 1:
                    self.log(tipo=EnumLogStatus.ERRO_FATAL,
                             texto=f"Precisa ser informado o template para o GEVT [{gevt_template}]")
                template_path = InOut.ajuste_path(separacao[1])
                template_file_name = (template_path.split(InOut.barra())[-1]).split('.')[0]
                template_prob = 1 / len(gevts_templates)
                if len(separacao) > 2:
                    template_prob = separacao[2]

                    gevts_templantes_executar[f'{gevt_file_name}_{template_file_name}'] = {'gevt_path': gevt_path,
                                                                                           'gevt_file_name': gevt_file_name,
                                                                                           'template_path': template_path,
                                                                                           'template_file_name': template_file_name,
                                                                                           'template_prob': template_prob}
        else:
            separacao = gevts_templates.split('#')
            gevt_path = InOut.ajuste_path(separacao[0])
            gevt_file_name = (gevt_path.split(InOut.barra())[-1]).split('.')[0]
            if len(separacao) <= 1:
                self.log(tipo=EnumLogStatus.ERRO_FATAL,
                         texto=f"Precisa ser informado o TPL para o GEVT [{gevts_templates}]")
            template_path = InOut.ajuste_path(separacao[1])
            template_file_name = (template_path.split(InOut.barra())[-1]).split('.')[0]
            template_prob = 1
            if len(separacao) > 2 and int(InOut.ajusta_entrada(separacao[2])) != int(1):
                self.log(tipo=EnumLogStatus.ERRO, texto=f"Não faz sentido probabilidade diferente de 1 quando há somente um template.")

            gevts_templantes_executar[f'{gevt_file_name}_{template_file_name}'] = {'gevt_path': gevt_path,
                                                                                   'gevt_file_name': gevt_file_name,
                                                                                   'template_path': template_path,
                                                                                   'template_file_name': template_file_name,
                                                                                   'template_prob': template_prob}
        return gevts_templantes_executar
예제 #2
0
    def _executar_fop(self, buffer, solucoes):
        unipro = buffer['unipro']
        if len(unipro) == 0:
            return solucoes

        unieco_path = InOut.ajuste_path(
            f"{self._path_projeto}/{self._uniecos[list(self._uniecos.keys())[0]]['unieco_path']}"
        )
        unieco_file = ((unieco_path.split(
            InOut.barra())[-1]).split("#")[0]).split(".")[0]
        cont = f'*PROJECT aux\n' \
               f'*SIMULATOR {self._contexto.get_atributo(EnumAtributo.SIMULADOR_NOME)} {self._contexto.get_atributo(EnumAtributo.SIMULADOR_VERSAO)}\n' \
               f'*UNIECO {unieco_path}\n' \
               f'*ECO_REFERENCE_DATE {self._contexto.get_atributo(EnumAtributo.AVALIACAO_MERO_ECO_REFERENCE_DATE)}\n' \
               f'*MODEL_LIST\n' \
               f'ID\n'

        iteracaoes = {}
        ids = {}
        for prefixo in unipro.keys():
            cont += f'{prefixo}\n'
            iteracaoes[unipro[prefixo]['iteracao']] = True
            ids[unipro[prefixo]['iteracao']] = True

        iteracaoes_str = ""
        ids_str = ""
        for iteracao in iteracaoes.keys():
            iteracaoes_str = f'{iteracaoes_str}_{iteracao}'
        for id in ids.keys():
            ids_str = f'{ids_str}_{id}'

        cont += self._adiciona_discretizacao_plat()

        path = InOut.ajuste_path(
            f'{self._path_projeto}/{self._path_simulacao}/{self._qualificador}_it{iteracaoes_str}_id{ids_str}_fop'
        )
        if not TXT().salvar(path_arquivo=f'{path}.mero', conteudo=cont):
            self.log(tipo=EnumLogStatus.ERRO,
                     texto=f'Erro ao escrever aquivo {path}.')
            keys = deepcopy(list(unipro.keys()))
            for ii in range(len(keys)):
                prefixo = keys[ii]
                iteracao = unipro[prefixo]['iteracao']
                id = unipro[prefixo]['id']
                self.log(
                    tipo=EnumLogStatus.ERRO,
                    texto=
                    f'Erro ao escrever fop.mero para a solucao  {prefixo}) iteracao [{iteracao}] e id [{id}].'
                )
                solucoes.get_solucao_by_iteracao_id(
                    iteracao=iteracao, id=id).has_erro = "Escrever_FOP.Mero"
            return solucoes
        else:
            ler_resultados = {}
            mero_executavel = InOut.ajuste_path(
                self._contexto.get_atributo(
                    EnumAtributo.AVALIACAO_MERO_EXECUTAVEL))

            thread_argument = ''
            if self._contexto.tem_atributo(
                    EnumAtributo.AVALIACAO_MERO_FOP_MULTI_THREAD):
                if self._contexto.get_atributo(
                        EnumAtributo.AVALIACAO_MERO_FOP_MULTI_THREAD):
                    thread_argument = ' --multi-thread'

            comando = f'{mero_executavel} fop -i {path}.mero -t Local -s Local -p 1 -n 1 -q LocalQueue -f XML --no-wait -r{thread_argument}'
            self.log(texto=f'Executando comando [{comando}]')
            self.log(texto=f'Aguarde ...')

            retorno_terminal = Terminal().run(comando)

            path_fop_eof = f"{path}.eof.csv"
            if not os.path.isfile(path_fop_eof):
                path_fop_eof = f"{path}_{unieco_file}.eof.csv"

            if (retorno_terminal is
                    False) or (not os.path.isfile(path_fop_eof)):
                keys = deepcopy(list(unipro.keys()))
                for ii in range(len(keys)):
                    prefixo = keys[ii]
                    iteracao = unipro[prefixo]['iteracao']
                    id = unipro[prefixo]['id']
                    self.log(
                        tipo=EnumLogStatus.ERRO,
                        texto=
                        f'Erro ao executar FOP para a solucao  {prefixo}) iteracao [{iteracao}] e id [{id}].'
                    )
                    solucoes.get_solucao_by_iteracao_id(
                        iteracao=iteracao, id=id).has_erro = "Executando_FOP"
                return solucoes

            keys = deepcopy(list(unipro.keys()))
            for ii in range(len(keys)):
                prefixo = keys[ii]
                iteracao = unipro[prefixo]['iteracao']
                id = unipro[prefixo]['id']
                self.log(
                    texto=
                    f'Fop da solucao [{prefixo}] iteracao [{iteracao}] e id [{id}] foi calculada com sucesso.'
                )
                ler_resultados[prefixo] = unipro[prefixo]

            solucoes = self._ler_dados_economicos(solucoes, path_fop_eof,
                                                  ler_resultados,
                                                  EnumValues.VPL.name)

        return solucoes