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.*;
31 public class AltosFlightStats {
34 double max_acceleration;
35 double[] state_speed = new double[Altos.ao_flight_invalid + 1];
36 double[] state_baro_speed = new double[Altos.ao_flight_invalid + 1];
37 double[] state_accel = new double[Altos.ao_flight_invalid + 1];
38 int[] state_count = new int[Altos.ao_flight_invalid + 1];
39 double[] state_start = new double[Altos.ao_flight_invalid + 1];
40 double[] state_end = new double[Altos.ao_flight_invalid + 1];
44 int hour, minute, second;
46 double landed_time(AltosRecordIterable iterable) {
47 AltosState state = null;
48 for (AltosRecord record : iterable) {
49 state = new AltosState(record, state);
51 if (state.state == Altos.ao_flight_landed)
55 double landed_height = state.height;
61 double landed_time = -1000;
63 for (AltosRecord record : iterable) {
64 state = new AltosState(record, state);
66 if (state.height > landed_height + 10) {
69 if (above && state.height < landed_height + 2) {
71 landed_time = state.time;
75 if (landed_time == -1000)
76 landed_time = state.time;
80 public AltosFlightStats(AltosRecordIterable iterable) throws InterruptedException, IOException {
81 AltosState state = null;
82 AltosState new_state = null;
83 double boost_time = -1;
85 double landed_time = landed_time(iterable);
87 year = month = day = -1;
88 hour = minute = second = -1;
90 for (AltosRecord record : iterable) {
92 serial = record.serial;
93 if ((record.seen & AltosRecord.seen_flight) != 0 && flight < 0)
94 flight = record.flight;
95 new_state = new AltosState(record, state);
96 end_time = new_state.time;
98 if (0 <= state.state && state.state < Altos.ao_flight_invalid) {
99 if (state.state >= Altos.ao_flight_boost) {
100 if (boost_time == -1)
101 boost_time = state.time;
102 if (state.gps != null && state.gps.locked &&
104 year = state.gps.year;
105 month = state.gps.month;
107 hour = state.gps.hour;
108 minute = state.gps.minute;
109 second = state.gps.second;
112 if (state.time >= landed_time)
113 state.state = Altos.ao_flight_landed;
114 state_accel[state.state] += state.acceleration;
115 state_speed[state.state] += state.speed;
116 state_baro_speed[state.state] += state.baro_speed;
117 state_count[state.state]++;
118 if (state_start[state.state] == 0.0)
119 state_start[state.state] = state.time;
120 if (state_end[state.state] < state.time)
121 state_end[state.state] = state.time;
122 max_height = state.max_height;
123 if (state.max_speed != 0)
124 max_speed = state.max_speed;
126 max_speed = state.max_baro_speed;
127 max_acceleration = state.max_acceleration;
130 for (int s = Altos.ao_flight_startup; s <= Altos.ao_flight_landed; s++) {
131 if (state_count[s] > 0) {
132 state_speed[s] /= state_count[s];
133 state_baro_speed[s] /= state_count[s];
134 state_accel[s] /= state_count[s];
136 if (state_start[s] == 0)
137 state_start[s] = end_time;
138 if (state_end[s] == 0)
139 state_end[s] = end_time;