Commit 6ea753ed authored by Alexander.Trofimov's avatar Alexander.Trofimov

accelerated function LARGE (get only no empty values)

parent 9ed6855e
......@@ -715,27 +715,23 @@ cArea.prototype.foreach = function ( action ) {
r._foreach2( action );
}
};
cArea.prototype._parseCellValue = function ( cell ) {
var result, cellType, cellValue;
if ( cell ) {
cArea.prototype._parseCellValue = function (cell) {
var result = null, cellType, cellValue;
if (cell) {
cellType = cell.getType();
cellValue = cell.getValueWithoutFormat();
if ( cellType === CellValueType.Number ) {
result = cell.isEmptyTextString() ? new cEmpty() : new cNumber( cellValue );
if (cellType === CellValueType.Number) {
result = cell.isEmptyTextString() ? new cEmpty() : new cNumber(cellValue);
} else if (cellType === CellValueType.Bool) {
result = new cBool( cellValue );
result = new cBool(cellValue);
} else if (cellType === CellValueType.Error) {
result = new cError( cellValue );
result = new cError(cellValue);
} else if (cellType === CellValueType.String) {
result = new cString( cellValue );
} else {
result = cell.isEmptyTextString() ? checkTypeCell( "" + cellValue ) : new cNumber( cellValue );
result = new cString(cellValue);
}
} else {
result = new cEmpty();
}
return result;
};
return result || new cEmpty();
};
cArea.prototype.foreach2 = function ( action ) {
var t = this, r = this.getRange();
if ( r ) {
......@@ -744,16 +740,23 @@ cArea.prototype.foreach2 = function ( action ) {
} );
}
};
cArea.prototype.getMatrix = function () {
cArea.prototype.getMatrix = function () {
var t = this, arr = [], r = this.getRange();
r._foreach2( function ( cell, i, j, r1, c1 ) {
r._foreach2(function (cell, i, j, r1, c1) {
if (!arr[i - r1]) {
arr[i - r1] = [];
}
arr[i - r1][j - c1] = t._parseCellValue( cell );
} );
arr[i - r1][j - c1] = t._parseCellValue(cell);
});
return arr;
};
};
cArea.prototype.getValuesNoEmpty = function () {
var t = this, arr = [], r = this.getRange();
r._foreachNoEmpty(function (cell) {
arr.push(t._parseCellValue(cell));
});
return [arr];
};
cArea.prototype.getRefMatrix = function () {
var t = this, arr = [], r = this.getRange();
r._foreach2( function ( cell, i, j, r1, c1 ) {
......
......@@ -2407,12 +2407,7 @@ cKURT.prototype.getInfo = function () {
};
};
function cLARGE() {
// cBaseFunction.call( this, "LARGE" );
// this.setArgumentsMin( 2 );
// this.setArgumentsMax( 2 );
// this.setFormat( this.formatType.noneFormat );
function cLARGE() {
this.name = "LARGE";
this.type = cElementType.func;
this.value = null;
......@@ -2420,73 +2415,72 @@ function cLARGE() {
this.argumentsCurrent = 0;
this.argumentsMax = 2;
this.formatType = {
def:-1, //подразумевается формат первой ячейки входящей в формулу.
noneFormat:-2
def: -1, //подразумевается формат первой ячейки входящей в формулу.
noneFormat: -2
};
this.numFormat = this.formatType.noneFormat;
}
}
cLARGE.prototype = Object.create( cBaseFunction.prototype );
cLARGE.prototype.Calculate = function ( arg ) {
function frequency( A, k ) {
var tA = [];
for ( var i = 0; i < A.length; i++ ) {
for ( var j = 0; j < A[i].length; j++ ) {
if ( A[i][j] instanceof cError ) {
return A[i][j];
cLARGE.prototype = Object.create(cBaseFunction.prototype);
cLARGE.prototype._getValue = function (arg0, arg1) {
if (cElementType.error === arg1.type) {
return arg1;
}
else if ( A[i][j] instanceof cNumber ) {
tA.push( A[i][j].getValue() );
arg1 = arg1.getValue();
if (arg1 <= 0) {
return new cError(cErrorType.not_available);
}
else if ( A[i][j] instanceof cBool ) {
tA.push( A[i][j].tocNumber().getValue() );
var v, tA = [];
for (var i = 0; i < arg0.length; i++) {
for (var j = 0; j < arg0[i].length; j++) {
v = arg0[i][j];
if (cElementType.error === v.type) {
return v;
} else if (cElementType.number === v.type) {
tA.push(v.getValue());
} else if (cElementType.bool === v.type) {
tA.push(v.tocNumber().getValue());
}
}
}
tA.sort(AscCommon.fSortDescending);
if ( k.getValue() > tA.length || k.getValue() <= 0 )
return new cError( cErrorType.not_available );
else
return new cNumber( tA[k.getValue() - 1] );
if (arg1 > tA.length) {
return new cError(cErrorType.not_available);
} else {
return new cNumber(tA[arg1 - 1]);
}
};
cLARGE.prototype.Calculate = function (arg) {
var arg0 = arg[0], arg1 = arg[1];
if ( arg0 instanceof cArea || arg0 instanceof cArray ) {
if (cElementType.cellsRange === arg0.type) {
arg0 = arg0.getValuesNoEmpty();
} else if (cElementType.array === arg0.type) {
arg0 = arg0.getMatrix();
}
else if ( arg0 instanceof cArea3D ) {
} else if (cElementType.cellsRange3D === arg0.type) {
arg0 = arg0.getMatrix()[0];
} else {
return this.value = new cError(cErrorType.not_available);
}
else
return this.value = new cError( cErrorType.not_available );
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first );
}
else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElement( 0 );
if (cElementType.cellsRange === arg1.type || cElementType.cellsRange3D === arg1.type) {
arg1 = arg1.cross(arguments[1].first);
} else if (cElementType.array === arg1.type) {
arg1 = arg1.getElement(0);
}
arg1 = arg1.tocNumber();
if ( arg1 instanceof cError ) return this.value = arg1;
return this.value = frequency( arg0, arg1 );
};
cLARGE.prototype.getInfo = function () {
return this.value = this._getValue(arg0, arg1);
};
cLARGE.prototype.getInfo = function () {
return {
name:this.name,
args:"( array , k )"
name: this.name, args: "( array , k )"
};
};
};
function cLINEST() {
cBaseFunction.call( this, "LINEST" );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment