diff --git a/apps/Makefile b/apps/Makefile index 0027090ed..103696197 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -1,7 +1,8 @@ -include apps/home/Makefile -include apps/graph/Makefile -include apps/probability/Makefile include apps/calculation/Makefile +include apps/graph/Makefile +include apps/home/Makefile +include apps/probability/Makefile +include apps/regression/Makefile include apps/statistics/Makefile #include apps/picview/Makefile diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index 29a904415..51f843831 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -9,6 +9,7 @@ AppsContainer::AppsContainer() : m_graphApp(this, &m_globalContext), m_probabilityApp(this), m_calculationApp(this, &m_globalContext), + m_regressionApp(this), m_statisticsApp(this), m_globalContext(GlobalContext()), m_variableBoxController(&m_globalContext) @@ -25,6 +26,7 @@ App * AppsContainer::appAtIndex(int index) { &m_graphApp, &m_probabilityApp, &m_calculationApp, + &m_regressionApp, &m_statisticsApp }; assert(sizeof(apps)/sizeof(apps[0]) == k_numberOfApps); diff --git a/apps/apps_container.h b/apps/apps_container.h index f7c042c3d..4dd3f4aa2 100644 --- a/apps/apps_container.h +++ b/apps/apps_container.h @@ -5,6 +5,7 @@ #include "graph/app.h" #include "probability/app.h" #include "calculation/app.h" +#include "regression/app.h" #include "statistics/app.h" #include "toolbox_controller.h" #include "variable_box_controller.h" @@ -25,11 +26,12 @@ public: VariableBoxController * variableBoxController(); bool handleEvent(Ion::Events::Event event) override; private: - static constexpr int k_numberOfApps = 5; + static constexpr int k_numberOfApps = 6; Home::App m_homeApp; Graph::App m_graphApp; Probability::App m_probabilityApp; Calculation::App m_calculationApp; + Regression::App m_regressionApp; Statistics::App m_statisticsApp; #if USE_PIC_VIEW_APP PicViewApp m_picViewApp; diff --git a/apps/regression/Makefile b/apps/regression/Makefile new file mode 100644 index 000000000..c48d7dccf --- /dev/null +++ b/apps/regression/Makefile @@ -0,0 +1,8 @@ +app_objs += $(addprefix apps/regression/,\ + app.o\ + calculation_controller.o\ + data_controller.o\ + graph_controller.o\ +) + +app_images += apps/regression/regression_icon.png diff --git a/apps/regression/app.cpp b/apps/regression/app.cpp new file mode 100644 index 000000000..9f35363cc --- /dev/null +++ b/apps/regression/app.cpp @@ -0,0 +1,20 @@ +#include "app.h" +#include "regression_icon.h" + +namespace Regression { + +App::App(Container * container) : + TextFieldDelegateApp(container, &m_tabViewController, "Resgression", ImageStore::RegressionIcon), + m_calculationController(CalculationController(&m_calculationAlternateEmptyViewController)), + m_calculationAlternateEmptyViewController(AlternateEmptyViewController(&m_tabViewController, &m_calculationController, &m_calculationController)), + m_graphController(GraphController(&m_graphHeader, &m_graphHeader)), + m_graphHeader(HeaderViewController(&m_graphAlternateEmptyViewController, &m_graphController, &m_graphController)), + m_graphAlternateEmptyViewController(AlternateEmptyViewController(nullptr, &m_graphHeader, &m_graphController)), + m_graphStackViewController(StackViewController(&m_tabViewController, &m_graphAlternateEmptyViewController)), + m_dataController(DataController(nullptr)), + m_dataStackViewController(StackViewController(&m_tabViewController, &m_dataController)), + m_tabViewController(&m_modalViewController, &m_dataStackViewController, &m_graphStackViewController, &m_calculationAlternateEmptyViewController) +{ +} + +} diff --git a/apps/regression/app.h b/apps/regression/app.h new file mode 100644 index 000000000..3c03eb2f8 --- /dev/null +++ b/apps/regression/app.h @@ -0,0 +1,29 @@ +#ifndef REGRESSION_APP_H +#define REGRESSION_APP_H + +#include +#include "../text_field_delegate_app.h" +#include "data_controller.h" +#include "graph_controller.h" +#include "calculation_controller.h" + +namespace Regression { + +class App : public TextFieldDelegateApp { +public: + App(Container * container); +private: + CalculationController m_calculationController; + AlternateEmptyViewController m_calculationAlternateEmptyViewController; + GraphController m_graphController; + HeaderViewController m_graphHeader; + AlternateEmptyViewController m_graphAlternateEmptyViewController; + StackViewController m_graphStackViewController; + DataController m_dataController; + StackViewController m_dataStackViewController; + TabViewController m_tabViewController; +}; + +} + +#endif diff --git a/apps/regression/calculation_controller.cpp b/apps/regression/calculation_controller.cpp new file mode 100644 index 000000000..8918e87a2 --- /dev/null +++ b/apps/regression/calculation_controller.cpp @@ -0,0 +1,44 @@ +#include "calculation_controller.h" + +namespace Regression { + +CalculationController::CalculationController(Responder * parentResponder) : + ViewController(parentResponder), + m_view(SolidColorView(KDColorGreen)) +{ +} + +const char * CalculationController::title() const { + return "Stats"; +} + +View * CalculationController::view() { + return &m_view; +} + +bool CalculationController::handleEvent(Ion::Events::Event event) { + if (event == Ion::Events::Up) { + app()->setFirstResponder(tabController()); + return true; + } + return false; +} + +bool CalculationController::isEmpty() { + return false; +} + +const char * CalculationController::emptyMessage() { + return "Aucune donnée à tracer"; +} + +Responder * CalculationController::defaultController() { + return tabController(); +} + +Responder * CalculationController::tabController() const { + return (parentResponder()->parentResponder()->parentResponder()); +} + +} + diff --git a/apps/regression/calculation_controller.h b/apps/regression/calculation_controller.h new file mode 100644 index 000000000..e36089604 --- /dev/null +++ b/apps/regression/calculation_controller.h @@ -0,0 +1,26 @@ +#ifndef REGRESSION_CALCULATION_CONTROLLER_H +#define REGRESSION_CALCULATION_CONTROLLER_H + +#include + +namespace Regression { + +class CalculationController : public ViewController, public AlternateEmptyViewDelegate { + +public: + CalculationController(Responder * parentResponder); + const char * title() const override; + View * view() override; + bool handleEvent(Ion::Events::Event event) override; + bool isEmpty() override; + const char * emptyMessage() override; + Responder * defaultController() override; +private: + Responder * tabController() const; + SolidColorView m_view; +}; + +} + + +#endif \ No newline at end of file diff --git a/apps/regression/data_controller.cpp b/apps/regression/data_controller.cpp new file mode 100644 index 000000000..7fb6078dc --- /dev/null +++ b/apps/regression/data_controller.cpp @@ -0,0 +1,112 @@ +#include "data_controller.h" +#include "app.h" +#include "../apps_container.h" +#include "../constant.h" +#include + +namespace Regression { + +DataController::DataController(Responder * parentResponder) : + EditableCellTableViewController(parentResponder, Metric::TopMargin, Metric::RightMargin, Metric::BottomMargin, Metric::LeftMargin), + m_editableCells{EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), + EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), + EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), + EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer)} +{ +} + +const char * DataController::title() const { + return "Donnees"; +} + +int DataController::numberOfColumns() { + return 2; +}; + +KDCoordinate DataController::columnWidth(int i) { + return k_cellWidth; +} + +KDCoordinate DataController::cumulatedWidthFromIndex(int i) { + return i*k_cellWidth; +} + +int DataController::indexFromCumulatedWidth(KDCoordinate offsetX) { + return (offsetX-1) / k_cellWidth; +} + +TableViewCell * DataController::reusableCell(int index, int type) { + assert(index >= 0); + switch (type) { + case 0: + assert(index < k_numberOfTitleCells); + return &m_titleCells[index]; + case 1: + assert(index < k_maxNumberOfEditableCells); + return &m_editableCells[index]; + default: + assert(false); + return nullptr; + } +} + +int DataController::reusableCellCount(int type) { + if (type == 0) { + return k_numberOfTitleCells; + } + return k_maxNumberOfEditableCells; +} + +void DataController::willDisplayCellAtLocation(TableViewCell * cell, int i, int j) { + EditableCellTableViewController::willDisplayCellAtLocation(cell, i, j); + if (cellAtLocationIsEditable(i, j)) { + return; + } + EvenOddPointerTextCell * mytitleCell = (EvenOddPointerTextCell *)cell; + if (i == 0) { + mytitleCell->setText("Valeurs"); + return; + } + mytitleCell->setText("Effectifs"); +} + +int DataController::typeAtLocation(int i, int j) { + return j!=0; +} + +bool DataController::handleEvent(Ion::Events::Event event) { + if (event == Ion::Events::Up) { + m_selectableTableView.deselectTable(); + assert(m_selectableTableView.selectedRow() == -1); + app()->setFirstResponder(tabController()); + return true; + } + return false; +} + +Responder * DataController::tabController() const { + return (parentResponder()->parentResponder()); +} + +bool DataController::cellAtLocationIsEditable(int columnIndex, int rowIndex) { + if (rowIndex > 0) { + return true; + } + return false; +} + +void DataController::setDataAtLocation(float floatBody, int columnIndex, int rowIndex) { +} + +float DataController::dataAtLocation(int columnIndex, int rowIndex) { +} + +int DataController::numberOfElements() { + return 8; +} + +int DataController::maxNumberOfElements() const { + return 8; +} + +} diff --git a/apps/regression/data_controller.h b/apps/regression/data_controller.h new file mode 100644 index 000000000..ab340877f --- /dev/null +++ b/apps/regression/data_controller.h @@ -0,0 +1,39 @@ +#ifndef REGRESSION_DATA_CONTROLLER_H +#define REGRESSION_DATA_CONTROLLER_H + +#include +#include "../editable_cell_table_view_controller.h" + +namespace Regression { + +class DataController : public EditableCellTableViewController { +public: + DataController(Responder * parentResponder); + const char * title() const override; + int numberOfColumns() override; + void willDisplayCellAtLocation(TableViewCell * cell, int i, int j) override; + KDCoordinate columnWidth(int i) override; + KDCoordinate cumulatedWidthFromIndex(int i) override; + int indexFromCumulatedWidth(KDCoordinate offsetX) override; + TableViewCell * reusableCell(int index, int type) override; + int reusableCellCount(int type) override; + int typeAtLocation(int i, int j) override; + bool handleEvent(Ion::Events::Event event) override; +private: + static constexpr KDCoordinate k_cellWidth = 100; + constexpr static int k_maxNumberOfEditableCells = 20; + constexpr static int k_numberOfTitleCells = 2; + Responder * tabController() const; + bool cellAtLocationIsEditable(int columnIndex, int rowIndex) override; + void setDataAtLocation(float floatBody, int columnIndex, int rowIndex) override; + float dataAtLocation(int columnIndex, int rowIndex) override; + int numberOfElements() override; + int maxNumberOfElements() const override; + char m_draftTextBuffer[EditableTextCell::k_bufferLength]; + EvenOddEditableTextCell m_editableCells[k_maxNumberOfEditableCells]; + EvenOddPointerTextCell m_titleCells[k_numberOfTitleCells]; +}; + +} + +#endif diff --git a/apps/regression/graph_controller.cpp b/apps/regression/graph_controller.cpp new file mode 100644 index 000000000..04ace4097 --- /dev/null +++ b/apps/regression/graph_controller.cpp @@ -0,0 +1,57 @@ +#include "graph_controller.h" + +namespace Regression { + +GraphController::GraphController(Responder * parentResponder, HeaderViewController * headerViewController) : + ViewController(parentResponder), + HeaderViewDelegate(headerViewController), + m_view(SolidColorView(KDColorGreen)), + m_windowButton(this, "Axes", Invocation([](void * context, void * sender) {}, this)), + m_zoomButton(this, "Zoom", Invocation([](void * context, void * sender) {}, this)), + m_defaultInitialisationButton(this, "Initialisation", Invocation([](void * context, void * sender) {}, this)) +{ +} + +const char * GraphController::title() const { + return "Graph"; +} + +View * GraphController::view() { + return &m_view; +} + +bool GraphController::handleEvent(Ion::Events::Event event) { + return false; +} + +int GraphController::numberOfButtons() const { + return 3; +} +Button * GraphController::buttonAtIndex(int index) { + if (index == 0) { + return &m_windowButton; + } + if (index == 1) { + return &m_zoomButton; + } + return &m_defaultInitialisationButton; +} + +bool GraphController::isEmpty() { + return false; +} + +const char * GraphController::emptyMessage() { + return "Aucune donnée à tracer"; +} + +Responder * GraphController::defaultController() { + return tabController(); +} + +Responder * GraphController::tabController() const { + return (parentResponder()->parentResponder()->parentResponder()->parentResponder()); +} + +} + diff --git a/apps/regression/graph_controller.h b/apps/regression/graph_controller.h new file mode 100644 index 000000000..ca42688c5 --- /dev/null +++ b/apps/regression/graph_controller.h @@ -0,0 +1,33 @@ +#ifndef REGRESSION_GRAPH_CONTROLLER_H +#define REGRESSION_GRAPH_CONTROLLER_H + +#include + +namespace Regression { + +class GraphController : public ViewController, public HeaderViewDelegate, public AlternateEmptyViewDelegate { + +public: + GraphController(Responder * parentResponder, HeaderViewController * headerViewController); + const char * title() const override; + View * view() override; + bool handleEvent(Ion::Events::Event event) override; + + int numberOfButtons() const override; + Button * buttonAtIndex(int index) override; + + bool isEmpty() override; + const char * emptyMessage() override; + Responder * defaultController() override; +private: + Responder * tabController() const; + SolidColorView m_view; + Button m_windowButton; + Button m_zoomButton; + Button m_defaultInitialisationButton; +}; + +} + + +#endif \ No newline at end of file diff --git a/apps/regression/regression_icon.png b/apps/regression/regression_icon.png new file mode 100644 index 000000000..3818c7bf1 Binary files /dev/null and b/apps/regression/regression_icon.png differ