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.*;
23 public class AltosFlightStats {
26 double max_acceleration;
27 double[] state_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 landed_time(AltosRecordIterable iterable) {
39 AltosState state = null;
40 for (AltosRecord record : iterable) {
41 state = new AltosState(record, state);
43 if (state.state == Altos.ao_flight_landed)
47 double landed_height = state.height;
53 double landed_time = -1000;
55 for (AltosRecord record : iterable) {
56 state = new AltosState(record, state);
58 if (state.height > landed_height + 10) {
61 if (above && state.height < landed_height + 2) {
63 landed_time = state.time;
67 if (landed_time == -1000)
68 landed_time = state.time;
72 double boost_time(AltosRecordIterable iterable) {
73 double boost_time = -1000;
75 AltosState state = null;
77 for (AltosRecord record : iterable) {
78 state = new AltosState(record, state);
80 if (state.acceleration < 1)
81 boost_time = state.time;
82 if (state.state >= Altos.ao_flight_boost)
85 if (boost_time == -1000)
86 boost_time = state.time;
91 public AltosFlightStats(AltosRecordIterable iterable) throws InterruptedException, IOException {
92 AltosState state = null;
93 AltosState new_state = null;
94 double boost_time = boost_time(iterable);
96 double landed_time = landed_time(iterable);
98 year = month = day = -1;
99 hour = minute = second = -1;
100 serial = flight = -1;
101 for (AltosRecord record : iterable) {
103 serial = record.serial;
104 if ((record.seen & AltosRecord.seen_flight) != 0 && flight < 0)
105 flight = record.flight;
106 new_state = new AltosState(record, state);
107 end_time = new_state.time;
109 if (state.time >= boost_time && state.state < Altos.ao_flight_boost)
110 state.state = Altos.ao_flight_boost;
111 if (state.time >= landed_time && state.state < Altos.ao_flight_landed)
112 state.state = Altos.ao_flight_landed;
113 if (0 <= state.state && state.state < Altos.ao_flight_invalid) {
114 if (state.state >= Altos.ao_flight_boost) {
115 if (state.gps != null && state.gps.locked &&
117 year = state.gps.year;
118 month = state.gps.month;
120 hour = state.gps.hour;
121 minute = state.gps.minute;
122 second = state.gps.second;
125 state_accel[state.state] += state.acceleration;
126 state_speed[state.state] += state.speed;
127 state_baro_speed[state.state] += state.baro_speed;
128 state_count[state.state]++;
129 if (state_start[state.state] == 0.0)
130 state_start[state.state] = state.time;
131 if (state_end[state.state] < state.time)
132 state_end[state.state] = state.time;
133 max_height = state.max_height;
134 if (state.max_speed != 0)
135 max_speed = state.max_speed;
137 max_speed = state.max_baro_speed;
138 max_acceleration = state.max_acceleration;
141 for (int s = Altos.ao_flight_startup; s <= Altos.ao_flight_landed; s++) {
142 if (state_count[s] > 0) {
143 state_speed[s] /= state_count[s];
144 state_baro_speed[s] /= state_count[s];
145 state_accel[s] /= state_count[s];
147 if (state_start[s] == 0)
148 state_start[s] = end_time;
149 if (state_end[s] == 0)
150 state_end[s] = end_time;