[apps/regression] Create the structure of the application regression

Change-Id: I2433a5e6dabdd9a15d87c8e2ddf3cea5ad329a0e
This commit is contained in:
Émilie Feral
2016-12-29 15:40:31 +01:00
parent 3c3a900bb7
commit 60cb611278
13 changed files with 377 additions and 4 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -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;

8
apps/regression/Makefile Normal file
View File

@@ -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

20
apps/regression/app.cpp Normal file
View File

@@ -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)
{
}
}

29
apps/regression/app.h Normal file
View File

@@ -0,0 +1,29 @@
#ifndef REGRESSION_APP_H
#define REGRESSION_APP_H
#include <escher.h>
#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

View File

@@ -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());
}
}

View File

@@ -0,0 +1,26 @@
#ifndef REGRESSION_CALCULATION_CONTROLLER_H
#define REGRESSION_CALCULATION_CONTROLLER_H
#include <escher.h>
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

View File

@@ -0,0 +1,112 @@
#include "data_controller.h"
#include "app.h"
#include "../apps_container.h"
#include "../constant.h"
#include <assert.h>
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;
}
}

View File

@@ -0,0 +1,39 @@
#ifndef REGRESSION_DATA_CONTROLLER_H
#define REGRESSION_DATA_CONTROLLER_H
#include <escher.h>
#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

View File

@@ -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());
}
}

View File

@@ -0,0 +1,33 @@
#ifndef REGRESSION_GRAPH_CONTROLLER_H
#define REGRESSION_GRAPH_CONTROLLER_H
#include <escher.h>
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

Binary file not shown.

After

Width:  |  Height:  |  Size: 459 B