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 org.altusmetrum.altoslib_1.*;
23 public class AltosFlightStats {
26 double max_acceleration;
27 double[] state_accel_speed = new double[Altos.ao_flight_invalid + 1];
28 double[] state_baro_speed = new double[Altos.ao_flight_invalid + 1];
29 double[] state_accel = new double[Altos.ao_flight_invalid + 1];
30 int[] state_count = new int[Altos.ao_flight_invalid + 1];
31 double[] state_start = new double[Altos.ao_flight_invalid + 1];
32 double[] state_end = new double[Altos.ao_flight_invalid + 1];
36 int hour, minute, second;
38 double pad_lat, pad_lon;
40 boolean has_other_adc;
43 double landed_time(AltosRecordIterable iterable) {
44 AltosState state = null;
45 for (AltosRecord record : iterable) {
46 state = new AltosState(record, state);
48 if (state.state == Altos.ao_flight_landed)
52 double landed_height = state.height;
58 double landed_time = -1000;
60 for (AltosRecord record : iterable) {
61 state = new AltosState(record, state);
63 if (state.height > landed_height + 10) {
66 if (above && state.height < landed_height + 2) {
68 landed_time = state.time;
72 if (landed_time == -1000)
73 landed_time = state.time;
77 double boost_time(AltosRecordIterable iterable) {
78 double boost_time = -1000;
80 AltosState state = null;
82 for (AltosRecord record : iterable) {
83 state = new AltosState(record, state);
85 if (state.acceleration < 1)
86 boost_time = state.time;
87 if (state.state >= Altos.ao_flight_boost)
90 if (boost_time == -1000)
91 boost_time = state.time;
96 public AltosFlightStats(AltosRecordIterable iterable) throws InterruptedException, IOException {
97 AltosState state = null;
98 AltosState new_state = null;
99 double boost_time = boost_time(iterable);
101 double landed_time = landed_time(iterable);
103 year = month = day = -1;
104 hour = minute = second = -1;
105 serial = flight = -1;
108 has_other_adc = false;
110 for (AltosRecord record : iterable) {
112 serial = record.serial;
113 if ((record.seen & AltosRecord.seen_flight) != 0 && flight < 0)
114 flight = record.flight;
115 if ((record.seen & AltosRecord.seen_temp_volt) != 0)
116 has_other_adc = true;
117 if (record.rssi != 0)
119 new_state = new AltosState(record, state);
120 end_time = new_state.time;
122 if (state.time >= boost_time && state.state < Altos.ao_flight_boost)
123 state.state = Altos.ao_flight_boost;
124 if (state.time >= landed_time && state.state < Altos.ao_flight_landed)
125 state.state = Altos.ao_flight_landed;
126 if (0 <= state.state && state.state < Altos.ao_flight_invalid) {
127 if (state.state >= Altos.ao_flight_boost) {
128 if (state.gps != null && state.gps.locked &&
130 year = state.gps.year;
131 month = state.gps.month;
133 hour = state.gps.hour;
134 minute = state.gps.minute;
135 second = state.gps.second;
138 state_accel[state.state] += state.acceleration;
139 state_accel_speed[state.state] += state.accel_speed;
140 state_baro_speed[state.state] += state.baro_speed;
141 state_count[state.state]++;
142 if (state_start[state.state] == 0.0)
143 state_start[state.state] = state.time;
144 if (state_end[state.state] < state.time)
145 state_end[state.state] = state.time;
146 max_height = state.max_height;
147 if (state.max_accel_speed != 0)
148 max_speed = state.max_accel_speed;
150 max_speed = state.max_baro_speed;
151 max_acceleration = state.max_acceleration;
153 if (state.gps != null && state.gps.locked && state.gps.nsat >= 4) {
154 if (state.state <= Altos.ao_flight_pad) {
155 pad_lat = state.gps.lat;
156 pad_lon = state.gps.lon;
163 for (int s = Altos.ao_flight_startup; s <= Altos.ao_flight_landed; s++) {
164 if (state_count[s] > 0) {
165 state_accel_speed[s] /= state_count[s];
166 state_baro_speed[s] /= state_count[s];
167 state_accel[s] /= state_count[s];
169 if (state_start[s] == 0)
170 state_start[s] = end_time;
171 if (state_end[s] == 0)
172 state_end[s] = end_time;