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 double landed_time(AltosRecordIterable iterable) {
41 AltosState state = null;
42 for (AltosRecord record : iterable) {
43 state = new AltosState(record, state);
45 if (state.state == Altos.ao_flight_landed)
49 double landed_height = state.height;
55 double landed_time = -1000;
57 for (AltosRecord record : iterable) {
58 state = new AltosState(record, state);
60 if (state.height > landed_height + 10) {
63 if (above && state.height < landed_height + 2) {
65 landed_time = state.time;
69 if (landed_time == -1000)
70 landed_time = state.time;
74 double boost_time(AltosRecordIterable iterable) {
75 double boost_time = -1000;
77 AltosState state = null;
79 for (AltosRecord record : iterable) {
80 state = new AltosState(record, state);
82 if (state.acceleration < 1)
83 boost_time = state.time;
84 if (state.state >= Altos.ao_flight_boost)
87 if (boost_time == -1000)
88 boost_time = state.time;
93 public AltosFlightStats(AltosRecordIterable iterable) throws InterruptedException, IOException {
94 AltosState state = null;
95 AltosState new_state = null;
96 double boost_time = boost_time(iterable);
98 double landed_time = landed_time(iterable);
100 year = month = day = -1;
101 hour = minute = second = -1;
102 serial = flight = -1;
104 for (AltosRecord record : iterable) {
106 serial = record.serial;
107 if ((record.seen & AltosRecord.seen_flight) != 0 && flight < 0)
108 flight = record.flight;
109 new_state = new AltosState(record, state);
110 end_time = new_state.time;
112 if (state.time >= boost_time && state.state < Altos.ao_flight_boost)
113 state.state = Altos.ao_flight_boost;
114 if (state.time >= landed_time && state.state < Altos.ao_flight_landed)
115 state.state = Altos.ao_flight_landed;
116 if (0 <= state.state && state.state < Altos.ao_flight_invalid) {
117 if (state.state >= Altos.ao_flight_boost) {
118 if (state.gps != null && state.gps.locked &&
120 year = state.gps.year;
121 month = state.gps.month;
123 hour = state.gps.hour;
124 minute = state.gps.minute;
125 second = state.gps.second;
128 state_accel[state.state] += state.acceleration;
129 state_accel_speed[state.state] += state.accel_speed;
130 state_baro_speed[state.state] += state.baro_speed;
131 state_count[state.state]++;
132 if (state_start[state.state] == 0.0)
133 state_start[state.state] = state.time;
134 if (state_end[state.state] < state.time)
135 state_end[state.state] = state.time;
136 max_height = state.max_height;
137 if (state.max_accel_speed != 0)
138 max_speed = state.max_accel_speed;
140 max_speed = state.max_baro_speed;
141 max_acceleration = state.max_acceleration;
143 if (state.gps.locked && state.gps.nsat >= 4) {
144 if (state.state <= Altos.ao_flight_pad) {
145 pad_lat = state.gps.lat;
146 pad_lon = state.gps.lon;
152 for (int s = Altos.ao_flight_startup; s <= Altos.ao_flight_landed; s++) {
153 if (state_count[s] > 0) {
154 state_accel_speed[s] /= state_count[s];
155 state_baro_speed[s] /= state_count[s];
156 state_accel[s] /= state_count[s];
158 if (state_start[s] == 0)
159 state_start[s] = end_time;
160 if (state_end[s] == 0)
161 state_end[s] = end_time;