2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 import java.awt.event.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.*;
30 import org.altusmetrum.AltosLib.*;
32 public class AltosFlightStats {
35 double max_acceleration;
36 double[] state_speed = new double[Altos.ao_flight_invalid + 1];
37 double[] state_baro_speed = new double[Altos.ao_flight_invalid + 1];
38 double[] state_accel = new double[Altos.ao_flight_invalid + 1];
39 int[] state_count = new int[Altos.ao_flight_invalid + 1];
40 double[] state_start = new double[Altos.ao_flight_invalid + 1];
41 double[] state_end = new double[Altos.ao_flight_invalid + 1];
45 int hour, minute, second;
47 public AltosFlightStats(AltosFlightReader reader) throws InterruptedException, IOException {
48 AltosState state = null;
49 AltosState new_state = null;
50 double boost_time = -1;
53 year = month = day = -1;
54 hour = minute = second = -1;
58 AltosRecord record = reader.read();
62 serial = record.serial;
63 if ((record.seen & AltosRecord.seen_flight) != 0 && flight < 0)
64 flight = record.flight;
65 new_state = new AltosState(record, state);
66 end_time = new_state.time;
68 if (0 <= state.state && state.state < Altos.ao_flight_invalid) {
69 if (state.state >= Altos.ao_flight_boost) {
71 boost_time = state.time;
72 if (state.gps != null && state.gps.locked &&
74 year = state.gps.year;
75 month = state.gps.month;
77 hour = state.gps.hour;
78 minute = state.gps.minute;
79 second = state.gps.second;
82 state_accel[state.state] += state.acceleration;
83 state_speed[state.state] += state.speed;
84 state_baro_speed[state.state] += state.baro_speed;
85 state_count[state.state]++;
86 if (state_start[state.state] == 0.0)
87 state_start[state.state] = state.time;
88 if (state_end[state.state] < state.time)
89 state_end[state.state] = state.time;
90 max_height = state.max_height;
91 if (state.max_speed != 0)
92 max_speed = state.max_speed;
94 max_speed = state.max_baro_speed;
95 max_acceleration = state.max_acceleration;
97 } catch (ParseException pp) {
98 System.out.printf("Parse error: %d \"%s\"\n", pp.getErrorOffset(), pp.getMessage());
99 } catch (AltosCRCException ce) {
103 for (int s = Altos.ao_flight_startup; s <= Altos.ao_flight_landed; s++) {
104 if (state_count[s] > 0) {
105 state_speed[s] /= state_count[s];
106 state_baro_speed[s] /= state_count[s];
107 state_accel[s] /= state_count[s];
109 if (state_start[s] == 0)
110 state_start[s] = end_time;
111 if (state_end[s] == 0)
112 state_end[s] = end_time;
116 public AltosFlightStats(AltosRecordIterable iterable, File file) throws InterruptedException, IOException {
117 this(new AltosReplayReader(iterable.iterator(), file));
120 public AltosFlightStats(AltosRecordIterable iterable) throws InterruptedException, IOException {
121 this(iterable, new File(""));