forked from betaflight/blackbox-log-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple stats table (betaflight#661)
* Add simple stats table * PR fixes
- Loading branch information
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const SimpleStats = function (flightLog) { | ||
const frames = _(flightLog.getChunksInTimeRange(flightLog.getMinTime(), flightLog.getMaxTime())) | ||
.map(chunk => chunk.frames).flatten().value(), | ||
fields = _.map(flightLog.getMainFieldNames(), (f) => { | ||
// fix typo. potential bug in either FW or BBE | ||
if (f === "BaroAlt") { return "baroAlt"; } else { return f; } | ||
}); | ||
|
||
const getMinMaxMean = (fieldName) => { | ||
const index = _.findIndex(fields, (f) => f === fieldName); | ||
if (index === -1 || !frames.length || !(index in frames[0])) { | ||
return undefined; | ||
} | ||
const result = _.mapValues({ | ||
"min": _.minBy(frames, (f) => f[index])[index], | ||
"max": _.maxBy(frames, (f) => f[index])[index], | ||
"mean": _.meanBy(frames, (f) => f[index]), | ||
}); | ||
result["name"] = fieldName; | ||
return result; | ||
}; | ||
|
||
const template = { | ||
"roll": () => getMinMaxMean("rcCommand[0]"), | ||
"pitch": () => getMinMaxMean("rcCommand[1]"), | ||
"yaw": () => getMinMaxMean("rcCommand[2]"), | ||
"throttle": () => getMinMaxMean("rcCommand[3]"), | ||
"vbat": () => getMinMaxMean("vbatLatest"), | ||
"amps": () => getMinMaxMean("amperageLatest"), | ||
"rssi": () => getMinMaxMean("rssi"), | ||
"alt_baro": () => getMinMaxMean("baroAlt"), | ||
"alt_gps": () => getMinMaxMean("GPS_altitude"), | ||
}; | ||
|
||
function calculate() { | ||
return _.mapValues(template, (f) => f.call()); | ||
} | ||
|
||
return { | ||
calculate: calculate, | ||
}; | ||
}; |