mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
fix: TimeTable average with nulls calculations (#13122)
This commit is contained in:
@@ -209,10 +209,21 @@ const TimeTable = ({
|
||||
.reduce((a, b) => a + b);
|
||||
} else if (column.colType === 'avg') {
|
||||
// Average over the last {timeLag}
|
||||
v =
|
||||
reversedEntries
|
||||
.map((k, i) => (i < column.timeLag ? k[valueField] : 0))
|
||||
.reduce((a, b) => a + b) / column.timeLag;
|
||||
v = null;
|
||||
if (reversedEntries.length > 0) {
|
||||
const stats = reversedEntries.slice(undefined, column.timeLag).reduce(
|
||||
function ({ count, sum }, entry) {
|
||||
return entry[valueField] !== undefined &&
|
||||
entry[valueField] !== null
|
||||
? { count: count + 1, sum: sum + entry[valueField] }
|
||||
: { count, sum };
|
||||
},
|
||||
{ count: 0, sum: 0 },
|
||||
);
|
||||
if (stats.count > 0) {
|
||||
v = stats.sum / stats.count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const color = colorFromBounds(v, column.bounds);
|
||||
|
||||
Reference in New Issue
Block a user