Skip to content

Commit 9771888

Browse files
authored
Add simple stats table (#661)
* Add simple stats table * PR fixes
1 parent 1483793 commit 9771888

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

index.html

+21
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,26 @@ <h4>Field values</h4>
565565
</tr>
566566
</tbody>
567567
</table>
568+
569+
<a href="#log-field-values">
570+
<h4>Statistics</h4>
571+
</a>
572+
<table id="stats-table" class="table table-condensed">
573+
<caption>Min/max values from this log</caption>
574+
<thead>
575+
<tr>
576+
<th>&nbsp;</th>
577+
<th>Min</th>
578+
<th>Max</th>
579+
<th>Mean</th>
580+
</tr>
581+
</thead>
582+
<tbody>
583+
<tr>
584+
<!-- auto filled by updateValues function -->
585+
</tr>
586+
</tbody>
587+
</table>
568588
</div>
569589
<div class="configuration-file" id="configuration-file">
570590
<!-- auto filled by configuration function -->
@@ -3232,6 +3252,7 @@ <h4 class="modal-title">Advanced User Settings</h4>
32323252
<script src="js/laptimer.js"></script>
32333253
<script src="js/localization.js"></script>
32343254
<script src="js/graph_map.js"></script>
3255+
<script src="js/simple-stats.js"></script>
32353256
<script src="js/main.js"></script>
32363257
<script src="index.js"></script>
32373258

js/main.js

+21
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,27 @@ function BlackboxLogViewer() {
214214

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

217+
const statRows = [];
218+
const statsTable = $(".log-field-values #stats-table");
219+
$("tr:not(:first)", statsTable).remove();
220+
const stats = SimpleStats(flightLog).calculate();
221+
const tpl = _.template("<tr><td><%= name %></td><td><%= min %> (<%= min_raw %>)</td><td><%= max %> (<%= max_raw %>)</td><td><%= mean %> (<%= mean_raw %>)</td></tr>");
222+
for (const field in stats) {
223+
const stat = stats[field];
224+
if (stat === undefined) {
225+
continue;
226+
}
227+
statRows.push(tpl({
228+
name: fieldPresenter.fieldNameToFriendly(stat.name, flightLog.getSysConfig().debug_mode),
229+
min_raw: atMost2DecPlaces(stat.min),
230+
min: FlightLogFieldPresenter.decodeFieldToFriendly(flightLog, stat.name, stat.min),
231+
max_raw: atMost2DecPlaces(stat.max),
232+
max: FlightLogFieldPresenter.decodeFieldToFriendly(flightLog, stat.name, stat.max),
233+
mean_raw: atMost2DecPlaces(stat.mean),
234+
mean: FlightLogFieldPresenter.decodeFieldToFriendly(flightLog, stat.name, stat.mean),
235+
}));
236+
}
237+
statsTable.append(statRows.join(""));
217238
}
218239

219240
// Update flight mode flags on status bar

js/simple-stats.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const SimpleStats = function (flightLog) {
2+
const frames = _(flightLog.getChunksInTimeRange(flightLog.getMinTime(), flightLog.getMaxTime()))
3+
.map(chunk => chunk.frames).flatten().value(),
4+
fields = _.map(flightLog.getMainFieldNames(), (f) => {
5+
// fix typo. potential bug in either FW or BBE
6+
if (f === "BaroAlt") { return "baroAlt"; } else { return f; }
7+
});
8+
9+
const getMinMaxMean = (fieldName) => {
10+
const index = _.findIndex(fields, (f) => f === fieldName);
11+
if (index === -1 || !frames.length || !(index in frames[0])) {
12+
return undefined;
13+
}
14+
const result = _.mapValues({
15+
"min": _.minBy(frames, (f) => f[index])[index],
16+
"max": _.maxBy(frames, (f) => f[index])[index],
17+
"mean": _.meanBy(frames, (f) => f[index]),
18+
});
19+
result["name"] = fieldName;
20+
return result;
21+
};
22+
23+
const template = {
24+
"roll": () => getMinMaxMean("rcCommand[0]"),
25+
"pitch": () => getMinMaxMean("rcCommand[1]"),
26+
"yaw": () => getMinMaxMean("rcCommand[2]"),
27+
"throttle": () => getMinMaxMean("rcCommand[3]"),
28+
"vbat": () => getMinMaxMean("vbatLatest"),
29+
"amps": () => getMinMaxMean("amperageLatest"),
30+
"rssi": () => getMinMaxMean("rssi"),
31+
"alt_baro": () => getMinMaxMean("baroAlt"),
32+
"alt_gps": () => getMinMaxMean("GPS_altitude"),
33+
};
34+
35+
function calculate() {
36+
return _.mapValues(template, (f) => f.call());
37+
}
38+
39+
return {
40+
calculate: calculate,
41+
};
42+
};

0 commit comments

Comments
 (0)