Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sdkjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
sdkjs
Commits
8fdf08e5
Commit
8fdf08e5
authored
Jun 20, 2017
by
GoshaZotov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add RANK formula
parent
5a1c014b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
4 deletions
+110
-4
cell/model/FormulaObjects/parserFormula.js
cell/model/FormulaObjects/parserFormula.js
+19
-4
cell/model/FormulaObjects/statisticalFunctions.js
cell/model/FormulaObjects/statisticalFunctions.js
+91
-0
No files found.
cell/model/FormulaObjects/parserFormula.js
View file @
8fdf08e5
...
...
@@ -2417,14 +2417,18 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
if
(
cElementType
.
string
===
inputArguments
[
i
].
type
&&
!
dNotCheckNumberType
){
return
new
cError
(
cErrorType
.
wrong_value_type
);
}
else
{
argsArray
[
i
]
=
inputArguments
[
i
].
getValue
();
if
(
inputArguments
[
i
].
getValue
){
argsArray
[
i
]
=
inputArguments
[
i
].
getValue
();
}
else
{
argsArray
[
i
]
=
inputArguments
[
i
];
}
}
}
}
return
calculateFunc
(
argsArray
);
};
cBaseFunction
.
prototype
.
_prepareArguments
=
function
(
args
,
arg1
,
bAddFirstArrElem
)
{
cBaseFunction
.
prototype
.
_prepareArguments
=
function
(
args
,
arg1
,
bAddFirstArrElem
,
typeArray
)
{
var
newArgs
=
[];
var
indexArr
=
null
;
...
...
@@ -2432,10 +2436,21 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
var
arg
=
args
[
i
];
if
(
cElementType
.
cellsRange
===
arg
.
type
||
cElementType
.
cellsRange3D
===
arg
.
type
)
{
newArgs
[
i
]
=
arg
.
cross
(
arg1
);
if
(
typeArray
&&
cElementType
.
array
===
typeArray
[
i
]){
newArgs
[
i
]
=
arg
;
}
else
{
newArgs
[
i
]
=
arg
.
cross
(
arg1
);
}
}
else
if
(
cElementType
.
array
===
arg
.
type
){
if
(
bAddFirstArrElem
){
newArgs
[
i
]
=
arg
.
getElementRowCol
(
0
,
0
);
if
(
typeArray
&&
cElementType
.
array
===
typeArray
[
i
]){
newArgs
[
i
]
=
[];
arg
.
foreach
(
function
(
elem
)
{
newArgs
[
i
].
push
(
elem
);
});
}
else
{
newArgs
[
i
]
=
arg
.
getElementRowCol
(
0
,
0
);
}
}
else
{
indexArr
=
i
;
newArgs
[
i
]
=
arg
;
...
...
cell/model/FormulaObjects/statisticalFunctions.js
View file @
8fdf08e5
...
...
@@ -903,6 +903,61 @@
return
(
u
<
0
&&
w
>
0
)
||
(
u
>
0
&&
w
<
0
);
}
function
rank
(
fVal
,
aSortArray
,
bAscending
,
bAverage
)
{
//sort array
aSortArray
.
sort
(
function
sortArr
(
a
,
b
)
{
return
a
.
value
-
b
.
value
;
});
var
nSize
=
aSortArray
.
length
;
var
res
;
if
(
nSize
==
0
/*|| nGlobalError != FormulaError::NONE*/
){
res
=
null
;
}
else
{
if
(
fVal
<
aSortArray
[
0
].
value
||
fVal
>
aSortArray
[
nSize
-
1
].
value
){
res
=
null
;
}
else
{
var
fLastPos
=
0
;
var
fFirstPos
=
-
1.0
;
var
bFinished
=
false
;
var
i
;
for
(
i
=
0
;
i
<
nSize
&&
!
bFinished
/*&& nGlobalError == FormulaError::NONE*/
;
i
++
){
if
(
aSortArray
[
i
].
value
===
fVal
){
if
(
fFirstPos
<
0
){
fFirstPos
=
i
+
1.0
;
}
}
else
{
if
(
aSortArray
[
i
].
value
>
fVal
){
fLastPos
=
i
;
bFinished
=
true
;
}
}
}
if
(
!
bFinished
){
fLastPos
=
i
;
}
if
(
!
bAverage
){
if
(
bAscending
){
res
=
fFirstPos
;
}
else
{
res
=
nSize
+
1.0
-
fLastPos
;
}
}
else
{
if
(
bAscending
){
res
=
(
fFirstPos
+
fLastPos
)
/
2.0
;
}
else
{
res
=
nSize
+
1.0
-
(
fFirstPos
+
fLastPos
)
/
2.0
;
}
}
}
}
return
res
;
}
function
GAMMADISTFUNCTION
(
fp
,
fAlpha
,
fBeta
){
this
.
fp
=
fp
;
this
.
fAlpha
=
fAlpha
;
...
...
@@ -5504,6 +5559,42 @@
cRANK
.
prototype
=
Object
.
create
(
cBaseFunction
.
prototype
);
cRANK
.
prototype
.
constructor
=
cRANK
;
cRANK
.
prototype
.
argumentsMin
=
2
;
cRANK
.
prototype
.
argumentsMax
=
3
;
cRANK
.
prototype
.
Calculate
=
function
(
arg
)
{
var
oArguments
=
this
.
_prepareArguments
(
arg
,
arguments
[
1
],
true
,
[
null
,
cElementType
.
array
]);
var
argClone
=
oArguments
.
args
;
//1 argument - array
argClone
[
0
]
=
argClone
[
0
].
tocNumber
();
argClone
[
2
]
=
undefined
!==
argClone
[
2
]
?
argClone
[
2
].
tocNumber
()
:
new
cNumber
(
0
);
var
argError
;
if
(
argError
=
this
.
_checkErrorArg
(
argClone
))
{
return
this
.
value
=
argError
;
}
var
calcTDist
=
function
(
argArray
){
var
number
=
argArray
[
0
];
var
ref
=
argArray
[
1
];
var
order
=
argArray
[
2
];
if
(
!
ref
.
length
){
return
new
cError
(
cErrorType
.
wrong_value_type
);
}
var
changedRef
=
[];
for
(
var
i
=
0
;
i
<
ref
.
length
;
i
++
){
if
(
cElementType
.
number
===
ref
[
i
].
type
){
changedRef
.
push
(
ref
[
i
]);
}
}
var
res
=
rank
(
number
,
changedRef
,
order
);
return
null
!==
res
&&
!
isNaN
(
res
)
?
new
cNumber
(
res
)
:
new
cError
(
cErrorType
.
wrong_value_type
);
};
return
this
.
value
=
this
.
_findArrayInNumberArguments
(
oArguments
,
calcTDist
);
};
/**
* @constructor
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment