mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01: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 {
|
for _, v := range r.Contents {
|
||||||
if KeyTypeNumber == v.Type && nil != v.Number && v.Number.IsNotEmpty {
|
if KeyTypeNumber == v.Type && nil != v.Number && v.Number.IsNotEmpty {
|
||||||
sum += v.Number.Content
|
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)}}
|
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 {
|
if KeyTypeNumber == v.Type && nil != v.Number && v.Number.IsNotEmpty {
|
||||||
sum += v.Number.Content
|
sum += v.Number.Content
|
||||||
count++
|
count++
|
||||||
|
} else {
|
||||||
|
content := v.String(false)
|
||||||
|
f, _ := util.Convert2Float(content)
|
||||||
|
sum += f
|
||||||
|
count++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if 0 < count {
|
if 0 < count {
|
||||||
|
|
@ -919,6 +928,10 @@ func (r *ValueRollup) calcContents(calc *RollupCalc, destKey *Key) {
|
||||||
for _, v := range r.Contents {
|
for _, v := range r.Contents {
|
||||||
if KeyTypeNumber == v.Type && nil != v.Number && v.Number.IsNotEmpty {
|
if KeyTypeNumber == v.Type && nil != v.Number && v.Number.IsNotEmpty {
|
||||||
numbers = append(numbers, v.Number.Content)
|
numbers = append(numbers, v.Number.Content)
|
||||||
|
} else {
|
||||||
|
content := v.String(false)
|
||||||
|
f, _ := util.Convert2Float(content)
|
||||||
|
numbers = append(numbers, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sort.Float64s(numbers)
|
sort.Float64s(numbers)
|
||||||
|
|
@ -936,6 +949,12 @@ func (r *ValueRollup) calcContents(calc *RollupCalc, destKey *Key) {
|
||||||
if v.Number.Content < minVal {
|
if v.Number.Content < minVal {
|
||||||
minVal = v.Number.Content
|
minVal = v.Number.Content
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
content := v.String(false)
|
||||||
|
f, _ := util.Convert2Float(content)
|
||||||
|
if f < minVal {
|
||||||
|
minVal = f
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if math.MaxFloat64 != minVal {
|
if math.MaxFloat64 != minVal {
|
||||||
|
|
@ -948,6 +967,12 @@ func (r *ValueRollup) calcContents(calc *RollupCalc, destKey *Key) {
|
||||||
if v.Number.Content > maxVal {
|
if v.Number.Content > maxVal {
|
||||||
maxVal = v.Number.Content
|
maxVal = v.Number.Content
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
content := v.String(false)
|
||||||
|
f, _ := util.Convert2Float(content)
|
||||||
|
if f > maxVal {
|
||||||
|
maxVal = f
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if -math.MaxFloat64 != maxVal {
|
if -math.MaxFloat64 != maxVal {
|
||||||
|
|
@ -1004,6 +1029,15 @@ func (r *ValueRollup) calcContents(calc *RollupCalc, destKey *Key) {
|
||||||
isNotTime = true
|
isNotTime = true
|
||||||
hasEndDate = false
|
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 {
|
if 0 != earliest && 0 != latest {
|
||||||
r.Contents = []*Value{{Type: KeyTypeCreated, Created: NewFormattedValueCreated(earliest, latest, CreatedFormatDuration)}}
|
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:
|
case CalcOperatorEarliest:
|
||||||
if 1 > len(r.Contents) {
|
if 1 > len(r.Contents) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue