altoslib: Make sure AltosFlightSeries is filled in before use
authorKeith Packard <keithp@keithp.com>
Sat, 27 May 2017 00:14:29 +0000 (17:14 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 27 May 2017 00:14:29 +0000 (17:14 -0700)
After all of the raw data is captured, the derived data needs to be
computed by calling the 'finish' function.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosCSV.java
altoslib/AltosDataListener.java
altoslib/AltosEepromRecordSet.java
altoslib/AltosFlightSeries.java
altoslib/AltosFlightStats.java
altoslib/AltosTelemetryFile.java
altoslib/AltosTelemetryRecordSet.java
altosui/AltosGraphUI.java
altosuilib/AltosUIFlightSeries.java

index 38afdc6..5117a70 100644 (file)
@@ -393,7 +393,7 @@ public class AltosCSV implements AltosWriter {
 
                this.series = series;
 
-               series.fill_in();
+               series.finish();
 
                has_flight_state = false;
                has_basic = false;
index 4a6fe04..14c29d8 100644 (file)
@@ -36,6 +36,10 @@ public abstract class AltosDataListener {
                        this.state = state;
        }
 
+       /* Called after all records are captured */
+       public void finish() {
+       }
+
        public abstract void set_rssi(int rssi, int status);
        public abstract void set_received_time(long received_time);
 
index 69159cd..183cb9a 100644 (file)
@@ -44,6 +44,7 @@ public class AltosEepromRecordSet implements AltosRecordSet {
                for (AltosEepromRecord record : ordered) {
                        record.provide_data(listener, cal_data);
                }
+               listener.finish();
        }
 
        public AltosEepromRecordSet(AltosEepromNew eeprom) {
index 7bedf38..6f4f7bb 100644 (file)
@@ -18,7 +18,7 @@ import java.util.*;
 
 public class AltosFlightSeries extends AltosDataListener {
 
-       public ArrayList<AltosTimeSeries> series;
+       public ArrayList<AltosTimeSeries> series = new ArrayList<AltosTimeSeries>();
 
        public int[] indices() {
                int[] indices = new int[series.size()];
@@ -206,8 +206,9 @@ public class AltosFlightSeries extends AltosDataListener {
                altitude_series.add(time(), altitude);
        }
 
-       private void compute_height(double ground_altitude) {
-               if (height_series == null) {
+       private void compute_height() {
+               double ground_altitude = cal_data.ground_altitude;
+               if (height_series == null && ground_altitude != AltosLib.MISSING) {
                        height_series = add_series(height_name, AltosConvert.height);
                        for (AltosTimeValue alt : altitude_series)
                                height_series.add(alt.time, alt.value - ground_altitude);
@@ -563,25 +564,18 @@ public class AltosFlightSeries extends AltosDataListener {
        public void set_companion(AltosCompanion companion) {
        }
 
-       public void fill_in() {
+       public void finish() {
                compute_speed();
                compute_accel();
-               if (cal_data.ground_altitude != AltosLib.MISSING)
-                       compute_height(cal_data.ground_altitude);
-       }
-
-       public void init() {
-               time = AltosLib.MISSING;
-               series = new ArrayList<AltosTimeSeries>();
+               compute_height();
        }
 
        public AltosTimeSeries[] series() {
-               fill_in();
+               finish();
                return series.toArray(new AltosTimeSeries[0]);
        }
 
        public AltosFlightSeries(AltosCalData cal_data) {
                super(cal_data);
-               init();
        }
 }
index 2948ad3..32beb8b 100644 (file)
@@ -59,7 +59,7 @@ public class AltosFlightStats {
                }
 
                if (landed_state_time == AltosLib.MISSING)
-                       return AltosLib.MISSING;
+                       landed_state_time = series.height_series.get(series.height_series.size()-1).time;
 
                double landed_height = AltosLib.MISSING;
                for (AltosTimeValue height : series.height_series) {
@@ -115,6 +115,8 @@ public class AltosFlightStats {
                double          end_time = 0;
                double          landed_time = landed_time(series);
 
+               series.finish();
+
                year = month = day = AltosLib.MISSING;
                hour = minute = second = AltosLib.MISSING;
                serial = flight = AltosLib.MISSING;
@@ -136,7 +138,7 @@ public class AltosFlightStats {
                                state_start[s] = boost_time;
                        else
                                state_start[s] = series.state_series.time_of(s);
-                       if (s == AltosLib.ao_flight_landed)
+                       if (s == AltosLib.ao_flight_main)
                                state_end[s] = landed_time;
                        else
                                state_end[s] = series.state_series.time_of(s+1);
index 8adf7e6..46a5d06 100644 (file)
@@ -124,6 +124,7 @@ public class AltosTelemetryFile implements AltosRecordSet {
                        if (cal_data.time() >= -1)
                                telem.provide_data(listener, cal_data);
                }
+               listener.finish();
        }
 
        public AltosTelemetryFile(FileInputStream input) {
index 0cb9526..0323c25 100644 (file)
@@ -21,10 +21,11 @@ public class AltosTelemetryRecordSet implements AltosRecordSet {
        AltosTelemetry                  telemetry;
        TreeSet<AltosTelemetryRecord>   ordered;
 
-       public void capture_series(AltosDataListener series) {
+       public void capture_series(AltosDataListener listener) {
                for (AltosTelemetryRecord record : ordered) {
-                       record.update_state(series);
+                       record.update_state(listener);
                }
+               listener.finish();
        }
 
        public AltosTelemetryRecordSet(AltosTelemetry telemetry) {
index a3107f2..db0cac2 100644 (file)
@@ -93,7 +93,7 @@ public class AltosGraphUI extends AltosUIFrame implements AltosFontListener, Alt
 
                set.capture_series(flight_series);
 
-               flight_series.fill_in();
+               flight_series.finish();
 
                stats = new AltosFlightStats(flight_series);
 
index 0bcc8a6..eade12a 100644 (file)
@@ -113,7 +113,7 @@ public class AltosUIFlightSeries extends AltosFlightSeries {
        }
 
        public AltosUITimeSeries[] series(AltosCalData cal_data) {
-               fill_in();
+               finish();
                return series.toArray(new AltosUITimeSeries[0]);
        }