123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632 |
- // 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 (
- "math"
- "sort"
- "strconv"
- )
- // LayoutTable 描述了表格布局的结构。
- type LayoutTable struct {
- Spec int `json:"spec"` // 布局格式版本
- ID string `json:"id"` // 布局 ID
- Columns []*ViewTableColumn `json:"columns"` // 表格列
- RowIDs []string `json:"rowIds"` // 行 ID,用于自定义排序
- Filters []*ViewFilter `json:"filters"` // 过滤规则
- Sorts []*ViewSort `json:"sorts"` // 排序规则
- PageSize int `json:"pageSize"` // 每页行数
- }
- type ViewTableColumn struct {
- ID string `json:"id"` // 列 ID
- Wrap bool `json:"wrap"` // 是否换行
- Hidden bool `json:"hidden"` // 是否隐藏
- Pin bool `json:"pin"` // 是否固定
- Width string `json:"width"` // 列宽度
- Calc *ColumnCalc `json:"calc,omitempty"` // 计算
- }
- 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"
- CalcOperatorChecked CalcOperator = "Checked"
- CalcOperatorUnchecked CalcOperator = "Unchecked"
- CalcOperatorPercentChecked CalcOperator = "Percent checked"
- CalcOperatorPercentUnchecked CalcOperator = "Percent unchecked"
- )
- // Table 描述了表格实例的结构。
- type Table struct {
- 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"` // 每页行数
- }
- 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"` // 是否隐藏
- Pin bool `json:"pin"` // 是否固定
- Width string `json:"width"` // 列宽度
- Calc *ColumnCalc `json:"calc"` // 计算
- // 以下是某些列类型的特有属性
- Options []*SelectOption `json:"options,omitempty"` // 选项列表
- NumberFormat NumberFormat `json:"numberFormat"` // 列数字格式化
- Template string `json:"template"` // 模板内容
- Relation *Relation `json:"relation,omitempty"` // 关联列
- Rollup *Rollup `json:"rollup,omitempty"` // 汇总列
- }
- type TableCell struct {
- ID string `json:"id"`
- Value *Value `json:"value"`
- ValueType KeyType `json:"valueType"`
- Color string `json:"color"`
- BgColor string `json:"bgColor"`
- }
- type TableRow struct {
- ID string `json:"id"`
- Cells []*TableCell `json:"cells"`
- }
- func (row *TableRow) GetBlockValue() (ret *Value) {
- for _, cell := range row.Cells {
- if KeyTypeBlock == cell.ValueType {
- ret = cell.Value
- break
- }
- }
- return
- }
- 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
- }
- func (table *Table) GetType() LayoutType {
- return LayoutTypeTable
- }
- func (table *Table) GetID() string {
- return table.ID
- }
- 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
- }
- }
- }
- includeUneditedRows := map[string]bool{}
- for i, row := range table.Rows {
- for _, colIndexSort := range colIndexSorts {
- 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 {
- sorted := true
- 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)
- if 0 == result {
- sorted = false
- continue
- }
- sorted = true
- if colIndexSort.Order == SortOrderAsc {
- return 0 > result
- }
- return 0 < result
- }
- if !sorted {
- key1 := editedRows[i].GetBlockValue()
- if nil == key1 {
- return false
- }
- key2 := editedRows[j].GetBlockValue()
- if nil == key2 {
- return false
- }
- return key1.CreatedAt < key2.CreatedAt
- }
- return false
- })
- // 将包含未编辑的行放在最后
- table.Rows = append(editedRows, uneditedRows...)
- if 1 > len(table.Rows) {
- table.Rows = []*TableRow{}
- }
- }
- func (table *Table) FilterRows(attrView *AttributeView) {
- 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
- }
- }
- }
- rows := []*TableRow{}
- for _, row := range table.Rows {
- pass := true
- for j, index := range colIndexes {
- operator := table.Filters[j].Operator
- if nil == row.Cells[index].Value {
- if FilterOperatorIsNotEmpty == operator {
- pass = false
- } else if FilterOperatorIsEmpty == operator {
- pass = true
- break
- }
- if KeyTypeText != row.Cells[index].ValueType {
- pass = false
- }
- break
- }
- if !row.Cells[index].Value.Filter(table.Filters[j], attrView, row.ID) {
- 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 {
- case KeyTypeBlock:
- table.calcColBlock(col, i)
- case KeyTypeText:
- table.calcColText(col, i)
- case KeyTypeNumber:
- table.calcColNumber(col, i)
- case KeyTypeDate:
- table.calcColDate(col, i)
- case KeyTypeSelect:
- table.calcColSelect(col, i)
- case KeyTypeMSelect:
- table.calcColMSelect(col, i)
- case KeyTypeURL:
- table.calcColURL(col, i)
- case KeyTypeEmail:
- table.calcColEmail(col, i)
- case KeyTypePhone:
- table.calcColPhone(col, i)
- case KeyTypeMAsset:
- table.calcColMAsset(col, i)
- case KeyTypeTemplate:
- table.calcColTemplate(col, i)
- case KeyTypeCreated:
- table.calcColCreated(col, i)
- case KeyTypeUpdated:
- table.calcColUpdated(col, i)
- case KeyTypeCheckbox:
- table.calcColCheckbox(col, i)
- case KeyTypeRelation:
- table.calcColRelation(col, i)
- case KeyTypeRollup:
- table.calcColRollup(col, i)
- }
- }
- }
- 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 {
- if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Template && "" != row.Cells[colIndex].Value.Template.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.Template && "" != row.Cells[colIndex].Value.Template.Content {
- if !uniqueValues[row.Cells[colIndex].Value.Template.Content] {
- uniqueValues[row.Cells[colIndex].Value.Template.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.Template || "" == row.Cells[colIndex].Value.Template.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.Template && "" != row.Cells[colIndex].Value.Template.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.Template || "" == row.Cells[colIndex].Value.Template.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.Template && "" != row.Cells[colIndex].Value.Template.Content {
- countNotEmpty++
- }
- }
- if 0 < len(table.Rows) {
- col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
- }
- 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)}
- }
- }
- }
- 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)}
- }
- }
- }
- func (table *Table) calcColMSelect(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.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) {
- countValues += len(row.Cells[colIndex].Value.MSelect)
- }
- }
- 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.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++
- }
- }
- }
- }
- 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.MSelect || 0 == len(row.Cells[colIndex].Value.MSelect) {
- 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.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) {
- 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.MSelect || 0 == len(row.Cells[colIndex].Value.MSelect) {
- 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.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) {
- countNotEmpty++
- }
- }
- if 0 < len(table.Rows) {
- col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
- }
- }
- }
- func (table *Table) calcColSelect(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.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) && nil != row.Cells[colIndex].Value.MSelect[0] && "" != row.Cells[colIndex].Value.MSelect[0].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.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) && nil != row.Cells[colIndex].Value.MSelect[0] && "" != row.Cells[colIndex].Value.MSelect[0].Content {
- if _, ok := uniqueValues[row.Cells[colIndex].Value.MSelect[0].Content]; !ok {
- uniqueValues[row.Cells[colIndex].Value.MSelect[0].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.MSelect || 1 > len(row.Cells[colIndex].Value.MSelect) || nil == row.Cells[colIndex].Value.MSelect[0] || "" == row.Cells[colIndex].Value.MSelect[0].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.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) && nil != row.Cells[colIndex].Value.MSelect[0] && "" != row.Cells[colIndex].Value.MSelect[0].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.MSelect || 1 > len(row.Cells[colIndex].Value.MSelect) || nil == row.Cells[colIndex].Value.MSelect[0] || "" == row.Cells[colIndex].Value.MSelect[0].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.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) && nil != row.Cells[colIndex].Value.MSelect[0] && "" != row.Cells[colIndex].Value.MSelect[0].Content {
- countNotEmpty++
- }
- }
- if 0 < len(table.Rows) {
- col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
- }
- }
- }
- func (table *Table) calcColDate(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.Date && row.Cells[colIndex].Value.Date.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.Date && row.Cells[colIndex].Value.Date.IsNotEmpty {
- if _, ok := uniqueValues[row.Cells[colIndex].Value.Date.Content]; !ok {
- countUniqueValues++
- uniqueValues[row.Cells[colIndex].Value.Date.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.Date || !row.Cells[colIndex].Value.Date.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.Date && row.Cells[colIndex].Value.Date.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.Date || !row.Cells[colIndex].Value.Date.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.Date && row.Cells[colIndex].Value.Date.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)
- var isNotTime, hasEndDate bool
- for _, row := range table.Rows {
- if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Date && row.Cells[colIndex].Value.Date.IsNotEmpty {
- if 0 == earliest || earliest > row.Cells[colIndex].Value.Date.Content {
- earliest = row.Cells[colIndex].Value.Date.Content
- isNotTime = row.Cells[colIndex].Value.Date.IsNotTime
- hasEndDate = row.Cells[colIndex].Value.Date.HasEndDate
- }
- }
- }
- if 0 != earliest {
- col.Calc.Result = &Value{Date: NewFormattedValueDate(earliest, 0, DateFormatNone, isNotTime, hasEndDate)}
- }
- case CalcOperatorLatest:
- latest := int64(0)
- var isNotTime, hasEndDate bool
- for _, row := range table.Rows {
- if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Date && row.Cells[colIndex].Value.Date.IsNotEmpty {
- if 0 == latest || latest < row.Cells[colIndex].Value.Date.Content {
- latest = row.Cells[colIndex].Value.Date.Content
- isNotTime = row.Cells[colIndex].Value.Date.IsNotTime
- hasEndDate = row.Cells[colIndex].Value.Date.HasEndDate
- }
- }
- }
- if 0 != latest {
- col.Calc.Result = &Value{Date: NewFormattedValueDate(latest, 0, DateFormatNone, isNotTime, hasEndDate)}
- }
- case CalcOperatorRange:
- earliest := int64(0)
- latest := int64(0)
- var isNotTime, hasEndDate bool
- for _, row := range table.Rows {
- if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Date && row.Cells[colIndex].Value.Date.IsNotEmpty {
- if 0 == earliest || earliest > row.Cells[colIndex].Value.Date.Content {
- earliest = row.Cells[colIndex].Value.Date.Content
- isNotTime = row.Cells[colIndex].Value.Date.IsNotTime
- hasEndDate = row.Cells[colIndex].Value.Date.HasEndDate
- }
- if 0 == latest || latest < row.Cells[colIndex].Value.Date.Content {
- latest = row.Cells[colIndex].Value.Date.Content
- isNotTime = row.Cells[colIndex].Value.Date.IsNotTime
- hasEndDate = row.Cells[colIndex].Value.Date.HasEndDate
- }
- }
- }
- if 0 != earliest && 0 != latest {
- col.Calc.Result = &Value{Date: NewFormattedValueDate(earliest, latest, DateFormatDuration, isNotTime, hasEndDate)}
- }
- }
- }
- func (table *Table) calcColNumber(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.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
- countValues++
- }
- }
- col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countValues), NumberFormatNone)}
- case CalcOperatorCountUniqueValues:
- countUniqueValues := 0
- uniqueValues := map[float64]bool{}
- for _, row := range table.Rows {
- if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
- if !uniqueValues[row.Cells[colIndex].Value.Number.Content] {
- uniqueValues[row.Cells[colIndex].Value.Number.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.Number || !row.Cells[colIndex].Value.Number.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.Number && row.Cells[colIndex].Value.Number.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.Number || !row.Cells[colIndex].Value.Number.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.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
- countNotEmpty++
- }
- }
- if 0 < len(table.Rows) {
- col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
- }
- 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.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
- sum += row.Cells[colIndex].Value.Number.Content
- }
- }
- 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.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
- sum += row.Cells[colIndex].Value.Number.Content
- 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.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
- values = append(values, row.Cells[colIndex].Value.Number.Content)
- }
- }
- 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.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
- if row.Cells[colIndex].Value.Number.Content < minVal {
- minVal = row.Cells[colIndex].Value.Number.Content
- }
- }
- }
- 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.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
- if row.Cells[colIndex].Value.Number.Content > maxVal {
- maxVal = row.Cells[colIndex].Value.Number.Content
- }
- }
- }
- 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.Number && row.Cells[colIndex].Value.Number.IsNotEmpty {
- if row.Cells[colIndex].Value.Number.Content < minVal {
- minVal = row.Cells[colIndex].Value.Number.Content
- }
- if row.Cells[colIndex].Value.Number.Content > maxVal {
- maxVal = row.Cells[colIndex].Value.Number.Content
- }
- }
- }
- if math.MaxFloat64 != minVal && -math.MaxFloat64 != maxVal {
- col.Calc.Result = &Value{Number: NewFormattedValueNumber(maxVal-minVal, col.NumberFormat)}
- }
- }
- }
- func (table *Table) calcColText(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.Text && "" != row.Cells[colIndex].Value.Text.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.Text && "" != row.Cells[colIndex].Value.Text.Content {
- if !uniqueValues[row.Cells[colIndex].Value.Text.Content] {
- uniqueValues[row.Cells[colIndex].Value.Text.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.Text || "" == row.Cells[colIndex].Value.Text.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.Text && "" != row.Cells[colIndex].Value.Text.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.Text || "" == row.Cells[colIndex].Value.Text.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.Text && "" != row.Cells[colIndex].Value.Text.Content {
- countNotEmpty++
- }
- }
- if 0 < len(table.Rows) {
- col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
- }
- }
- }
- 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)}
- }
- }
- }
- 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)}
- }
- }
- }
- func (table *Table) calcColBlock(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.Block && "" != row.Cells[colIndex].Value.Block.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.Block && "" != row.Cells[colIndex].Value.Block.Content {
- if !uniqueValues[row.Cells[colIndex].Value.Block.Content] {
- uniqueValues[row.Cells[colIndex].Value.Block.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.Block || "" == row.Cells[colIndex].Value.Block.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.Block && "" != row.Cells[colIndex].Value.Block.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.Block || "" == row.Cells[colIndex].Value.Block.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.Block && "" != row.Cells[colIndex].Value.Block.Content {
- countNotEmpty++
- }
- }
- if 0 < len(table.Rows) {
- col.Calc.Result = &Value{Number: NewFormattedValueNumber(float64(countNotEmpty)/float64(len(table.Rows)), NumberFormatPercent)}
- }
- }
- }
- 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)}
- }
- }
- }
- 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)}
- }
- }
- }
- 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 {
- if !uniqueValues[content.String()] {
- uniqueValues[content.String()] = 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.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)}
- }
- }
- }
|