Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,26 @@ <h4>Field values</h4>
</tr>
</tbody>
</table>

<a href="#log-field-values">
<h4>Statistics</h4>
</a>
<table id="stats-table" class="table table-condensed">
<caption>Min/max values from this log</caption>
<thead>
<tr>
<th>&nbsp;</th>
<th>Min</th>
<th>Max</th>
<th>Mean</th>
</tr>
</thead>
<tbody>
<tr>
<!-- auto filled by updateValues function -->
</tr>
</tbody>
</table>
</div>
<div class="configuration-file" id="configuration-file">
<!-- auto filled by configuration function -->
Expand Down Expand Up @@ -3224,6 +3244,7 @@ <h4 class="modal-title">Advanced User Settings</h4>
<script src="js/laptimer.js"></script>
<script src="js/localization.js"></script>
<script src="js/graph_map.js"></script>
<script src="js/simple-stats.js"></script>
<script src="js/main.js"></script>
<script src="index.js"></script>

Expand Down
21 changes: 21 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,27 @@ function BlackboxLogViewer() {

table.append(rows.join(""));

const statRows = [];
const statsTable = $(".log-field-values #stats-table");
$("tr:not(:first)", statsTable).remove();
const stats = SimpleStats(flightLog).calculate();
const tpl = _.template("<tr><td><%= name %></td><td><%= min %> (<%= min_raw %>)</td><td><%= max %> (<%= max_raw %>)</td><td><%= mean %> (<%= mean_raw %>)</td></tr>");
for (const field in stats) {
const stat = stats[field];
if (stat === undefined) {
continue;
}
statRows.push(tpl({
name: fieldPresenter.fieldNameToFriendly(stat.name, flightLog.getSysConfig().debug_mode),
min_raw: atMost2DecPlaces(stat.min),
min: FlightLogFieldPresenter.decodeFieldToFriendly(flightLog, stat.name, stat.min),
max_raw: atMost2DecPlaces(stat.max),
max: FlightLogFieldPresenter.decodeFieldToFriendly(flightLog, stat.name, stat.max),
mean_raw: atMost2DecPlaces(stat.mean),
mean: FlightLogFieldPresenter.decodeFieldToFriendly(flightLog, stat.name, stat.mean),
}));
}
statsTable.append(statRows.join(""));
}

// Update flight mode flags on status bar
Expand Down
42 changes: 42 additions & 0 deletions js/simple-stats.js
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; }
Copy link
Member

@haslinghuis haslinghuis Nov 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameter was renamed in betaflight/betaflight#11911

});

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,
};
};