Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xuri
excelize
提交
66776730
excelize
项目概览
xuri
/
excelize
通知
13
Star
2
Fork
4
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
excelize
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
已验证
提交
66776730
编写于
4月 15, 2022
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ref #65, new formula functions: PEARSON and RSQ
上级
c0d34170
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
74 addition
and
0 deletion
+74
-0
calc.go
calc.go
+62
-0
calc_test.go
calc_test.go
+12
-0
未找到文件。
calc.go
浏览文件 @
66776730
...
...
@@ -584,6 +584,7 @@ type formulaFuncs struct {
// ODDFPRICE
// OR
// PDURATION
// PEARSON
// PERCENTILE.EXC
// PERCENTILE.INC
// PERCENTILE
...
...
@@ -628,6 +629,7 @@ type formulaFuncs struct {
// ROW
// ROWS
// RRI
// RSQ
// SEC
// SECH
// SECOND
...
...
@@ -8858,6 +8860,56 @@ func (fn *formulaFuncs) min(mina bool, argsList *list.List) formulaArg {
return
newNumberFormulaArg
(
min
)
}
// pearsonProduct is an implementation of the formula functions PEARSON and
// RSQ.
func
(
fn
*
formulaFuncs
)
pearsonProduct
(
name
string
,
argsList
*
list
.
List
)
formulaArg
{
if
argsList
.
Len
()
!=
2
{
return
newErrorFormulaArg
(
formulaErrorVALUE
,
fmt
.
Sprintf
(
"%s requires 2 arguments"
,
name
))
}
array1
:=
argsList
.
Front
()
.
Value
.
(
formulaArg
)
.
ToList
()
array2
:=
argsList
.
Back
()
.
Value
.
(
formulaArg
)
.
ToList
()
if
len
(
array1
)
!=
len
(
array2
)
{
return
newErrorFormulaArg
(
formulaErrorNA
,
formulaErrorNA
)
}
var
sum
,
deltaX
,
deltaY
,
x
,
y
,
length
float64
for
i
:=
0
;
i
<
len
(
array1
);
i
++
{
num1
,
num2
:=
array1
[
i
]
.
ToNumber
(),
array2
[
i
]
.
ToNumber
()
if
!
(
num1
.
Type
==
ArgNumber
&&
num2
.
Type
==
ArgNumber
)
{
continue
}
x
+=
num1
.
Number
y
+=
num2
.
Number
length
++
}
x
/=
length
y
/=
length
for
i
:=
0
;
i
<
len
(
array1
);
i
++
{
num1
,
num2
:=
array1
[
i
]
.
ToNumber
(),
array2
[
i
]
.
ToNumber
()
if
!
(
num1
.
Type
==
ArgNumber
&&
num2
.
Type
==
ArgNumber
)
{
continue
}
sum
+=
(
num1
.
Number
-
x
)
*
(
num2
.
Number
-
y
)
deltaX
+=
(
num1
.
Number
-
x
)
*
(
num1
.
Number
-
x
)
deltaY
+=
(
num2
.
Number
-
y
)
*
(
num2
.
Number
-
y
)
}
if
deltaX
==
0
||
deltaY
==
0
{
return
newErrorFormulaArg
(
formulaErrorDIV
,
formulaErrorDIV
)
}
if
name
==
"RSQ"
{
return
newNumberFormulaArg
(
math
.
Pow
(
sum
/
math
.
Sqrt
(
deltaX
*
deltaY
),
2
))
}
return
newNumberFormulaArg
(
sum
/
math
.
Sqrt
(
deltaX
*
deltaY
))
}
// PEARSON function calculates the Pearson Product-Moment Correlation
// Coefficient for two sets of values. The syntax of the function is:
//
// PEARSON(array1,array2)
//
func
(
fn
*
formulaFuncs
)
PEARSON
(
argsList
*
list
.
List
)
formulaArg
{
return
fn
.
pearsonProduct
(
"PEARSON"
,
argsList
)
}
// PERCENTILEdotEXC function returns the k'th percentile (i.e. the value below
// which k% of the data values fall) for a supplied range of values and a
// supplied k (between 0 & 1 exclusive).The syntax of the function is:
...
...
@@ -9206,6 +9258,16 @@ func (fn *formulaFuncs) RANK(argsList *list.List) formulaArg {
return
fn
.
rank
(
"RANK"
,
argsList
)
}
// RSQ function calculates the square of the Pearson Product-Moment Correlation
// Coefficient for two supplied sets of values. The syntax of the function
// is:
//
// RSQ(known_y's,known_x's)
//
func
(
fn
*
formulaFuncs
)
RSQ
(
argsList
*
list
.
List
)
formulaArg
{
return
fn
.
pearsonProduct
(
"RSQ"
,
argsList
)
}
// SKEW function calculates the skewness of the distribution of a supplied set
// of values. The syntax of the function is:
//
...
...
calc_test.go
浏览文件 @
66776730
...
...
@@ -1095,6 +1095,8 @@ func TestCalcCellValue(t *testing.T) {
"=MINA(A1:B4,MUNIT(1),INT(0),1,E1:F2,
\"\"
)"
:
"0"
,
// MINIFS
"=MINIFS(F2:F4,A2:A4,
\"
>0
\"
)"
:
"22100"
,
// PEARSON
"=PEARSON(A1:A4,B1:B4)"
:
"1"
,
// PERCENTILE.EXC
"=PERCENTILE.EXC(A1:A4,0.2)"
:
"0"
,
"=PERCENTILE.EXC(A1:A4,0.6)"
:
"2"
,
...
...
@@ -1149,6 +1151,8 @@ func TestCalcCellValue(t *testing.T) {
"=RANK.EQ(1,A1:B5)"
:
"5"
,
"=RANK.EQ(1,A1:B5,0)"
:
"5"
,
"=RANK.EQ(1,A1:B5,1)"
:
"2"
,
// RSQ
"=RSQ(A1:A4,B1:B4)"
:
"1"
,
// SKEW
"=SKEW(1,2,3,4,3)"
:
"-0.404796008910937"
,
"=SKEW(A1:B2)"
:
"0"
,
...
...
@@ -2974,6 +2978,10 @@ func TestCalcCellValue(t *testing.T) {
// MINIFS
"=MINIFS()"
:
"MINIFS requires at least 3 arguments"
,
"=MINIFS(F2:F4,A2:A4,
\"
<0
\"
,D2:D9)"
:
"#N/A"
,
// PEARSON
"=PEARSON()"
:
"PEARSON requires 2 arguments"
,
"=PEARSON(A1:A2,B1:B1)"
:
"#N/A"
,
"=PEARSON(A4,A4)"
:
"#DIV/0!"
,
// PERCENTILE.EXC
"=PERCENTILE.EXC()"
:
"PERCENTILE.EXC requires 2 arguments"
,
"=PERCENTILE.EXC(A1:A4,
\"\"
)"
:
"strconv.ParseFloat: parsing
\"\"
: invalid syntax"
,
...
...
@@ -3047,6 +3055,10 @@ func TestCalcCellValue(t *testing.T) {
"=RANK.EQ(-1,A1:B5)"
:
"#N/A"
,
"=RANK.EQ(
\"\"
,A1:B5)"
:
"strconv.ParseFloat: parsing
\"\"
: invalid syntax"
,
"=RANK.EQ(1,A1:B5,
\"\"
)"
:
"strconv.ParseFloat: parsing
\"\"
: invalid syntax"
,
// RSQ
"=RSQ()"
:
"RSQ requires 2 arguments"
,
"=RSQ(A1:A2,B1:B1)"
:
"#N/A"
,
"=RSQ(A4,A4)"
:
"#DIV/0!"
,
// SKEW
"=SKEW()"
:
"SKEW requires at least 1 argument"
,
"=SKEW(
\"\"
)"
:
"strconv.ParseFloat: parsing
\"\"
: invalid syntax"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录