mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[Stat+Reg] Allowing lists of values to be sorted
Change-Id: I181bb55443bf87356d127eb6c56ff6140806fdea
This commit is contained in:
committed by
Émilie Feral
parent
018dd91ca1
commit
09e39ad890
@@ -76,6 +76,7 @@ int StoreParameterController::typeAtLocation(int i, int j) {
|
||||
void StoreParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) {
|
||||
if (index == numberOfRows() -1) {
|
||||
m_changeRegressionCell.setLayout(static_cast<Store *>(m_store)->modelForSeries(m_series)->layout());
|
||||
return;
|
||||
}
|
||||
Shared::StoreParameterController::willDisplayCellForIndex(cell, index);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
int typeAtLocation(int i, int j) override;
|
||||
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
|
||||
private:
|
||||
I18n::Message sortMessage() override { return I18n::Message::SortValues; }
|
||||
static constexpr int k_regressionCellType = 1;
|
||||
MessageTableCellWithChevronAndExpression m_changeRegressionCell;
|
||||
bool m_lastSelectionIsRegression;
|
||||
|
||||
@@ -63,6 +63,7 @@ public:
|
||||
assert(i < Palette::numberOfLightDataColors());
|
||||
return Palette::DataColorLight[i];
|
||||
}
|
||||
double * data() { return reinterpret_cast<double*>(&m_data); }
|
||||
protected:
|
||||
virtual double defaultValue(int series, int i, int j) const;
|
||||
double m_data[k_numberOfSeries][k_numberOfColumnsPerSeries][k_maxNumberOfPairs];
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "store_parameter_controller.h"
|
||||
#include "store_controller.h"
|
||||
#include <poincare/helpers.h>
|
||||
#include <assert.h>
|
||||
|
||||
namespace Shared {
|
||||
@@ -9,61 +10,87 @@ StoreParameterController::StoreParameterController(Responder * parentResponder,
|
||||
m_store(store),
|
||||
m_series(0),
|
||||
m_selectableTableView(this, this, this),
|
||||
m_deleteColumn(I18n::Message::ClearColumn),
|
||||
m_fillWithFormula(I18n::Message::FillWithFormula),
|
||||
#if COPY_IMPORT_LIST
|
||||
m_copyColumn(I18n::Message::CopyColumnInList),
|
||||
m_importList(I18n::Message::ImportList),
|
||||
#endif
|
||||
m_cells{I18n::Message::ClearColumn, I18n::Message::FillWithFormula},
|
||||
m_storeController(storeController),
|
||||
m_xColumnSelected(true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void StoreParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) {
|
||||
MessageTableCellWithEditableText * myCell = static_cast<MessageTableCellWithEditableText *>(cell);
|
||||
assert(index >= 0 && index < k_totalNumberOfCell);
|
||||
if (index == 2) {
|
||||
myCell->setMessage(sortMessage());
|
||||
}
|
||||
ListViewDataSource::willDisplayCellForIndex(cell, index);
|
||||
}
|
||||
|
||||
const char * StoreParameterController::title() {
|
||||
return I18n::translate(I18n::Message::ColumnOptions);
|
||||
}
|
||||
|
||||
void StoreParameterController::viewWillAppear() {
|
||||
m_selectableTableView.reloadData();
|
||||
}
|
||||
|
||||
void StoreParameterController::didBecomeFirstResponder() {
|
||||
selectCellAtLocation(0, 0);
|
||||
Container::activeApp()->setFirstResponder(&m_selectableTableView);
|
||||
}
|
||||
|
||||
bool StoreParameterController::handleEvent(Ion::Events::Event event) {
|
||||
if (event == Ion::Events::OK || event == Ion::Events::EXE) {
|
||||
switch (selectedRow()) {
|
||||
case 0:
|
||||
{
|
||||
if (m_xColumnSelected) {
|
||||
m_store->deleteAllPairsOfSeries(m_series);
|
||||
} else {
|
||||
m_store->resetColumn(m_series, !m_xColumnSelected);
|
||||
}
|
||||
StackViewController * stack = ((StackViewController *)parentResponder());
|
||||
stack->pop();
|
||||
return true;
|
||||
if (event != Ion::Events::OK && event != Ion::Events::EXE) {
|
||||
return false;
|
||||
}
|
||||
switch (selectedRow()) {
|
||||
case 0:
|
||||
{
|
||||
if (m_xColumnSelected) {
|
||||
m_store->deleteAllPairsOfSeries(m_series);
|
||||
} else {
|
||||
m_store->resetColumn(m_series, !m_xColumnSelected);
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
m_storeController->displayFormulaInput();
|
||||
StackViewController * stack = ((StackViewController *)parentResponder());
|
||||
stack->pop();
|
||||
return true;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
m_storeController->displayFormulaInput();
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
Poincare::Helpers::Swap swapRows = [](int i, int j, void * context, int numberOfElements) {
|
||||
double * contextI = (static_cast<double*>(context) + i);
|
||||
double * contextJ = (static_cast<double*>(context) + j);
|
||||
double * contextIOtherColumn = (static_cast<double*>(context) + DoublePairStore::k_maxNumberOfPairs + i);
|
||||
double * contextJOtherColumn = (static_cast<double*>(context) + DoublePairStore::k_maxNumberOfPairs + j);
|
||||
double temp1 = *contextI;
|
||||
double temp2 = *contextIOtherColumn;
|
||||
*contextI = *contextJ;
|
||||
*contextIOtherColumn = *contextJOtherColumn;
|
||||
*contextJ = temp1;
|
||||
*contextJOtherColumn = temp2;
|
||||
};
|
||||
Poincare::Helpers::Compare compareX = [](int a, int b, void * context, int numberOfElements)->bool{
|
||||
double * contextA = (static_cast<double*>(context) + a);
|
||||
double * contextB = (static_cast<double*>(context) + b);
|
||||
return *contextA > *contextB;
|
||||
};
|
||||
Poincare::Helpers::Compare compareY = [](int a, int b, void * context, int numberOfElements)->bool{
|
||||
double * contextAOtherColumn = (static_cast<double*>(context) + DoublePairStore::k_maxNumberOfPairs + a);
|
||||
double * contextBOtherColumn = (static_cast<double*>(context) + DoublePairStore::k_maxNumberOfPairs + b);
|
||||
return *contextAOtherColumn > *contextBOtherColumn;
|
||||
};
|
||||
if (m_xColumnSelected) {
|
||||
Poincare::Helpers::Sort(swapRows, compareX, (m_store->data() + m_series), m_store->numberOfPairsOfSeries(m_series));
|
||||
} else {
|
||||
Poincare::Helpers::Sort(swapRows, compareY, (m_store->data() + m_series), m_store->numberOfPairsOfSeries(m_series));
|
||||
}
|
||||
|
||||
#if COPY_IMPORT_LIST
|
||||
/* TODO: implement copy column and import list */
|
||||
case 2:
|
||||
return true;
|
||||
case 3:
|
||||
return true;
|
||||
#endif
|
||||
default:
|
||||
assert(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
assert(selectedRow() >= 0 && selectedRow() <= 2);
|
||||
StackViewController * stack = static_cast<StackViewController *>(parentResponder());
|
||||
stack->pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
KDCoordinate StoreParameterController::cumulatedHeightFromIndex(int j) {
|
||||
@@ -88,8 +115,7 @@ HighlightCell * StoreParameterController::reusableCell(int index, int type) {
|
||||
assert(type == k_standardCellType);
|
||||
assert(index >= 0);
|
||||
assert(index < k_totalNumberOfCell);
|
||||
HighlightCell * cells[] = {&m_deleteColumn, &m_fillWithFormula};// {&m_deleteColumn, &m_fillWithFormula, &m_copyColumn, &m_importList};
|
||||
return cells[index];
|
||||
return &m_cells[index];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,8 +15,10 @@ public:
|
||||
void selectXColumn(bool xColumnSelected) { m_xColumnSelected = xColumnSelected; }
|
||||
void selectSeries(int series) { m_series = series; }
|
||||
View * view() override { return &m_selectableTableView; }
|
||||
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
|
||||
const char * title() override;
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
void viewWillAppear() override;
|
||||
void didBecomeFirstResponder() override;
|
||||
int numberOfRows() const override { return k_totalNumberOfCell; }
|
||||
KDCoordinate rowHeight(int j) override { return Metric::ParameterCellHeight; }
|
||||
@@ -34,15 +36,9 @@ protected:
|
||||
int m_series;
|
||||
SelectableTableView m_selectableTableView;
|
||||
private:
|
||||
#if COPY_IMPORT_LIST
|
||||
constexpr static int k_totalNumberOfCell = 4;
|
||||
MessageTableCellWithChevron m_copyColumn;
|
||||
MessageTableCellWithChevron m_importList;
|
||||
#else
|
||||
constexpr static int k_totalNumberOfCell = 2;
|
||||
#endif
|
||||
MessageTableCell m_deleteColumn;
|
||||
MessageTableCell m_fillWithFormula;
|
||||
virtual I18n::Message sortMessage() { return m_xColumnSelected ? I18n::Message::SortValues : I18n::Message::SortSizes; }
|
||||
constexpr static int k_totalNumberOfCell = 3;
|
||||
MessageTableCell m_cells[k_totalNumberOfCell];
|
||||
StoreController * m_storeController;
|
||||
bool m_xColumnSelected;
|
||||
};
|
||||
|
||||
@@ -23,3 +23,5 @@ Range = "Spannweite"
|
||||
StandardDeviationSigma = "Standardabweichung σ"
|
||||
SampleStandardDeviationS = "Standardabweichung s"
|
||||
InterquartileRange = "Interquartilsabstand"
|
||||
SortValues = "Nach steigenden Werten sortieren"
|
||||
SortSizes = "Nach steigenden Frequenzen sortieren"
|
||||
|
||||
@@ -23,3 +23,5 @@ Range = "Range"
|
||||
StandardDeviationSigma = "Standard deviation σ"
|
||||
SampleStandardDeviationS = "Sample std deviation s"
|
||||
InterquartileRange = "Interquartile range"
|
||||
SortValues = "Sort by increasing values"
|
||||
SortSizes = "Sort by increasing sizes"
|
||||
@@ -23,3 +23,5 @@ Range = "Rango"
|
||||
StandardDeviationSigma = "Desviación típica σ"
|
||||
SampleStandardDeviationS = "Desviación típica s"
|
||||
InterquartileRange = "Rango intercuartilo"
|
||||
SortValues = "Ordenar por valores crecientes"
|
||||
SortSizes = "Ordenar por frecuencias crecientes"
|
||||
@@ -23,3 +23,5 @@ Range = "Étendue"
|
||||
StandardDeviationSigma = "Écart type"
|
||||
SampleStandardDeviationS = "Écart type échantillon"
|
||||
InterquartileRange = "Écart interquartile"
|
||||
SortValues = "Trier par valeurs croissantes"
|
||||
SortSizes = "Trier par effectifs croissants"
|
||||
|
||||
@@ -23,3 +23,5 @@ Range = "Ampiezza"
|
||||
StandardDeviationSigma = "Deviazione standard σ"
|
||||
SampleStandardDeviationS = "Dev. std campionaria s"
|
||||
InterquartileRange = "Scarto interquartile"
|
||||
SortValues = "Ordinare per valori crescenti"
|
||||
SortSizes = "Ordinare per frequenze crescenti"
|
||||
@@ -23,3 +23,5 @@ Range = "Bereik"
|
||||
StandardDeviationSigma = "Standaardafwijking σ"
|
||||
SampleStandardDeviationS = "Standaardafwijking s"
|
||||
InterquartileRange = "Interkwartielafstand"
|
||||
SortValues = "Sorteer door waarden te verhogen"
|
||||
SortSizes = "Sorteer door verhogen frequenties"
|
||||
@@ -23,3 +23,5 @@ Range = "Amplitude"
|
||||
StandardDeviationSigma = "Desvio padrão σ"
|
||||
SampleStandardDeviationS = "Desvio padrão amostral s"
|
||||
InterquartileRange = "Amplitude interquartil"
|
||||
SortValues = "Ordenar por ordem crescente"
|
||||
SortSizes = "Ordenar por ordem crescente"
|
||||
@@ -8,9 +8,13 @@ namespace Poincare {
|
||||
|
||||
namespace Helpers {
|
||||
|
||||
typedef void (*Swap) (int i, int j, void * context, int numberOfElements);
|
||||
typedef bool (*Compare) (int i, int j, void * context, int numberOfElements);
|
||||
|
||||
size_t AlignedSize(size_t realSize, size_t alignment);
|
||||
size_t Gcd(size_t a, size_t b);
|
||||
bool Rotate(uint32_t * dst, uint32_t * src, size_t len);
|
||||
void Sort(Swap swap, Compare compare, void * context, int numberOfElements);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -98,5 +98,15 @@ bool Rotate(uint32_t * dst, uint32_t * src, size_t len) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Sort(Swap swap, Compare compare, void * context, int numberOfElements) {
|
||||
for (int i = 0; i < numberOfElements-1; i++) {
|
||||
for (int j = 0; j < numberOfElements - i - 1; j++) {
|
||||
if (compare(j, j+1, context, numberOfElements)) {
|
||||
swap(j, j+1, context, numberOfElements);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user