Commit 24fe24a9 authored by GoshaZotov's avatar GoshaZotov

add COVARIANCE.P formula

parent 7956149a
......@@ -55,7 +55,7 @@
cFormulaFunctionGroup['TextAndData'] = cFormulaFunctionGroup['TextAndData'] || [];
cFormulaFunctionGroup['TextAndData'].push(cDBCS, cUNICHAR, cUNICODE);
cFormulaFunctionGroup['Statistical'] = cFormulaFunctionGroup['Statistical'] || [];
cFormulaFunctionGroup['Statistical'].push(cBINOM_DIST_RANGE, cCHISQ_TEST, cCOVARIANCE_P,
cFormulaFunctionGroup['Statistical'].push(cBINOM_DIST_RANGE, cCHISQ_TEST,
cCOVARIANCE_S, cF_TEST, cFORECAST_ETS, cFORECAST_ETS_CONFINT, cFORECAST_ETS_SEASONALITY, cFORECAST_ETS_STAT,
cHYPGEOM_DIST, cNEGBINOM_DIST, cNORM_DIST, cNORM_INV, cNORM_S_DIST,
cNORM_S_INV, cPERMUTATIONA, cPHI, cSTDEV_P, cSTDEV_S,
......@@ -72,7 +72,7 @@
cFormulaFunctionGroup['NotRealised'] = cFormulaFunctionGroup['NotRealised'] || [];
cFormulaFunctionGroup['NotRealised'].push(cDAYS, cISOWEEKNUM, cBITAND, cBITLSHIFT, cBITOR, cBITRSHIFT, cBITXOR,
cDBCS, cUNICHAR, cUNICODE, cBINOM_DIST_RANGE, cCHISQ_TEST,
cCOVARIANCE_P, cCOVARIANCE_S, cF_TEST, cFORECAST_ETS, cFORECAST_ETS_CONFINT, cFORECAST_ETS_SEASONALITY,
cCOVARIANCE_S, cF_TEST, cFORECAST_ETS, cFORECAST_ETS_CONFINT, cFORECAST_ETS_SEASONALITY,
cFORECAST_ETS_STAT, cHYPGEOM_DIST, cNEGBINOM_DIST, cNORM_DIST,
cNORM_INV, cNORM_S_DIST, cNORM_S_INV, cPERMUTATIONA, cPHI,
cSTDEV_P, cSTDEV_S, cT_TEST, cWEIBULL_DIST, cZ_TEST, cPDURATION, cRRI, cAGGREGATE, cMUNIT,
......@@ -186,18 +186,6 @@
cCOMBINA.prototype = Object.create(cBaseFunction.prototype);
cCOMBINA.prototype.constructor = cCOMBINA;
/**
* @constructor
* @extends {AscCommonExcel.cBaseFunction}
*/
function cCOVARIANCE_P() {
cBaseFunction.call(this, "COVARIANCE.P");
this.isXLFN = true;
}
cCOVARIANCE_P.prototype = Object.create(cBaseFunction.prototype);
cCOVARIANCE_P.prototype.constructor = cCOVARIANCE_P;
/**
* @constructor
* @extends {AscCommonExcel.cBaseFunction}
......
......@@ -63,7 +63,7 @@
cFormulaFunctionGroup['Statistical'].push(cAVEDEV, cAVERAGE, cAVERAGEA, cAVERAGEIF, cAVERAGEIFS, cBETADIST,
cBETA_DIST, cBETA_INV, cBINOMDIST, cBINOM_DIST, cBINOM_INV, cCHIDIST, cCHIINV, cCHISQ_DIST, cCHISQ_DIST_RT,
cCHISQ_INV, cCHISQ_INV_RT, cCHITEST, cCONFIDENCE, cCONFIDENCE_NORM, cCONFIDENCE_T, cCORREL, cCOUNT, cCOUNTA,
cCOUNTBLANK, cCOUNTIF, cCOUNTIFS, cCOVAR, cCRITBINOM, cDEVSQ, cEXPON_DIST, cEXPONDIST, cF_DIST, cFDIST,
cCOUNTBLANK, cCOUNTIF, cCOUNTIFS, cCOVAR, cCOVARIANCE_P, cCRITBINOM, cDEVSQ, cEXPON_DIST, cEXPONDIST, cF_DIST, cFDIST,
cF_DIST_RT, cF_INV, cFINV, cF_INV_RT, cFISHER, cFISHERINV, cFORECAST, cFORECAST_LINEAR, cFREQUENCY, cFTEST,
cGAMMA, cGAMMA_DIST, cGAMMADIST, cGAMMA_INV, cGAMMAINV, cGAMMALN, cGAMMALN_PRECISE, cGAUSS, cGEOMEAN, cGROWTH,
cHARMEAN, cHYPGEOMDIST, cINTERCEPT, cKURT, cLARGE, cLINEST, cLOGEST, cLOGINV, cLOGNORM_DIST, cLOGNORM_INV,
......@@ -2551,6 +2551,101 @@
};
/**
* @constructor
* @extends {AscCommonExcel.cBaseFunction}
*/
function cCOVARIANCE_P() {
this.name = "COVARIANCE.P";
this.value = null;
this.argumentsCurrent = 0;
}
cCOVARIANCE_P.prototype = Object.create(cBaseFunction.prototype);
cCOVARIANCE_P.prototype.constructor = cCOVARIANCE_P;
cCOVARIANCE_P.prototype.argumentsMin = 2;
cCOVARIANCE_P.prototype.argumentsMax = 2;
cCOVARIANCE_P.prototype.isXLFN = true;
cCOVARIANCE_P.prototype.Calculate = function (arg) {
var arg2 = [arg[0], arg[1]];
//если первое или второе значение строка
if(cElementType.string === arg[0].type || cElementType.bool === arg[0].type){
return this.value = new cError(cErrorType.wrong_value_type);
}
if(cElementType.string === arg[1].type || cElementType.bool === arg[1].type){
return this.value = new cError(cErrorType.wrong_value_type);
}
//если первое или второе значение число
if(cElementType.number === arg[0].type){
arg2[0] = new cArray();
arg2[0].addElement(arg[0]);
}
if(cElementType.number === arg[1].type){
arg2[1] = new cArray();
arg2[1].addElement(arg[1]);
}
var oArguments = this._prepareArguments(arg2, arguments[1], true, [cElementType.array, cElementType.array]);
var argClone = oArguments.args;
var argError;
if (argError = this._checkErrorArg(argClone)) {
return this.value = argError;
}
function pearson(argArray) {
var arg1 = argArray[0];
var arg2 = argArray[1];
var x = [];
var y = [];
for (var i = 0; i < arg1.length; i++) {
for (var j = 0; j < arg1[i].length; j++) {
x.push(arg1[i][j]);
}
}
for (var i = 0; i < arg2.length; i++) {
for (var j = 0; j < arg2[i].length; j++) {
y.push(arg2[i][j]);
}
}
var sumXDeltaYDelta = 0, sqrXDelta = 0, sqrYDelta = 0, _x = 0, _y = 0, xLength = 0, i;
if (x.length !== y.length) {
return new cError(cErrorType.not_available);
}
for (i = 0; i < x.length; i++) {
if (!( x[i] instanceof cNumber && y[i] instanceof cNumber )) {
continue;
}
_x += x[i].getValue();
_y += y[i].getValue();
xLength++;
}
_x /= xLength;
_y /= xLength;
for (i = 0; i < x.length; i++) {
if (!( x[i] instanceof cNumber && y[i] instanceof cNumber )) {
continue;
}
sumXDeltaYDelta += (x[i].getValue() - _x) * (y[i].getValue() - _y);
}
return new cNumber(sumXDeltaYDelta / xLength);
}
return this.value = this._findArrayInNumberArguments(oArguments, pearson);
};
/**
* @constructor
* @extends {AscCommonExcel.cBaseFunction}
......
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