diff --git a/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/.ipynb_checkpoints/components-01-catalog-checkpoint.ipynb b/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/.ipynb_checkpoints/components-01-catalog-checkpoint.ipynb new file mode 100644 index 000000000..c7f391b30 --- /dev/null +++ b/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/.ipynb_checkpoints/components-01-catalog-checkpoint.ipynb @@ -0,0 +1,732 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Componentes de Software\n", + "\n", + "A seguir são reunidos alguns conceitos importantes para se entender o princípio de **Componentes de Software**.\n", + "\n", + "Em linhas gerais, um componente é um módulo de software reusável, que se liga aos seus parceiros exclusivamente através de interfaces. Apresentaremos aqui uma abordagem típica de ligação de componentes baseada em interfaces e conexões:\n", + "* **Interfaces** - expressam os serviços providos pelos componentes, declarados através de `interfaces` Java;\n", + "* **Conexões** - é a forma como componentes são ligados entre si; a partir delas um componente toma conhecimento do outro para que se comuniquem.\n", + "\n", + "## Interfaces\n", + "\n", + "Idealmente, todas as funcionalidades de um componente deveriam ser acessadas exclusivamente através de interfaces.\n", + "\n", + "Vamos analisar o processo de definição do `DataSetComponent` como um componente de software. Considerando que o código a seguir é uma versão inicial do componente, uma representação visual para o mesmo pode ser feita em UML, conforme segue:\n", + "\n", + "![Componente](console-dataset-a.png)\n", + "\n", + "Veja a seguir a representação em Java:\n", + "\n", + "~~~java\n", + "public interface IDataSetProperties {\n", + " public String getDataSource();\n", + " public void setDataSource(String dataSource);\n", + "}\n", + "\n", + "public interface ITableProducer {\n", + " String[] requestAttributes();\n", + " String[][] requestInstances();\n", + "}\n", + "~~~\n", + "\n", + "Note que cada interface que ele disponibiliza é apresentada na forma de uma haste com um círculo na ponta.\n", + "\n", + "Como a interface `IDataSetProperties` tem métodos `get` e `set` para definir a propriedade `DataSource`, em vez de representar essa interface da forma tradicional, podemos representá-la na forma de uma propriedade associada ao componente como segue:\n", + "\n", + "![Componente](console-dataset-b.png)\n", + "\n", + "A representação de propriedades não é padrão UML, mas é usada por algumas extensões. Isso introduz um terceiro elemento usual em algumas implementações de componentes:\n", + "\n", + "* **Propriedades** - podem ser usadas como mecanismos de configuração externa do componente; por exemplo, através da propriedade `dataSource` é possível externamente se configurar a fonte de dados do componente.\n", + "\n", + "A partir de agora, criaremos uma interface específica para a modificação de propriedades e usaremos a representação na forma de propriedade.\n", + "\n", + "Para englobar todas as interfaces em uma única, foi usada a estratégia de criar uma interface para o componente (`IDataSet`) unificando as demais na forma de herança:\n", + "\n", + "~~~java\n", + "public interface IDataSet extends IDataSetProperties, ITableProducer {\n", + "}\n", + "~~~\n", + "\n", + "Essa estratégia será adotada em todos os componentes." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Conexões\n", + "\n", + "Uma das formas mais comuns de comunicação entre componentes é a criação de uma conexão entre eles. Em linguagens orientadas a objetos uma estratégia consiste em um objeto (componente) guardar a referência de outro objeto (componente).\n", + "\n", + "Utilizaremos um método padrão chamado `connect` que conecta dois componentes. Para isso um dos objetos recebe a referência de outro:\n", + "~~~java\n", + "public void connect(ITableProducer producer)\n", + "~~~\n", + "\n", + "Esse método recebe a referência para qualquer objeto que implementa a interface `ITableProducer` e a guarda. A referência é posteriormente usada para a comunicação entre os dois objetos.\n", + "\n", + "# Interface Requerida\n", + "\n", + "O ideal é que tudo seja explícito e que haja uma interface para realizar essa conexão. Desse modo, criaremos uma interface chamada `ITableReceptacle`. Ela define o método para se estabelecer a conexão com objetos que têm a interface `ITableProducer`.\n", + "\n", + "~~~java\n", + "public interface ITableReceptacle {\n", + " public void connect(ITableProducer producer);\n", + "}\n", + "~~~\n", + "\n", + "A interface requerida é representada visualmente por um meio círculo e indica o nome da interface que ela requer:\n", + "\n", + "![Componente](console-dataset-d.svg)\n", + "\n", + "Outra maneira bastante usual de representar os dois componentes conectados é ligando diretamente a interface provida com a requerida:\n", + "\n", + "![Componente](console-dataset-e.svg)\n", + "\n", + "Para tornar o componente `ConsoleComponent` completamente acessível por interfaces, acrescentamos outra interface para o seu método `update()`.\n", + "\n", + "~~~java\n", + "public interface IConsoleUpdate {\n", + " public void update();\n", + "}\n", + "~~~\n", + "\n", + "O Diagrama completo fica:\n", + "\n", + "![Componente](console-dataset-f.svg)\n", + "\n", + "Como foi feito antes, usamos a interface `IConsole` para juntar as duas outras interfaces através da herança:\n", + "\n", + "~~~java\n", + "public interface IConsole extends ITableReceptacle, IConsoleUpdate {\n", + "}\n", + "~~~" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Composição de Componentes\n", + "\n", + "Vamos ilustrar agora como criar uma composição de componentes. Inicialmente, vamos importar a biblioteca onde estão implementados:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "1553b31d-3362-4da7-bb86-791b7de45195", + "version_major": 2, + "version_minor": 0 + }, + "method": "display_data" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%classpath add jar ../../../lib/component-catalog-2020-08-04.jar" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Usando a Interface Requerida\n", + "\n", + "Note no código a seguir que ambos os componentes passam a ser tratados completamente a partir de suas interfaces. Mais adiante analisaremos a importância de realizar dessa maneira." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "=== Attributes ===\n", + "name, age, paralysis, yellow_tong, member_loss, chest_pain, trembling_finger, severe_anger, history_bacteria, diagnostic, days_recovery, has_disease\n", + "\n", + "=== Instances ===\n", + "Rot Donnadd, 43, t, t, f, f, f, f, f, bacterial_infection, 9, t\n", + "Pid Mught, 38, f, t, f, f, f, f, f, bacterial_infection, 7, t\n", + "Thulk Lebbimp, 63, f, t, f, f, t, f, t, bite_deficit, 10, t\n", + "Bouvossam Damme, 71, f, t, t, f, t, f, f, bite_deficit, 13, t\n", + "Pirg Zall, 48, f, f, t, t, f, f, f, viral_infection, 4, t\n", + "Nullon Rackindock, 23, f, f, t, f, f, t, f, fights, 8, f\n", + "Shor Splitturch, 35, f, f, f, f, f, t, f, nothing, 0, f\n", + "Ger Ackeng, 66, f, f, f, f, t, f, f, bite_deficit, 11, t\n", + "Gleldo Shruck, 45, f, t, f, t, f, f, f, bacterial_infection, 8, t\n", + "Nadross Pilch, 60, f, f, f, t, f, f, f, viral_infection, 8, t\n", + "Sadrent Pemmir, 73, f, t, t, f, f, f, t, bite_deficit, 14, t\n", + "Read Rait, 55, t, t, f, f, f, f, f, bacterial_infection, 9, t\n", + "Dallun Whadder, 15, f, f, f, t, f, f, t, viral_infection, 2, t\n", + "Eapplar Thorg, 25, f, f, t, f, f, f, f, fights, 5, f\n", + "Blottork Patter, 68, f, t, f, f, t, f, t, bite_deficit, 12, t\n", + "Darrutt Bottall, 75, f, t, t, f, t, f, f, bite_deficit, 16, t\n", + "Gallir Shauch, 20, f, f, f, t, f, f, f, fights, 12, f\n", + "Dirpe Polnay, 39, f, t, f, f, f, f, f, bacterial_infection, 7, t\n", + "Harrimp Fottiem, 65, f, f, f, f, t, f, f, bite_deficit, 9, t\n" + ] + }, + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pt.c08componentes.s20catalog.s10ds.*;\n", + "import pt.c08componentes.s20catalog.s20console.*;\n", + "\n", + "IDataSet dataset = new DataSetComponent();\n", + "dataset.setDataSource(\"../../../db/zombie/zombie-health-spreadsheet.csv\");\n", + "\n", + "IConsole console = new ConsoleComponent();\n", + "console.connect(dataset);\n", + "\n", + "console.update();" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Projection Component\n", + "\n", + "Componente que realiza o recorte (projeção) de colunas em uma tabela.\n", + "\n", + "![Projection Component](projection-component.png)\n", + "\n", + "~~~java\n", + "public interface IProjectionProperties {\n", + " String[] getAttributes();\n", + " void setAttributes(String attribute[]);\n", + "}\n", + "\n", + "public interface IProjection extends IProjectionProperties, ITableProducer, ITableReceptacle {\n", + "}\n", + "~~~\n", + "\n", + "Recebe uma tabela de entrada (através da interface requerida `ITableProducer`) e gera uma tabela com as colunas recortadas (através da interface provida `ITableProducer`). A propriedade `attributes` contém um vetor com o nome das colunas a serem filtradas." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Tarefa 1\n", + "\n", + "Conecte o componente `DataSet` aos componentes de projeção e console para mostrar na tela as seguintes colunas: `name` e `age`." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pt.c08componentes.s20catalog.s10ds.*;\n", + "import pt.c08componentes.s20catalog.s20console.*;\n", + "import pt.c08componentes.s20catalog.s30projection.*;\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Selection Component\n", + "\n", + "Componente que seleciona linhas da tabela que atendem a uma certa condição.\n", + "\n", + "![Selection Component](selection-component.png)\n", + "\n", + "~~~java\n", + "public interface ISelectionProperties {\n", + " String getAttribute();\n", + " void setAttribute(String attributeA);\n", + " public String getOperator();\n", + " public void setOperator(String operator);\n", + " public String getValue();\n", + " public void setValue(String value);\n", + " boolean isNominalComparison();\n", + " void setNominalComparison(boolean nominalComparison);\n", + "}\n", + "~~~\n", + "\n", + "Os três propriedades `attribute`, `operator` e `value` definem a expressão de seleção. Por exemplo, a seguinte seleção `name = Rot Donnadd` seria:\n", + "* **attribute:** `name`\n", + "* **operator:** `=`\n", + "* **value:** ` Rot Donnadd`\n", + "\n", + "A propriedade `nominalComparison` indica se a comparação será entre strings (`true`) ou números (`false`). O padrão é `true`.\n", + "\n", + "A interface unificada do componente é:\n", + "~~~java\n", + "public interface ISelection extends ISelectionProperties, ITableProducer, ITableReceptacle {\n", + "}\n", + "~~~" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Tarefa 2\n", + "\n", + "Conecte o componente `DataSet` aos componentes de seleção e console para mostrar na tela aquelas instâncias cujo diagnóstico seja `bacterial_infection`." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pt.c08componentes.s20catalog.s10ds.*;\n", + "import pt.c08componentes.s20catalog.s20console.*;\n", + "import pt.c08componentes.s20catalog.s40selection.*;\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Tarefa 3\n", + "\n", + "Conecte os componentes que você achar necessários para mostrar no console as colunas `name` e `age` de zumbis com `bacterial_infection`." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pt.c08componentes.s20catalog.s10ds.*;\n", + "import pt.c08componentes.s20catalog.s20console.*;\n", + "import pt.c08componentes.s20catalog.s40selection.*;\n", + "import pt.c08componentes.s20catalog.s30projection.*;\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Bubble Chart Component\n", + "\n", + "Componente que plota um gráfico de dispersão de uma tabela recebida como entrada. Para isso a tabela deve ter recortadas apenas as duas colunas que serão apresentadas.\n", + "\n", + "![Bubble Chart Component](chartbubble-component.png)\n", + "\n", + "As propriedades `Title`, `XTitle` e `YTitle` são os títulos do gráfico, do eixo X e Y respectivamente.\n", + "\n", + "A interface `IRun` dispõe de métodos para ativar e desativar a plotagem do gráfico (métodos `start` e `stop` respectivamente):\n", + "\n", + "~~~java\n", + "public interface IRun {\n", + " public boolean start();\n", + " public boolean stop();\n", + "}\n", + "\n", + "public interface IChart extends ITableReceptacle, IRun, IChartProperties {\n", + " /* Component Interfaces Set */\n", + "}\n", + "~~~\n", + "\n", + "A interface unificada é:\n", + "\n", + "~~~java\n", + "public interface IChart extends ITableReceptacle, IRun, IChartProperties {\n", + " /* Component Interfaces Set */\n", + "}\n", + "~~~\n", + "\n", + "O comando a seguir importa uma biblioteca gráfica necessária para o componente:" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "ee23ed2d-8bb6-44f9-bcb5-5c53fefe7ca4", + "version_major": 2, + "version_minor": 0 + }, + "method": "display_data" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%classpath add jar ../../../lib/xchart-3.5.2.jar" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "jupyter": { + "source_hidden": true + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrba9cd7a8.ChartBubbleComponent" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import java.util.ArrayList;\n", + "import java.util.Hashtable;\n", + "import java.util.List;\n", + "\n", + "import java.io.IOException;\n", + "\n", + "import org.knowm.xchart.BubbleChart;\n", + "import org.knowm.xchart.BubbleChartBuilder;\n", + "import org.knowm.xchart.SwingWrapper;\n", + "import org.knowm.xchart.BitmapEncoder;\n", + "import org.knowm.xchart.BitmapEncoder.BitmapFormat;\n", + "\n", + "import com.twosigma.beakerx.mimetype.MIMEContainer;\n", + "import java.io.File;\n", + "import java.nio.file.Files;\n", + "\n", + "import pt.c08componentes.s20catalog.s00shared.*;\n", + "import pt.c08componentes.s20catalog.s50chart.IChart;\n", + "\n", + "public class ChartBubbleComponent implements IChart {\n", + " private BubbleChart chart = null;\n", + "\n", + " private String title = \"Chart\";\n", + " private String xTitle = \"X\",\n", + " yTitle = \"Y\";\n", + "\n", + " private ITableProducer producer = null;\n", + " \n", + " public void connect(ITableProducer producer) {\n", + " this.producer = producer;\n", + " }\n", + " \n", + " public ChartBubbleComponent() {\n", + " }\n", + " \n", + " public String getTitle() {\n", + " return title;\n", + " }\n", + " \n", + " public void setTitle(String title) {\n", + " this.title = title;\n", + " }\n", + "\n", + " public String getXTitle() {\n", + " return xTitle;\n", + " }\n", + " \n", + " public void setXTitle(String title) {\n", + " xTitle = title;\n", + " }\n", + "\n", + " public String getYTitle() {\n", + " return title;\n", + " }\n", + " \n", + " public void setYTitle(String title) {\n", + " yTitle = title;\n", + " }\n", + "\n", + " public boolean start() {\n", + " boolean status = true;\n", + " \n", + " chart = new BubbleChartBuilder().width(600).height(400).title(title).xAxisTitle(xTitle).yAxisTitle(yTitle).build();\n", + " try{\n", + " \n", + " buildChart(); \n", + " BitmapEncoder.saveBitmap(chart, \"./chart\", BitmapFormat.PNG);\n", + " \n", + " File file = new File(\"chart.png\");\n", + " byte[] data = Files.readAllBytes(file.toPath());\n", + " \n", + " MIMEContainer image = new MIMEContainer(MIMEContainer.MIME.IMAGE_PNG, data);\n", + " display(image);\n", + " }catch(IOException ex){\n", + " status = false;\n", + " System.out.println (ex.toString()); \n", + " }\n", + " \n", + " return status;\n", + " }\n", + " \n", + " public boolean stop() {\n", + " return true;\n", + " }\n", + " \n", + " public double[] toDouble(String[][] instances, int column ) {\n", + " double[] numbers = new double[instances.length];\n", + " for (int i = 0; i < instances.length; i++)\n", + " numbers[i] = Double.parseDouble(instances[i][column]);\n", + " return numbers;\n", + " }\n", + "\n", + " private void buildChart() {\n", + " if (chart != null && producer != null) {\n", + " String[][] instances = producer.requestInstances();\n", + "\n", + " if (instances != null) {\n", + " double[] xData = toDouble(instances, 0),\n", + " yData = toDouble(instances, 1);\n", + " \n", + " String[] categoryData = null;\n", + " if (instances[0].length > 2) {\n", + " categoryData = new String[instances.length];\n", + " for (int c = 0; c < instances.length; c++)\n", + " categoryData[c] = instances[c][2];\n", + " }\n", + " \n", + " double[] bubbleData = null;\n", + " if (instances[0].length > 3)\n", + " bubbleData = toDouble(producer.requestInstances(), 3);\n", + " else {\n", + " bubbleData = new double[instances.length];\n", + " for (int i = 0; i < xData.length; i++)\n", + " bubbleData[i] = 10;\n", + " }\n", + " \n", + " \n", + " if (categoryData == null ||\n", + " xData.length != yData.length || yData.length != bubbleData.length ||\n", + " bubbleData.length != categoryData.length) {\n", + " chart.addSeries(\" \", xData, yData, bubbleData);\n", + " } else {\n", + " Hashtable hash = new Hashtable();\n", + " int outer = 0;\n", + " int size = categoryData.length;\n", + " while (outer < size) {\n", + " if (hash.containsKey(categoryData[outer]))\n", + " outer++;\n", + " else {\n", + " hash.put(categoryData[outer],categoryData[outer]);\n", + " List xSub = new ArrayList(),\n", + " ySub = new ArrayList(),\n", + " bubbleSub = new ArrayList();\n", + " for (int inner = outer; inner < size; inner++)\n", + " if (categoryData[inner].equalsIgnoreCase(categoryData[outer])) {\n", + " xSub.add(xData[inner]);\n", + " ySub.add(yData[inner]);\n", + " bubbleSub.add(bubbleData[inner]);\n", + " }\n", + " chart.addSeries(categoryData[outer], xSub, ySub, bubbleSub);\n", + " outer++;\n", + " }\n", + " }\n", + " }\n", + " }\n", + " \n", + " }\n", + " \n", + " }\n", + " \n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Tarefa 4\n", + "\n", + "Conecte os componentes que você achar necessários para apresentar um gráfico comparativo entre idade e tempo de recuperação dos zumbis, conforme exemplo abaixo.\n", + "\n", + "![Graph](example1.png)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pt.c08componentes.s20catalog.s10ds.*;\n", + "import pt.c08componentes.s20catalog.s30projection.*;\n", + "import pt.c08componentes.s20catalog.s50chart.IChart;\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Tarefa 5\n", + "\n", + "Conecte os componentes que você achar necessários para apresentar um gráfico comparativo entre idade e tempo de recuperação dos zumbis, colorindo os pontos por diagnóstico, conforme exemplo abaixo.\n", + "\n", + "**Recomendação:** Se você recortar uma terceira coluna com o diagnóstico, o gráfico resultante irá colorir os pontos por diagnóstico.\n", + "\n", + "![Graph](example2.png)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pt.c08componentes.s20catalog.s10ds.*;\n", + "import pt.c08componentes.s20catalog.s30projection.*;\n", + "import pt.c08componentes.s20catalog.s50chart.IChart;\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Tarefa 6\n", + "\n", + "Conecte os componentes que você achar necessários para apresentar um gráfico comparativo entre idade e tempo de recuperação, filtrando apenas a doença “bacterial_infection”." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pt.c08componentes.s20catalog.s10ds.*;\n", + "import pt.c08componentes.s20catalog.s30projection.*;\n", + "import pt.c08componentes.s20catalog.s40selection.*;\n", + "import pt.c08componentes.s20catalog.s50chart.IChart;\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Java", + "language": "java", + "name": "java" + }, + "language_info": { + "codemirror_mode": "text/x-java", + "file_extension": ".java", + "mimetype": "", + "name": "Java", + "nbconverter_exporter": "", + "version": "1.8.0_152-release" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": false, + "sideBar": false, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": false, + "toc_window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/.ipynb_checkpoints/components-02-whitebox-checkpoint.ipynb b/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/.ipynb_checkpoints/components-02-whitebox-checkpoint.ipynb new file mode 100644 index 000000000..9d9fa154f --- /dev/null +++ b/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/.ipynb_checkpoints/components-02-whitebox-checkpoint.ipynb @@ -0,0 +1,958 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Visão Interna dos Componentes (WhiteBox)\n", + "\n", + "A seguir é apresentada a implementação de cada um dos componentes do notebook anterior." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## DataSet" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkre3c6118d.ITableProducer" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface ITableProducer {\n", + " String[] requestAttributes();\n", + " String[][] requestInstances();\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkre3c6118d.IDataSetProperties" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IDataSetProperties {\n", + " public String getDataSource();\n", + " public void setDataSource(String dataSource);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkre3c6118d.IDataSet" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IDataSet extends IDataSetProperties, ITableProducer {\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkre3c6118d.DataSetComponent" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import java.io.BufferedReader;\n", + "import java.io.FileReader;\n", + "import java.io.IOException;\n", + "import java.util.ArrayList;\n", + "\n", + "public class DataSetComponent implements IDataSet {\n", + " private String dataSource = null;\n", + " private String[] attributes = null;\n", + " private String[][] instances = null;\n", + " \n", + " public DataSetComponent() {\n", + " /* nothing */\n", + " }\n", + "\n", + " public String getDataSource() {\n", + " return dataSource;\n", + " }\n", + "\n", + " public void setDataSource(String dataSource) {\n", + " this.dataSource = dataSource;\n", + " if (dataSource == null) {\n", + " attributes = null;\n", + " instances = null;\n", + " } else\n", + " readDS();\n", + " }\n", + " \n", + " public String[] requestAttributes() {\n", + " return attributes;\n", + " }\n", + " \n", + " public String[][] requestInstances() {\n", + " return instances;\n", + " }\n", + " \n", + " private void readDS() {\n", + " ArrayList instArray = new ArrayList();\n", + " try {\n", + " BufferedReader file = new BufferedReader(new FileReader(dataSource));\n", + " \n", + " String line = file.readLine();\n", + " if (line != null) {\n", + " attributes = line.split(\",\");\n", + " line = file.readLine();\n", + " while (line != null) {\n", + " String[] instLine = line.split(\",\");\n", + " instArray.add(instLine);\n", + " line = file.readLine();\n", + " }\n", + " instances = instArray.toArray(new String[0][]);\n", + " }\n", + " \n", + " file.close();\n", + " } catch (IOException erro) {\n", + " erro.printStackTrace();\n", + " }\n", + " }\n", + " \n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Console" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkre3c6118d.ITableReceptacle" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface ITableReceptacle {\n", + " public void connect(ITableProducer producer);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkre3c6118d.IConsoleUpdate" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IConsoleUpdate {\n", + " public void update();\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkre3c6118d.IConsole" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IConsole extends ITableReceptacle, IConsoleUpdate {\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkre3c6118d.ConsoleComponent" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class ConsoleComponent implements IConsole {\n", + " private ITableProducer iProducer;\n", + " \n", + " public void connect(ITableProducer producer) {\n", + " iProducer = producer;\n", + " }\n", + " \n", + " public void update() {\n", + " if (iProducer != null) {\n", + " System.out.println(\"=== Attributes ===\");\n", + " String attributes[] = iProducer.requestAttributes();\n", + " for (int a = 0; a < attributes.length-1; a++)\n", + " System.out.print(attributes[a] + \", \");\n", + " System.out.println(attributes[attributes.length-1]);\n", + "\n", + " System.out.println();\n", + " System.out.println(\"=== Instances ===\");\n", + " String instances[][] = iProducer.requestInstances();\n", + " for (int i = 0; i < instances.length; i++) {\n", + " for (int a = 0; a < attributes.length-1; a ++)\n", + " System.out.print(instances[i][a] + \", \");\n", + " System.out.println(instances[i][attributes.length-1]);\n", + " }\n", + " }\n", + " }\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Revendo a Composição de Dois Componentes\n", + "\n", + "A seguir retomamos o exemplo do notebook anterior em que o DataSet é conectado ao Console." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "=== Attributes ===\n", + "name, age, paralysis, yellow_tong, member_loss, chest_pain, trembling_finger, severe_anger, history_bacteria, diagnostic, days_recovery, has_disease\n", + "\n", + "=== Instances ===\n", + "Rot Donnadd, 43, t, t, f, f, f, f, f, bacterial_infection, 9, t\n", + "Pid Mught, 38, f, t, f, f, f, f, f, bacterial_infection, 7, t\n", + "Thulk Lebbimp, 63, f, t, f, f, t, f, t, bite_deficit, 10, t\n", + "Bouvossam Damme, 71, f, t, t, f, t, f, f, bite_deficit, 13, t\n", + "Pirg Zall, 48, f, f, t, t, f, f, f, viral_infection, 4, t\n", + "Nullon Rackindock, 23, f, f, t, f, f, t, f, fights, 8, f\n", + "Shor Splitturch, 35, f, f, f, f, f, t, f, nothing, 0, f\n", + "Ger Ackeng, 66, f, f, f, f, t, f, f, bite_deficit, 11, t\n", + "Gleldo Shruck, 45, f, t, f, t, f, f, f, bacterial_infection, 8, t\n", + "Nadross Pilch, 60, f, f, f, t, f, f, f, viral_infection, 8, t\n", + "Sadrent Pemmir, 73, f, t, t, f, f, f, t, bite_deficit, 14, t\n", + "Read Rait, 55, t, t, f, f, f, f, f, bacterial_infection, 9, t\n", + "Dallun Whadder, 15, f, f, f, t, f, f, t, viral_infection, 2, t\n", + "Eapplar Thorg, 25, f, f, t, f, f, f, f, fights, 5, f\n", + "Blottork Patter, 68, f, t, f, f, t, f, t, bite_deficit, 12, t\n", + "Darrutt Bottall, 75, f, t, t, f, t, f, f, bite_deficit, 16, t\n", + "Gallir Shauch, 20, f, f, f, t, f, f, f, fights, 12, f\n", + "Dirpe Polnay, 39, f, t, f, f, f, f, f, bacterial_infection, 7, t\n", + "Harrimp Fottiem, 65, f, f, f, f, t, f, f, bite_deficit, 9, t\n" + ] + }, + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "IDataSet dataset = new DataSetComponent();\n", + "dataset.setDataSource(\"../../../db/zombie/zombie-health-spreadsheet.csv\");\n", + "\n", + "IConsole console = new ConsoleComponent();\n", + "console.connect(dataset);\n", + "\n", + "console.update();" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Projeção" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkre3c6118d.IProjectionProperties" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IProjectionProperties {\n", + " String[] getAttributes();\n", + " void setAttributes(String attribute[]);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkre3c6118d.IProjection" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IProjection extends IProjectionProperties, ITableProducer, ITableReceptacle {\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkre3c6118d.ProjectionComponent" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class ProjectionComponent implements IProjection {\n", + " private ITableProducer provider;\n", + " \n", + " private String attributes[] = null;\n", + " \n", + " public String[] getAttributes() {\n", + " return attributes;\n", + " }\n", + "\n", + " public void setAttributes(String attributes[]) {\n", + " this.attributes = attributes;\n", + " }\n", + " \n", + " public void connect(ITableProducer provider) {\n", + " this.provider = provider;\n", + " }\n", + " \n", + " public String[] requestAttributes() {\n", + " return attributes;\n", + " }\n", + " \n", + " public String[][] requestInstances() {\n", + " String[][] instances = null;\n", + " \n", + " if (provider != null) {\n", + " String[][] allInstances = provider.requestInstances();\n", + " if (allInstances != null && attributes != null) {\n", + " instances = new String[allInstances.length][];\n", + " \n", + " // busca a posicao dos atributos selecionados na tabela original\n", + " String[] allAttributes = provider.requestAttributes();\n", + " int attrPos[] = new int[attributes.length];\n", + " for (int as = 0; as < attributes.length; as++) {\n", + " int aa;\n", + " for (aa = 0; aa < allAttributes.length &&\n", + " !attributes[as].equalsIgnoreCase(allAttributes[aa]); aa++)\n", + " /* nothing */;\n", + " if (aa < allAttributes.length)\n", + " attrPos[as] = aa;\n", + " else\n", + " attrPos[as] = -1;\n", + " }\n", + " \n", + " // filtra atributos selecionados\n", + " for (int i = 0; i < allInstances.length; i++) {\n", + " instances[i] = new String[attributes.length];\n", + " for (int as = 0; as < attributes.length; as++)\n", + " if (attrPos[as] > -1)\n", + " instances[i][as] = allInstances[i][attrPos[as]];\n", + " }\n", + " }\n", + " }\n", + " \n", + " return instances;\n", + " }\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Seleção" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkre3c6118d.ISelectionProperties" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface ISelectionProperties {\n", + " String getAttribute();\n", + " void setAttribute(String attributeA);\n", + " public String getOperator();\n", + " public void setOperator(String operator);\n", + " public String getValue();\n", + " public void setValue(String value);\n", + " boolean isNominalComparison();\n", + " void setNominalComparison(boolean nominalComparison);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkre3c6118d.ISelection" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface ISelection extends ISelectionProperties, ITableProducer, ITableReceptacle {\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkre3c6118d.SelectionComponent" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import java.util.ArrayList;\n", + "\n", + "public class SelectionComponent implements ISelection {\n", + " private ITableProducer provider;\n", + " \n", + " private String attribute = null,\n", + " operator = null,\n", + " value = null;\n", + " private boolean nominalComparison = true;\n", + " \n", + " public String getAttribute() {\n", + " return attribute;\n", + " }\n", + "\n", + " public void setAttribute(String attribute) {\n", + " this.attribute = attribute;\n", + " }\n", + " \n", + " public String getOperator() {\n", + " return operator;\n", + " }\n", + " \n", + " public void setOperator(String operator) {\n", + " this.operator = operator;\n", + " }\n", + " \n", + " public String getValue() {\n", + " return value;\n", + " }\n", + " \n", + " public void setValue(String value) {\n", + " this.value = value;\n", + " }\n", + " \n", + " public boolean isNominalComparison() {\n", + " return nominalComparison;\n", + " }\n", + "\n", + " public void setNominalComparison(boolean nominalComparison) {\n", + " this.nominalComparison = nominalComparison;\n", + " }\n", + "\n", + " public void connect(ITableProducer provider) {\n", + " this.provider = provider;\n", + " }\n", + " \n", + " public String[] requestAttributes() {\n", + " return (provider == null) ? null : provider.requestAttributes();\n", + " }\n", + " \n", + " public String[][] requestInstances() {\n", + " ArrayList instances = null;\n", + " \n", + " if (provider != null) {\n", + " String[][] allInstances = provider.requestInstances();\n", + " \n", + " if (allInstances != null) {\n", + " // busca a posicao dos atributos selecionados na tabela original\n", + " String[] allAttributes = provider.requestAttributes();\n", + " int atrPos;\n", + " for (atrPos = 0; atrPos < allAttributes.length &&\n", + " !attribute.equalsIgnoreCase(allAttributes[atrPos]); atrPos++)\n", + " /* nothing */;\n", + " if (atrPos < allAttributes.length) {\n", + " instances = new ArrayList();\n", + " \n", + " for (String[] ai: allInstances) {\n", + " boolean match = false;\n", + " if (nominalComparison) {\n", + " switch (operator.charAt(0)) {\n", + " case '=': if (ai[atrPos].equalsIgnoreCase(value))\n", + " match = true;\n", + " break;\n", + " case '<': if (ai[atrPos].compareTo(value) < 0)\n", + " match = true;\n", + " break;\n", + " case '>': if (ai[atrPos].compareTo(value) > 0)\n", + " match = true;\n", + " break;\n", + " case '!': if (!ai[atrPos].equalsIgnoreCase(value))\n", + " match = true;\n", + " break;\n", + " }\n", + " } else {\n", + " switch (operator.charAt(0)) {\n", + " case '=': if (Double.parseDouble(ai[atrPos]) == Double.parseDouble(value))\n", + " match = true;\n", + " break;\n", + " case '<': if (Double.parseDouble(ai[atrPos]) < Double.parseDouble(value))\n", + " match = true;\n", + " break;\n", + " case '>': if (Double.parseDouble(ai[atrPos]) > Double.parseDouble(value))\n", + " match = true;\n", + " break;\n", + " case '!': if (Double.parseDouble(ai[atrPos]) != Double.parseDouble(value))\n", + " match = true;\n", + " break;\n", + " }\n", + " }\n", + " if (match)\n", + " instances.add(ai);\n", + " \n", + " }\n", + " }\n", + " }\n", + " }\n", + " \n", + " return (instances == null) ? null : instances.toArray(new String[1][]);\n", + " }\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chart" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkre3c6118d.IChartProperties" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IChartProperties {\n", + " String getTitle();\n", + " void setTitle(String title);\n", + " String getXTitle();\n", + " void setXTitle(String title);\n", + " String getYTitle();\n", + " void setYTitle(String title);\n", + "}\n" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkre3c6118d.IRun" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "public interface IRun {\n", + " public boolean start();\n", + " public boolean stop();\n", + "}\n" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkre3c6118d.IChart" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "public interface IChart extends ITableReceptacle, IRun, IChartProperties {\n", + " /* Component Interfaces Set */\n", + "}\n" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "3b1e48f0-c16d-4f5c-ba16-a2ba99784e73", + "version_major": 2, + "version_minor": 0 + }, + "method": "display_data" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%classpath add jar ../../../lib/xchart-3.5.2.jar" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkre3c6118d.ChartBubbleComponent" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import java.util.ArrayList;\n", + "import java.util.Hashtable;\n", + "import java.util.List;\n", + "\n", + "import java.io.IOException;\n", + "\n", + "import org.knowm.xchart.BubbleChart;\n", + "import org.knowm.xchart.BubbleChartBuilder;\n", + "import org.knowm.xchart.SwingWrapper;\n", + "import org.knowm.xchart.BitmapEncoder;\n", + "import org.knowm.xchart.BitmapEncoder.BitmapFormat;\n", + "\n", + "import com.twosigma.beakerx.mimetype.MIMEContainer;\n", + "import java.io.File;\n", + "import java.nio.file.Files;\n", + "\n", + "public class ChartBubbleComponent implements IChart {\n", + " private BubbleChart chart = null;\n", + "\n", + " private String title = \"Chart\";\n", + " private String xTitle = \"X\",\n", + " yTitle = \"Y\";\n", + "\n", + " private ITableProducer producer = null;\n", + " \n", + " public void connect(ITableProducer producer) {\n", + " this.producer = producer;\n", + " }\n", + " \n", + " public ChartBubbleComponent() {\n", + " }\n", + " \n", + " public String getTitle() {\n", + " return title;\n", + " }\n", + " \n", + " public void setTitle(String title) {\n", + " this.title = title;\n", + " }\n", + "\n", + " public String getXTitle() {\n", + " return xTitle;\n", + " }\n", + " \n", + " public void setXTitle(String title) {\n", + " xTitle = title;\n", + " }\n", + "\n", + " public String getYTitle() {\n", + " return title;\n", + " }\n", + " \n", + " public void setYTitle(String title) {\n", + " yTitle = title;\n", + " }\n", + "\n", + " public boolean start() {\n", + " boolean status = true;\n", + " \n", + " chart = new BubbleChartBuilder().width(600).height(400).title(title).xAxisTitle(xTitle).yAxisTitle(yTitle).build();\n", + " try{\n", + " \n", + " buildChart(); \n", + " BitmapEncoder.saveBitmap(chart, \"./chart\", BitmapFormat.PNG);\n", + " \n", + " File file = new File(\"chart.png\");\n", + " byte[] data = Files.readAllBytes(file.toPath());\n", + " \n", + " MIMEContainer image = new MIMEContainer(MIMEContainer.MIME.IMAGE_PNG, data);\n", + " display(image);\n", + " }catch(IOException ex){\n", + " status = false;\n", + " System.out.println (ex.toString()); \n", + " }\n", + " \n", + " return status;\n", + " }\n", + " \n", + " public boolean stop() {\n", + " return true;\n", + " }\n", + " \n", + " public double[] toDouble(String[][] instances, int column ) {\n", + " double[] numbers = new double[instances.length];\n", + " for (int i = 0; i < instances.length; i++)\n", + " numbers[i] = Double.parseDouble(instances[i][column]);\n", + " return numbers;\n", + " }\n", + "\n", + " private void buildChart() {\n", + " if (chart != null && producer != null) {\n", + " String[][] instances = producer.requestInstances();\n", + "\n", + " if (instances != null) {\n", + " double[] xData = toDouble(instances, 0),\n", + " yData = toDouble(instances, 1);\n", + " \n", + " String[] categoryData = null;\n", + " if (instances[0].length > 2) {\n", + " categoryData = new String[instances.length];\n", + " for (int c = 0; c < instances.length; c++)\n", + " categoryData[c] = instances[c][2];\n", + " }\n", + " \n", + " double[] bubbleData = null;\n", + " if (instances[0].length > 3)\n", + " bubbleData = toDouble(producer.requestInstances(), 3);\n", + " else {\n", + " bubbleData = new double[instances.length];\n", + " for (int i = 0; i < xData.length; i++)\n", + " bubbleData[i] = 10;\n", + " }\n", + " \n", + " \n", + " if (categoryData == null ||\n", + " xData.length != yData.length || yData.length != bubbleData.length ||\n", + " bubbleData.length != categoryData.length) {\n", + " chart.addSeries(\" \", xData, yData, bubbleData);\n", + " } else {\n", + " Hashtable hash = new Hashtable();\n", + " int outer = 0;\n", + " int size = categoryData.length;\n", + " while (outer < size) {\n", + " if (hash.containsKey(categoryData[outer]))\n", + " outer++;\n", + " else {\n", + " hash.put(categoryData[outer],categoryData[outer]);\n", + " List xSub = new ArrayList(),\n", + " ySub = new ArrayList(),\n", + " bubbleSub = new ArrayList();\n", + " for (int inner = outer; inner < size; inner++)\n", + " if (categoryData[inner].equalsIgnoreCase(categoryData[outer])) {\n", + " xSub.add(xData[inner]);\n", + " ySub.add(yData[inner]);\n", + " bubbleSub.add(bubbleData[inner]);\n", + " }\n", + " chart.addSeries(categoryData[outer], xSub, ySub, bubbleSub);\n", + " outer++;\n", + " }\n", + " }\n", + " }\n", + " }\n", + " \n", + " }\n", + " \n", + " }\n", + " \n", + "}" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Java", + "language": "java", + "name": "java" + }, + "language_info": { + "codemirror_mode": "text/x-java", + "file_extension": ".java", + "mimetype": "", + "name": "Java", + "nbconverter_exporter": "", + "version": "1.8.0_152-release" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": false, + "sideBar": false, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": false, + "toc_window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/.ipynb_checkpoints/components-03-statistics-checkpoint.ipynb b/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/.ipynb_checkpoints/components-03-statistics-checkpoint.ipynb new file mode 100644 index 000000000..26923bb9e --- /dev/null +++ b/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/.ipynb_checkpoints/components-03-statistics-checkpoint.ipynb @@ -0,0 +1,1735 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Catálogo de componentes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## DataSet" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr59f575d5.ITableProducer" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface ITableProducer {\n", + " \n", + " String[] requestAttributes();\n", + " String[][] requestInstances();\n", + "\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr59f575d5.IDataSetProperties" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IDataSetProperties {\n", + "\n", + " public String getDataSource();\n", + " public void setDataSource(String dataSource);\n", + "\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr59f575d5.IDataSet" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IDataSet extends IDataSetProperties, ITableProducer {\n", + " \n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr59f575d5.DataSetComponent" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import java.io.BufferedReader;\n", + "import java.io.FileReader;\n", + "import java.io.IOException;\n", + "import java.util.ArrayList;\n", + "\n", + "public class DataSetComponent implements IDataSet {\n", + " private String dataSource = null;\n", + " private String[] attributes = null;\n", + " private String[][] instances = null;\n", + " \n", + " public DataSetComponent() {\n", + " /* nothing */\n", + " }\n", + "\n", + " public String getDataSource() {\n", + " return dataSource;\n", + " }\n", + "\n", + " public void setDataSource(String dataSource) {\n", + " this.dataSource = dataSource;\n", + " if (dataSource == null) {\n", + " attributes = null;\n", + " instances = null;\n", + " } else\n", + " readDS();\n", + " }\n", + " \n", + " public String[] requestAttributes() {\n", + " return attributes;\n", + " }\n", + " \n", + " public String[][] requestInstances() {\n", + " return instances;\n", + " }\n", + " \n", + " private void readDS() {\n", + " ArrayList instArray = new ArrayList();\n", + " try {\n", + " BufferedReader file = new BufferedReader(new FileReader(dataSource));\n", + " \n", + " String line = file.readLine();\n", + " if (line != null) {\n", + " attributes = line.split(\",\");\n", + " line = file.readLine();\n", + " while (line != null) {\n", + " String[] instLine = line.split(\",\");\n", + " instArray.add(instLine);\n", + " line = file.readLine();\n", + " }\n", + " instances = instArray.toArray(new String[0][]);\n", + " }\n", + " \n", + " file.close();\n", + " } catch (IOException erro) {\n", + " erro.printStackTrace();\n", + " }\n", + " }\n", + " \n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "=== Attributes ===\n", + "name, age, paralysis, yellow_tong, member_loss, chest_pain, trembling_finger, severe_anger, history_bacteria, diagnostic, days_recovery, has_disease\n", + "\n", + "=== Instances ===\n", + "Rot Donnadd, 43, t, t, f, f, f, f, f, bacterial_infection, 9, t\n", + "Pid Mught, 38, f, t, f, f, f, f, f, bacterial_infection, 7, t\n", + "Thulk Lebbimp, 63, f, t, f, f, t, f, t, bite_deficit, 10, t\n", + "Bouvossam Damme, 71, f, t, t, f, t, f, f, bite_deficit, 13, t\n", + "Pirg Zall, 48, f, f, t, t, f, f, f, viral_infection, 4, t\n", + "Nullon Rackindock, 23, f, f, t, f, f, t, f, fights, 8, f\n", + "Shor Splitturch, 35, f, f, f, f, f, t, f, nothing, 0, f\n", + "Ger Ackeng, 66, f, f, f, f, t, f, f, bite_deficit, 11, t\n", + "Gleldo Shruck, 45, f, t, f, t, f, f, f, bacterial_infection, 8, t\n", + "Nadross Pilch, 60, f, f, f, t, f, f, f, viral_infection, 8, t\n", + "Sadrent Pemmir, 73, f, t, t, f, f, f, t, bite_deficit, 14, t\n", + "Read Rait, 55, t, t, f, f, f, f, f, bacterial_infection, 9, t\n", + "Dallun Whadder, 15, f, f, f, t, f, f, t, viral_infection, 2, t\n", + "Eapplar Thorg, 25, f, f, t, f, f, f, f, fights, 5, f\n", + "Blottork Patter, 68, f, t, f, f, t, f, t, bite_deficit, 12, t\n", + "Darrutt Bottall, 75, f, t, t, f, t, f, f, bite_deficit, 16, t\n", + "Gallir Shauch, 20, f, f, f, t, f, f, f, fights, 12, f\n", + "Dirpe Polnay, 39, f, t, f, f, f, f, f, bacterial_infection, 7, t\n", + "Harrimp Fottiem, 65, f, f, f, f, t, f, f, bite_deficit, 9, t\n" + ] + }, + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "try {\n", + " IDataSet ds = new DataSetComponent();\n", + " ds.setDataSource(\"../../../../src/db/datasets/zombie/complete/zombie-health-spreadsheet-ml-training.csv\");\n", + "\n", + " System.out.println(\"=== Attributes ===\");\n", + " String attributes[] = ds.requestAttributes();\n", + " for (int a = 0; a < attributes.length-1; a++)\n", + " System.out.print(attributes[a] + \", \");\n", + " System.out.println(attributes[attributes.length-1]);\n", + "\n", + " System.out.println();\n", + " System.out.println(\"=== Instances ===\");\n", + " String instances[][] = ds.requestInstances();\n", + " for (int i = 0; i < instances.length; i++) {\n", + " for (int a = 0; a < attributes.length-1; a ++)\n", + " System.out.print(instances[i][a] + \", \");\n", + " System.out.println(instances[i][attributes.length-1]);\n", + " }\n", + "\n", + "} catch (Exception e) {\n", + " e.printStackTrace();\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Console" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.ITableReceptacle" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface ITableReceptacle {\n", + " public void connect(ITableProducer producer);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.IConsoleUpdate" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IConsoleUpdate {\n", + " public void update();\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.IConsole" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IConsole extends ITableReceptacle, IConsoleUpdate {\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.ConsoleComponent" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class ConsoleComponent implements IConsole {\n", + " private ITableProducer iProducer;\n", + " \n", + " public void connect(ITableProducer producer) {\n", + " iProducer = producer;\n", + " }\n", + " \n", + " public void update() {\n", + " if (iProducer != null) {\n", + " System.out.println(\"=== Attributes ===\");\n", + " String attributes[] = iProducer.requestAttributes();\n", + " for (int a = 0; a < attributes.length-1; a++)\n", + " System.out.print(attributes[a] + \", \");\n", + " System.out.println(attributes[attributes.length-1]);\n", + "\n", + " System.out.println();\n", + " System.out.println(\"=== Instances ===\");\n", + " String instances[][] = iProducer.requestInstances();\n", + " for (int i = 0; i < instances.length; i++) {\n", + " for (int a = 0; a < attributes.length-1; a ++)\n", + " System.out.print(instances[i][a] + \", \");\n", + " System.out.println(instances[i][attributes.length-1]);\n", + " }\n", + " }\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "=== Attributes ===\n", + "name, age, paralysis, yellow_tong, member_loss, chest_pain, trembling_finger, severe_anger, history_bacteria, diagnostic, days_recovery, has_disease\n", + "\n", + "=== Instances ===\n", + "Rot Donnadd, 43, t, t, f, f, f, f, f, bacterial_infection, 9, t\n", + "Pid Mught, 38, f, t, f, f, f, f, f, bacterial_infection, 7, t\n", + "Thulk Lebbimp, 63, f, t, f, f, t, f, t, bite_deficit, 10, t\n", + "Bouvossam Damme, 71, f, t, t, f, t, f, f, bite_deficit, 13, t\n", + "Pirg Zall, 48, f, f, t, t, f, f, f, viral_infection, 4, t\n", + "Nullon Rackindock, 23, f, f, t, f, f, t, f, fights, 8, f\n", + "Shor Splitturch, 35, f, f, f, f, f, t, f, nothing, 0, f\n", + "Ger Ackeng, 66, f, f, f, f, t, f, f, bite_deficit, 11, t\n", + "Gleldo Shruck, 45, f, t, f, t, f, f, f, bacterial_infection, 8, t\n", + "Nadross Pilch, 60, f, f, f, t, f, f, f, viral_infection, 8, t\n", + "Sadrent Pemmir, 73, f, t, t, f, f, f, t, bite_deficit, 14, t\n", + "Read Rait, 55, t, t, f, f, f, f, f, bacterial_infection, 9, t\n", + "Dallun Whadder, 15, f, f, f, t, f, f, t, viral_infection, 2, t\n", + "Eapplar Thorg, 25, f, f, t, f, f, f, f, fights, 5, f\n", + "Blottork Patter, 68, f, t, f, f, t, f, t, bite_deficit, 12, t\n", + "Darrutt Bottall, 75, f, t, t, f, t, f, f, bite_deficit, 16, t\n", + "Gallir Shauch, 20, f, f, f, t, f, f, f, fights, 12, f\n", + "Dirpe Polnay, 39, f, t, f, f, f, f, f, bacterial_infection, 7, t\n", + "Harrimp Fottiem, 65, f, f, f, f, t, f, f, bite_deficit, 9, t\n" + ] + }, + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "try {\n", + " IDataSet dataset = new DataSetComponent();\n", + " dataset.setDataSource(\"../../../../src/db/datasets/zombie/complete/zombie-health-spreadsheet-ml-training.csv\");\n", + "\n", + " IConsole console = new ConsoleComponent();\n", + " console.connect(dataset);\n", + "\n", + " console.update();\n", + " \n", + " } catch (Exception e) {\n", + " \n", + " e.printStackTrace();\n", + " \n", + " }" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Projeção" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.IProjectionProperties" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IProjectionProperties {\n", + " String[] getAttributes();\n", + " void setAttributes(String attribute[]);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.IProjection" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IProjection extends IProjectionProperties, ITableProducer, ITableReceptacle {\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.ProjectionComponent" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class ProjectionComponent implements IProjection {\n", + " private ITableProducer provider;\n", + " \n", + " private String attributes[] = null;\n", + " \n", + " public String[] getAttributes() {\n", + " return attributes;\n", + " }\n", + "\n", + " public void setAttributes(String attributes[]) {\n", + " this.attributes = attributes;\n", + " }\n", + " \n", + " public void connect(ITableProducer provider) {\n", + " this.provider = provider;\n", + " }\n", + " \n", + " public String[] requestAttributes() {\n", + " return attributes;\n", + " }\n", + " \n", + " public String[][] requestInstances() {\n", + " String[][] instances = null;\n", + " \n", + " if (provider != null) {\n", + " String[][] allInstances = provider.requestInstances();\n", + " if (allInstances != null && attributes != null) {\n", + " instances = new String[allInstances.length][];\n", + " \n", + " // busca a posicao dos atributos selecionados na tabela original\n", + " String[] allAttributes = provider.requestAttributes();\n", + " int attrPos[] = new int[attributes.length];\n", + " for (int as = 0; as < attributes.length; as++) {\n", + " int aa;\n", + " for (aa = 0; aa < allAttributes.length &&\n", + " !attributes[as].equalsIgnoreCase(allAttributes[aa]); aa++)\n", + " /* nothing */;\n", + " if (aa < allAttributes.length)\n", + " attrPos[as] = aa;\n", + " else\n", + " attrPos[as] = -1;\n", + " }\n", + " \n", + " // filtra atributos selecionados\n", + " for (int i = 0; i < allInstances.length; i++) {\n", + " instances[i] = new String[attributes.length];\n", + " for (int as = 0; as < attributes.length; as++)\n", + " if (attrPos[as] > -1)\n", + " instances[i][as] = allInstances[i][attrPos[as]];\n", + " }\n", + " }\n", + " }\n", + " \n", + " return instances;\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "=== Attributes ===\n", + "name, age\n", + "\n", + "=== Instances ===\n", + "Rot Donnadd, 43\n", + "Pid Mught, 38\n", + "Thulk Lebbimp, 63\n", + "Bouvossam Damme, 71\n", + "Pirg Zall, 48\n", + "Nullon Rackindock, 23\n", + "Shor Splitturch, 35\n", + "Ger Ackeng, 66\n", + "Gleldo Shruck, 45\n", + "Nadross Pilch, 60\n", + "Sadrent Pemmir, 73\n", + "Read Rait, 55\n", + "Dallun Whadder, 15\n", + "Eapplar Thorg, 25\n", + "Blottork Patter, 68\n", + "Darrutt Bottall, 75\n", + "Gallir Shauch, 20\n", + "Dirpe Polnay, 39\n", + "Harrimp Fottiem, 65\n" + ] + }, + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "try {\n", + " IDataSet dataset = new DataSetComponent();\n", + " dataset.setDataSource(\"../../../../src/db/datasets/zombie/complete/zombie-health-spreadsheet-ml-training.csv\");\n", + "\n", + " IProjection projection = new ProjectionComponent();\n", + " projection.connect(dataset);\n", + "\n", + " IConsole console = new ConsoleComponent();\n", + " console.connect(projection);\n", + "\n", + " String[] attributes = {\"name\", \"age\"};\n", + " projection.setAttributes(attributes);\n", + " console.update();\n", + "} catch (Exception e) {\n", + " e.printStackTrace();\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Seleção" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.ISelectionProperties" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface ISelectionProperties {\n", + " String getAttribute();\n", + " void setAttribute(String attributeA);\n", + " public String getOperator();\n", + " public void setOperator(String operator);\n", + " public String getValue();\n", + " public void setValue(String value);\n", + " boolean isNominalComparison();\n", + " void setNominalComparison(boolean nominalComparison);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.ISelection" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface ISelection extends ISelectionProperties, ITableProducer, ITableReceptacle {\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.SelectionComponent" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import java.util.ArrayList;\n", + "\n", + "public class SelectionComponent implements ISelection {\n", + " private ITableProducer provider;\n", + " \n", + " private String attribute = null,\n", + " operator = null,\n", + " value = null;\n", + " private boolean nominalComparison = true;\n", + " \n", + " public String getAttribute() {\n", + " return attribute;\n", + " }\n", + "\n", + " public void setAttribute(String attribute) {\n", + " this.attribute = attribute;\n", + " }\n", + " \n", + " public String getOperator() {\n", + " return operator;\n", + " }\n", + " \n", + " public void setOperator(String operator) {\n", + " this.operator = operator;\n", + " }\n", + " \n", + " public String getValue() {\n", + " return value;\n", + " }\n", + " \n", + " public void setValue(String value) {\n", + " this.value = value;\n", + " }\n", + " \n", + " public boolean isNominalComparison() {\n", + " return nominalComparison;\n", + " }\n", + "\n", + " public void setNominalComparison(boolean nominalComparison) {\n", + " this.nominalComparison = nominalComparison;\n", + " }\n", + "\n", + " public void connect(ITableProducer provider) {\n", + " this.provider = provider;\n", + " }\n", + " \n", + " public String[] requestAttributes() {\n", + " return (provider == null) ? null : provider.requestAttributes();\n", + " }\n", + " \n", + " public String[][] requestInstances() {\n", + " ArrayList instances = null;\n", + " \n", + " if (provider != null) {\n", + " String[][] allInstances = provider.requestInstances();\n", + " \n", + " if (allInstances != null) {\n", + " // busca a posicao dos atributos selecionados na tabela original\n", + " String[] allAttributes = provider.requestAttributes();\n", + " int atrPos;\n", + " for (atrPos = 0; atrPos < allAttributes.length &&\n", + " !attribute.equalsIgnoreCase(allAttributes[atrPos]); atrPos++)\n", + " /* nothing */;\n", + " if (atrPos < allAttributes.length) {\n", + " instances = new ArrayList();\n", + " \n", + " for (String[] ai: allInstances) {\n", + " boolean match = false;\n", + " if (nominalComparison) {\n", + " switch (operator.charAt(0)) {\n", + " case '=': if (ai[atrPos].equalsIgnoreCase(value))\n", + " match = true;\n", + " break;\n", + " case '<': if (ai[atrPos].compareTo(value) < 0)\n", + " match = true;\n", + " break;\n", + " case '>': if (ai[atrPos].compareTo(value) > 0)\n", + " match = true;\n", + " break;\n", + " case '!': if (!ai[atrPos].equalsIgnoreCase(value))\n", + " match = true;\n", + " break;\n", + " }\n", + " } else {\n", + " switch (operator.charAt(0)) {\n", + " case '=': if (Double.parseDouble(ai[atrPos]) == Double.parseDouble(value))\n", + " match = true;\n", + " break;\n", + " case '<': if (Double.parseDouble(ai[atrPos]) < Double.parseDouble(value))\n", + " match = true;\n", + " break;\n", + " case '>': if (Double.parseDouble(ai[atrPos]) > Double.parseDouble(value))\n", + " match = true;\n", + " break;\n", + " case '!': if (Double.parseDouble(ai[atrPos]) != Double.parseDouble(value))\n", + " match = true;\n", + " break;\n", + " }\n", + " }\n", + " if (match)\n", + " instances.add(ai);\n", + " \n", + " }\n", + " }\n", + " }\n", + " }\n", + " \n", + " return (instances == null) ? null : instances.toArray(new String[1][]);\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "=== Attributes ===\n", + "name, age, paralysis, yellow_tong, member_loss, chest_pain, trembling_finger, severe_anger, history_bacteria, diagnostic, days_recovery, has_disease\n", + "\n", + "=== Instances ===\n", + "Rot Donnadd, 43, t, t, f, f, f, f, f, bacterial_infection, 9, t\n", + "Pid Mught, 38, f, t, f, f, f, f, f, bacterial_infection, 7, t\n", + "Gleldo Shruck, 45, f, t, f, t, f, f, f, bacterial_infection, 8, t\n", + "Read Rait, 55, t, t, f, f, f, f, f, bacterial_infection, 9, t\n", + "Dirpe Polnay, 39, f, t, f, f, f, f, f, bacterial_infection, 7, t\n" + ] + }, + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "try {\n", + " IDataSet dataset = new DataSetComponent();\n", + " dataset.setDataSource(\"../../../../src/db/datasets/zombie/complete/zombie-health-spreadsheet-ml-training.csv\");\n", + "\n", + " ISelection selection = new SelectionComponent();\n", + " selection.connect(dataset);\n", + " selection.setAttribute(\"diagnostic\");\n", + " selection.setOperator(\"=\");\n", + " selection.setValue(\"bacterial_infection\");\n", + "\n", + " IConsole console = new ConsoleComponent();\n", + " console.connect(selection);\n", + " console.update();\n", + "} catch (Exception e) {\n", + " e.printStackTrace();\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Chart" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.IChartProperties" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IChartProperties {\n", + " \n", + " String getTitle();\n", + " void setTitle(String title);\n", + " String getXTitle();\n", + " void setXTitle(String title);\n", + " String getYTitle();\n", + " void setYTitle(String title);\n", + "\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.IRun" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IRun {\n", + "\n", + " public boolean start();\n", + " public boolean stop();\n", + " \n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.IChart" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IChart extends ITableReceptacle, IRun, IChartProperties {\n", + " \n", + " /* Component Interfaces Set */\n", + "\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "3421dfed-f815-4247-a26f-490ee0637955", + "version_major": 2, + "version_minor": 0 + }, + "method": "display_data" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%classpath add jar ../../../../src/lib/xchart-3.5.2.jar" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.ChartBubbleComponent" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import java.util.ArrayList;\n", + "import java.util.Hashtable;\n", + "import java.util.List;\n", + "\n", + "import java.io.IOException;\n", + "\n", + "import org.knowm.xchart.BubbleChart;\n", + "import org.knowm.xchart.BubbleChartBuilder;\n", + "import org.knowm.xchart.SwingWrapper;\n", + "import org.knowm.xchart.BitmapEncoder;\n", + "import org.knowm.xchart.BitmapEncoder.BitmapFormat;\n", + "\n", + "import com.twosigma.beakerx.mimetype.MIMEContainer;\n", + "import java.io.File;\n", + "import java.nio.file.Files;\n", + "\n", + "public class ChartBubbleComponent implements IChart {\n", + " private BubbleChart chart = null;\n", + "\n", + " private String title = \"Chart\";\n", + " private String xTitle = \"X\",\n", + " yTitle = \"Y\";\n", + "\n", + " private ITableProducer producer = null;\n", + " \n", + " public void connect(ITableProducer producer) {\n", + " this.producer = producer;\n", + " }\n", + " \n", + " public ChartBubbleComponent() {\n", + " }\n", + " \n", + " public String getTitle() {\n", + " return title;\n", + " }\n", + " \n", + " public void setTitle(String title) {\n", + " this.title = title;\n", + " }\n", + "\n", + " public String getXTitle() {\n", + " return xTitle;\n", + " }\n", + " \n", + " public void setXTitle(String title) {\n", + " xTitle = title;\n", + " }\n", + "\n", + " public String getYTitle() {\n", + " return title;\n", + " }\n", + " \n", + " public void setYTitle(String title) {\n", + " yTitle = title;\n", + " }\n", + "\n", + " public boolean start() {\n", + " boolean status = true;\n", + " \n", + " chart = new BubbleChartBuilder().width(600).height(400).title(title).xAxisTitle(xTitle).yAxisTitle(yTitle).build();\n", + " try{\n", + " \n", + " buildChart(); \n", + " BitmapEncoder.saveBitmap(chart, \"./chart\", BitmapFormat.PNG);\n", + " \n", + " File file = new File(\"chart.png\");\n", + " byte[] data = Files.readAllBytes(file.toPath());\n", + " \n", + " MIMEContainer image = new MIMEContainer(MIMEContainer.MIME.IMAGE_PNG, data);\n", + " display(image);\n", + " }catch(IOException ex){\n", + " status = false;\n", + " System.out.println (ex.toString()); \n", + " }\n", + " \n", + " return status;\n", + " }\n", + " \n", + " public boolean stop() {\n", + " return true;\n", + " }\n", + " \n", + " public double[] toDouble(String[][] instances, int column ) {\n", + " double[] numbers = new double[instances.length];\n", + " for (int i = 0; i < instances.length; i++)\n", + " numbers[i] = Double.parseDouble(instances[i][column]);\n", + " return numbers;\n", + " }\n", + "\n", + " private void buildChart() {\n", + " if (chart != null && producer != null) {\n", + " String[][] instances = producer.requestInstances();\n", + "\n", + " if (instances != null) {\n", + " double[] xData = toDouble(instances, 0),\n", + " yData = toDouble(instances, 1);\n", + " \n", + " String[] categoryData = null;\n", + " if (instances[0].length > 2) {\n", + " categoryData = new String[instances.length];\n", + " for (int c = 0; c < instances.length; c++)\n", + " categoryData[c] = instances[c][2];\n", + " }\n", + " \n", + " double[] bubbleData = null;\n", + " if (instances[0].length > 3)\n", + " bubbleData = toDouble(producer.requestInstances(), 3);\n", + " else {\n", + " bubbleData = new double[instances.length];\n", + " for (int i = 0; i < xData.length; i++)\n", + " bubbleData[i] = 10;\n", + " }\n", + " \n", + " \n", + " if (categoryData == null ||\n", + " xData.length != yData.length || yData.length != bubbleData.length ||\n", + " bubbleData.length != categoryData.length) {\n", + " chart.addSeries(\" \", xData, yData, bubbleData);\n", + " } else {\n", + " Hashtable hash = new Hashtable();\n", + " int outer = 0;\n", + " int size = categoryData.length;\n", + " while (outer < size) {\n", + " if (hash.containsKey(categoryData[outer]))\n", + " outer++;\n", + " else {\n", + " hash.put(categoryData[outer],categoryData[outer]);\n", + " List xSub = new ArrayList(),\n", + " ySub = new ArrayList(),\n", + " bubbleSub = new ArrayList();\n", + " for (int inner = outer; inner < size; inner++)\n", + " if (categoryData[inner].equalsIgnoreCase(categoryData[outer])) {\n", + " xSub.add(xData[inner]);\n", + " ySub.add(yData[inner]);\n", + " bubbleSub.add(bubbleData[inner]);\n", + " }\n", + " chart.addSeries(categoryData[outer], xSub, ySub, bubbleSub);\n", + " outer++;\n", + " }\n", + " }\n", + " }\n", + " }\n", + " \n", + " }\n", + " \n", + " }\n", + " \n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAlgAAAGQCAIAAAD9V4nPAAA4e0lEQVR42u2df0xc157YLU1bunS9dVv24ZBn4rFJgoNDQl5wiHkxecAkYBMw2CYQY4cYG3tsSPCz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9isAH/NQBECBArIpQEyxKeEZskUmIaa4VkI0LzMnFPVlaWbEgqZn5dUrT09HSrEXJxRxjz58RMYhqTyZmWTPP+kqv5LllnloiT4zk5Ob5vYg7m5ub67prXSACyXVVVZXxmAlvqzS0Rmn/KtwQW/2sAiBDAySKsqakRM0mSZFaHN9mV8YfZNm2GljMkjUtMTIyLi3O5XKYp8tP5riVWv5XKysqAq8z7etdqbpXfEmXKdnJystWTxTTJGhnLHxoYGDB/YmxszLxYPDo6OiqRmKXDzW1CeYG82CjWyiOXevOAIgz4rwEgQgCHi9AXSa2MMLq6ukxXFMmuxCJ+zhBrmiONjY3miKhUXiz6kXxLRLJMRmhEKMoxu8aXpmeKOEx+XVRktVh6PB4ThrxY3lYOyi9mZ2ebbNU4z+12W/cjTYcXQbJD6+8u9eaLRRjwXwNAhACORa715s7ZmTNnWltbh4aGfJ8Vk5WVlVVXV4sqzMusnE/EY3I1y0DylLxbeXl5SUlJVVWV7403vz9nOqp8On9bUXaNb0RvbW1t5tflL8qfNr1UfI/LiyULNAclWolNDorwrKgEyR39Ql3mzRe/MuC/BoAIAWABFy5cqKmpMQMP+NcAECFAzGGaNFNTUxePFORfA0CEAAAAiBAAAAARAgAAIEIAAABECAAAgAgBAAAQIQAAACIEAABAhAAAAIgQAADA1vx/EbPcLSwNmGwAAAAASUVORK5CYII=" + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "true" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "IDataSet dataset = new DataSetComponent();\n", + "dataset.setDataSource(\"../../../../src/db/datasets/zombie/complete/zombie-health-spreadsheet-ml-training.csv\");\n", + "\n", + "IProjection projection = new ProjectionComponent();\n", + "projection.connect(dataset);\n", + "String attributes[] = {\"days_recovery\", \"age\"};\n", + "projection.setAttributes(attributes);\n", + "\n", + "IChart chart = new ChartBubbleComponent();\n", + "chart.setTitle(\"Zombie Health\");\n", + "chart.setXTitle(\"Days Recovery\");\n", + "chart.setYTitle(\"Age\");\n", + "chart.connect(projection);\n", + "\n", + "return chart.start();\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Statistics" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.IStatisticsProperties" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IStatisticsProperties {\n", + "\n", + " int getSize();\n", + "\n", + " double[] getValueSet();\n", + "\n", + " void setValueSet(double[] valueSet);\n", + "\n", + " double getValueSet(int index);\n", + "\n", + " void setValueSet(int index, double value);\n", + "\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.IStatisticsServices" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "/**\n", + " * Interface for a Statistics Class that registers a set of numbers\n", + " * and calculates the sum and average of these numbers. \n", + " * \n", + " * @author Andre Santanche\n", + " */\n", + "public interface IStatisticsServices {\n", + " /**\n", + " * Inserts a value into the set.\n", + " * @param value the value to be inserted into the set\n", + " */\n", + " public void insertValue(double value);\n", + "\n", + " \n", + " /**\n", + " * Calculates the sum of the values in the set. Returns zero if the set is empty.\n", + " * @return sum of the values in the set\n", + " */\n", + " public double sum();\n", + " \n", + " \n", + " /**\n", + " * Calculates the average of the values in the set. Returns zero if the set is empty.\n", + " * @return average of the values in the set\n", + " */\n", + " public double average();\n", + "}\n" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.IStatistics" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IStatistics extends IStatisticsServices, IStatisticsProperties {\n", + "\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.StatisticsComponent" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import java.util.Vector;\n", + "\n", + "/**\n", + " * Registers a set of numbers and calculates the sum and average of these numbers.\n", + " * \n", + " * @author Andre Santanche\n", + " */\n", + "public class StatisticsComponent implements IStatistics {\n", + " private Vector valueSet;\n", + " \n", + " /*\n", + " * Constructor\n", + " **************/\n", + "\n", + " public StatisticsComponent() {\n", + " super();\n", + " valueSet = new Vector();\n", + " }\n", + " \n", + " public StatisticsComponent(int capacity) {\n", + " super();\n", + " valueSet = new Vector(capacity);\n", + " }\n", + "\n", + " /* Properties\n", + " ************/\n", + " \n", + " public int getSize() {\n", + " return valueSet.size();\n", + " }\n", + " \n", + " public double[] getValueSet() {\n", + " int size = valueSet.size();\n", + " double result[] = new double[size];\n", + " for (int d = 0; d < size; d++)\n", + " result[d] = valueSet.get(d);\n", + " return result;\n", + " }\n", + "\n", + " public void setValueSet(double[] valueSet) {\n", + " for (int d = 0; d < valueSet.length; d++)\n", + " this.valueSet.add(valueSet[d]);\n", + " }\n", + " \n", + " public double getValueSet(int index) {\n", + " return (index < getSize()) ? valueSet.get(index) : 0;\n", + " }\n", + " \n", + " public void setValueSet(int index, double value) {\n", + " int position = (index < getSize()) ? index : getSize();\n", + " if (position < getSize())\n", + " valueSet.set(index, value);\n", + " else\n", + " valueSet.add(value);\n", + " }\n", + "\n", + " /*\n", + " * IStatisticsServices Interface\n", + " *******************************/\n", + " \n", + " public void insertValue(double value) {\n", + " valueSet.add(value);\n", + " }\n", + "\n", + " public double sum() {\n", + " double theSum = 0.0f;\n", + " \n", + " for (double value : valueSet)\n", + " theSum += value;\n", + " \n", + " return theSum;\n", + " }\n", + "\n", + " public double average() {\n", + " double avg = 0;\n", + " \n", + " if (valueSet.size() > 0)\n", + " avg = sum() / valueSet.size();\n", + " \n", + " return avg;\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "inserido valor: 50.0\n", + "inserido valor: 70.0\n", + "inserido valor: 30.0\n", + "-- somatorio: 150.0\n", + "-- media: 50.0\n", + "-- tamanho: 3\n" + ] + }, + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "try {\n", + " IStatistics stat = new StatisticsComponent(3);\n", + "\n", + " System.out.println(\"inserido valor: \" + 50.0f);\n", + " stat.insertValue(50.0f);\n", + " System.out.println(\"inserido valor: \" + 70.0f);\n", + " stat.insertValue(70.0f);\n", + " System.out.println(\"inserido valor: \" + 30.0f);\n", + " stat.insertValue(30.0f);\n", + "\n", + " System.out.println(\"-- somatorio: \" + stat.sum());\n", + " System.out.println(\"-- media: \" + stat.average());\n", + " System.out.println(\"-- tamanho: \" + stat.getSize());\n", + "} catch (Exception e) {\n", + " e.printStackTrace();\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Statistics Required" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.IRun" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IRun {\n", + " \n", + " public void start();\n", + " \n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.IStatisticsReceptacle" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IStatisticsReceptacle{\n", + " \n", + " public void connect(IStatistics provider);\n", + " \n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.IClientProperties" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IClientProperties {\n", + " public int getSize(); \n", + " public void setSize(int size);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.IClient" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IClient extends IStatisticsReceptacle, IClientProperties, IRun {\n", + "\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkra530b65c.ClientComponent" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class ClientComponent implements IClient {\n", + " public final static int STANDARD_SIZE = 5;\n", + " \n", + " private int size;\n", + " private int first, second;\n", + " \n", + " private IStatistics provider = null;\n", + " \n", + " /*\n", + " * Constructor\n", + " *************/\n", + " \n", + " public ClientComponent() {\n", + " super();\n", + " size = STANDARD_SIZE;\n", + " first = 1;\n", + " second = 1;\n", + " }\n", + " \n", + " /*\n", + " * Properties\n", + " */\n", + " \n", + " public int getSize() {\n", + " return size;\n", + " }\n", + " \n", + " public void setSize(int size) {\n", + " this.size = size;\n", + " }\n", + " \n", + " /*\n", + " * IStatisticsReceptacle Interface\n", + " **********************************/\n", + " \n", + " public void connect(IStatistics provider)\n", + " {\n", + " this.provider = provider;\n", + " }\n", + " \n", + " public int next() {\n", + " int returnNumber = first;\n", + " first = second;\n", + " second = returnNumber + first;\n", + " return returnNumber;\n", + " }\n", + " \n", + " public void start()\n", + " {\n", + " for (int f = 1; f <= size; f++) {\n", + " int nextNumber = next();\n", + " System.out.println(\"produzido: \" + nextNumber);\n", + " provider.insertValue(nextNumber);\n", + " }\n", + " \n", + " System.out.println(\"-- somatorio: \" + provider.sum());\n", + " System.out.println(\"-- media: \" + provider.average());\n", + " }\n", + " \n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Exercícios" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercício 1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Conecte os componentes que você achar necessário para mostrar no console o nome e a idade de zumbis com infecção bacteriana." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercício 2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Considerando que o `ClientComponent` gera uma sequência de Fibonacci e que a propriedade `size` deste componente define quantos elementos haverá nessa sequência, conecte `StatisticsComponent` e o `ClientComponent` para que em conjunto calculem a média dos 10 primeiros termos da sequência de Fibonacci." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercício 3" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Escreva um componente que se ligue a um componente que forneça a interface `ITableProducer` e que gere uma saída convertendo a primeira coluna da tabela em um vetor de double. Este componente espera que a primeira coluna seja double." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercício 4\n", + "\n", + "Usando o seu componente e o `StatisticsComponent`, escreva um código que calcule a média de idade de zumbis." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercício 5" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Construa um componente que, dado um dataset e duas colunas alvo, faça a média dos valores da segunda coluna em relação a cada valor distinto da primeira coluna. Seu componente espera o dataset e duas variáveis do tipo `String` referentes à colunas alvo. A primeira String é referente a uma coluna com valores categóricos do Dataset. A segunda String é referente a uma coluna numérica do dataset. Seu componente deverá fazer, para cada valor distinto da primeira coluna alvo, a média dos valores da segunda coluna alvo.\n", + "\n", + "\n", + "Considere, por exemplo, o csv disponível no caminho `\"../../../../src/db/datasets/zombie/complete/zombie-health-spreadsheet-ml-training.csv\"`. \n", + "Dadas as Strings `column1 = \"diagnostic\"` e `column2 = \"age\"`, seu componente deverá fazer a média das idades associadas a cada um dos diagnósticos.\n", + "\n", + "Este componente deve obrigatoriamente ser feito pela conexão de outros componentes." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Java", + "language": "java", + "name": "java" + }, + "language_info": { + "codemirror_mode": "text/x-java", + "file_extension": ".java", + "mimetype": "", + "name": "Java", + "nbconverter_exporter": "", + "version": "1.8.0_152-release" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": false, + "sideBar": false, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": false, + "toc_window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/components-01-catalog.ipynb b/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/components-01-catalog.ipynb index 4d9a70467..c7f391b30 100644 --- a/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/components-01-catalog.ipynb +++ b/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/components-01-catalog.ipynb @@ -1 +1,732 @@ -{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Componentes de Software\n\nA seguir são reunidos alguns conceitos importantes para se entender o princípio de **Componentes de Software**.\n\nEm linhas gerais, um componente é um módulo de software reusável, que se liga aos seus parceiros exclusivamente através de interfaces. Apresentaremos aqui uma abordagem típica de ligação de componentes baseada em interfaces e conexões:\n* **Interfaces** - expressam os serviços providos pelos componentes, declarados através de `interfaces` Java;\n* **Conexões** - é a forma como componentes são ligados entre si; a partir delas um componente toma conhecimento do outro para que se comuniquem.\n\n## Interfaces\n\nIdealmente, todas as funcionalidades de um componente deveriam ser acessadas exclusivamente através de interfaces.\n\nVamos analisar o processo de definição do `DataSetComponent` como um componente de software. Considerando que o código a seguir é uma versão inicial do componente, uma representação visual para o mesmo pode ser feita em UML, conforme segue:\n\n![Componente](console-dataset-a.png)\n\nVeja a seguir a representação em Java:\n\n~~~java\npublic interface IDataSetProperties {\n public String getDataSource();\n public void setDataSource(String dataSource);\n}\n\npublic interface ITableProducer {\n String[] requestAttributes();\n String[][] requestInstances();\n}\n~~~\n\nNote que cada interface que ele disponibiliza é apresentada na forma de uma haste com um círculo na ponta.\n\nComo a interface `IDataSetProperties` tem métodos `get` e `set` para definir a propriedade `DataSource`, em vez de representar essa interface da forma tradicional, podemos representá-la na forma de uma propriedade associada ao componente como segue:\n\n![Componente](console-dataset-b.png)\n\nA representação de propriedades não é padrão UML, mas é usada por algumas extensões. Isso introduz um terceiro elemento usual em algumas implementações de componentes:\n\n* **Propriedades** - podem ser usadas como mecanismos de configuração externa do componente; por exemplo, através da propriedade `dataSource` é possível externamente se configurar a fonte de dados do componente.\n\nA partir de agora, criaremos uma interface específica para a modificação de propriedades e usaremos a representação na forma de propriedade.\n\nPara englobar todas as interfaces em uma única, foi usada a estratégia de criar uma interface para o componente (`IDataSet`) unificando as demais na forma de herança:\n\n~~~java\npublic interface IDataSet extends IDataSetProperties, ITableProducer {\n}\n~~~\n\nEssa estratégia será adotada em todos os componentes."},{"metadata":{},"cell_type":"markdown","source":"## Conexões\n\nUma das formas mais comuns de comunicação entre componentes é a criação de uma conexão entre eles. Em linguagens orientadas a objetos uma estratégia consiste em um objeto (componente) guardar a referência de outro objeto (componente).\n\nUtilizaremos um método padrão chamado `connect` que conecta dois componentes. Para isso um dos objetos recebe a referência de outro:\n~~~java\npublic void connect(ITableProducer producer)\n~~~\n\nEsse método recebe a referência para qualquer objeto que implementa a interface `ITableProducer` e a guarda. A referência é posteriormente usada para a comunicação entre os dois objetos.\n\n# Interface Requerida\n\nO ideal é que tudo seja explícito e que haja uma interface para realizar essa conexão. Desse modo, criaremos uma interface chamada `ITableReceptacle`. Ela define o método para se estabelecer a conexão com objetos que têm a interface `ITableProducer`.\n\n~~~java\npublic interface ITableReceptacle {\n public void connect(ITableProducer producer);\n}\n~~~\n\nA interface requerida é representada visualmente por um meio círculo e indica o nome da interface que ela requer:\n\n![Componente](console-dataset-d.svg)\n\nOutra maneira bastante usual de representar os dois componentes conectados é ligando diretamente a interface provida com a requerida:\n\n![Componente](console-dataset-e.svg)\n\nPara tornar o componente `ConsoleComponent` completamente acessível por interfaces, acrescentamos outra interface para o seu método `update()`.\n\n~~~java\npublic interface IConsoleUpdate {\n public void update();\n}\n~~~\n\nO Diagrama completo fica:\n\n![Componente](console-dataset-f.svg)\n\nComo foi feito antes, usamos a interface `IConsole` para juntar as duas outras interfaces através da herança:\n\n~~~java\npublic interface IConsole extends ITableReceptacle, IConsoleUpdate {\n}\n~~~"},{"metadata":{},"cell_type":"markdown","source":"# Composição de Componentes\n\nVamos ilustrar agora como criar uma composição de componentes. Inicialmente, vamos importar a biblioteca onde estão implementados:"},{"metadata":{"trusted":false},"cell_type":"code","source":"%classpath add jar ../../../lib/component-catalog-2020-08-04.jar","execution_count":1,"outputs":[{"data":{"application/vnd.jupyter.widget-view+json":{"model_id":"1553b31d-3362-4da7-bb86-791b7de45195","version_major":2,"version_minor":0},"method":"display_data"},"metadata":{},"output_type":"display_data"}]},{"metadata":{},"cell_type":"markdown","source":"## Usando a Interface Requerida\n\nNote no código a seguir que ambos os componentes passam a ser tratados completamente a partir de suas interfaces. Mais adiante analisaremos a importância de realizar dessa maneira."},{"metadata":{"trusted":false},"cell_type":"code","source":"import pt.c08componentes.s20catalog.s10ds.*;\nimport pt.c08componentes.s20catalog.s20console.*;\n\nIDataSet dataset = new DataSetComponent();\ndataset.setDataSource(\"../../../db/zombie/zombie-health-spreadsheet.csv\");\n\nIConsole console = new ConsoleComponent();\nconsole.connect(dataset);\n\nconsole.update();","execution_count":2,"outputs":[{"name":"stdout","output_type":"stream","text":"=== Attributes ===\nname, age, paralysis, yellow_tong, member_loss, chest_pain, trembling_finger, severe_anger, history_bacteria, diagnostic, days_recovery, has_disease\n\n=== Instances ===\nRot Donnadd, 43, t, t, f, f, f, f, f, bacterial_infection, 9, t\nPid Mught, 38, f, t, f, f, f, f, f, bacterial_infection, 7, t\nThulk Lebbimp, 63, f, t, f, f, t, f, t, bite_deficit, 10, t\nBouvossam Damme, 71, f, t, t, f, t, f, f, bite_deficit, 13, t\nPirg Zall, 48, f, f, t, t, f, f, f, viral_infection, 4, t\nNullon Rackindock, 23, f, f, t, f, f, t, f, fights, 8, f\nShor Splitturch, 35, f, f, f, f, f, t, f, nothing, 0, f\nGer Ackeng, 66, f, f, f, f, t, f, f, bite_deficit, 11, t\nGleldo Shruck, 45, f, t, f, t, f, f, f, bacterial_infection, 8, t\nNadross Pilch, 60, f, f, f, t, f, f, f, viral_infection, 8, t\nSadrent Pemmir, 73, f, t, t, f, f, f, t, bite_deficit, 14, t\nRead Rait, 55, t, t, f, f, f, f, f, bacterial_infection, 9, t\nDallun Whadder, 15, f, f, f, t, f, f, t, viral_infection, 2, t\nEapplar Thorg, 25, f, f, t, f, f, f, f, fights, 5, f\nBlottork Patter, 68, f, t, f, f, t, f, t, bite_deficit, 12, t\nDarrutt Bottall, 75, f, t, t, f, t, f, f, bite_deficit, 16, t\nGallir Shauch, 20, f, f, f, t, f, f, f, fights, 12, f\nDirpe Polnay, 39, f, t, f, f, f, f, f, bacterial_infection, 7, t\nHarrimp Fottiem, 65, f, f, f, f, t, f, f, bite_deficit, 9, t\n"},{"data":{"text/plain":"null"},"execution_count":2,"metadata":{},"output_type":"execute_result"}]},{"metadata":{},"cell_type":"markdown","source":"# Projection Component\n\nComponente que realiza o recorte (projeção) de colunas em uma tabela.\n\n![Projection Component](projection-component.png)\n\n~~~java\npublic interface IProjectionProperties {\n String[] getAttributes();\n void setAttributes(String attribute[]);\n}\n\npublic interface IProjection extends IProjectionProperties, ITableProducer, ITableReceptacle {\n}\n~~~\n\nRecebe uma tabela de entrada (através da interface requerida `ITableProducer`) e gera uma tabela com as colunas recortadas (através da interface provida `ITableProducer`). A propriedade `attributes` contém um vetor com o nome das colunas a serem filtradas."},{"metadata":{},"cell_type":"markdown","source":"## Tarefa 1\n\nConecte o componente `DataSet` aos componentes de projeção e console para mostrar na tela as seguintes colunas: `name` e `age`."},{"metadata":{"trusted":false},"cell_type":"code","source":"import pt.c08componentes.s20catalog.s10ds.*;\nimport pt.c08componentes.s20catalog.s20console.*;\nimport pt.c08componentes.s20catalog.s30projection.*;\n\n","execution_count":3,"outputs":[{"data":{"text/plain":"null"},"execution_count":3,"metadata":{},"output_type":"execute_result"}]},{"metadata":{},"cell_type":"markdown","source":"# Selection Component\n\nComponente que seleciona linhas da tabela que atendem a uma certa condição.\n\n![Selection Component](selection-component.png)\n\n~~~java\npublic interface ISelectionProperties {\n String getAttribute();\n void setAttribute(String attributeA);\n public String getOperator();\n public void setOperator(String operator);\n public String getValue();\n public void setValue(String value);\n boolean isNominalComparison();\n void setNominalComparison(boolean nominalComparison);\n}\n~~~\n\nOs três propriedades `attribute`, `operator` e `value` definem a expressão de seleção. Por exemplo, a seguinte seleção `name = Rot Donnadd` seria:\n* **attribute:** `name`\n* **operator:** `=`\n* **value:** ` Rot Donnadd`\n\nA propriedade `nominalComparison` indica se a comparação será entre strings (`true`) ou números (`false`). O padrão é `true`.\n\nA interface unificada do componente é:\n~~~java\npublic interface ISelection extends ISelectionProperties, ITableProducer, ITableReceptacle {\n}\n~~~"},{"metadata":{},"cell_type":"markdown","source":"## Tarefa 2\n\nConecte o componente `DataSet` aos componentes de seleção e console para mostrar na tela aquelas instâncias cujo diagnóstico seja `bacterial_infection`."},{"metadata":{"trusted":false},"cell_type":"code","source":"import pt.c08componentes.s20catalog.s10ds.*;\nimport pt.c08componentes.s20catalog.s20console.*;\nimport pt.c08componentes.s20catalog.s40selection.*;\n\n","execution_count":4,"outputs":[{"data":{"text/plain":"null"},"execution_count":4,"metadata":{},"output_type":"execute_result"}]},{"metadata":{},"cell_type":"markdown","source":"## Tarefa 3\n\nConecte os componentes que você achar necessários para mostrar no console as colunas `name` e `age` de zumbis com `bacterial_infection`."},{"metadata":{"trusted":false},"cell_type":"code","source":"import pt.c08componentes.s20catalog.s10ds.*;\nimport pt.c08componentes.s20catalog.s20console.*;\nimport pt.c08componentes.s20catalog.s40selection.*;\nimport pt.c08componentes.s20catalog.s30projection.*;\n\n","execution_count":5,"outputs":[{"data":{"text/plain":"null"},"execution_count":5,"metadata":{},"output_type":"execute_result"}]},{"metadata":{},"cell_type":"markdown","source":"# Bubble Chart Component\n\nComponente que plota um gráfico de dispersão de uma tabela recebida como entrada. Para isso a tabela deve ter recortadas apenas as duas colunas que serão apresentadas.\n\n![Bubble Chart Component](chartbubble-component.png)\n\nAs propriedades `Title`, `XTitle` e `YTitle` são os títulos do gráfico, do eixo X e Y respectivamente.\n\nA interface `IRun` dispõe de métodos para ativar e desativar a plotagem do gráfico (métodos `start` e `stop` respectivamente):\n\n~~~java\npublic interface IRun {\n public boolean start();\n public boolean stop();\n}\n\npublic interface IChart extends ITableReceptacle, IRun, IChartProperties {\n /* Component Interfaces Set */\n}\n~~~\n\nA interface unificada é:\n\n~~~java\npublic interface IChart extends ITableReceptacle, IRun, IChartProperties {\n /* Component Interfaces Set */\n}\n~~~\n\nO comando a seguir importa uma biblioteca gráfica necessária para o componente:"},{"metadata":{"trusted":false},"cell_type":"code","source":"%classpath add jar ../../../lib/xchart-3.5.2.jar","execution_count":6,"outputs":[{"data":{"application/vnd.jupyter.widget-view+json":{"model_id":"ee23ed2d-8bb6-44f9-bcb5-5c53fefe7ca4","version_major":2,"version_minor":0},"method":"display_data"},"metadata":{},"output_type":"display_data"}]},{"metadata":{"jupyter":{"source_hidden":true},"trusted":false},"cell_type":"code","source":"import java.util.ArrayList;\nimport java.util.Hashtable;\nimport java.util.List;\n\nimport java.io.IOException;\n\nimport org.knowm.xchart.BubbleChart;\nimport org.knowm.xchart.BubbleChartBuilder;\nimport org.knowm.xchart.SwingWrapper;\nimport org.knowm.xchart.BitmapEncoder;\nimport org.knowm.xchart.BitmapEncoder.BitmapFormat;\n\nimport com.twosigma.beakerx.mimetype.MIMEContainer;\nimport java.io.File;\nimport java.nio.file.Files;\n\nimport pt.c08componentes.s20catalog.s00shared.*;\nimport pt.c08componentes.s20catalog.s50chart.IChart;\n\npublic class ChartBubbleComponent implements IChart {\n private BubbleChart chart = null;\n\n private String title = \"Chart\";\n private String xTitle = \"X\",\n yTitle = \"Y\";\n\n private ITableProducer producer = null;\n \n public void connect(ITableProducer producer) {\n this.producer = producer;\n }\n \n public ChartBubbleComponent() {\n }\n \n public String getTitle() {\n return title;\n }\n \n public void setTitle(String title) {\n this.title = title;\n }\n\n public String getXTitle() {\n return xTitle;\n }\n \n public void setXTitle(String title) {\n xTitle = title;\n }\n\n public String getYTitle() {\n return title;\n }\n \n public void setYTitle(String title) {\n yTitle = title;\n }\n\n public boolean start() {\n boolean status = true;\n \n chart = new BubbleChartBuilder().width(600).height(400).title(title).xAxisTitle(xTitle).yAxisTitle(yTitle).build();\n try{\n \n buildChart(); \n BitmapEncoder.saveBitmap(chart, \"./chart\", BitmapFormat.PNG);\n \n File file = new File(\"chart.png\");\n byte[] data = Files.readAllBytes(file.toPath());\n \n MIMEContainer image = new MIMEContainer(MIMEContainer.MIME.IMAGE_PNG, data);\n display(image);\n }catch(IOException ex){\n status = false;\n System.out.println (ex.toString()); \n }\n \n return status;\n }\n \n public boolean stop() {\n return true;\n }\n \n public double[] toDouble(String[][] instances, int column ) {\n double[] numbers = new double[instances.length];\n for (int i = 0; i < instances.length; i++)\n numbers[i] = Double.parseDouble(instances[i][column]);\n return numbers;\n }\n\n private void buildChart() {\n if (chart != null && producer != null) {\n String[][] instances = producer.requestInstances();\n\n if (instances != null) {\n double[] xData = toDouble(instances, 0),\n yData = toDouble(instances, 1);\n \n String[] categoryData = null;\n if (instances[0].length > 2) {\n categoryData = new String[instances.length];\n for (int c = 0; c < instances.length; c++)\n categoryData[c] = instances[c][2];\n }\n \n double[] bubbleData = null;\n if (instances[0].length > 3)\n bubbleData = toDouble(producer.requestInstances(), 3);\n else {\n bubbleData = new double[instances.length];\n for (int i = 0; i < xData.length; i++)\n bubbleData[i] = 10;\n }\n \n \n if (categoryData == null ||\n xData.length != yData.length || yData.length != bubbleData.length ||\n bubbleData.length != categoryData.length) {\n chart.addSeries(\" \", xData, yData, bubbleData);\n } else {\n Hashtable hash = new Hashtable();\n int outer = 0;\n int size = categoryData.length;\n while (outer < size) {\n if (hash.containsKey(categoryData[outer]))\n outer++;\n else {\n hash.put(categoryData[outer],categoryData[outer]);\n List xSub = new ArrayList(),\n ySub = new ArrayList(),\n bubbleSub = new ArrayList();\n for (int inner = outer; inner < size; inner++)\n if (categoryData[inner].equalsIgnoreCase(categoryData[outer])) {\n xSub.add(xData[inner]);\n ySub.add(yData[inner]);\n bubbleSub.add(bubbleData[inner]);\n }\n chart.addSeries(categoryData[outer], xSub, ySub, bubbleSub);\n outer++;\n }\n }\n }\n }\n \n }\n \n }\n \n}","execution_count":7,"outputs":[{"data":{"text/plain":"com.twosigma.beaker.javash.bkrba9cd7a8.ChartBubbleComponent"},"execution_count":7,"metadata":{},"output_type":"execute_result"}]},{"metadata":{},"cell_type":"markdown","source":"## Tarefa 4\n\nConecte os componentes que você achar necessários para apresentar um gráfico comparativo entre idade e tempo de recuperação dos zumbis, conforme exemplo abaixo.\n\n![Graph](example1.png)"},{"metadata":{"trusted":false},"cell_type":"code","source":"import pt.c08componentes.s20catalog.s10ds.*;\nimport pt.c08componentes.s20catalog.s30projection.*;\nimport pt.c08componentes.s20catalog.s50chart.IChart;\n\n","execution_count":8,"outputs":[{"data":{"text/plain":"null"},"execution_count":8,"metadata":{},"output_type":"execute_result"}]},{"metadata":{},"cell_type":"markdown","source":"## Tarefa 5\n\nConecte os componentes que você achar necessários para apresentar um gráfico comparativo entre idade e tempo de recuperação dos zumbis, colorindo os pontos por diagnóstico, conforme exemplo abaixo.\n\n**Recomendação:** Se você recortar uma terceira coluna com o diagnóstico, o gráfico resultante irá colorir os pontos por diagnóstico.\n\n![Graph](example2.png)"},{"metadata":{"trusted":false},"cell_type":"code","source":"import pt.c08componentes.s20catalog.s10ds.*;\nimport pt.c08componentes.s20catalog.s30projection.*;\nimport pt.c08componentes.s20catalog.s50chart.IChart;\n\n","execution_count":9,"outputs":[{"data":{"text/plain":"null"},"execution_count":9,"metadata":{},"output_type":"execute_result"}]},{"metadata":{},"cell_type":"markdown","source":"# Tarefa 6\n\nConecte os componentes que você achar necessários para apresentar um gráfico comparativo entre idade e tempo de recuperação, filtrando apenas a doença “bacterial_infection”."},{"metadata":{"trusted":false},"cell_type":"code","source":"import pt.c08componentes.s20catalog.s10ds.*;\nimport pt.c08componentes.s20catalog.s30projection.*;\nimport pt.c08componentes.s20catalog.s40selection.*;\nimport pt.c08componentes.s20catalog.s50chart.IChart;\n","execution_count":10,"outputs":[{"data":{"text/plain":"null"},"execution_count":10,"metadata":{},"output_type":"execute_result"}]}],"metadata":{"kernelspec":{"name":"java","display_name":"Java","language":"java"},"language_info":{"nbconverter_exporter":"","codemirror_mode":"text/x-java","name":"Java","mimetype":"","file_extension":".java","version":"11.0.8"},"toc":{"nav_menu":{},"number_sections":false,"sideBar":false,"skip_h1_title":false,"base_numbering":1,"title_cell":"Table of Contents","title_sidebar":"Contents","toc_cell":false,"toc_position":{},"toc_section_display":false,"toc_window_display":false}},"nbformat":4,"nbformat_minor":4} \ No newline at end of file +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Componentes de Software\n", + "\n", + "A seguir são reunidos alguns conceitos importantes para se entender o princípio de **Componentes de Software**.\n", + "\n", + "Em linhas gerais, um componente é um módulo de software reusável, que se liga aos seus parceiros exclusivamente através de interfaces. Apresentaremos aqui uma abordagem típica de ligação de componentes baseada em interfaces e conexões:\n", + "* **Interfaces** - expressam os serviços providos pelos componentes, declarados através de `interfaces` Java;\n", + "* **Conexões** - é a forma como componentes são ligados entre si; a partir delas um componente toma conhecimento do outro para que se comuniquem.\n", + "\n", + "## Interfaces\n", + "\n", + "Idealmente, todas as funcionalidades de um componente deveriam ser acessadas exclusivamente através de interfaces.\n", + "\n", + "Vamos analisar o processo de definição do `DataSetComponent` como um componente de software. Considerando que o código a seguir é uma versão inicial do componente, uma representação visual para o mesmo pode ser feita em UML, conforme segue:\n", + "\n", + "![Componente](console-dataset-a.png)\n", + "\n", + "Veja a seguir a representação em Java:\n", + "\n", + "~~~java\n", + "public interface IDataSetProperties {\n", + " public String getDataSource();\n", + " public void setDataSource(String dataSource);\n", + "}\n", + "\n", + "public interface ITableProducer {\n", + " String[] requestAttributes();\n", + " String[][] requestInstances();\n", + "}\n", + "~~~\n", + "\n", + "Note que cada interface que ele disponibiliza é apresentada na forma de uma haste com um círculo na ponta.\n", + "\n", + "Como a interface `IDataSetProperties` tem métodos `get` e `set` para definir a propriedade `DataSource`, em vez de representar essa interface da forma tradicional, podemos representá-la na forma de uma propriedade associada ao componente como segue:\n", + "\n", + "![Componente](console-dataset-b.png)\n", + "\n", + "A representação de propriedades não é padrão UML, mas é usada por algumas extensões. Isso introduz um terceiro elemento usual em algumas implementações de componentes:\n", + "\n", + "* **Propriedades** - podem ser usadas como mecanismos de configuração externa do componente; por exemplo, através da propriedade `dataSource` é possível externamente se configurar a fonte de dados do componente.\n", + "\n", + "A partir de agora, criaremos uma interface específica para a modificação de propriedades e usaremos a representação na forma de propriedade.\n", + "\n", + "Para englobar todas as interfaces em uma única, foi usada a estratégia de criar uma interface para o componente (`IDataSet`) unificando as demais na forma de herança:\n", + "\n", + "~~~java\n", + "public interface IDataSet extends IDataSetProperties, ITableProducer {\n", + "}\n", + "~~~\n", + "\n", + "Essa estratégia será adotada em todos os componentes." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Conexões\n", + "\n", + "Uma das formas mais comuns de comunicação entre componentes é a criação de uma conexão entre eles. Em linguagens orientadas a objetos uma estratégia consiste em um objeto (componente) guardar a referência de outro objeto (componente).\n", + "\n", + "Utilizaremos um método padrão chamado `connect` que conecta dois componentes. Para isso um dos objetos recebe a referência de outro:\n", + "~~~java\n", + "public void connect(ITableProducer producer)\n", + "~~~\n", + "\n", + "Esse método recebe a referência para qualquer objeto que implementa a interface `ITableProducer` e a guarda. A referência é posteriormente usada para a comunicação entre os dois objetos.\n", + "\n", + "# Interface Requerida\n", + "\n", + "O ideal é que tudo seja explícito e que haja uma interface para realizar essa conexão. Desse modo, criaremos uma interface chamada `ITableReceptacle`. Ela define o método para se estabelecer a conexão com objetos que têm a interface `ITableProducer`.\n", + "\n", + "~~~java\n", + "public interface ITableReceptacle {\n", + " public void connect(ITableProducer producer);\n", + "}\n", + "~~~\n", + "\n", + "A interface requerida é representada visualmente por um meio círculo e indica o nome da interface que ela requer:\n", + "\n", + "![Componente](console-dataset-d.svg)\n", + "\n", + "Outra maneira bastante usual de representar os dois componentes conectados é ligando diretamente a interface provida com a requerida:\n", + "\n", + "![Componente](console-dataset-e.svg)\n", + "\n", + "Para tornar o componente `ConsoleComponent` completamente acessível por interfaces, acrescentamos outra interface para o seu método `update()`.\n", + "\n", + "~~~java\n", + "public interface IConsoleUpdate {\n", + " public void update();\n", + "}\n", + "~~~\n", + "\n", + "O Diagrama completo fica:\n", + "\n", + "![Componente](console-dataset-f.svg)\n", + "\n", + "Como foi feito antes, usamos a interface `IConsole` para juntar as duas outras interfaces através da herança:\n", + "\n", + "~~~java\n", + "public interface IConsole extends ITableReceptacle, IConsoleUpdate {\n", + "}\n", + "~~~" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Composição de Componentes\n", + "\n", + "Vamos ilustrar agora como criar uma composição de componentes. Inicialmente, vamos importar a biblioteca onde estão implementados:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "1553b31d-3362-4da7-bb86-791b7de45195", + "version_major": 2, + "version_minor": 0 + }, + "method": "display_data" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%classpath add jar ../../../lib/component-catalog-2020-08-04.jar" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Usando a Interface Requerida\n", + "\n", + "Note no código a seguir que ambos os componentes passam a ser tratados completamente a partir de suas interfaces. Mais adiante analisaremos a importância de realizar dessa maneira." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "=== Attributes ===\n", + "name, age, paralysis, yellow_tong, member_loss, chest_pain, trembling_finger, severe_anger, history_bacteria, diagnostic, days_recovery, has_disease\n", + "\n", + "=== Instances ===\n", + "Rot Donnadd, 43, t, t, f, f, f, f, f, bacterial_infection, 9, t\n", + "Pid Mught, 38, f, t, f, f, f, f, f, bacterial_infection, 7, t\n", + "Thulk Lebbimp, 63, f, t, f, f, t, f, t, bite_deficit, 10, t\n", + "Bouvossam Damme, 71, f, t, t, f, t, f, f, bite_deficit, 13, t\n", + "Pirg Zall, 48, f, f, t, t, f, f, f, viral_infection, 4, t\n", + "Nullon Rackindock, 23, f, f, t, f, f, t, f, fights, 8, f\n", + "Shor Splitturch, 35, f, f, f, f, f, t, f, nothing, 0, f\n", + "Ger Ackeng, 66, f, f, f, f, t, f, f, bite_deficit, 11, t\n", + "Gleldo Shruck, 45, f, t, f, t, f, f, f, bacterial_infection, 8, t\n", + "Nadross Pilch, 60, f, f, f, t, f, f, f, viral_infection, 8, t\n", + "Sadrent Pemmir, 73, f, t, t, f, f, f, t, bite_deficit, 14, t\n", + "Read Rait, 55, t, t, f, f, f, f, f, bacterial_infection, 9, t\n", + "Dallun Whadder, 15, f, f, f, t, f, f, t, viral_infection, 2, t\n", + "Eapplar Thorg, 25, f, f, t, f, f, f, f, fights, 5, f\n", + "Blottork Patter, 68, f, t, f, f, t, f, t, bite_deficit, 12, t\n", + "Darrutt Bottall, 75, f, t, t, f, t, f, f, bite_deficit, 16, t\n", + "Gallir Shauch, 20, f, f, f, t, f, f, f, fights, 12, f\n", + "Dirpe Polnay, 39, f, t, f, f, f, f, f, bacterial_infection, 7, t\n", + "Harrimp Fottiem, 65, f, f, f, f, t, f, f, bite_deficit, 9, t\n" + ] + }, + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pt.c08componentes.s20catalog.s10ds.*;\n", + "import pt.c08componentes.s20catalog.s20console.*;\n", + "\n", + "IDataSet dataset = new DataSetComponent();\n", + "dataset.setDataSource(\"../../../db/zombie/zombie-health-spreadsheet.csv\");\n", + "\n", + "IConsole console = new ConsoleComponent();\n", + "console.connect(dataset);\n", + "\n", + "console.update();" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Projection Component\n", + "\n", + "Componente que realiza o recorte (projeção) de colunas em uma tabela.\n", + "\n", + "![Projection Component](projection-component.png)\n", + "\n", + "~~~java\n", + "public interface IProjectionProperties {\n", + " String[] getAttributes();\n", + " void setAttributes(String attribute[]);\n", + "}\n", + "\n", + "public interface IProjection extends IProjectionProperties, ITableProducer, ITableReceptacle {\n", + "}\n", + "~~~\n", + "\n", + "Recebe uma tabela de entrada (através da interface requerida `ITableProducer`) e gera uma tabela com as colunas recortadas (através da interface provida `ITableProducer`). A propriedade `attributes` contém um vetor com o nome das colunas a serem filtradas." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Tarefa 1\n", + "\n", + "Conecte o componente `DataSet` aos componentes de projeção e console para mostrar na tela as seguintes colunas: `name` e `age`." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pt.c08componentes.s20catalog.s10ds.*;\n", + "import pt.c08componentes.s20catalog.s20console.*;\n", + "import pt.c08componentes.s20catalog.s30projection.*;\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Selection Component\n", + "\n", + "Componente que seleciona linhas da tabela que atendem a uma certa condição.\n", + "\n", + "![Selection Component](selection-component.png)\n", + "\n", + "~~~java\n", + "public interface ISelectionProperties {\n", + " String getAttribute();\n", + " void setAttribute(String attributeA);\n", + " public String getOperator();\n", + " public void setOperator(String operator);\n", + " public String getValue();\n", + " public void setValue(String value);\n", + " boolean isNominalComparison();\n", + " void setNominalComparison(boolean nominalComparison);\n", + "}\n", + "~~~\n", + "\n", + "Os três propriedades `attribute`, `operator` e `value` definem a expressão de seleção. Por exemplo, a seguinte seleção `name = Rot Donnadd` seria:\n", + "* **attribute:** `name`\n", + "* **operator:** `=`\n", + "* **value:** ` Rot Donnadd`\n", + "\n", + "A propriedade `nominalComparison` indica se a comparação será entre strings (`true`) ou números (`false`). O padrão é `true`.\n", + "\n", + "A interface unificada do componente é:\n", + "~~~java\n", + "public interface ISelection extends ISelectionProperties, ITableProducer, ITableReceptacle {\n", + "}\n", + "~~~" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Tarefa 2\n", + "\n", + "Conecte o componente `DataSet` aos componentes de seleção e console para mostrar na tela aquelas instâncias cujo diagnóstico seja `bacterial_infection`." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pt.c08componentes.s20catalog.s10ds.*;\n", + "import pt.c08componentes.s20catalog.s20console.*;\n", + "import pt.c08componentes.s20catalog.s40selection.*;\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Tarefa 3\n", + "\n", + "Conecte os componentes que você achar necessários para mostrar no console as colunas `name` e `age` de zumbis com `bacterial_infection`." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pt.c08componentes.s20catalog.s10ds.*;\n", + "import pt.c08componentes.s20catalog.s20console.*;\n", + "import pt.c08componentes.s20catalog.s40selection.*;\n", + "import pt.c08componentes.s20catalog.s30projection.*;\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Bubble Chart Component\n", + "\n", + "Componente que plota um gráfico de dispersão de uma tabela recebida como entrada. Para isso a tabela deve ter recortadas apenas as duas colunas que serão apresentadas.\n", + "\n", + "![Bubble Chart Component](chartbubble-component.png)\n", + "\n", + "As propriedades `Title`, `XTitle` e `YTitle` são os títulos do gráfico, do eixo X e Y respectivamente.\n", + "\n", + "A interface `IRun` dispõe de métodos para ativar e desativar a plotagem do gráfico (métodos `start` e `stop` respectivamente):\n", + "\n", + "~~~java\n", + "public interface IRun {\n", + " public boolean start();\n", + " public boolean stop();\n", + "}\n", + "\n", + "public interface IChart extends ITableReceptacle, IRun, IChartProperties {\n", + " /* Component Interfaces Set */\n", + "}\n", + "~~~\n", + "\n", + "A interface unificada é:\n", + "\n", + "~~~java\n", + "public interface IChart extends ITableReceptacle, IRun, IChartProperties {\n", + " /* Component Interfaces Set */\n", + "}\n", + "~~~\n", + "\n", + "O comando a seguir importa uma biblioteca gráfica necessária para o componente:" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "ee23ed2d-8bb6-44f9-bcb5-5c53fefe7ca4", + "version_major": 2, + "version_minor": 0 + }, + "method": "display_data" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%classpath add jar ../../../lib/xchart-3.5.2.jar" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "jupyter": { + "source_hidden": true + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrba9cd7a8.ChartBubbleComponent" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import java.util.ArrayList;\n", + "import java.util.Hashtable;\n", + "import java.util.List;\n", + "\n", + "import java.io.IOException;\n", + "\n", + "import org.knowm.xchart.BubbleChart;\n", + "import org.knowm.xchart.BubbleChartBuilder;\n", + "import org.knowm.xchart.SwingWrapper;\n", + "import org.knowm.xchart.BitmapEncoder;\n", + "import org.knowm.xchart.BitmapEncoder.BitmapFormat;\n", + "\n", + "import com.twosigma.beakerx.mimetype.MIMEContainer;\n", + "import java.io.File;\n", + "import java.nio.file.Files;\n", + "\n", + "import pt.c08componentes.s20catalog.s00shared.*;\n", + "import pt.c08componentes.s20catalog.s50chart.IChart;\n", + "\n", + "public class ChartBubbleComponent implements IChart {\n", + " private BubbleChart chart = null;\n", + "\n", + " private String title = \"Chart\";\n", + " private String xTitle = \"X\",\n", + " yTitle = \"Y\";\n", + "\n", + " private ITableProducer producer = null;\n", + " \n", + " public void connect(ITableProducer producer) {\n", + " this.producer = producer;\n", + " }\n", + " \n", + " public ChartBubbleComponent() {\n", + " }\n", + " \n", + " public String getTitle() {\n", + " return title;\n", + " }\n", + " \n", + " public void setTitle(String title) {\n", + " this.title = title;\n", + " }\n", + "\n", + " public String getXTitle() {\n", + " return xTitle;\n", + " }\n", + " \n", + " public void setXTitle(String title) {\n", + " xTitle = title;\n", + " }\n", + "\n", + " public String getYTitle() {\n", + " return title;\n", + " }\n", + " \n", + " public void setYTitle(String title) {\n", + " yTitle = title;\n", + " }\n", + "\n", + " public boolean start() {\n", + " boolean status = true;\n", + " \n", + " chart = new BubbleChartBuilder().width(600).height(400).title(title).xAxisTitle(xTitle).yAxisTitle(yTitle).build();\n", + " try{\n", + " \n", + " buildChart(); \n", + " BitmapEncoder.saveBitmap(chart, \"./chart\", BitmapFormat.PNG);\n", + " \n", + " File file = new File(\"chart.png\");\n", + " byte[] data = Files.readAllBytes(file.toPath());\n", + " \n", + " MIMEContainer image = new MIMEContainer(MIMEContainer.MIME.IMAGE_PNG, data);\n", + " display(image);\n", + " }catch(IOException ex){\n", + " status = false;\n", + " System.out.println (ex.toString()); \n", + " }\n", + " \n", + " return status;\n", + " }\n", + " \n", + " public boolean stop() {\n", + " return true;\n", + " }\n", + " \n", + " public double[] toDouble(String[][] instances, int column ) {\n", + " double[] numbers = new double[instances.length];\n", + " for (int i = 0; i < instances.length; i++)\n", + " numbers[i] = Double.parseDouble(instances[i][column]);\n", + " return numbers;\n", + " }\n", + "\n", + " private void buildChart() {\n", + " if (chart != null && producer != null) {\n", + " String[][] instances = producer.requestInstances();\n", + "\n", + " if (instances != null) {\n", + " double[] xData = toDouble(instances, 0),\n", + " yData = toDouble(instances, 1);\n", + " \n", + " String[] categoryData = null;\n", + " if (instances[0].length > 2) {\n", + " categoryData = new String[instances.length];\n", + " for (int c = 0; c < instances.length; c++)\n", + " categoryData[c] = instances[c][2];\n", + " }\n", + " \n", + " double[] bubbleData = null;\n", + " if (instances[0].length > 3)\n", + " bubbleData = toDouble(producer.requestInstances(), 3);\n", + " else {\n", + " bubbleData = new double[instances.length];\n", + " for (int i = 0; i < xData.length; i++)\n", + " bubbleData[i] = 10;\n", + " }\n", + " \n", + " \n", + " if (categoryData == null ||\n", + " xData.length != yData.length || yData.length != bubbleData.length ||\n", + " bubbleData.length != categoryData.length) {\n", + " chart.addSeries(\" \", xData, yData, bubbleData);\n", + " } else {\n", + " Hashtable hash = new Hashtable();\n", + " int outer = 0;\n", + " int size = categoryData.length;\n", + " while (outer < size) {\n", + " if (hash.containsKey(categoryData[outer]))\n", + " outer++;\n", + " else {\n", + " hash.put(categoryData[outer],categoryData[outer]);\n", + " List xSub = new ArrayList(),\n", + " ySub = new ArrayList(),\n", + " bubbleSub = new ArrayList();\n", + " for (int inner = outer; inner < size; inner++)\n", + " if (categoryData[inner].equalsIgnoreCase(categoryData[outer])) {\n", + " xSub.add(xData[inner]);\n", + " ySub.add(yData[inner]);\n", + " bubbleSub.add(bubbleData[inner]);\n", + " }\n", + " chart.addSeries(categoryData[outer], xSub, ySub, bubbleSub);\n", + " outer++;\n", + " }\n", + " }\n", + " }\n", + " }\n", + " \n", + " }\n", + " \n", + " }\n", + " \n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Tarefa 4\n", + "\n", + "Conecte os componentes que você achar necessários para apresentar um gráfico comparativo entre idade e tempo de recuperação dos zumbis, conforme exemplo abaixo.\n", + "\n", + "![Graph](example1.png)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pt.c08componentes.s20catalog.s10ds.*;\n", + "import pt.c08componentes.s20catalog.s30projection.*;\n", + "import pt.c08componentes.s20catalog.s50chart.IChart;\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Tarefa 5\n", + "\n", + "Conecte os componentes que você achar necessários para apresentar um gráfico comparativo entre idade e tempo de recuperação dos zumbis, colorindo os pontos por diagnóstico, conforme exemplo abaixo.\n", + "\n", + "**Recomendação:** Se você recortar uma terceira coluna com o diagnóstico, o gráfico resultante irá colorir os pontos por diagnóstico.\n", + "\n", + "![Graph](example2.png)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pt.c08componentes.s20catalog.s10ds.*;\n", + "import pt.c08componentes.s20catalog.s30projection.*;\n", + "import pt.c08componentes.s20catalog.s50chart.IChart;\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Tarefa 6\n", + "\n", + "Conecte os componentes que você achar necessários para apresentar um gráfico comparativo entre idade e tempo de recuperação, filtrando apenas a doença “bacterial_infection”." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pt.c08componentes.s20catalog.s10ds.*;\n", + "import pt.c08componentes.s20catalog.s30projection.*;\n", + "import pt.c08componentes.s20catalog.s40selection.*;\n", + "import pt.c08componentes.s20catalog.s50chart.IChart;\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Java", + "language": "java", + "name": "java" + }, + "language_info": { + "codemirror_mode": "text/x-java", + "file_extension": ".java", + "mimetype": "", + "name": "Java", + "nbconverter_exporter": "", + "version": "1.8.0_152-release" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": false, + "sideBar": false, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": false, + "toc_window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/components-02-whitebox.ipynb b/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/components-02-whitebox.ipynb index 71e134430..9d9fa154f 100644 --- a/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/components-02-whitebox.ipynb +++ b/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/components-02-whitebox.ipynb @@ -937,7 +937,7 @@ "mimetype": "", "name": "Java", "nbconverter_exporter": "", - "version": "11.0.8" + "version": "1.8.0_152-release" }, "toc": { "base_numbering": 1, diff --git a/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/components-03-statistics.ipynb b/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/components-03-statistics.ipynb index 8a347d184..26923bb9e 100644 --- a/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/components-03-statistics.ipynb +++ b/labs/2020/02-data-flow_messages/notebooks/data-flow/s02catalog/components-03-statistics.ipynb @@ -1714,7 +1714,20 @@ "mimetype": "", "name": "Java", "nbconverter_exporter": "", - "version": "11.0.4" + "version": "1.8.0_152-release" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": false, + "sideBar": false, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": false, + "toc_window_display": false } }, "nbformat": 4, diff --git a/labs/2021/02-dataflow_mvc/notebooks/components-chart-1-single-class.ipynb b/labs/2021/02-dataflow_mvc/notebooks/components-chart-1-single-class.ipynb new file mode 100644 index 000000000..023410f9f --- /dev/null +++ b/labs/2021/02-dataflow_mvc/notebooks/components-chart-1-single-class.ipynb @@ -0,0 +1,571 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Componentes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Componente `GeometricProgression`\n", + "\n", + "Gera uma progressão geométrica a partir de um valor `inicial` e de uma `razão`." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Interface `ISequence`\n", + "\n", + "Percorre os elementos da razão em sequência. Métodos:\n", + "* `first` - se desloca para (ou calcula) o primeiro elemento da sequência e o retorna\n", + "* `next` - se desloca para (ou calcula) o pŕoximo elemento da sequência e o retorna" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr023d9f95.ISequence" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface ISequence {\n", + " public int first();\n", + " public int next();\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Interface `IGeometricProgressionProperties`\n", + "\n", + "Propriedades de uma progressão geométrica.\n", + "\n", + "Métodos `get` e `set` para as propriedades:\n", + "* `initial` - valor inicial da progressão\n", + "* `ratio` - razão da progressão" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr023d9f95.IGeometricProgressionProperties" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IGeometricProgressionProperties {\n", + " public int getInitial();\n", + " public void setInitial(int initial);\n", + " \n", + " public int getRatio();\n", + " public void setRatio(int ratio);\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Interface `IGeometricProgression`\n", + "\n", + "Unifica as duas interfaces anteriores." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr023d9f95.IGeometricProgression" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IGeometricProgression\n", + " extends ISequence, IGeometricProgressionProperties {\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Classe `GeometricProgression`\n", + "\n", + "Gera uma **Progressão Geométrica** a partir de um valor inicial (`initial`) e de uma razão (`ratio`)." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr023d9f95.GeometricProgression" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class GeometricProgression implements IGeometricProgression {\n", + " private int initial,\n", + " ratio;\n", + " private int current;\n", + " \n", + " public GeometricProgression() {\n", + " initial = 1;\n", + " ratio = 2;\n", + " current = initial;\n", + " }\n", + " \n", + " public int getInitial() {\n", + " return initial;\n", + " }\n", + " \n", + " public void setInitial(int initial) {\n", + " this.initial = initial;\n", + " }\n", + " \n", + " public int getRatio() {\n", + " return ratio;\n", + " }\n", + " \n", + " public void setRatio(int ratio) {\n", + " this.ratio = ratio;\n", + " }\n", + " \n", + " public int first() {\n", + " current = initial;\n", + " return current;\n", + " }\n", + " \n", + " public int next() {\n", + " current *= ratio;\n", + " return current;\n", + " }\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exemplo de uso do Componente" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Progressão Geométrica: 1, 2, 4, 8, 16, " + ] + }, + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "IGeometricProgression gp = new GeometricProgression();\n", + "gp.setInitial(1);\n", + "gp.setRatio(2);\n", + "System.out.print(\"Progressão Geométrica: \");\n", + "int value = gp.first();\n", + "for (int g = 1; g <= 5; g++) {\n", + " System.out.print(value + \", \");\n", + " value = gp.next();\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Componente `BarChart`\n", + "\n", + "Apresenta um diagrama de barras no console a partir de uma sequência de números. A sequência é produzida por um componente a ele conectado." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Interface `IChart`\n", + "\n", + "Dispara a apresentação do diagrama a partir do método `plot()`." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr023d9f95.IChart" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IChart {\n", + " public void plot();\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Interface `IBarChartProperties`\n", + "\n", + "Propriedades para configurar um gráfico de barras.\n", + "\n", + "Métodos `get` e `set` para as propriedades:\n", + "* `filled` - define se o gráfico será preenchido\n", + "* `character` - caractere que será usado para plotar o gráfico\n", + "* `n` - número de barras que serão apresentadas" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr023d9f95.IBarChartProperties" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IBarChartProperties {\n", + " public boolean isFilled();\n", + " public void setFilled(boolean filled);\n", + "\n", + " public char getCharacter();\n", + " public void setCharacter(char character);\n", + "\n", + " public int getN();\n", + " public void setN(int n);\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Interface Requerida `IRSequence`\n", + "\n", + "Interface que requer outra interface `ISequence`. Método:\n", + "* `connect` - realiza a conexão com um componente que tem a interface ISequence" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr023d9f95.IRSequence" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IRSequence {\n", + " public void connect(ISequence sequence);\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Interface `IBarChart`\n", + "\n", + "Unifica as três interfaces anteriores." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr023d9f95.IBarChart" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IBarChart\n", + " extends IChart, IBarChartProperties, IRSequence {\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Classe `BarChart`\n", + "\n", + "Implementa a apresentação de um gráfico de barras." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr023d9f95.BarChart" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class BarChart implements IBarChart {\n", + " private boolean filled;\n", + " private char character;\n", + " private int n;\n", + " \n", + " private ISequence sequence;\n", + " \n", + " public BarChart() {\n", + " filled = true;\n", + " character = '*';\n", + " n = 3;\n", + " }\n", + "\n", + " public boolean isFilled() {\n", + " return filled;\n", + " }\n", + "\n", + " public void setFilled(boolean filled) {\n", + " this.filled = filled;\n", + " }\n", + "\n", + " public char getCharacter() {\n", + " return character;\n", + " }\n", + "\n", + " public void setCharacter(char character) {\n", + " this.character = character;\n", + " }\n", + "\n", + " public int getN() {\n", + " return n;\n", + " }\n", + "\n", + " public void setN(int n) {\n", + " this.n = n;\n", + " }\n", + "\n", + " public void connect(ISequence sequence) {\n", + " this.sequence = sequence;\n", + " }\n", + " \n", + " public void plot() {\n", + " if (sequence != null) {\n", + " int value = sequence.first();\n", + " for (int s = 1; s <= n; s++) {\n", + " for (int v = 1; v < value; v++)\n", + " System.out.print((filled) ? character : ' ');\n", + " System.out.println(character);\n", + " value = sequence.next();\n", + " }\n", + " }\n", + " }\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Aplicação Exemplo\n", + "Instancia os dois componentes (progressão geométrica e gráfico de barras), os conecta e dispara o processo de plotagem no componente do gráfico de barras." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "#\n", + "##\n", + "####\n", + "########\n", + "################\n" + ] + }, + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "IGeometricProgression gp = new GeometricProgression();\n", + "gp.setInitial(1);\n", + "gp.setRatio(2);\n", + "\n", + "IBarChart bc = new BarChart();\n", + "bc.setFilled(true);\n", + "bc.setCharacter('#');\n", + "bc.setN(5);\n", + "\n", + "bc.connect(gp);\n", + "bc.plot();" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Exercício do Gráfico de Segundo Grau\n", + "\n", + "## Função de segundo grau\n", + "\n", + "Escreva uma classe `SegundoGrau` cujos objetos produzam valores de uma função de segundo grau." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Plotagem de parábola\n", + "\n", + "Escreva um programa que conecte um objeto da classe `SegundoGrau` a um objeto da classe `Grafico` de forma que seja plotada uma parábola. Por conta do comportamento da classe `Grafico`, a parábola será plotada virada, ou seja eixos X e Y trocados." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Java", + "language": "java", + "name": "java" + }, + "language_info": { + "codemirror_mode": "text/x-java", + "file_extension": ".java", + "mimetype": "", + "name": "Java", + "nbconverter_exporter": "", + "version": "1.8.0_152-release" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": false, + "sideBar": false, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": false, + "toc_window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}