2023-07-11 19:45:27 +08:00
|
|
|
|
// SiYuan - Refactor your thinking
|
|
|
|
|
// Copyright (c) 2020-present, b3log.org
|
|
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
package av
|
|
|
|
|
|
|
|
|
|
import (
|
2024-02-04 09:54:43 +08:00
|
|
|
|
"bytes"
|
2024-03-01 09:08:04 +08:00
|
|
|
|
"github.com/siyuan-note/siyuan/kernel/util"
|
2023-07-11 19:45:27 +08:00
|
|
|
|
"math"
|
|
|
|
|
"sort"
|
2023-10-12 12:01:53 +08:00
|
|
|
|
"strconv"
|
2023-07-12 19:10:05 +08:00
|
|
|
|
"strings"
|
2024-03-01 09:08:04 +08:00
|
|
|
|
"time"
|
2023-07-11 19:45:27 +08:00
|
|
|
|
)
|
|
|
|
|
|
2023-07-12 10:35:17 +08:00
|
|
|
|
// LayoutTable 描述了表格布局的结构。
|
|
|
|
|
type LayoutTable struct {
|
|
|
|
|
Spec int `json:"spec"` // 布局格式版本
|
|
|
|
|
ID string `json:"id"` // 布局 ID
|
2023-07-11 19:45:27 +08:00
|
|
|
|
|
2023-12-08 21:05:21 +08:00
|
|
|
|
Columns []*ViewTableColumn `json:"columns"` // 表格列
|
|
|
|
|
RowIDs []string `json:"rowIds"` // 行 ID,用于自定义排序
|
|
|
|
|
Filters []*ViewFilter `json:"filters"` // 过滤规则
|
|
|
|
|
Sorts []*ViewSort `json:"sorts"` // 排序规则
|
|
|
|
|
PageSize int `json:"pageSize"` // 每页行数
|
2023-07-11 23:40:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 19:10:05 +08:00
|
|
|
|
type ViewTableColumn struct {
|
|
|
|
|
ID string `json:"id"` // 列 ID
|
2023-07-11 23:40:05 +08:00
|
|
|
|
|
2023-07-12 23:52:25 +08:00
|
|
|
|
Wrap bool `json:"wrap"` // 是否换行
|
|
|
|
|
Hidden bool `json:"hidden"` // 是否隐藏
|
2023-11-10 10:22:19 +08:00
|
|
|
|
Pin bool `json:"pin"` // 是否固定
|
2023-07-12 23:52:25 +08:00
|
|
|
|
Width string `json:"width"` // 列宽度
|
|
|
|
|
Calc *ColumnCalc `json:"calc,omitempty"` // 计算
|
2023-07-11 23:40:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 19:10:05 +08:00
|
|
|
|
type Calculable interface {
|
|
|
|
|
CalcCols()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ColumnCalc struct {
|
|
|
|
|
Operator CalcOperator `json:"operator"`
|
|
|
|
|
Result *Value `json:"result"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type CalcOperator string
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
CalcOperatorNone CalcOperator = ""
|
|
|
|
|
CalcOperatorCountAll CalcOperator = "Count all"
|
|
|
|
|
CalcOperatorCountValues CalcOperator = "Count values"
|
|
|
|
|
CalcOperatorCountUniqueValues CalcOperator = "Count unique values"
|
|
|
|
|
CalcOperatorCountEmpty CalcOperator = "Count empty"
|
|
|
|
|
CalcOperatorCountNotEmpty CalcOperator = "Count not empty"
|
|
|
|
|
CalcOperatorPercentEmpty CalcOperator = "Percent empty"
|
|
|
|
|
CalcOperatorPercentNotEmpty CalcOperator = "Percent not empty"
|
|
|
|
|
CalcOperatorSum CalcOperator = "Sum"
|
|
|
|
|
CalcOperatorAverage CalcOperator = "Average"
|
|
|
|
|
CalcOperatorMedian CalcOperator = "Median"
|
|
|
|
|
CalcOperatorMin CalcOperator = "Min"
|
|
|
|
|
CalcOperatorMax CalcOperator = "Max"
|
|
|
|
|
CalcOperatorRange CalcOperator = "Range"
|
|
|
|
|
CalcOperatorEarliest CalcOperator = "Earliest"
|
|
|
|
|
CalcOperatorLatest CalcOperator = "Latest"
|
2023-11-17 09:03:17 +08:00
|
|
|
|
CalcOperatorChecked CalcOperator = "Checked"
|
|
|
|
|
CalcOperatorUnchecked CalcOperator = "Unchecked"
|
|
|
|
|
CalcOperatorPercentChecked CalcOperator = "Percent checked"
|
|
|
|
|
CalcOperatorPercentUnchecked CalcOperator = "Percent unchecked"
|
2023-07-12 19:10:05 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (value *Value) Compare(other *Value) int {
|
2023-11-08 16:44:03 +08:00
|
|
|
|
switch value.Type {
|
|
|
|
|
case KeyTypeBlock:
|
|
|
|
|
if nil != value.Block && nil != other.Block {
|
2024-03-08 10:30:41 +08:00
|
|
|
|
ret := strings.Compare(value.Block.Content, other.Block.Content)
|
|
|
|
|
if 0 == ret {
|
|
|
|
|
ret = int(value.CreatedAt - other.CreatedAt)
|
|
|
|
|
}
|
|
|
|
|
return ret
|
2023-07-12 19:10:05 +08:00
|
|
|
|
}
|
2023-11-08 16:44:03 +08:00
|
|
|
|
case KeyTypeText:
|
|
|
|
|
if nil != value.Text && nil != other.Text {
|
2024-03-08 10:30:41 +08:00
|
|
|
|
ret := strings.Compare(value.Text.Content, other.Text.Content)
|
|
|
|
|
if 0 == ret {
|
|
|
|
|
ret = int(value.CreatedAt - other.CreatedAt)
|
|
|
|
|
}
|
|
|
|
|
return ret
|
2023-07-12 19:10:05 +08:00
|
|
|
|
}
|
2023-11-08 16:44:03 +08:00
|
|
|
|
case KeyTypeNumber:
|
|
|
|
|
if nil != value.Number && nil != other.Number {
|
2024-03-01 10:33:25 +08:00
|
|
|
|
if value.Number.IsNotEmpty {
|
|
|
|
|
if !other.Number.IsNotEmpty {
|
|
|
|
|
return 1
|
|
|
|
|
}
|
2024-03-03 16:32:55 +08:00
|
|
|
|
|
|
|
|
|
if value.Number.Content > other.Number.Content {
|
|
|
|
|
return 1
|
|
|
|
|
} else if value.Number.Content < other.Number.Content {
|
|
|
|
|
return -1
|
|
|
|
|
} else {
|
2024-03-08 10:30:41 +08:00
|
|
|
|
return int(value.CreatedAt - other.CreatedAt)
|
2024-03-03 16:32:55 +08:00
|
|
|
|
}
|
2024-03-01 10:33:25 +08:00
|
|
|
|
} else {
|
|
|
|
|
if other.Number.IsNotEmpty {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
2024-03-03 16:32:55 +08:00
|
|
|
|
return int(value.CreatedAt - other.CreatedAt)
|
2023-11-08 16:44:03 +08:00
|
|
|
|
}
|
2023-10-09 12:06:09 +08:00
|
|
|
|
}
|
2023-11-08 16:44:03 +08:00
|
|
|
|
case KeyTypeDate:
|
|
|
|
|
if nil != value.Date && nil != other.Date {
|
2024-03-01 10:33:25 +08:00
|
|
|
|
if value.Date.IsNotEmpty {
|
|
|
|
|
if !other.Date.IsNotEmpty {
|
|
|
|
|
return 1
|
|
|
|
|
}
|
2024-03-03 16:32:55 +08:00
|
|
|
|
if value.Date.Content > other.Date.Content {
|
|
|
|
|
return 1
|
|
|
|
|
} else if value.Date.Content < other.Date.Content {
|
|
|
|
|
return -1
|
|
|
|
|
} else {
|
2024-03-08 10:30:41 +08:00
|
|
|
|
return int(value.CreatedAt - other.CreatedAt)
|
2024-03-03 16:32:55 +08:00
|
|
|
|
}
|
2024-03-01 10:33:25 +08:00
|
|
|
|
} else {
|
|
|
|
|
if other.Date.IsNotEmpty {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
2024-03-03 16:32:55 +08:00
|
|
|
|
return int(value.CreatedAt - other.CreatedAt)
|
2023-11-08 16:44:03 +08:00
|
|
|
|
}
|
2023-10-09 12:06:09 +08:00
|
|
|
|
}
|
2023-11-08 16:44:03 +08:00
|
|
|
|
case KeyTypeCreated:
|
|
|
|
|
if nil != value.Created && nil != other.Created {
|
|
|
|
|
if value.Created.Content > other.Created.Content {
|
|
|
|
|
return 1
|
|
|
|
|
} else if value.Created.Content < other.Created.Content {
|
|
|
|
|
return -1
|
|
|
|
|
} else {
|
2024-03-08 10:30:41 +08:00
|
|
|
|
return int(value.CreatedAt - other.CreatedAt)
|
2023-11-08 16:44:03 +08:00
|
|
|
|
}
|
2023-07-12 19:10:05 +08:00
|
|
|
|
}
|
2023-11-08 16:44:03 +08:00
|
|
|
|
case KeyTypeUpdated:
|
|
|
|
|
if nil != value.Updated && nil != other.Updated {
|
|
|
|
|
if value.Updated.Content > other.Updated.Content {
|
|
|
|
|
return 1
|
|
|
|
|
} else if value.Updated.Content < other.Updated.Content {
|
|
|
|
|
return -1
|
|
|
|
|
} else {
|
2024-03-08 10:30:41 +08:00
|
|
|
|
return int(value.CreatedAt - other.CreatedAt)
|
2023-11-08 16:44:03 +08:00
|
|
|
|
}
|
2023-07-12 19:10:05 +08:00
|
|
|
|
}
|
2023-11-08 16:44:03 +08:00
|
|
|
|
case KeyTypeSelect, KeyTypeMSelect:
|
|
|
|
|
if nil != value.MSelect && nil != other.MSelect {
|
|
|
|
|
var v1 string
|
|
|
|
|
for _, v := range value.MSelect {
|
|
|
|
|
v1 += v.Content
|
|
|
|
|
}
|
|
|
|
|
var v2 string
|
|
|
|
|
for _, v := range other.MSelect {
|
|
|
|
|
v2 += v.Content
|
|
|
|
|
}
|
2024-03-08 10:30:41 +08:00
|
|
|
|
ret := strings.Compare(v1, v2)
|
|
|
|
|
if 0 == ret {
|
|
|
|
|
ret = int(value.CreatedAt - other.CreatedAt)
|
|
|
|
|
}
|
|
|
|
|
return ret
|
2023-09-21 16:58:24 +08:00
|
|
|
|
}
|
2023-11-08 16:44:03 +08:00
|
|
|
|
case KeyTypeURL:
|
|
|
|
|
if nil != value.URL && nil != other.URL {
|
2024-03-08 10:30:41 +08:00
|
|
|
|
ret := strings.Compare(value.URL.Content, other.URL.Content)
|
|
|
|
|
if 0 == ret {
|
|
|
|
|
ret = int(value.CreatedAt - other.CreatedAt)
|
|
|
|
|
}
|
|
|
|
|
return ret
|
2023-11-08 16:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
case KeyTypeEmail:
|
|
|
|
|
if nil != value.Email && nil != other.Email {
|
2024-03-08 10:30:41 +08:00
|
|
|
|
ret := strings.Compare(value.Email.Content, other.Email.Content)
|
|
|
|
|
if 0 == ret {
|
|
|
|
|
ret = int(value.CreatedAt - other.CreatedAt)
|
|
|
|
|
}
|
|
|
|
|
return ret
|
2023-11-08 16:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
case KeyTypePhone:
|
|
|
|
|
if nil != value.Phone && nil != other.Phone {
|
2024-03-08 10:30:41 +08:00
|
|
|
|
ret := strings.Compare(value.Phone.Content, other.Phone.Content)
|
|
|
|
|
if 0 == ret {
|
|
|
|
|
ret = int(value.CreatedAt - other.CreatedAt)
|
|
|
|
|
}
|
|
|
|
|
return ret
|
2023-11-08 16:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
case KeyTypeMAsset:
|
|
|
|
|
if nil != value.MAsset && nil != other.MAsset {
|
|
|
|
|
var v1 string
|
|
|
|
|
for _, v := range value.MAsset {
|
|
|
|
|
v1 += v.Content
|
|
|
|
|
}
|
|
|
|
|
var v2 string
|
|
|
|
|
for _, v := range other.MAsset {
|
|
|
|
|
v2 += v.Content
|
|
|
|
|
}
|
2024-03-08 10:30:41 +08:00
|
|
|
|
ret := strings.Compare(v1, v2)
|
|
|
|
|
if 0 == ret {
|
|
|
|
|
ret = int(value.CreatedAt - other.CreatedAt)
|
|
|
|
|
}
|
|
|
|
|
return ret
|
2023-11-08 16:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
case KeyTypeTemplate:
|
|
|
|
|
if nil != value.Template && nil != other.Template {
|
2023-12-20 11:12:31 +08:00
|
|
|
|
vContent := strings.TrimSpace(value.Template.Content)
|
|
|
|
|
oContent := strings.TrimSpace(other.Template.Content)
|
|
|
|
|
if util.IsNumeric(vContent) && util.IsNumeric(oContent) {
|
|
|
|
|
v1, _ := strconv.ParseFloat(vContent, 64)
|
|
|
|
|
v2, _ := strconv.ParseFloat(oContent, 64)
|
2023-12-18 19:17:04 +08:00
|
|
|
|
if v1 > v2 {
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
if v1 < v2 {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
2024-03-08 10:30:41 +08:00
|
|
|
|
return int(value.CreatedAt - other.CreatedAt)
|
2023-12-18 19:17:04 +08:00
|
|
|
|
}
|
2024-03-08 10:30:41 +08:00
|
|
|
|
ret := strings.Compare(value.Template.Content, other.Template.Content)
|
|
|
|
|
if 0 == ret {
|
|
|
|
|
ret = int(value.CreatedAt - other.CreatedAt)
|
|
|
|
|
}
|
|
|
|
|
return ret
|
2023-09-21 16:58:24 +08:00
|
|
|
|
}
|
2023-11-17 09:03:17 +08:00
|
|
|
|
case KeyTypeCheckbox:
|
|
|
|
|
if nil != value.Checkbox && nil != other.Checkbox {
|
|
|
|
|
if value.Checkbox.Checked && !other.Checkbox.Checked {
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
if !value.Checkbox.Checked && other.Checkbox.Checked {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
2024-03-08 10:30:41 +08:00
|
|
|
|
return int(value.CreatedAt - other.CreatedAt)
|
2023-11-17 09:03:17 +08:00
|
|
|
|
}
|
2023-12-15 20:05:14 +08:00
|
|
|
|
case KeyTypeRelation:
|
2023-12-25 15:06:51 +08:00
|
|
|
|
if nil != value.Relation && nil != other.Relation {
|
2024-03-07 16:21:36 +08:00
|
|
|
|
vContentBuf := bytes.Buffer{}
|
|
|
|
|
for _, c := range value.Relation.Contents {
|
|
|
|
|
vContentBuf.WriteString(c.String())
|
|
|
|
|
vContentBuf.WriteByte(' ')
|
|
|
|
|
}
|
|
|
|
|
vContent := strings.TrimSpace(vContentBuf.String())
|
|
|
|
|
oContentBuf := bytes.Buffer{}
|
|
|
|
|
for _, c := range other.Relation.Contents {
|
|
|
|
|
oContentBuf.WriteString(c.String())
|
|
|
|
|
oContentBuf.WriteByte(' ')
|
|
|
|
|
}
|
|
|
|
|
oContent := strings.TrimSpace(oContentBuf.String())
|
|
|
|
|
|
|
|
|
|
if util.IsNumeric(vContent) && util.IsNumeric(oContent) {
|
|
|
|
|
v1, _ := strconv.ParseFloat(vContent, 64)
|
|
|
|
|
v2, _ := strconv.ParseFloat(oContent, 64)
|
|
|
|
|
if v1 > v2 {
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if v1 < v2 {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
2024-03-08 10:30:41 +08:00
|
|
|
|
return int(value.CreatedAt - other.CreatedAt)
|
2024-03-07 16:21:36 +08:00
|
|
|
|
}
|
2024-03-08 10:30:41 +08:00
|
|
|
|
ret := strings.Compare(vContent, oContent)
|
|
|
|
|
if 0 == ret {
|
|
|
|
|
ret = int(value.CreatedAt - other.CreatedAt)
|
|
|
|
|
}
|
|
|
|
|
return ret
|
2023-12-25 15:06:51 +08:00
|
|
|
|
}
|
2023-12-15 20:05:14 +08:00
|
|
|
|
case KeyTypeRollup:
|
2023-12-25 15:06:51 +08:00
|
|
|
|
if nil != value.Rollup && nil != other.Rollup {
|
2024-02-04 09:54:43 +08:00
|
|
|
|
vContentBuf := bytes.Buffer{}
|
|
|
|
|
for _, c := range value.Rollup.Contents {
|
|
|
|
|
vContentBuf.WriteString(c.String())
|
|
|
|
|
vContentBuf.WriteByte(' ')
|
|
|
|
|
}
|
|
|
|
|
vContent := strings.TrimSpace(vContentBuf.String())
|
|
|
|
|
oContentBuf := bytes.Buffer{}
|
|
|
|
|
for _, c := range other.Rollup.Contents {
|
|
|
|
|
oContentBuf.WriteString(c.String())
|
|
|
|
|
oContentBuf.WriteByte(' ')
|
|
|
|
|
}
|
|
|
|
|
oContent := strings.TrimSpace(oContentBuf.String())
|
|
|
|
|
|
2023-12-25 15:06:51 +08:00
|
|
|
|
if util.IsNumeric(vContent) && util.IsNumeric(oContent) {
|
|
|
|
|
v1, _ := strconv.ParseFloat(vContent, 64)
|
|
|
|
|
v2, _ := strconv.ParseFloat(oContent, 64)
|
|
|
|
|
if v1 > v2 {
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
if v1 < v2 {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
2024-03-08 10:30:41 +08:00
|
|
|
|
return int(value.CreatedAt - other.CreatedAt)
|
|
|
|
|
}
|
|
|
|
|
ret := strings.Compare(vContent, oContent)
|
|
|
|
|
if 0 == ret {
|
|
|
|
|
ret = int(value.CreatedAt - other.CreatedAt)
|
2023-12-25 15:06:51 +08:00
|
|
|
|
}
|
2024-03-08 10:30:41 +08:00
|
|
|
|
return ret
|
2023-12-25 15:06:51 +08:00
|
|
|
|
}
|
2023-10-13 08:46:29 +08:00
|
|
|
|
}
|
2024-03-03 16:32:55 +08:00
|
|
|
|
return int(value.CreatedAt - other.CreatedAt)
|
2023-07-12 19:10:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-06 22:47:21 +08:00
|
|
|
|
func (value *Value) Filter(filter *ViewFilter, attrView *AttributeView, rowID string) bool {
|
|
|
|
|
if nil == filter || (nil == filter.Value && nil == filter.RelativeDate) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if nil != filter.Value && value.Type != filter.Value.Type {
|
|
|
|
|
// 由于字段类型被用户编辑过导致和过滤器值类型不匹配,该情况下不过滤
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if nil != value.Rollup && KeyTypeRollup == value.Type && nil != filter && nil != filter.Value && KeyTypeRollup == filter.Value.Type &&
|
|
|
|
|
nil != filter.Value.Rollup && 0 < len(filter.Value.Rollup.Contents) {
|
2024-03-06 16:20:45 +08:00
|
|
|
|
// 单独处理汇总类型的比较
|
2024-03-06 00:15:56 +08:00
|
|
|
|
key, _ := attrView.GetKey(value.KeyID)
|
|
|
|
|
if nil == key {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2024-03-05 23:43:42 +08:00
|
|
|
|
|
|
|
|
|
relKey, _ := attrView.GetKey(key.Rollup.RelationKeyID)
|
2023-12-30 23:01:21 +08:00
|
|
|
|
if nil == relKey {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
relVal := attrView.GetValue(relKey.ID, rowID)
|
|
|
|
|
if nil == relVal || nil == relVal.Relation {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
destAv, _ := ParseAttributeView(relKey.Relation.AvID)
|
|
|
|
|
if nil == destAv {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, blockID := range relVal.Relation.BlockIDs {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
destVal := destAv.GetValue(key.Rollup.KeyID, blockID)
|
2023-12-30 23:01:21 +08:00
|
|
|
|
if nil == destVal {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if destVal.filter(filter.Value.Rollup.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator) {
|
2023-12-30 23:01:21 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-08 00:58:33 +08:00
|
|
|
|
if nil != value.Relation && KeyTypeRelation == value.Type && 0 < len(value.Relation.Contents) && nil != filter && nil != filter.Value && KeyTypeRelation == filter.Value.Type &&
|
2024-03-08 01:01:28 +08:00
|
|
|
|
nil != filter.Value.Relation && 0 < len(filter.Value.Relation.BlockIDs) {
|
2024-03-07 16:21:36 +08:00
|
|
|
|
// 单独处理关联类型的比较
|
2024-03-08 00:58:33 +08:00
|
|
|
|
relationValue := value.Relation.Contents[0]
|
|
|
|
|
filterValue := &Value{Type: KeyTypeBlock, Block: &ValueBlock{Content: filter.Value.Relation.BlockIDs[0]}}
|
|
|
|
|
return relationValue.filter(filterValue, filter.RelativeDate, filter.RelativeDate2, filter.Operator)
|
2024-03-07 16:21:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.filter(filter.Value, filter.RelativeDate, filter.RelativeDate2, filter.Operator)
|
|
|
|
|
}
|
2024-03-06 16:20:45 +08:00
|
|
|
|
|
2024-03-06 22:47:21 +08:00
|
|
|
|
func (value *Value) filter(other *Value, relativeDate, relativeDate2 *RelativeDate, operator FilterOperator) bool {
|
2024-03-06 00:15:56 +08:00
|
|
|
|
switch value.Type {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case KeyTypeBlock:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if nil != value.Block && nil != other && nil != other.Block {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Block.Content == other.Block.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsNotEqual:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Block.Content != other.Block.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorContains:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return strings.Contains(value.Block.Content, other.Block.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorDoesNotContain:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return !strings.Contains(value.Block.Content, other.Block.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorStartsWith:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return strings.HasPrefix(value.Block.Content, other.Block.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorEndsWith:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return strings.HasSuffix(value.Block.Content, other.Block.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
return "" == strings.TrimSpace(value.Block.Content)
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
return "" != strings.TrimSpace(value.Block.Content)
|
2023-10-11 08:50:13 +08:00
|
|
|
|
}
|
2024-03-05 23:43:42 +08:00
|
|
|
|
}
|
|
|
|
|
case KeyTypeText:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if nil != value.Text && nil != other && nil != other.Text {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if "" == strings.TrimSpace(other.Text.Content) {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Text.Content == other.Text.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsNotEqual:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if "" == strings.TrimSpace(other.Text.Content) {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Text.Content != other.Text.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorContains:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if "" == strings.TrimSpace(other.Text.Content) {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return strings.Contains(value.Text.Content, other.Text.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorDoesNotContain:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if "" == strings.TrimSpace(other.Text.Content) {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return !strings.Contains(value.Text.Content, other.Text.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorStartsWith:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if "" == strings.TrimSpace(other.Text.Content) {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return strings.HasPrefix(value.Text.Content, other.Text.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorEndsWith:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if "" == strings.TrimSpace(other.Text.Content) {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return strings.HasSuffix(value.Text.Content, other.Text.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
return "" == strings.TrimSpace(value.Text.Content)
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
return "" != strings.TrimSpace(value.Text.Content)
|
2023-10-11 08:50:13 +08:00
|
|
|
|
}
|
2024-03-05 23:43:42 +08:00
|
|
|
|
}
|
|
|
|
|
case KeyTypeNumber:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if nil != value.Number && nil != other && nil != other.Number {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if !other.Number.IsNotEmpty {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Number.Content == other.Number.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsNotEqual:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if !other.Number.IsNotEmpty {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Number.Content != other.Number.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsGreater:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Number.Content > other.Number.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsGreaterOrEqual:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Number.Content >= other.Number.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsLess:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Number.Content < other.Number.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsLessOrEqual:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Number.Content <= other.Number.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
return !value.Number.IsNotEmpty
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
return value.Number.IsNotEmpty
|
2023-10-11 08:50:13 +08:00
|
|
|
|
}
|
2023-07-12 19:10:05 +08:00
|
|
|
|
}
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case KeyTypeDate:
|
|
|
|
|
if nil != value.Date {
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if nil != relativeDate {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
// 使用相对时间比较
|
|
|
|
|
|
2024-03-06 22:47:21 +08:00
|
|
|
|
count := relativeDate.Count
|
|
|
|
|
unit := relativeDate.Unit
|
|
|
|
|
direction := relativeDate.Direction
|
2024-03-05 23:43:42 +08:00
|
|
|
|
relativeTimeStart, relativeTimeEnd := calcRelativeTimeRegion(count, unit, direction)
|
2024-03-08 09:16:36 +08:00
|
|
|
|
_, relativeTimeEnd2 := calcRelativeTimeRegion(relativeDate2.Count, relativeDate2.Unit, relativeDate2.Direction)
|
2024-03-08 09:32:18 +08:00
|
|
|
|
return filterTime(value.Date.Content, value.Date.IsNotEmpty, relativeTimeStart, relativeTimeEnd, relativeTimeEnd2, operator)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
} else { // 使用具体时间比较
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if nil == other.Date {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2023-07-12 19:10:05 +08:00
|
|
|
|
|
2024-03-08 09:16:36 +08:00
|
|
|
|
otherTime := time.UnixMilli(other.Date.Content)
|
|
|
|
|
otherStart := time.Date(otherTime.Year(), otherTime.Month(), otherTime.Day(), 0, 0, 0, 0, otherTime.Location())
|
|
|
|
|
otherEnd := time.Date(otherTime.Year(), otherTime.Month(), otherTime.Day(), 23, 59, 59, 999999999, otherTime.Location())
|
|
|
|
|
return filterTime(value.Date.Content, value.Date.IsNotEmpty, otherStart, otherEnd, time.Now(), operator)
|
2023-10-11 08:50:13 +08:00
|
|
|
|
}
|
2023-07-12 19:10:05 +08:00
|
|
|
|
}
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case KeyTypeCreated:
|
2024-03-08 00:23:45 +08:00
|
|
|
|
if nil != value.Created {
|
|
|
|
|
if nil != relativeDate {
|
|
|
|
|
// 使用相对时间比较
|
|
|
|
|
|
|
|
|
|
count := relativeDate.Count
|
|
|
|
|
unit := relativeDate.Unit
|
|
|
|
|
direction := relativeDate.Direction
|
|
|
|
|
relativeTimeStart, relativeTimeEnd := calcRelativeTimeRegion(count, unit, direction)
|
2024-03-08 09:16:36 +08:00
|
|
|
|
return filterTime(value.Created.Content, true, relativeTimeStart, relativeTimeEnd, time.Now(), operator)
|
2024-03-08 00:23:45 +08:00
|
|
|
|
} else { // 使用具体时间比较
|
|
|
|
|
if nil == other.Created {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-08 09:16:36 +08:00
|
|
|
|
otherTime := time.UnixMilli(other.Created.Content)
|
|
|
|
|
otherStart := time.Date(otherTime.Year(), otherTime.Month(), otherTime.Day(), 0, 0, 0, 0, otherTime.Location())
|
|
|
|
|
otherEnd := time.Date(otherTime.Year(), otherTime.Month(), otherTime.Day(), 23, 59, 59, 999999999, otherTime.Location())
|
|
|
|
|
return filterTime(value.Created.Content, value.Created.IsNotEmpty, otherStart, otherEnd, time.Now(), operator)
|
2024-03-03 23:36:53 +08:00
|
|
|
|
}
|
2024-03-05 23:43:42 +08:00
|
|
|
|
}
|
|
|
|
|
case KeyTypeUpdated:
|
2024-03-08 00:23:45 +08:00
|
|
|
|
if nil != value.Updated {
|
|
|
|
|
if nil != relativeDate {
|
|
|
|
|
// 使用相对时间比较
|
|
|
|
|
|
|
|
|
|
count := relativeDate.Count
|
|
|
|
|
unit := relativeDate.Unit
|
|
|
|
|
direction := relativeDate.Direction
|
|
|
|
|
relativeTimeStart, relativeTimeEnd := calcRelativeTimeRegion(count, unit, direction)
|
2024-03-08 09:16:36 +08:00
|
|
|
|
return filterTime(value.Updated.Content, true, relativeTimeStart, relativeTimeEnd, time.Now(), operator)
|
2024-03-08 00:23:45 +08:00
|
|
|
|
} else { // 使用具体时间比较
|
|
|
|
|
if nil == other.Updated {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-08 09:16:36 +08:00
|
|
|
|
otherTime := time.UnixMilli(other.Updated.Content)
|
|
|
|
|
otherStart := time.Date(otherTime.Year(), otherTime.Month(), otherTime.Day(), 0, 0, 0, 0, otherTime.Location())
|
|
|
|
|
otherEnd := time.Date(otherTime.Year(), otherTime.Month(), otherTime.Day(), 23, 59, 59, 999999999, otherTime.Location())
|
|
|
|
|
return filterTime(value.Updated.Content, value.Updated.IsNotEmpty, otherStart, otherEnd, time.Now(), operator)
|
2023-07-25 12:26:45 +08:00
|
|
|
|
}
|
2023-07-12 19:10:05 +08:00
|
|
|
|
}
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case KeyTypeSelect, KeyTypeMSelect:
|
|
|
|
|
if nil != value.MSelect {
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if nil != other && nil != other.MSelect {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEqual, FilterOperatorContains:
|
|
|
|
|
contains := false
|
|
|
|
|
for _, v := range value.MSelect {
|
2024-03-06 22:47:21 +08:00
|
|
|
|
for _, v2 := range other.MSelect {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
if v.Content == v2.Content {
|
|
|
|
|
contains = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return contains
|
|
|
|
|
case FilterOperatorIsNotEqual, FilterOperatorDoesNotContain:
|
|
|
|
|
contains := false
|
|
|
|
|
for _, v := range value.MSelect {
|
2024-03-06 22:47:21 +08:00
|
|
|
|
for _, v2 := range other.MSelect {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
if v.Content == v2.Content {
|
|
|
|
|
contains = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return !contains
|
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
return 0 == len(value.MSelect) || 1 == len(value.MSelect) && "" == value.MSelect[0].Content
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
return 0 != len(value.MSelect) && !(1 == len(value.MSelect) && "" == value.MSelect[0].Content)
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2023-07-12 19:10:05 +08:00
|
|
|
|
|
2024-03-05 23:43:42 +08:00
|
|
|
|
// 没有设置比较值
|
2023-10-09 12:06:09 +08:00
|
|
|
|
|
2024-03-05 23:43:42 +08:00
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEqual, FilterOperatorIsNotEqual, FilterOperatorContains, FilterOperatorDoesNotContain:
|
|
|
|
|
return true
|
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
return 0 == len(value.MSelect) || 1 == len(value.MSelect) && "" == value.MSelect[0].Content
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
return 0 != len(value.MSelect) && !(1 == len(value.MSelect) && "" == value.MSelect[0].Content)
|
|
|
|
|
}
|
2023-10-09 12:06:09 +08:00
|
|
|
|
}
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case KeyTypeURL:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if nil != value.URL && nil != other && nil != other.URL {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.URL.Content == other.URL.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsNotEqual:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.URL.Content != other.URL.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorContains:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return strings.Contains(value.URL.Content, other.URL.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorDoesNotContain:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return !strings.Contains(value.URL.Content, other.URL.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorStartsWith:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return strings.HasPrefix(value.URL.Content, other.URL.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorEndsWith:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return strings.HasSuffix(value.URL.Content, other.URL.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
return "" == strings.TrimSpace(value.URL.Content)
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
return "" != strings.TrimSpace(value.URL.Content)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case KeyTypeEmail:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if nil != value.Email && nil != other && nil != other.Email {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Email.Content == other.Email.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsNotEqual:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Email.Content != other.Email.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorContains:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return strings.Contains(value.Email.Content, other.Email.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorDoesNotContain:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return !strings.Contains(value.Email.Content, other.Email.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorStartsWith:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return strings.HasPrefix(value.Email.Content, other.Email.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorEndsWith:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return strings.HasSuffix(value.Email.Content, other.Email.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
return "" == strings.TrimSpace(value.Email.Content)
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
return "" != strings.TrimSpace(value.Email.Content)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case KeyTypePhone:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if nil != value.Phone && nil != other && nil != other.Phone {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Phone.Content == other.Phone.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsNotEqual:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Phone.Content != other.Phone.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorContains:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return strings.Contains(value.Phone.Content, other.Phone.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorDoesNotContain:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return !strings.Contains(value.Phone.Content, other.Phone.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorStartsWith:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return strings.HasPrefix(value.Phone.Content, other.Phone.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorEndsWith:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return strings.HasSuffix(value.Phone.Content, other.Phone.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
return "" == strings.TrimSpace(value.Phone.Content)
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
return "" != strings.TrimSpace(value.Phone.Content)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case KeyTypeMAsset:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if nil != value.MAsset && nil != other && nil != other.MAsset && 0 < len(value.MAsset) && 0 < len(other.MAsset) {
|
2024-01-16 17:00:34 +08:00
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEqual, FilterOperatorContains:
|
|
|
|
|
contains := false
|
2024-03-05 23:43:42 +08:00
|
|
|
|
for _, v := range value.MAsset {
|
2024-03-06 22:47:21 +08:00
|
|
|
|
for _, v2 := range other.MAsset {
|
2024-01-16 17:00:34 +08:00
|
|
|
|
if v.Content == v2.Content {
|
|
|
|
|
contains = true
|
|
|
|
|
break
|
|
|
|
|
}
|
2023-07-13 23:34:13 +08:00
|
|
|
|
}
|
2023-07-12 19:10:05 +08:00
|
|
|
|
}
|
2024-01-16 17:00:34 +08:00
|
|
|
|
return contains
|
|
|
|
|
case FilterOperatorIsNotEqual, FilterOperatorDoesNotContain:
|
|
|
|
|
contains := false
|
2024-03-05 23:43:42 +08:00
|
|
|
|
for _, v := range value.MAsset {
|
2024-03-06 22:47:21 +08:00
|
|
|
|
for _, v2 := range other.MAsset {
|
2024-01-16 17:00:34 +08:00
|
|
|
|
if v.Content == v2.Content {
|
|
|
|
|
contains = true
|
|
|
|
|
break
|
|
|
|
|
}
|
2023-07-13 23:34:13 +08:00
|
|
|
|
}
|
2023-07-12 19:10:05 +08:00
|
|
|
|
}
|
2024-01-16 17:00:34 +08:00
|
|
|
|
return !contains
|
|
|
|
|
case FilterOperatorIsEmpty:
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return 0 == len(value.MAsset) || 1 == len(value.MAsset) && "" == value.MAsset[0].Content
|
2024-01-16 17:00:34 +08:00
|
|
|
|
case FilterOperatorIsNotEmpty:
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return 0 != len(value.MAsset) && !(1 == len(value.MAsset) && "" == value.MAsset[0].Content)
|
2023-07-12 19:10:05 +08:00
|
|
|
|
}
|
2023-08-03 12:21:11 +08:00
|
|
|
|
}
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case KeyTypeTemplate:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if nil != value.Template && nil != other && nil != other.Template {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
2023-09-21 16:58:24 +08:00
|
|
|
|
}
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Template.Content == other.Template.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsNotEqual:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Template.Content != other.Template.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsGreater:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
2023-09-21 16:58:24 +08:00
|
|
|
|
}
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Template.Content > other.Template.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsGreaterOrEqual:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Template.Content >= other.Template.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsLess:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Template.Content < other.Template.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsLessOrEqual:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return value.Template.Content <= other.Template.Content
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorContains:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return strings.Contains(value.Template.Content, other.Template.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorDoesNotContain:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return !strings.Contains(value.Template.Content, other.Template.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorStartsWith:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return strings.HasPrefix(value.Template.Content, other.Template.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorEndsWith:
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if "" == strings.TrimSpace(other.Template.Content) {
|
2024-03-05 23:43:42 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2024-03-06 22:47:21 +08:00
|
|
|
|
return strings.HasSuffix(value.Template.Content, other.Template.Content)
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
return "" == strings.TrimSpace(value.Template.Content)
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
return "" != strings.TrimSpace(value.Template.Content)
|
2023-09-21 16:58:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-05 23:43:42 +08:00
|
|
|
|
case KeyTypeCheckbox:
|
|
|
|
|
if nil != value.Checkbox {
|
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsTrue:
|
|
|
|
|
return value.Checkbox.Checked
|
|
|
|
|
case FilterOperatorIsFalse:
|
|
|
|
|
return !value.Checkbox.Checked
|
2023-10-12 17:15:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-15 20:05:14 +08:00
|
|
|
|
}
|
2023-12-05 21:32:41 +08:00
|
|
|
|
return false
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-08 09:16:36 +08:00
|
|
|
|
func filterTime(valueMills int64, valueIsNotEmpty bool, otherValueStart, otherValueEnd, otherValueEnd2 time.Time, operator FilterOperator) bool {
|
|
|
|
|
valueTime := time.UnixMilli(valueMills)
|
|
|
|
|
switch operator {
|
|
|
|
|
case FilterOperatorIsEqual:
|
2024-03-08 09:32:18 +08:00
|
|
|
|
return (valueTime.After(otherValueStart) || valueTime.Equal(otherValueStart)) && valueTime.Before(otherValueEnd)
|
2024-03-08 09:16:36 +08:00
|
|
|
|
case FilterOperatorIsNotEqual:
|
2024-03-08 09:32:18 +08:00
|
|
|
|
return valueTime.Before(otherValueStart) || valueTime.After(otherValueEnd)
|
2024-03-08 09:16:36 +08:00
|
|
|
|
case FilterOperatorIsGreater:
|
2024-03-08 09:32:18 +08:00
|
|
|
|
return valueTime.After(otherValueEnd) || valueTime.Equal(otherValueEnd)
|
2024-03-08 09:16:36 +08:00
|
|
|
|
case FilterOperatorIsGreaterOrEqual:
|
|
|
|
|
return valueTime.After(otherValueStart) || valueTime.Equal(otherValueStart)
|
|
|
|
|
case FilterOperatorIsLess:
|
|
|
|
|
return valueTime.Before(otherValueStart)
|
|
|
|
|
case FilterOperatorIsLessOrEqual:
|
2024-03-08 09:32:18 +08:00
|
|
|
|
return valueTime.Before(otherValueEnd) || valueTime.Equal(otherValueEnd)
|
2024-03-08 09:16:36 +08:00
|
|
|
|
case FilterOperatorIsBetween:
|
|
|
|
|
return (valueTime.After(otherValueStart) || valueTime.Equal(otherValueStart)) && (valueTime.Before(otherValueEnd2) || valueTime.Equal(otherValueEnd2))
|
|
|
|
|
case FilterOperatorIsEmpty:
|
|
|
|
|
return !valueIsNotEmpty
|
|
|
|
|
case FilterOperatorIsNotEmpty:
|
|
|
|
|
return valueIsNotEmpty
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-03 23:36:53 +08:00
|
|
|
|
// 根据 Count、Unit 和 Direction 计算相对当前时间的开始时间和结束时间
|
|
|
|
|
func calcRelativeTimeRegion(count int, unit RelativeDateUnit, direction RelativeDateDirection) (start, end time.Time) {
|
|
|
|
|
now := time.Now()
|
|
|
|
|
switch unit {
|
|
|
|
|
case RelativeDateUnitDay:
|
|
|
|
|
switch direction {
|
|
|
|
|
case RelativeDateDirectionBefore:
|
|
|
|
|
// 结束时间使用今天的开始时间
|
|
|
|
|
end = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
|
|
|
|
// 开始时间使用结束时间减去 count 天
|
|
|
|
|
start = end.AddDate(0, 0, -count)
|
|
|
|
|
case RelativeDateDirectionThis:
|
|
|
|
|
// 开始时间使用今天的开始时间
|
|
|
|
|
start = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
|
|
|
|
// 结束时间使用开始时间加上 count 天
|
|
|
|
|
end = start.AddDate(0, 0, count)
|
|
|
|
|
case RelativeDateDirectionAfter:
|
|
|
|
|
// 开始时间使用今天的结束时间
|
|
|
|
|
start = time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 999999999, now.Location())
|
|
|
|
|
// 结束时间使用开始时间加上 count 天
|
|
|
|
|
end = start.AddDate(0, 0, count)
|
|
|
|
|
}
|
|
|
|
|
case RelativeDateUnitWeek:
|
|
|
|
|
weekday := int(now.Weekday())
|
|
|
|
|
if 0 == weekday {
|
|
|
|
|
weekday = 7
|
|
|
|
|
}
|
|
|
|
|
switch direction {
|
|
|
|
|
case RelativeDateDirectionBefore:
|
|
|
|
|
// 结束时间使用本周的开始时间
|
|
|
|
|
end = time.Date(now.Year(), now.Month(), now.Day()-weekday, 0, 0, 0, 0, now.Location())
|
|
|
|
|
// 开始时间使用结束时间减去 count*7 天
|
|
|
|
|
start = end.AddDate(0, 0, -count*7)
|
|
|
|
|
case RelativeDateDirectionThis:
|
|
|
|
|
// 开始时间使用本周的开始时间
|
|
|
|
|
start = time.Date(now.Year(), now.Month(), now.Day()-weekday, 0, 0, 0, 0, now.Location())
|
|
|
|
|
// 结束时间使用开始时间加上 count*7 天
|
|
|
|
|
end = start.AddDate(0, 0, count*7)
|
|
|
|
|
case RelativeDateDirectionAfter:
|
|
|
|
|
// 开始时间使用本周的结束时间
|
|
|
|
|
start = time.Date(now.Year(), now.Month(), now.Day()-weekday+7, 23, 59, 59, 999999999, now.Location())
|
|
|
|
|
// 结束时间使用开始时间加上 count*7 天
|
|
|
|
|
end = start.AddDate(0, 0, count*7)
|
|
|
|
|
}
|
|
|
|
|
case RelativeDateUnitMonth:
|
|
|
|
|
switch direction {
|
|
|
|
|
case RelativeDateDirectionBefore:
|
|
|
|
|
// 结束时间使用本月的开始时间
|
|
|
|
|
end = time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
|
|
|
|
|
// 开始时间使用结束时间减去 count 个月
|
|
|
|
|
start = end.AddDate(0, -count, 0)
|
|
|
|
|
case RelativeDateDirectionThis:
|
|
|
|
|
// 开始时间使用本月的开始时间
|
|
|
|
|
start = time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
|
|
|
|
|
// 结束时间使用开始时间加上 count 个月
|
|
|
|
|
end = start.AddDate(0, count, 0)
|
|
|
|
|
case RelativeDateDirectionAfter:
|
|
|
|
|
// 开始时间使用本月的结束时间
|
|
|
|
|
start = time.Date(now.Year(), now.Month()+1, 1, 0, 0, 0, 0, now.Location()).Add(-time.Nanosecond)
|
|
|
|
|
// 结束时间使用开始时间加上 count 个月
|
|
|
|
|
end = start.AddDate(0, count, 0)
|
|
|
|
|
}
|
|
|
|
|
case RelativeDateUnitYear:
|
|
|
|
|
switch direction {
|
|
|
|
|
case RelativeDateDirectionBefore:
|
|
|
|
|
// 结束时间使用今年的开始时间
|
|
|
|
|
end = time.Date(now.Year(), 1, 1, 0, 0, 0, 0, now.Location())
|
|
|
|
|
// 开始时间使用结束时间减去 count 年
|
|
|
|
|
start = end.AddDate(-count, 0, 0)
|
|
|
|
|
case RelativeDateDirectionThis:
|
|
|
|
|
// 开始时间使用今年的开始时间
|
|
|
|
|
start = time.Date(now.Year(), 1, 1, 0, 0, 0, 0, now.Location())
|
|
|
|
|
// 结束时间使用开始时间加上 count 年
|
|
|
|
|
end = start.AddDate(count, 0, 0)
|
|
|
|
|
case RelativeDateDirectionAfter:
|
|
|
|
|
// 开始时间使用今年的结束时间
|
|
|
|
|
start = time.Date(now.Year()+1, 1, 1, 0, 0, 0, 0, now.Location()).Add(-time.Nanosecond)
|
|
|
|
|
// 结束时间使用开始时间加上 count 年
|
|
|
|
|
end = start.AddDate(count, 0, 0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 10:35:17 +08:00
|
|
|
|
// Table 描述了表格实例的结构。
|
|
|
|
|
type Table struct {
|
2024-03-01 22:40:56 +08:00
|
|
|
|
ID string `json:"id"` // 表格布局 ID
|
|
|
|
|
Icon string `json:"icon"` // 表格图标
|
|
|
|
|
Name string `json:"name"` // 表格名称
|
|
|
|
|
HideAttrViewName bool `json:"hideAttrViewName"` // 是否隐藏属性视图名称
|
|
|
|
|
Filters []*ViewFilter `json:"filters"` // 过滤规则
|
|
|
|
|
Sorts []*ViewSort `json:"sorts"` // 排序规则
|
|
|
|
|
Columns []*TableColumn `json:"columns"` // 表格列
|
|
|
|
|
Rows []*TableRow `json:"rows"` // 表格行
|
|
|
|
|
RowCount int `json:"rowCount"` // 表格总行数
|
|
|
|
|
PageSize int `json:"pageSize"` // 每页行数
|
2023-07-12 10:35:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 19:10:05 +08:00
|
|
|
|
type TableColumn struct {
|
|
|
|
|
ID string `json:"id"` // 列 ID
|
|
|
|
|
Name string `json:"name"` // 列名
|
|
|
|
|
Type KeyType `json:"type"` // 列类型
|
|
|
|
|
Icon string `json:"icon"` // 列图标
|
|
|
|
|
Wrap bool `json:"wrap"` // 是否换行
|
|
|
|
|
Hidden bool `json:"hidden"` // 是否隐藏
|
2023-11-10 10:22:19 +08:00
|
|
|
|
Pin bool `json:"pin"` // 是否固定
|
2023-07-12 19:10:05 +08:00
|
|
|
|
Width string `json:"width"` // 列宽度
|
|
|
|
|
Calc *ColumnCalc `json:"calc"` // 计算
|
2023-07-13 10:34:51 +08:00
|
|
|
|
|
|
|
|
|
// 以下是某些列类型的特有属性
|
|
|
|
|
|
2023-12-23 17:57:45 +08:00
|
|
|
|
Options []*SelectOption `json:"options,omitempty"` // 选项列表
|
|
|
|
|
NumberFormat NumberFormat `json:"numberFormat"` // 列数字格式化
|
|
|
|
|
Template string `json:"template"` // 模板内容
|
|
|
|
|
Relation *Relation `json:"relation,omitempty"` // 关联列
|
|
|
|
|
Rollup *Rollup `json:"rollup,omitempty"` // 汇总列
|
2023-07-12 19:10:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-13 10:44:29 +08:00
|
|
|
|
type TableCell struct {
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
Value *Value `json:"value"`
|
|
|
|
|
ValueType KeyType `json:"valueType"`
|
|
|
|
|
Color string `json:"color"`
|
|
|
|
|
BgColor string `json:"bgColor"`
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 19:10:05 +08:00
|
|
|
|
type TableRow struct {
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
Cells []*TableCell `json:"cells"`
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 10:48:29 +08:00
|
|
|
|
func (row *TableRow) GetBlockValue() (ret *Value) {
|
|
|
|
|
for _, cell := range row.Cells {
|
|
|
|
|
if KeyTypeBlock == cell.ValueType {
|
|
|
|
|
ret = cell.Value
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-06 11:20:20 +08:00
|
|
|
|
func (row *TableRow) GetValue(keyID string) (ret *Value) {
|
|
|
|
|
for _, cell := range row.Cells {
|
|
|
|
|
if nil != cell.Value && keyID == cell.Value.KeyID {
|
|
|
|
|
ret = cell.Value
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 10:35:17 +08:00
|
|
|
|
func (table *Table) GetType() LayoutType {
|
|
|
|
|
return LayoutTypeTable
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-11 21:31:19 +08:00
|
|
|
|
func (table *Table) GetID() string {
|
|
|
|
|
return table.ID
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-11 19:45:27 +08:00
|
|
|
|
func (table *Table) SortRows() {
|
|
|
|
|
if 1 > len(table.Sorts) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ColIndexSort struct {
|
|
|
|
|
Index int
|
|
|
|
|
Order SortOrder
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var colIndexSorts []*ColIndexSort
|
|
|
|
|
for _, s := range table.Sorts {
|
|
|
|
|
for i, c := range table.Columns {
|
|
|
|
|
if c.ID == s.Column {
|
|
|
|
|
colIndexSorts = append(colIndexSorts, &ColIndexSort{Index: i, Order: s.Order})
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-03 22:00:42 +08:00
|
|
|
|
includeUneditedRows := map[string]bool{}
|
|
|
|
|
for i, row := range table.Rows {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
for _, colIndexSort := range colIndexSorts {
|
2024-03-03 22:00:42 +08:00
|
|
|
|
val := table.Rows[i].Cells[colIndexSort.Index].Value
|
|
|
|
|
if !val.IsEdited() {
|
|
|
|
|
// 如果该行的某个列的值是未编辑的,则该行不参与排序
|
|
|
|
|
includeUneditedRows[row.ID] = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将包含未编辑的行和全部已编辑的行分开排序
|
|
|
|
|
var uneditedRows, editedRows []*TableRow
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if _, ok := includeUneditedRows[row.ID]; ok {
|
|
|
|
|
uneditedRows = append(uneditedRows, row)
|
|
|
|
|
} else {
|
|
|
|
|
editedRows = append(editedRows, row)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sort.Slice(uneditedRows, func(i, j int) bool {
|
|
|
|
|
val1 := uneditedRows[i].GetBlockValue()
|
|
|
|
|
if nil == val1 {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
val2 := uneditedRows[j].GetBlockValue()
|
|
|
|
|
if nil == val2 {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return val1.CreatedAt < val2.CreatedAt
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
sort.Slice(editedRows, func(i, j int) bool {
|
|
|
|
|
for _, colIndexSort := range colIndexSorts {
|
|
|
|
|
val1 := editedRows[i].Cells[colIndexSort.Index].Value
|
|
|
|
|
if nil == val1 {
|
|
|
|
|
return colIndexSort.Order == SortOrderAsc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val2 := editedRows[j].Cells[colIndexSort.Index].Value
|
|
|
|
|
if nil == val2 {
|
|
|
|
|
return colIndexSort.Order != SortOrderAsc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result := val1.Compare(val2)
|
2023-07-11 19:45:27 +08:00
|
|
|
|
if 0 == result {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if colIndexSort.Order == SortOrderAsc {
|
|
|
|
|
return 0 > result
|
|
|
|
|
}
|
|
|
|
|
return 0 < result
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
})
|
2024-03-03 22:00:42 +08:00
|
|
|
|
|
|
|
|
|
// 将包含未编辑的行放在最后
|
|
|
|
|
table.Rows = append(editedRows, uneditedRows...)
|
2024-03-04 13:54:17 +08:00
|
|
|
|
if 1 > len(table.Rows) {
|
|
|
|
|
table.Rows = []*TableRow{}
|
|
|
|
|
}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-30 23:01:21 +08:00
|
|
|
|
func (table *Table) FilterRows(attrView *AttributeView) {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
if 1 > len(table.Filters) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var colIndexes []int
|
|
|
|
|
for _, f := range table.Filters {
|
|
|
|
|
for i, c := range table.Columns {
|
|
|
|
|
if c.ID == f.Column {
|
|
|
|
|
colIndexes = append(colIndexes, i)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-11 23:40:05 +08:00
|
|
|
|
rows := []*TableRow{}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
pass := true
|
|
|
|
|
for j, index := range colIndexes {
|
2023-10-11 08:50:13 +08:00
|
|
|
|
operator := table.Filters[j].Operator
|
|
|
|
|
|
|
|
|
|
if nil == row.Cells[index].Value {
|
2023-10-20 23:37:55 +08:00
|
|
|
|
if FilterOperatorIsNotEmpty == operator {
|
2023-10-11 08:50:13 +08:00
|
|
|
|
pass = false
|
2023-10-20 23:37:55 +08:00
|
|
|
|
} else if FilterOperatorIsEmpty == operator {
|
|
|
|
|
pass = true
|
|
|
|
|
break
|
2023-10-11 08:50:13 +08:00
|
|
|
|
}
|
2023-10-11 10:04:39 +08:00
|
|
|
|
|
|
|
|
|
if KeyTypeText != row.Cells[index].ValueType {
|
|
|
|
|
pass = false
|
|
|
|
|
}
|
2023-10-11 08:50:13 +08:00
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-06 22:47:21 +08:00
|
|
|
|
if !row.Cells[index].Value.Filter(table.Filters[j], attrView, row.ID) {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
pass = false
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if pass {
|
|
|
|
|
rows = append(rows, row)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
table.Rows = rows
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (table *Table) CalcCols() {
|
|
|
|
|
for i, col := range table.Columns {
|
|
|
|
|
if nil == col.Calc {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if CalcOperatorNone == col.Calc.Operator {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch col.Type {
|
2023-07-16 00:28:17 +08:00
|
|
|
|
case KeyTypeBlock:
|
|
|
|
|
table.calcColBlock(col, i)
|
|
|
|
|
case KeyTypeText:
|
2023-07-11 19:45:27 +08:00
|
|
|
|
table.calcColText(col, i)
|
2023-07-12 19:10:05 +08:00
|
|
|
|
case KeyTypeNumber:
|
2023-07-11 19:45:27 +08:00
|
|
|
|
table.calcColNumber(col, i)
|
2023-07-12 19:10:05 +08:00
|
|
|
|
case KeyTypeDate:
|
2023-07-11 19:45:27 +08:00
|
|
|
|
table.calcColDate(col, i)
|
2023-07-12 19:10:05 +08:00
|
|
|
|
case KeyTypeSelect:
|
2023-07-11 19:45:27 +08:00
|
|
|
|
table.calcColSelect(col, i)
|
2023-07-12 19:10:05 +08:00
|
|
|
|
case KeyTypeMSelect:
|
2023-07-11 19:45:27 +08:00
|
|
|
|
table.calcColMSelect(col, i)
|
2023-07-30 20:53:40 +08:00
|
|
|
|
case KeyTypeURL:
|
|
|
|
|
table.calcColURL(col, i)
|
2023-08-03 12:21:11 +08:00
|
|
|
|
case KeyTypeEmail:
|
|
|
|
|
table.calcColEmail(col, i)
|
|
|
|
|
case KeyTypePhone:
|
|
|
|
|
table.calcColPhone(col, i)
|
2023-09-21 16:58:24 +08:00
|
|
|
|
case KeyTypeMAsset:
|
|
|
|
|
table.calcColMAsset(col, i)
|
2023-10-01 10:42:12 +08:00
|
|
|
|
case KeyTypeTemplate:
|
|
|
|
|
table.calcColTemplate(col, i)
|
2023-10-08 12:16:58 +08:00
|
|
|
|
case KeyTypeCreated:
|
|
|
|
|
table.calcColCreated(col, i)
|
|
|
|
|
case KeyTypeUpdated:
|
|
|
|
|
table.calcColUpdated(col, i)
|
2023-11-17 09:03:17 +08:00
|
|
|
|
case KeyTypeCheckbox:
|
|
|
|
|
table.calcColCheckbox(col, i)
|
2023-12-15 20:05:14 +08:00
|
|
|
|
case KeyTypeRelation:
|
|
|
|
|
table.calcColRelation(col, i)
|
|
|
|
|
case KeyTypeRollup:
|
|
|
|
|
table.calcColRollup(col, i)
|
2023-10-01 10:42:12 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (table *Table) calcColTemplate(col *TableColumn, colIndex int) {
|
|
|
|
|
switch col.Calc.Operator {
|
|
|
|
|
case CalcOperatorCountAll:
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(len(table.Rows)), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountValues:
|
|
|
|
|
countValues := 0
|
|
|
|
|
for _, row := range table.Rows {
|
2023-10-01 18:14:31 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.Content {
|
2023-10-01 10:42:12 +08:00
|
|
|
|
countValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countValues), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountUniqueValues:
|
|
|
|
|
countUniqueValues := 0
|
|
|
|
|
uniqueValues := map[string]bool{}
|
|
|
|
|
for _, row := range table.Rows {
|
2023-10-01 18:14:31 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.Content {
|
|
|
|
|
if !uniqueValues[row.Cells[colIndex].Value.Template.Content] {
|
|
|
|
|
uniqueValues[row.Cells[colIndex].Value.Template.Content] = true
|
2023-10-01 10:42:12 +08:00
|
|
|
|
countUniqueValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUniqueValues), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
2023-10-01 18:14:31 +08:00
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Template || "" == row.Cells[colIndex].Value.Template.Content {
|
2023-10-01 10:42:12 +08:00
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
2023-10-01 18:14:31 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.Content {
|
2023-10-01 10:42:12 +08:00
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorPercentEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
2023-10-01 18:14:31 +08:00
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Template || "" == row.Cells[colIndex].Value.Template.Content {
|
2023-10-01 10:42:12 +08:00
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorPercentNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
2023-10-01 18:14:31 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.Content {
|
2023-10-01 10:42:12 +08:00
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
2023-09-21 16:58:24 +08:00
|
|
|
|
}
|
2023-10-12 12:01:53 +08:00
|
|
|
|
case CalcOperatorSum:
|
|
|
|
|
sum := 0.0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.Content {
|
|
|
|
|
val, _ := strconv.ParseFloat(row.Cells[colIndex].Value.Template.Content, 64)
|
|
|
|
|
sum += val
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(sum, col.NumberFormat)}
|
|
|
|
|
case CalcOperatorAverage:
|
|
|
|
|
sum := 0.0
|
|
|
|
|
count := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.Content {
|
|
|
|
|
val, _ := strconv.ParseFloat(row.Cells[colIndex].Value.Template.Content, 64)
|
|
|
|
|
sum += val
|
|
|
|
|
count++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 != count {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(sum/float64(count), col.NumberFormat)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorMedian:
|
|
|
|
|
values := []float64{}
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.Content {
|
|
|
|
|
val, _ := strconv.ParseFloat(row.Cells[colIndex].Value.Template.Content, 64)
|
|
|
|
|
values = append(values, val)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sort.Float64s(values)
|
|
|
|
|
if len(values) > 0 {
|
|
|
|
|
if len(values)%2 == 0 {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber((values[len(values)/2-1]+values[len(values)/2])/2, col.NumberFormat)}
|
|
|
|
|
} else {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(values[len(values)/2], col.NumberFormat)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorMin:
|
|
|
|
|
minVal := math.MaxFloat64
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.Content {
|
|
|
|
|
val, _ := strconv.ParseFloat(row.Cells[colIndex].Value.Template.Content, 64)
|
|
|
|
|
if val < minVal {
|
|
|
|
|
minVal = val
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if math.MaxFloat64 != minVal {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(minVal, col.NumberFormat)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorMax:
|
|
|
|
|
maxVal := -math.MaxFloat64
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.Content {
|
|
|
|
|
val, _ := strconv.ParseFloat(row.Cells[colIndex].Value.Template.Content, 64)
|
|
|
|
|
if val > maxVal {
|
|
|
|
|
maxVal = val
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if -math.MaxFloat64 != maxVal {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(maxVal, col.NumberFormat)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorRange:
|
|
|
|
|
minVal := math.MaxFloat64
|
|
|
|
|
maxVal := -math.MaxFloat64
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.Content {
|
|
|
|
|
val, _ := strconv.ParseFloat(row.Cells[colIndex].Value.Template.Content, 64)
|
|
|
|
|
if val < minVal {
|
|
|
|
|
minVal = val
|
|
|
|
|
}
|
|
|
|
|
if val > maxVal {
|
|
|
|
|
maxVal = val
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if math.MaxFloat64 != minVal && -math.MaxFloat64 != maxVal {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(maxVal-minVal, col.NumberFormat)}
|
|
|
|
|
}
|
2023-09-21 16:58:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (table *Table) calcColMAsset(col *TableColumn, colIndex int) {
|
|
|
|
|
switch col.Calc.Operator {
|
|
|
|
|
case CalcOperatorCountAll:
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(len(table.Rows)), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountValues:
|
|
|
|
|
countValues := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.MAsset && 0 < len(row.Cells[colIndex].Value.MAsset) {
|
|
|
|
|
countValues += len(row.Cells[colIndex].Value.MAsset)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countValues), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountUniqueValues:
|
|
|
|
|
countUniqueValues := 0
|
|
|
|
|
uniqueValues := map[string]bool{}
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.MAsset && 0 < len(row.Cells[colIndex].Value.MAsset) {
|
|
|
|
|
for _, sel := range row.Cells[colIndex].Value.MAsset {
|
|
|
|
|
if _, ok := uniqueValues[sel.Content]; !ok {
|
|
|
|
|
uniqueValues[sel.Content] = true
|
|
|
|
|
countUniqueValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUniqueValues), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.MAsset || 0 == len(row.Cells[colIndex].Value.MAsset) {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.MAsset && 0 < len(row.Cells[colIndex].Value.MAsset) {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorPercentEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.MAsset || 0 == len(row.Cells[colIndex].Value.MAsset) {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorPercentNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.MAsset && 0 < len(row.Cells[colIndex].Value.MAsset) {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-11 23:40:05 +08:00
|
|
|
|
func (table *Table) calcColMSelect(col *TableColumn, colIndex int) {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
switch col.Calc.Operator {
|
|
|
|
|
case CalcOperatorCountAll:
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(len(table.Rows)), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountValues:
|
|
|
|
|
countValues := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) {
|
|
|
|
|
countValues += len(row.Cells[colIndex].Value.MSelect)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countValues), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountUniqueValues:
|
|
|
|
|
countUniqueValues := 0
|
|
|
|
|
uniqueValues := map[string]bool{}
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) {
|
|
|
|
|
for _, sel := range row.Cells[colIndex].Value.MSelect {
|
|
|
|
|
if _, ok := uniqueValues[sel.Content]; !ok {
|
|
|
|
|
uniqueValues[sel.Content] = true
|
|
|
|
|
countUniqueValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUniqueValues), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.MSelect || 0 == len(row.Cells[colIndex].Value.MSelect) {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorPercentEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.MSelect || 0 == len(row.Cells[colIndex].Value.MSelect) {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
if 0 < len(table.Rows) {
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorPercentNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
if 0 < len(table.Rows) {
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-11 23:40:05 +08:00
|
|
|
|
func (table *Table) calcColSelect(col *TableColumn, colIndex int) {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
switch col.Calc.Operator {
|
|
|
|
|
case CalcOperatorCountAll:
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(len(table.Rows)), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountValues:
|
|
|
|
|
countValues := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) && nil != row.Cells[colIndex].Value.MSelect[0] && "" != row.Cells[colIndex].Value.MSelect[0].Content {
|
|
|
|
|
countValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countValues), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountUniqueValues:
|
|
|
|
|
countUniqueValues := 0
|
|
|
|
|
uniqueValues := map[string]bool{}
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) && nil != row.Cells[colIndex].Value.MSelect[0] && "" != row.Cells[colIndex].Value.MSelect[0].Content {
|
2023-10-09 21:09:35 +08:00
|
|
|
|
if _, ok := uniqueValues[row.Cells[colIndex].Value.MSelect[0].Content]; !ok {
|
|
|
|
|
uniqueValues[row.Cells[colIndex].Value.MSelect[0].Content] = true
|
|
|
|
|
countUniqueValues++
|
|
|
|
|
}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUniqueValues), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.MSelect || 1 > len(row.Cells[colIndex].Value.MSelect) || nil == row.Cells[colIndex].Value.MSelect[0] || "" == row.Cells[colIndex].Value.MSelect[0].Content {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) && nil != row.Cells[colIndex].Value.MSelect[0] && "" != row.Cells[colIndex].Value.MSelect[0].Content {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorPercentEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.MSelect || 1 > len(row.Cells[colIndex].Value.MSelect) || nil == row.Cells[colIndex].Value.MSelect[0] || "" == row.Cells[colIndex].Value.MSelect[0].Content {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
if 0 < len(table.Rows) {
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorPercentNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) && nil != row.Cells[colIndex].Value.MSelect[0] && "" != row.Cells[colIndex].Value.MSelect[0].Content {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
if 0 < len(table.Rows) {
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-11 23:40:05 +08:00
|
|
|
|
func (table *Table) calcColDate(col *TableColumn, colIndex int) {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
switch col.Calc.Operator {
|
|
|
|
|
case CalcOperatorCountAll:
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(len(table.Rows)), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountValues:
|
|
|
|
|
countValues := 0
|
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Date && row.Cells[colIndex].Value.Date.IsNotEmpty {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
countValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countValues), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountUniqueValues:
|
|
|
|
|
countUniqueValues := 0
|
|
|
|
|
uniqueValues := map[int64]bool{}
|
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Date && row.Cells[colIndex].Value.Date.IsNotEmpty {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
if _, ok := uniqueValues[row.Cells[colIndex].Value.Date.Content]; !ok {
|
|
|
|
|
countUniqueValues++
|
|
|
|
|
uniqueValues[row.Cells[colIndex].Value.Date.Content] = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUniqueValues), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Date || !row.Cells[colIndex].Value.Date.IsNotEmpty {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Date && row.Cells[colIndex].Value.Date.IsNotEmpty {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorPercentEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Date || !row.Cells[colIndex].Value.Date.IsNotEmpty {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
if 0 < len(table.Rows) {
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorPercentNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Date && row.Cells[colIndex].Value.Date.IsNotEmpty {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
if 0 < len(table.Rows) {
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorEarliest:
|
|
|
|
|
earliest := int64(0)
|
2024-02-23 17:53:43 +08:00
|
|
|
|
var isNotTime, hasEndDate bool
|
2023-07-11 19:45:27 +08:00
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Date && row.Cells[colIndex].Value.Date.IsNotEmpty {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
if 0 == earliest || earliest > row.Cells[colIndex].Value.Date.Content {
|
|
|
|
|
earliest = row.Cells[colIndex].Value.Date.Content
|
2023-10-27 21:16:54 +08:00
|
|
|
|
isNotTime = row.Cells[colIndex].Value.Date.IsNotTime
|
2024-02-23 17:53:43 +08:00
|
|
|
|
hasEndDate = row.Cells[colIndex].Value.Date.HasEndDate
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 != earliest {
|
2024-02-23 17:53:43 +08:00
|
|
|
|
col.Calc.Result = &Value{Date: NewFormattedValueDate(earliest, 0, DateFormatNone, isNotTime, hasEndDate)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
case CalcOperatorLatest:
|
|
|
|
|
latest := int64(0)
|
2024-02-23 17:53:43 +08:00
|
|
|
|
var isNotTime, hasEndDate bool
|
2023-07-11 19:45:27 +08:00
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Date && row.Cells[colIndex].Value.Date.IsNotEmpty {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
if 0 == latest || latest < row.Cells[colIndex].Value.Date.Content {
|
|
|
|
|
latest = row.Cells[colIndex].Value.Date.Content
|
2023-10-27 21:16:54 +08:00
|
|
|
|
isNotTime = row.Cells[colIndex].Value.Date.IsNotTime
|
2024-02-23 17:53:43 +08:00
|
|
|
|
hasEndDate = row.Cells[colIndex].Value.Date.HasEndDate
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 != latest {
|
2024-02-23 17:53:43 +08:00
|
|
|
|
col.Calc.Result = &Value{Date: NewFormattedValueDate(latest, 0, DateFormatNone, isNotTime, hasEndDate)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
case CalcOperatorRange:
|
|
|
|
|
earliest := int64(0)
|
|
|
|
|
latest := int64(0)
|
2024-02-23 17:53:43 +08:00
|
|
|
|
var isNotTime, hasEndDate bool
|
2023-07-11 19:45:27 +08:00
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Date && row.Cells[colIndex].Value.Date.IsNotEmpty {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
if 0 == earliest || earliest > row.Cells[colIndex].Value.Date.Content {
|
|
|
|
|
earliest = row.Cells[colIndex].Value.Date.Content
|
2023-10-27 21:16:54 +08:00
|
|
|
|
isNotTime = row.Cells[colIndex].Value.Date.IsNotTime
|
2024-02-23 17:53:43 +08:00
|
|
|
|
hasEndDate = row.Cells[colIndex].Value.Date.HasEndDate
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
if 0 == latest || latest < row.Cells[colIndex].Value.Date.Content {
|
|
|
|
|
latest = row.Cells[colIndex].Value.Date.Content
|
2023-10-27 21:16:54 +08:00
|
|
|
|
isNotTime = row.Cells[colIndex].Value.Date.IsNotTime
|
2024-02-23 17:53:43 +08:00
|
|
|
|
hasEndDate = row.Cells[colIndex].Value.Date.HasEndDate
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 != earliest && 0 != latest {
|
2024-02-23 17:53:43 +08:00
|
|
|
|
col.Calc.Result = &Value{Date: NewFormattedValueDate(earliest, latest, DateFormatDuration, isNotTime, hasEndDate)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-11 23:40:05 +08:00
|
|
|
|
func (table *Table) calcColNumber(col *TableColumn, colIndex int) {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
switch col.Calc.Operator {
|
|
|
|
|
case CalcOperatorCountAll:
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(len(table.Rows)), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountValues:
|
|
|
|
|
countValues := 0
|
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
countValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countValues), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountUniqueValues:
|
|
|
|
|
countUniqueValues := 0
|
|
|
|
|
uniqueValues := map[float64]bool{}
|
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
if !uniqueValues[row.Cells[colIndex].Value.Number.Content] {
|
|
|
|
|
uniqueValues[row.Cells[colIndex].Value.Number.Content] = true
|
|
|
|
|
countUniqueValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUniqueValues), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Number || !row.Cells[colIndex].Value.Number.IsNotEmpty {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorPercentEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Number || !row.Cells[colIndex].Value.Number.IsNotEmpty {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
if 0 < len(table.Rows) {
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorPercentNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
if 0 < len(table.Rows) {
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorSum:
|
|
|
|
|
sum := 0.0
|
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
sum += row.Cells[colIndex].Value.Number.Content
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-04 00:07:12 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(sum, col.NumberFormat)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorAverage:
|
|
|
|
|
sum := 0.0
|
|
|
|
|
count := 0
|
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
sum += row.Cells[colIndex].Value.Number.Content
|
|
|
|
|
count++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-15 23:30:28 +08:00
|
|
|
|
if 0 != count {
|
2023-08-04 00:07:12 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(sum/float64(count), col.NumberFormat)}
|
2023-07-15 23:30:28 +08:00
|
|
|
|
}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorMedian:
|
|
|
|
|
values := []float64{}
|
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
values = append(values, row.Cells[colIndex].Value.Number.Content)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sort.Float64s(values)
|
|
|
|
|
if len(values) > 0 {
|
|
|
|
|
if len(values)%2 == 0 {
|
2023-08-04 00:07:12 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber((values[len(values)/2-1]+values[len(values)/2])/2, col.NumberFormat)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
} else {
|
2023-08-04 00:07:12 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(values[len(values)/2], col.NumberFormat)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorMin:
|
2023-10-01 18:14:31 +08:00
|
|
|
|
minVal := math.MaxFloat64
|
2023-07-11 19:45:27 +08:00
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
|
2023-10-01 18:14:31 +08:00
|
|
|
|
if row.Cells[colIndex].Value.Number.Content < minVal {
|
|
|
|
|
minVal = row.Cells[colIndex].Value.Number.Content
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-01 18:14:31 +08:00
|
|
|
|
if math.MaxFloat64 != minVal {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(minVal, col.NumberFormat)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
case CalcOperatorMax:
|
2023-09-21 16:58:24 +08:00
|
|
|
|
maxVal := -math.MaxFloat64
|
2023-07-11 19:45:27 +08:00
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
|
2023-09-21 16:58:24 +08:00
|
|
|
|
if row.Cells[colIndex].Value.Number.Content > maxVal {
|
|
|
|
|
maxVal = row.Cells[colIndex].Value.Number.Content
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-21 16:58:24 +08:00
|
|
|
|
if -math.MaxFloat64 != maxVal {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(maxVal, col.NumberFormat)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
case CalcOperatorRange:
|
2023-09-21 16:58:24 +08:00
|
|
|
|
minVal := math.MaxFloat64
|
|
|
|
|
maxVal := -math.MaxFloat64
|
2023-07-11 19:45:27 +08:00
|
|
|
|
for _, row := range table.Rows {
|
2023-08-01 21:00:57 +08:00
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
|
2023-09-21 16:58:24 +08:00
|
|
|
|
if row.Cells[colIndex].Value.Number.Content < minVal {
|
|
|
|
|
minVal = row.Cells[colIndex].Value.Number.Content
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
2023-09-21 16:58:24 +08:00
|
|
|
|
if row.Cells[colIndex].Value.Number.Content > maxVal {
|
|
|
|
|
maxVal = row.Cells[colIndex].Value.Number.Content
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-21 16:58:24 +08:00
|
|
|
|
if math.MaxFloat64 != minVal && -math.MaxFloat64 != maxVal {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(maxVal-minVal, col.NumberFormat)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-11 23:40:05 +08:00
|
|
|
|
func (table *Table) calcColText(col *TableColumn, colIndex int) {
|
2023-07-11 19:45:27 +08:00
|
|
|
|
switch col.Calc.Operator {
|
|
|
|
|
case CalcOperatorCountAll:
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(len(table.Rows)), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountValues:
|
|
|
|
|
countValues := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Text && "" != row.Cells[colIndex].Value.Text.Content {
|
|
|
|
|
countValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countValues), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountUniqueValues:
|
|
|
|
|
countUniqueValues := 0
|
|
|
|
|
uniqueValues := map[string]bool{}
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Text && "" != row.Cells[colIndex].Value.Text.Content {
|
|
|
|
|
if !uniqueValues[row.Cells[colIndex].Value.Text.Content] {
|
|
|
|
|
uniqueValues[row.Cells[colIndex].Value.Text.Content] = true
|
|
|
|
|
countUniqueValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUniqueValues), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Text || "" == row.Cells[colIndex].Value.Text.Content {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorCountNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Text && "" != row.Cells[colIndex].Value.Text.Content {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty), NumberFormatNone)}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorPercentEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Text || "" == row.Cells[colIndex].Value.Text.Content {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
if 0 < len(table.Rows) {
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
case CalcOperatorPercentNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Text && "" != row.Cells[colIndex].Value.Text.Content {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
if 0 < len(table.Rows) {
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
2023-07-16 00:08:01 +08:00
|
|
|
|
}
|
2023-07-11 19:45:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 00:22:14 +08:00
|
|
|
|
|
2023-07-30 20:53:40 +08:00
|
|
|
|
func (table *Table) calcColURL(col *TableColumn, colIndex int) {
|
|
|
|
|
switch col.Calc.Operator {
|
|
|
|
|
case CalcOperatorCountAll:
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(len(table.Rows)), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountValues:
|
|
|
|
|
countValues := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.URL && "" != row.Cells[colIndex].Value.URL.Content {
|
|
|
|
|
countValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countValues), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountUniqueValues:
|
|
|
|
|
countUniqueValues := 0
|
|
|
|
|
uniqueValues := map[string]bool{}
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.URL && "" != row.Cells[colIndex].Value.URL.Content {
|
|
|
|
|
if !uniqueValues[row.Cells[colIndex].Value.URL.Content] {
|
|
|
|
|
uniqueValues[row.Cells[colIndex].Value.URL.Content] = true
|
|
|
|
|
countUniqueValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUniqueValues), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.URL || "" == row.Cells[colIndex].Value.URL.Content {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.URL && "" != row.Cells[colIndex].Value.URL.Content {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorPercentEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.URL || "" == row.Cells[colIndex].Value.URL.Content {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorPercentNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.URL && "" != row.Cells[colIndex].Value.URL.Content {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 12:21:11 +08:00
|
|
|
|
func (table *Table) calcColEmail(col *TableColumn, colIndex int) {
|
|
|
|
|
switch col.Calc.Operator {
|
|
|
|
|
case CalcOperatorCountAll:
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(len(table.Rows)), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountValues:
|
|
|
|
|
countValues := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Email && "" != row.Cells[colIndex].Value.Email.Content {
|
|
|
|
|
countValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countValues), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountUniqueValues:
|
|
|
|
|
countUniqueValues := 0
|
|
|
|
|
uniqueValues := map[string]bool{}
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Email && "" != row.Cells[colIndex].Value.Email.Content {
|
|
|
|
|
if !uniqueValues[row.Cells[colIndex].Value.Email.Content] {
|
|
|
|
|
uniqueValues[row.Cells[colIndex].Value.Email.Content] = true
|
|
|
|
|
countUniqueValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUniqueValues), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Email || "" == row.Cells[colIndex].Value.Email.Content {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Email && "" != row.Cells[colIndex].Value.Email.Content {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorPercentEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Email || "" == row.Cells[colIndex].Value.Email.Content {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorPercentNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Email && "" != row.Cells[colIndex].Value.Email.Content {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (table *Table) calcColPhone(col *TableColumn, colIndex int) {
|
|
|
|
|
switch col.Calc.Operator {
|
|
|
|
|
case CalcOperatorCountAll:
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(len(table.Rows)), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountValues:
|
|
|
|
|
countValues := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Phone && "" != row.Cells[colIndex].Value.Phone.Content {
|
|
|
|
|
countValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countValues), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountUniqueValues:
|
|
|
|
|
countUniqueValues := 0
|
|
|
|
|
uniqueValues := map[string]bool{}
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Phone && "" != row.Cells[colIndex].Value.Phone.Content {
|
|
|
|
|
if !uniqueValues[row.Cells[colIndex].Value.Phone.Content] {
|
|
|
|
|
uniqueValues[row.Cells[colIndex].Value.Phone.Content] = true
|
|
|
|
|
countUniqueValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUniqueValues), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Phone || "" == row.Cells[colIndex].Value.Phone.Content {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Phone && "" != row.Cells[colIndex].Value.Phone.Content {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorPercentEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Phone || "" == row.Cells[colIndex].Value.Phone.Content {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorPercentNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Phone && "" != row.Cells[colIndex].Value.Phone.Content {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-16 00:28:17 +08:00
|
|
|
|
func (table *Table) calcColBlock(col *TableColumn, colIndex int) {
|
|
|
|
|
switch col.Calc.Operator {
|
|
|
|
|
case CalcOperatorCountAll:
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(len(table.Rows)), NumberFormatNone)}
|
2023-07-16 00:28:17 +08:00
|
|
|
|
case CalcOperatorCountValues:
|
|
|
|
|
countValues := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Block && "" != row.Cells[colIndex].Value.Block.Content {
|
|
|
|
|
countValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countValues), NumberFormatNone)}
|
2023-07-16 00:28:17 +08:00
|
|
|
|
case CalcOperatorCountUniqueValues:
|
|
|
|
|
countUniqueValues := 0
|
|
|
|
|
uniqueValues := map[string]bool{}
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Block && "" != row.Cells[colIndex].Value.Block.Content {
|
|
|
|
|
if !uniqueValues[row.Cells[colIndex].Value.Block.Content] {
|
|
|
|
|
uniqueValues[row.Cells[colIndex].Value.Block.Content] = true
|
|
|
|
|
countUniqueValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUniqueValues), NumberFormatNone)}
|
2023-07-16 00:28:17 +08:00
|
|
|
|
case CalcOperatorCountEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Block || "" == row.Cells[colIndex].Value.Block.Content {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty), NumberFormatNone)}
|
2023-07-16 00:28:17 +08:00
|
|
|
|
case CalcOperatorCountNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Block && "" != row.Cells[colIndex].Value.Block.Content {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty), NumberFormatNone)}
|
2023-07-16 00:28:17 +08:00
|
|
|
|
case CalcOperatorPercentEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Block || "" == row.Cells[colIndex].Value.Block.Content {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
2023-07-16 00:28:17 +08:00
|
|
|
|
}
|
|
|
|
|
case CalcOperatorPercentNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Block && "" != row.Cells[colIndex].Value.Block.Content {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
2023-07-16 22:03:39 +08:00
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
2023-07-16 00:28:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-08 12:16:58 +08:00
|
|
|
|
|
|
|
|
|
func (table *Table) calcColCreated(col *TableColumn, colIndex int) {
|
|
|
|
|
switch col.Calc.Operator {
|
|
|
|
|
case CalcOperatorCountAll:
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(len(table.Rows)), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountValues:
|
|
|
|
|
countValues := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Created {
|
|
|
|
|
countValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countValues), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountUniqueValues:
|
|
|
|
|
countUniqueValues := 0
|
|
|
|
|
uniqueValues := map[int64]bool{}
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Created {
|
|
|
|
|
if _, ok := uniqueValues[row.Cells[colIndex].Value.Created.Content]; !ok {
|
|
|
|
|
countUniqueValues++
|
|
|
|
|
uniqueValues[row.Cells[colIndex].Value.Created.Content] = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUniqueValues), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Created {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Created {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorPercentEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Created {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorPercentNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Created {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorEarliest:
|
|
|
|
|
earliest := int64(0)
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Created {
|
|
|
|
|
if 0 == earliest || earliest > row.Cells[colIndex].Value.Created.Content {
|
|
|
|
|
earliest = row.Cells[colIndex].Value.Created.Content
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 != earliest {
|
|
|
|
|
col.Calc.Result = &Value{Created: NewFormattedValueCreated(earliest, 0, CreatedFormatNone)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorLatest:
|
|
|
|
|
latest := int64(0)
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Created {
|
|
|
|
|
if 0 == latest || latest < row.Cells[colIndex].Value.Created.Content {
|
|
|
|
|
latest = row.Cells[colIndex].Value.Created.Content
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 != latest {
|
|
|
|
|
col.Calc.Result = &Value{Created: NewFormattedValueCreated(latest, 0, CreatedFormatNone)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorRange:
|
|
|
|
|
earliest := int64(0)
|
|
|
|
|
latest := int64(0)
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Created {
|
|
|
|
|
if 0 == earliest || earliest > row.Cells[colIndex].Value.Created.Content {
|
|
|
|
|
earliest = row.Cells[colIndex].Value.Created.Content
|
|
|
|
|
}
|
|
|
|
|
if 0 == latest || latest < row.Cells[colIndex].Value.Created.Content {
|
|
|
|
|
latest = row.Cells[colIndex].Value.Created.Content
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 != earliest && 0 != latest {
|
|
|
|
|
col.Calc.Result = &Value{Created: NewFormattedValueCreated(earliest, latest, CreatedFormatDuration)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (table *Table) calcColUpdated(col *TableColumn, colIndex int) {
|
|
|
|
|
switch col.Calc.Operator {
|
|
|
|
|
case CalcOperatorCountAll:
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(len(table.Rows)), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountValues:
|
|
|
|
|
countValues := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Updated && row.Cells[colIndex].Value.Updated.IsNotEmpty {
|
|
|
|
|
countValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countValues), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountUniqueValues:
|
|
|
|
|
countUniqueValues := 0
|
|
|
|
|
uniqueValues := map[int64]bool{}
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Updated && row.Cells[colIndex].Value.Updated.IsNotEmpty {
|
|
|
|
|
if _, ok := uniqueValues[row.Cells[colIndex].Value.Updated.Content]; !ok {
|
|
|
|
|
countUniqueValues++
|
|
|
|
|
uniqueValues[row.Cells[colIndex].Value.Updated.Content] = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUniqueValues), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Updated || !row.Cells[colIndex].Value.Updated.IsNotEmpty {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Updated && row.Cells[colIndex].Value.Updated.IsNotEmpty {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorPercentEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Updated || !row.Cells[colIndex].Value.Updated.IsNotEmpty {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorPercentNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Updated && row.Cells[colIndex].Value.Updated.IsNotEmpty {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorEarliest:
|
|
|
|
|
earliest := int64(0)
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Updated && row.Cells[colIndex].Value.Updated.IsNotEmpty {
|
|
|
|
|
if 0 == earliest || earliest > row.Cells[colIndex].Value.Updated.Content {
|
|
|
|
|
earliest = row.Cells[colIndex].Value.Updated.Content
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 != earliest {
|
|
|
|
|
col.Calc.Result = &Value{Updated: NewFormattedValueUpdated(earliest, 0, UpdatedFormatNone)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorLatest:
|
|
|
|
|
latest := int64(0)
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Updated && row.Cells[colIndex].Value.Updated.IsNotEmpty {
|
|
|
|
|
if 0 == latest || latest < row.Cells[colIndex].Value.Updated.Content {
|
|
|
|
|
latest = row.Cells[colIndex].Value.Updated.Content
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 != latest {
|
|
|
|
|
col.Calc.Result = &Value{Updated: NewFormattedValueUpdated(latest, 0, UpdatedFormatNone)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorRange:
|
|
|
|
|
earliest := int64(0)
|
|
|
|
|
latest := int64(0)
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Updated && row.Cells[colIndex].Value.Updated.IsNotEmpty {
|
|
|
|
|
if 0 == earliest || earliest > row.Cells[colIndex].Value.Updated.Content {
|
|
|
|
|
earliest = row.Cells[colIndex].Value.Updated.Content
|
|
|
|
|
}
|
|
|
|
|
if 0 == latest || latest < row.Cells[colIndex].Value.Updated.Content {
|
|
|
|
|
latest = row.Cells[colIndex].Value.Updated.Content
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 != earliest && 0 != latest {
|
|
|
|
|
col.Calc.Result = &Value{Updated: NewFormattedValueUpdated(earliest, latest, UpdatedFormatDuration)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-17 09:03:17 +08:00
|
|
|
|
|
|
|
|
|
func (table *Table) calcColCheckbox(col *TableColumn, colIndex int) {
|
|
|
|
|
switch col.Calc.Operator {
|
|
|
|
|
case CalcOperatorCountAll:
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(len(table.Rows)), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorChecked:
|
|
|
|
|
countChecked := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Checkbox && row.Cells[colIndex].Value.Checkbox.Checked {
|
|
|
|
|
countChecked++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countChecked), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorUnchecked:
|
|
|
|
|
countUnchecked := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Checkbox && !row.Cells[colIndex].Value.Checkbox.Checked {
|
|
|
|
|
countUnchecked++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUnchecked), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorPercentChecked:
|
|
|
|
|
countChecked := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Checkbox && row.Cells[colIndex].Value.Checkbox.Checked {
|
|
|
|
|
countChecked++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countChecked)/float64(len(table.Rows)), NumberFormatPercent)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorPercentUnchecked:
|
|
|
|
|
countUnchecked := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Checkbox && !row.Cells[colIndex].Value.Checkbox.Checked {
|
|
|
|
|
countUnchecked++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUnchecked)/float64(len(table.Rows)), NumberFormatPercent)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-15 20:05:14 +08:00
|
|
|
|
|
|
|
|
|
func (table *Table) calcColRelation(col *TableColumn, colIndex int) {
|
|
|
|
|
switch col.Calc.Operator {
|
|
|
|
|
case CalcOperatorCountAll:
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(len(table.Rows)), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountValues:
|
|
|
|
|
countValues := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Relation {
|
|
|
|
|
countValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countValues), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountUniqueValues:
|
|
|
|
|
countUniqueValues := 0
|
|
|
|
|
uniqueValues := map[string]bool{}
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Relation {
|
|
|
|
|
for _, id := range row.Cells[colIndex].Value.Relation.BlockIDs {
|
|
|
|
|
if !uniqueValues[id] {
|
|
|
|
|
uniqueValues[id] = true
|
|
|
|
|
countUniqueValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUniqueValues), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Relation || 0 == len(row.Cells[colIndex].Value.Relation.BlockIDs) {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Relation && 0 < len(row.Cells[colIndex].Value.Relation.BlockIDs) {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorPercentEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Relation || 0 == len(row.Cells[colIndex].Value.Relation.BlockIDs) {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorPercentNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Relation && 0 < len(row.Cells[colIndex].Value.Relation.BlockIDs) {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (table *Table) calcColRollup(col *TableColumn, colIndex int) {
|
|
|
|
|
switch col.Calc.Operator {
|
|
|
|
|
case CalcOperatorCountAll:
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(len(table.Rows)), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountValues:
|
|
|
|
|
countValues := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Rollup {
|
|
|
|
|
countValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countValues), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountUniqueValues:
|
|
|
|
|
countUniqueValues := 0
|
|
|
|
|
uniqueValues := map[string]bool{}
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Rollup {
|
|
|
|
|
for _, content := range row.Cells[colIndex].Value.Rollup.Contents {
|
2024-01-01 15:14:52 +08:00
|
|
|
|
if !uniqueValues[content.String()] {
|
|
|
|
|
uniqueValues[content.String()] = true
|
2023-12-15 20:05:14 +08:00
|
|
|
|
countUniqueValues++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countUniqueValues), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Rollup || 0 == len(row.Cells[colIndex].Value.Rollup.Contents) {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorCountNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Rollup && 0 < len(row.Cells[colIndex].Value.Rollup.Contents) {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty), NumberFormatNone)}
|
|
|
|
|
case CalcOperatorPercentEmpty:
|
|
|
|
|
countEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Rollup || 0 == len(row.Cells[colIndex].Value.Rollup.Contents) {
|
|
|
|
|
countEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
|
|
|
|
}
|
|
|
|
|
case CalcOperatorPercentNotEmpty:
|
|
|
|
|
countNotEmpty := 0
|
|
|
|
|
for _, row := range table.Rows {
|
|
|
|
|
if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Rollup && 0 < len(row.Cells[colIndex].Value.Rollup.Contents) {
|
|
|
|
|
countNotEmpty++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if 0 < len(table.Rows) {
|
|
|
|
|
col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|