|
| 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