Merge remote-tracking branch 'origin/micropeak-logging'
[fw/altos] / altosui / AltosGraphUI.java
index 4b994b4775cafd84ddadc4a0d6cc4211cdd9ab6b..d6891ffa04d33e7bb719b4cbd449700b582deddd 100644 (file)
@@ -7,77 +7,90 @@ package altosui;
 import java.io.*;
 import java.util.ArrayList;
 
-import javax.swing.JFrame;
-import java.awt.Color;
+import java.awt.*;
+import javax.swing.*;
+import org.altusmetrum.AltosLib.*;
+import org.altusmetrum.altosuilib.*;
 
 import org.jfree.chart.ChartPanel;
-import org.jfree.chart.ChartUtilities;
 import org.jfree.chart.JFreeChart;
-import org.jfree.chart.axis.AxisLocation;
-import org.jfree.ui.ApplicationFrame;
 import org.jfree.ui.RefineryUtilities;
 
-public class AltosGraphUI extends JFrame 
+public class AltosGraphUI extends AltosUIFrame 
 {
+    JTabbedPane        pane;
+
     static final private Color red = new Color(194,31,31);
     static final private Color green = new Color(31,194,31);
     static final private Color blue = new Color(31,31,194);
-    static final private Color black = new Color(31,31,31);
+    //static final private Color black = new Color(31,31,31);
+    static final private Color yellow = new Color(194,194,31);
+    //static final private Color cyan = new Color(31,194,194);
+    static final private Color magenta = new Color(194,31,194);
 
     static private class OverallGraphs {
         AltosGraphTime.Element height = 
-            new AltosGraphTime.TimeSeries("Height (m)", "Height (AGL)", red) {
+               new AltosGraphTime.TimeSeries("Height", AltosConvert.height.show_units(), "Height (AGL)", red) {
                 public void gotTimeData(double time, AltosDataPoint d) {
-                    series.add(time, d.height()); 
+                       double  height = d.height();
+                       if (height != AltosRecord.MISSING)
+                               series.add(time, AltosConvert.height.value(height));
                 } 
             };
     
         AltosGraphTime.Element speed =
-            new AltosGraphTime.TimeSeries("Speed (m/s)", "Vertical Speed", green) { 
+               new AltosGraphTime.TimeSeries("Speed", AltosConvert.speed.show_units(), "Vertical Speed", green) { 
                 public void gotTimeData(double time, AltosDataPoint d) {
-                   if (d.state() < Altos.ao_flight_drogue && d.has_accel()) {
-                        series.add(time, d.accel_speed());
-                    } else {
-                        series.add(time, d.baro_speed());
-                    }
+                   double      speed = d.speed();
+                   if (speed != AltosRecord.MISSING)
+                           series.add(time, AltosConvert.speed.value(speed));
                 }
             };
     
         AltosGraphTime.Element acceleration =
-            new AltosGraphTime.TimeSeries("Acceleration (m/s\u00B2)", 
-                    "Axial Acceleration", blue) 
+               new AltosGraphTime.TimeSeries("Acceleration",
+                                             AltosConvert.accel.show_units(),
+                                             "Axial Acceleration", blue)
             {
                 public void gotTimeData(double time, AltosDataPoint d) {
-                    series.add(time, d.acceleration());
+                   double acceleration = d.acceleration();
+                   if (acceleration != AltosRecord.MISSING)
+                           series.add(time, AltosConvert.accel.value(acceleration));
                 }
             };
     
         AltosGraphTime.Element temperature =
-            new AltosGraphTime.TimeSeries("Temperature (\u00B0C)", 
-                    "Board temperature", red) 
+           new AltosGraphTime.TimeSeries("Temperature", "\u00B0C", 
+                                         "Board temperature", red) 
             {
                 public void gotTimeData(double time, AltosDataPoint d) {
-                    series.add(time, d.temperature());
+                   double temp = d.temperature();
+                   if (temp != AltosRecord.MISSING)
+                       series.add(time, d.temperature());
                 }
             };
     
         AltosGraphTime.Element drogue_voltage =
-            new AltosGraphTime.TimeSeries("Voltage (V)", "Drogue Continuity", blue
+            new AltosGraphTime.TimeSeries("Voltage", "(V)", "Drogue Continuity", yellow
             {
                 public void gotTimeData(double time, AltosDataPoint d) {
-                    series.add(time, d.drogue_voltage());
+                   double v = d.drogue_voltage();
+                   if (v != AltosRecord.MISSING)
+                       series.add(time, v);
                 }
             };
     
         AltosGraphTime.Element main_voltage =
-            new AltosGraphTime.TimeSeries("Voltage (V)", "Main Continuity", green
+            new AltosGraphTime.TimeSeries("Voltage", "(V)", "Main Continuity", magenta
             {
                 public void gotTimeData(double time, AltosDataPoint d) {
-                    series.add(time, d.main_voltage());
+                   double v = d.main_voltage();
+                   if (v != AltosRecord.MISSING)
+                       series.add(time, v);
                 }
             };
     
-        AltosGraphTime.Element e_pad    = new AltosGraphTime.StateMarker(Altos.ao_flight_pad, "Pad");
+        //AltosGraphTime.Element e_pad    = new AltosGraphTime.StateMarker(Altos.ao_flight_pad, "Pad");
         AltosGraphTime.Element e_boost  = new AltosGraphTime.StateMarker(Altos.ao_flight_boost, "Boost");
         AltosGraphTime.Element e_fast   = new AltosGraphTime.StateMarker(Altos.ao_flight_fast, "Fast");
         AltosGraphTime.Element e_coast  = new AltosGraphTime.StateMarker(Altos.ao_flight_coast, "Coast");
@@ -88,6 +101,8 @@ public class AltosGraphUI extends JFrame
         protected AltosGraphTime myAltosGraphTime(String suffix) {
             return (new AltosGraphTime("Overall " + suffix))
                 .addElement(e_boost)
+               .addElement(e_fast)
+               .addElement(e_coast)
                 .addElement(e_drogue)
                 .addElement(e_main)
                 .addElement(e_landed);
@@ -124,7 +139,8 @@ public class AltosGraphUI extends JFrame
             return graphs;
         }
     }
-    
+
+    /*
     static private class AscentGraphs extends OverallGraphs {
         protected AltosGraphTime myAltosGraphTime(String suffix) {
             return (new AltosGraphTime("Ascent " + suffix) {
@@ -139,7 +155,9 @@ public class AltosGraphUI extends JFrame
               .addElement(e_coast);
         }
     }
-    
+    */
+
+    /*
     static private class DescentGraphs extends OverallGraphs {
         protected AltosGraphTime myAltosGraphTime(String suffix) {
             return (new AltosGraphTime("Descent " + suffix) {
@@ -154,34 +172,40 @@ public class AltosGraphUI extends JFrame
             // ((XYGraph)graph[8]).ymin = new Double(-50);
         }
     }
+    */
 
-       public AltosGraphUI(AltosRecordIterable records) {
-               super("Altos Graph");
+       public AltosGraphUI(AltosRecordIterable records, String name) throws InterruptedException, IOException {
+               super(String.format("Altos Graph %s", name));
 
                AltosDataPointReader reader = new AltosDataPointReader (records);
-               if (reader == null)
-                       return;
         
                if (reader.has_accel)
-                       init(reader, 0);
+                   init(reader, records, 0);
                else
-                       init(reader, 1);
+                   init(reader, records, 1);
        }
 
-    public AltosGraphUI(AltosDataPointReader data, int which)
-    {
-        super("Altos Graph");
-        init(data, which);
-    }
+//    public AltosGraphUI(AltosDataPointReader data, int which)
+    //  {
+//        super("Altos Graph");
+//        init(data, which);
+//    }
+
+    private void init(AltosDataPointReader data, AltosRecordIterable records, int which) throws InterruptedException, IOException {
+       pane = new JTabbedPane();
 
-    private void init(AltosDataPointReader data, int which) {
         AltosGraph graph = createGraph(data, which);
 
         JFreeChart chart = graph.createChart();
         ChartPanel chartPanel = new ChartPanel(chart);
         chartPanel.setMouseWheelEnabled(true);
         chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));
-        setContentPane(chartPanel);
+        pane.add(graph.title, chartPanel);
+
+       AltosFlightStatsTable stats = new AltosFlightStatsTable(new AltosFlightStats(records));
+       pane.add("Flight Statistics", stats);
+
+       setContentPane (pane);
 
         pack();
 
@@ -197,19 +221,21 @@ public class AltosGraphUI extends JFrame
         return createGraphsWhich(data, which).get(0);
     }
 
+    /*
     private static ArrayList<AltosGraph> createGraphs(
             Iterable<AltosDataPoint> data)
     {
         return createGraphsWhich(data, -1);
     }
+    */
 
     private static ArrayList<AltosGraph> createGraphsWhich(
             Iterable<AltosDataPoint> data, int which)
     {
         ArrayList<AltosGraph> graph = new ArrayList<AltosGraph>();
         graph.addAll((new OverallGraphs()).graphs());
-        graph.addAll((new AscentGraphs()).graphs());
-        graph.addAll((new DescentGraphs()).graphs());
+//        graph.addAll((new AscentGraphs()).graphs());
+//        graph.addAll((new DescentGraphs()).graphs());
 
         if (which > 0) {
             if (which >= graph.size()) {