altosui: comment out un-used classes and associated imports
[fw/altos] / altosui / AltosGraphUI.java
1
2 // Copyright (c) 2010 Anthony Towns
3 // GPL v2 or later
4
5 package altosui;
6
7 import java.io.*;
8 import java.util.ArrayList;
9
10 import java.awt.*;
11 import javax.swing.*;
12 import org.altusmetrum.AltosLib.*;
13
14 import org.jfree.chart.ChartPanel;
15 import org.jfree.chart.JFreeChart;
16 import org.jfree.ui.RefineryUtilities;
17
18 public class AltosGraphUI extends AltosFrame 
19 {
20     JTabbedPane pane;
21
22     static final private Color red = new Color(194,31,31);
23     static final private Color green = new Color(31,194,31);
24     static final private Color blue = new Color(31,31,194);
25     //static final private Color black = new Color(31,31,31);
26     static final private Color yellow = new Color(194,194,31);
27     //static final private Color cyan = new Color(31,194,194);
28     static final private Color magenta = new Color(194,31,194);
29
30     static private class OverallGraphs {
31         AltosGraphTime.Element height = 
32                 new AltosGraphTime.TimeSeries(String.format("Height (%s)", AltosConvert.height.show_units()), "Height (AGL)", red) {
33                 public void gotTimeData(double time, AltosDataPoint d) {
34                         double  height = d.height();
35                         if (height != AltosRecord.MISSING)
36                                 series.add(time, AltosConvert.height.value(height));
37                 } 
38             };
39     
40         AltosGraphTime.Element speed =
41                 new AltosGraphTime.TimeSeries(String.format("Speed (%s)", AltosConvert.speed.show_units()), "Vertical Speed", green) { 
42                 public void gotTimeData(double time, AltosDataPoint d) {
43                     double      speed;
44                     if (d.state() < Altos.ao_flight_drogue && d.has_accel()) {
45                         speed = d.accel_speed();
46                     } else {
47                         speed = d.baro_speed();
48                     }
49                     if (speed != AltosRecord.MISSING)
50                             series.add(time, AltosConvert.speed.value(speed));
51                 }
52             };
53     
54         AltosGraphTime.Element acceleration =
55                 new AltosGraphTime.TimeSeries(String.format("Acceleration (%s)",
56                                                             AltosConvert.accel.show_units()),
57                                               "Axial Acceleration", blue)
58             {
59                 public void gotTimeData(double time, AltosDataPoint d) {
60                     double acceleration = d.acceleration();
61                     if (acceleration != AltosRecord.MISSING)
62                             series.add(time, AltosConvert.accel.value(acceleration));
63                 }
64             };
65     
66         AltosGraphTime.Element temperature =
67             new AltosGraphTime.TimeSeries("Temperature (\u00B0C)", 
68                     "Board temperature", red) 
69             {
70                 public void gotTimeData(double time, AltosDataPoint d) {
71                     double temp = d.temperature();
72                     if (temp != AltosRecord.MISSING)
73                         series.add(time, d.temperature());
74                 }
75             };
76     
77         AltosGraphTime.Element drogue_voltage =
78             new AltosGraphTime.TimeSeries("Voltage (V)", "Drogue Continuity", yellow) 
79             {
80                 public void gotTimeData(double time, AltosDataPoint d) {
81                     double v = d.drogue_voltage();
82                     if (v != AltosRecord.MISSING)
83                         series.add(time, v);
84                 }
85             };
86     
87         AltosGraphTime.Element main_voltage =
88             new AltosGraphTime.TimeSeries("Voltage (V)", "Main Continuity", magenta) 
89             {
90                 public void gotTimeData(double time, AltosDataPoint d) {
91                     double v = d.main_voltage();
92                     if (v != AltosRecord.MISSING)
93                         series.add(time, v);
94                 }
95             };
96     
97         //AltosGraphTime.Element e_pad    = new AltosGraphTime.StateMarker(Altos.ao_flight_pad, "Pad");
98         AltosGraphTime.Element e_boost  = new AltosGraphTime.StateMarker(Altos.ao_flight_boost, "Boost");
99         AltosGraphTime.Element e_fast   = new AltosGraphTime.StateMarker(Altos.ao_flight_fast, "Fast");
100         AltosGraphTime.Element e_coast  = new AltosGraphTime.StateMarker(Altos.ao_flight_coast, "Coast");
101         AltosGraphTime.Element e_drogue = new AltosGraphTime.StateMarker(Altos.ao_flight_drogue, "Drogue");
102         AltosGraphTime.Element e_main   = new AltosGraphTime.StateMarker(Altos.ao_flight_main, "Main");
103         AltosGraphTime.Element e_landed = new AltosGraphTime.StateMarker(Altos.ao_flight_landed, "Landed");
104     
105         protected AltosGraphTime myAltosGraphTime(String suffix) {
106             return (new AltosGraphTime("Overall " + suffix))
107                 .addElement(e_boost)
108                 .addElement(e_fast)
109                 .addElement(e_coast)
110                 .addElement(e_drogue)
111                 .addElement(e_main)
112                 .addElement(e_landed);
113         }
114     
115         public ArrayList<AltosGraph> graphs() {
116             ArrayList<AltosGraph> graphs = new ArrayList<AltosGraph>();
117     
118             graphs.add( myAltosGraphTime("Summary")
119                         .addElement(height)
120                         .addElement(speed)
121                         .addElement(acceleration) );
122
123             graphs.add( myAltosGraphTime("Summary")
124                         .addElement(height)
125                         .addElement(speed));
126     
127             graphs.add( myAltosGraphTime("Altitude")
128                     .addElement(height) );
129     
130             graphs.add( myAltosGraphTime("Speed")
131                     .addElement(speed) );
132     
133             graphs.add( myAltosGraphTime("Acceleration")
134                         .addElement(acceleration) );
135     
136             graphs.add( myAltosGraphTime("Temperature")
137                     .addElement(temperature) );
138     
139             graphs.add( myAltosGraphTime("Continuity")
140                         .addElement(drogue_voltage)
141                         .addElement(main_voltage) );
142     
143             return graphs;
144         }
145     }
146
147     /*
148     static private class AscentGraphs extends OverallGraphs {
149         protected AltosGraphTime myAltosGraphTime(String suffix) {
150             return (new AltosGraphTime("Ascent " + suffix) {
151                 public void addData(AltosDataPoint d) {
152                     int state = d.state();
153                     if (Altos.ao_flight_boost <= state && state <= Altos.ao_flight_coast) {
154                         super.addData(d);
155                     }
156                 }
157             }).addElement(e_boost)
158               .addElement(e_fast)
159               .addElement(e_coast);
160         }
161     }
162     */
163
164     /*
165     static private class DescentGraphs extends OverallGraphs {
166         protected AltosGraphTime myAltosGraphTime(String suffix) {
167             return (new AltosGraphTime("Descent " + suffix) {
168                 public void addData(AltosDataPoint d) {
169                     int state = d.state();
170                     if (Altos.ao_flight_drogue <= state && state <= Altos.ao_flight_main) {
171                         super.addData(d);
172                     }
173                 }
174             }).addElement(e_drogue)
175               .addElement(e_main);
176             // ((XYGraph)graph[8]).ymin = new Double(-50);
177         }
178     }
179     */
180
181         public AltosGraphUI(AltosRecordIterable records, String name) throws InterruptedException, IOException {
182                 super(String.format("Altos Graph %s", name));
183
184                 AltosDataPointReader reader = new AltosDataPointReader (records);
185                 if (reader == null)
186                         return;
187         
188                 if (reader.has_accel)
189                     init(reader, records, 0);
190                 else
191                     init(reader, records, 1);
192         }
193
194 //    public AltosGraphUI(AltosDataPointReader data, int which)
195     //  {
196 //        super("Altos Graph");
197 //        init(data, which);
198 //    }
199
200     private void init(AltosDataPointReader data, AltosRecordIterable records, int which) throws InterruptedException, IOException {
201         pane = new JTabbedPane();
202
203         AltosGraph graph = createGraph(data, which);
204
205         JFreeChart chart = graph.createChart();
206         ChartPanel chartPanel = new ChartPanel(chart);
207         chartPanel.setMouseWheelEnabled(true);
208         chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));
209         pane.add(graph.title, chartPanel);
210
211         AltosFlightStatsTable stats = new AltosFlightStatsTable(new AltosFlightStats(records));
212         pane.add("Flight Statistics", stats);
213
214         setContentPane (pane);
215
216         pack();
217
218         RefineryUtilities.centerFrameOnScreen(this);
219
220         setDefaultCloseOperation(DISPOSE_ON_CLOSE);
221         setVisible(true);
222     }
223
224     private static AltosGraph createGraph(Iterable<AltosDataPoint> data,
225             int which)
226     {
227         return createGraphsWhich(data, which).get(0);
228     }
229
230     /*
231     private static ArrayList<AltosGraph> createGraphs(
232             Iterable<AltosDataPoint> data)
233     {
234         return createGraphsWhich(data, -1);
235     }
236     */
237
238     private static ArrayList<AltosGraph> createGraphsWhich(
239             Iterable<AltosDataPoint> data, int which)
240     {
241         ArrayList<AltosGraph> graph = new ArrayList<AltosGraph>();
242         graph.addAll((new OverallGraphs()).graphs());
243 //        graph.addAll((new AscentGraphs()).graphs());
244 //        graph.addAll((new DescentGraphs()).graphs());
245
246         if (which > 0) {
247             if (which >= graph.size()) {
248                 which = 0;
249             }
250             AltosGraph g = graph.get(which);
251             graph = new ArrayList<AltosGraph>();
252             graph.add(g);
253         }
254
255         for (AltosDataPoint dp : data) {
256             for (AltosGraph g : graph) {
257                 g.addData(dp);
258             }
259         }
260
261         return graph;
262     }
263 }
264
265 /* gnuplot bits...
266  *
267 300x400
268
269 --------------------------------------------------------
270 TOO HARD! :)
271
272 "ascent-gps-accuracy.png" "Vertical error margin to apogee - GPS v Baro (m)"
273     5:($7 < 6 ? $24-$11 : 1/0)
274 "descent-gps-accuracy.png" "Vertical error margin during descent - GPS v Baro (m)"
275     5:($7 < 6 ? 1/0 : $24-$11)
276
277 set output "overall-gps-accuracy.png"
278 set ylabel "distance above sea level (m)"
279 plot "telemetry.csv" using 5:11 with lines ti "baro altitude" axis x1y1, \
280     "telemetry.csv" using 5:24 with lines ti "gps altitude" axis x1y1
281
282 set term png tiny size 700,700 enhanced
283 set xlabel "m"
284 set ylabel "m"
285 set polar
286 set grid polar
287 set rrange[*:*]
288 set angles degrees
289
290 set output "overall-gps-path.png"
291 #:30 with yerrorlines
292 plot "telemetry.csv" using (90-$33):($7 == 2 ? $31 : 1/0) with lines ti "pad", \
293     "telemetry.csv" using (90-$33):($7 == 3 ? $31 : 1/0) with lines ti "boost", \
294     "telemetry.csv" using (90-$33):($7 == 4 ? $31 : 1/0) with lines ti "fast", \
295     "telemetry.csv" using (90-$33):($7 == 5 ? $31 : 1/0) with lines ti "coast", \
296     "telemetry.csv" using (90-$33):($7 == 6 ? $31 : 1/0) with lines ti "drogue", \
297     "telemetry.csv" using (90-$33):($7 == 7 ? $31 : 1/0) with lines ti "main", \
298     "telemetry.csv" using (90-$33):($7 == 8 ? $31 : 1/0) with lines ti "landed"
299
300 set output "ascent-gps-path.png"
301 plot "telemetry.csv" using (90-$33):($7 == 2 ? $31 : 1/0):30 with lines ti "pad", \
302     "telemetry.csv" using (90-$33):($7 == 3 ? $31 : 1/0):20 with lines ti "boost", \
303     "telemetry.csv" using (90-$33):($7 == 4 ? $31 : 1/0):10 with lines ti "fast", \
304     "telemetry.csv" using (90-$33):($7 == 5 ? $31 : 1/0):5 with lines ti "coast"
305
306 set output "descent-gps-path.png"
307 plot "telemetry.csv" using (90-$33):($7 == 6 ? $31 : 1/0) with lines ti "drogue", \
308     "telemetry.csv" using (90-$33):($7 == 7 ? $31 : 1/0) with lines ti "main", \
309     "telemetry.csv" using (90-$33):($7 == 8 ? $31 : 1/0) with lines ti "landed"
310
311  */
312
313