🎨 The database supports calculating the "Percent unique values" of the field https://github.com/siyuan-note/siyuan/issues/13192

This commit is contained in:
Daniel 2024-11-20 20:20:41 +08:00
parent 36df3d5ea1
commit 1e28680a58
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
15 changed files with 289 additions and 20 deletions

View file

@ -730,6 +730,18 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc, destKey *Key) {
if 0 < len(r.Contents) {
r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewFormattedValueNumber(float64(countNonEmpty)/float64(len(r.Contents)), NumberFormatPercent)}}
}
case CalcOperatorPercentUniqueValues:
countUniqueValues := 0
uniqueValues := map[string]bool{}
for _, v := range r.Contents {
if _, ok := uniqueValues[v.String(true)]; !ok {
uniqueValues[v.String(true)] = true
countUniqueValues++
}
}
if 0 < len(r.Contents) {
r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewFormattedValueNumber(float64(countUniqueValues)/float64(len(r.Contents)), NumberFormatPercent)}}
}
case CalcOperatorSum:
sum := 0.0
for _, v := range r.Contents {