mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
🐛 Database rollup template calculations are incorrect https://github.com/siyuan-note/siyuan/issues/15695
This commit is contained in:
parent
23ed5c8627
commit
138d6f57ee
1 changed files with 38 additions and 0 deletions
|
@ -899,6 +899,10 @@ func (r *ValueRollup) calcContents(calc *RollupCalc, destKey *Key) {
|
|||
for _, v := range r.Contents {
|
||||
if KeyTypeNumber == v.Type && nil != v.Number && v.Number.IsNotEmpty {
|
||||
sum += v.Number.Content
|
||||
} else {
|
||||
content := v.String(false)
|
||||
f, _ := util.Convert2Float(content)
|
||||
sum += f
|
||||
}
|
||||
}
|
||||
r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewFormattedValueNumber(sum, destKey.NumberFormat)}}
|
||||
|
@ -909,6 +913,11 @@ func (r *ValueRollup) calcContents(calc *RollupCalc, destKey *Key) {
|
|||
if KeyTypeNumber == v.Type && nil != v.Number && v.Number.IsNotEmpty {
|
||||
sum += v.Number.Content
|
||||
count++
|
||||
} else {
|
||||
content := v.String(false)
|
||||
f, _ := util.Convert2Float(content)
|
||||
sum += f
|
||||
count++
|
||||
}
|
||||
}
|
||||
if 0 < count {
|
||||
|
@ -919,6 +928,10 @@ func (r *ValueRollup) calcContents(calc *RollupCalc, destKey *Key) {
|
|||
for _, v := range r.Contents {
|
||||
if KeyTypeNumber == v.Type && nil != v.Number && v.Number.IsNotEmpty {
|
||||
numbers = append(numbers, v.Number.Content)
|
||||
} else {
|
||||
content := v.String(false)
|
||||
f, _ := util.Convert2Float(content)
|
||||
numbers = append(numbers, f)
|
||||
}
|
||||
}
|
||||
sort.Float64s(numbers)
|
||||
|
@ -936,6 +949,12 @@ func (r *ValueRollup) calcContents(calc *RollupCalc, destKey *Key) {
|
|||
if v.Number.Content < minVal {
|
||||
minVal = v.Number.Content
|
||||
}
|
||||
} else {
|
||||
content := v.String(false)
|
||||
f, _ := util.Convert2Float(content)
|
||||
if f < minVal {
|
||||
minVal = f
|
||||
}
|
||||
}
|
||||
}
|
||||
if math.MaxFloat64 != minVal {
|
||||
|
@ -948,6 +967,12 @@ func (r *ValueRollup) calcContents(calc *RollupCalc, destKey *Key) {
|
|||
if v.Number.Content > maxVal {
|
||||
maxVal = v.Number.Content
|
||||
}
|
||||
} else {
|
||||
content := v.String(false)
|
||||
f, _ := util.Convert2Float(content)
|
||||
if f > maxVal {
|
||||
maxVal = f
|
||||
}
|
||||
}
|
||||
}
|
||||
if -math.MaxFloat64 != maxVal {
|
||||
|
@ -1004,6 +1029,15 @@ func (r *ValueRollup) calcContents(calc *RollupCalc, destKey *Key) {
|
|||
isNotTime = true
|
||||
hasEndDate = false
|
||||
}
|
||||
} else {
|
||||
content := v.String(false)
|
||||
f, _ := util.Convert2Float(content)
|
||||
if f < minVal {
|
||||
minVal = f
|
||||
}
|
||||
if f > maxVal {
|
||||
maxVal = f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1025,6 +1059,10 @@ func (r *ValueRollup) calcContents(calc *RollupCalc, destKey *Key) {
|
|||
if 0 != earliest && 0 != latest {
|
||||
r.Contents = []*Value{{Type: KeyTypeCreated, Created: NewFormattedValueCreated(earliest, latest, CreatedFormatDuration)}}
|
||||
}
|
||||
default:
|
||||
if math.MaxFloat64 != minVal && -math.MaxFloat64 != maxVal {
|
||||
r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewFormattedValueNumber(maxVal-minVal, destKey.NumberFormat)}}
|
||||
}
|
||||
}
|
||||
case CalcOperatorEarliest:
|
||||
if 1 > len(r.Contents) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue