Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
calculate_python_expression_pt [2019/09/11 19:00] francisco created |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Suporte ao Python ====== | ||
- | |||
- | O suporte ao Python (atualmente na versão 3.7) está presente no ramo "Python" nos repositórios (em cima do ramo "Tasks"). Para compilar o ramo, é necessário ter as dependências do Python no dff_dependencies_windows. A versão contendo as dependências pode ser baixada em [[http://csr.ufmg.br/~romulo/dff_dependencies_windows_python.7z]]. Para execução, é necessário ter a pasta "PyEnvironment" dentro da pasta do Dinamica, o PyEnvironment também pode ser obtido em [[http://csr.ufmg.br/~romulo/PyEnvironment.7z]]. | ||
- | |||
- | === Exemplo: Calculate Python Expression === | ||
- | |||
- | Uma expressão que pode ser usada: | ||
- | <code> | ||
- | dinamica.package("numpy") | ||
- | |||
- | a = numpy.arange(15).reshape(3, 5) | ||
- | print(a) | ||
- | |||
- | print(dinamica.inputs) | ||
- | for row in dinamica.inputs["t1"]: | ||
- | print(row) | ||
- | |||
- | for row in dinamica.inputs["t2"]: | ||
- | print(row) | ||
- | |||
- | dinamica.outputs["teste"] = 2 | ||
- | dinamica.outputs["teste2"] = 2.5 | ||
- | dinamica.outputs["teste3"] = 'a' | ||
- | dinamica.outputs["outraSaida"] = "yoyo" | ||
- | dinamica.outputs["tabela"] = dinamica.prepareTable(dinamica.inputs["t1"], 3) | ||
- | dinamica.outputs["lut"] = dinamica.prepareLookupTable(dinamica.inputs["t2"]) | ||
- | </code> | ||
- | |||
- | onde: | ||
- | <code> | ||
- | dinamica.package("numpy") | ||
- | </code> | ||
- | Pede ao PIP que instale o pacote numpy e faça o import. | ||
- | \\ | ||
- | <code> | ||
- | print(dinamica.inputs) | ||
- | </code> | ||
- | Imprime o vetor com todas as entradas passadas pelo Dinamica. | ||
- | \\ | ||
- | <code> | ||
- | dinamica.outputs["teste2"] = 2.5 | ||
- | </code> | ||
- | Coloca uma saída na struct com nome "teste2", contendo uma double com valor 2.5 | ||
- | \\ | ||
- | <code> | ||
- | dinamica.outputs["tabela"] = dinamica.prepareTable(dinamica.inputs["t1"], 3) | ||
- | </code> | ||
- | Coloca uma saída na struct com nome "tabela", contendo uma tabela com 3 colunas de chave. Essa função não é necessária se a tabela já estiver com os '*' nos nomes da coluna (portanto o usuário poderia fazer apenas dinamica.outputs["teste2"] = dinamica.inputs["t1"]). Toda tabela no Python é tratada como uma lista de listas, onde cada lista interna corresponde a uma **linha** da tabela. | ||
- | \\ | ||
- | <code> | ||
- | dinamica.outputs["lut"] = dinamica.prepareLookupTable(dinamica.inputs["t2"]) | ||
- | </code> | ||
- | Coloca uma saída na struct com nome "lut", contendo uma LookupTable (Não existe outra forma de passar uma LookupTable de volta). | ||
- | |||
- | ---- | ||
- | |||
- | === Calculate Python Utilities === | ||
- | |||
- | ^ Utility Name ^ Description ^ Parameters ^ | ||
- | | prepareTable | It returns the table prepared to output. Input Table has to be in the form [[[header1...headerN][line1]...[lineM]]] where the first list contains the headers of the table and all the other lists are lines containing the data. | list(list) inputTable, int numKeys | | ||
- | | prepareLookupTable | It returns the lookup table prepared to output. The lut has to be in the form [[[key,value][line1]...[lineM]]] where the first list contains the headers of the table and all the other lists are lines containing the data. | list(list) lut | | ||
- | | toTable | It returns a valid representation of dinamica table to output. Input Table can be: [[[header1...headerN][line1]...[lineM]]] where the first list contains the headers of the table and all the other lists are lines containing the data; {header1: [valuesOfColumn1], header2: [valuesOfColumn2]...} where the valuesOfComlumn# are all values of that column in table; [[(header1...headerN)(line)...(lineM)]] where the first tuple contains the headers of the table and all the other tuples are lines containing the data; [value1, value2, ..., valueN], those are the values for a lookup table with sequential key; pandas.Dataframe is a commom structure table used to manipulate CSVs; numpy.array is a commom structure for matrix, that can be tables as well. The first line of matrix needs to be the table header. | list(list);dict(list);list(tuple);list;pandas.DataFrame;numpy.array inputTable | | ||