Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Linq;
- using System.Text;
- using System.IO;
- using ZedGraph;
- using FileHelpers;
- namespace DataAnalysisGUI
- {
- class mathStuff
- {
- // Set up initial variables
- DataVars[] fileData;
- double[][] jerkData = new double[2][];
- public void analyseData(string filename, ZedGraphControl zgc)
- {
- readDataFile(filename);
- double[] xAccel = new double[this.fileData.Length];
- double[] yAccel = new double[this.fileData.Length];
- for (int i = 0; i < this.fileData.Length; i++)
- {
- xAccel[i] = this.fileData[i].xAccel;
- yAccel[i] = this.fileData[i].yAccel;
- }
- double[] xAccelc = calibData(xAccel, 1.3);
- double[] yAccelc = calibData(yAccel, -1.3);
- this.jerkData[0] = this.numericalDiff(xAccelc);
- this.jerkData[1] = this.numericalDiff(yAccelc);
- CreateChart(zgc);
- }
- public void CreateChart(ZedGraphControl zgc)
- {
- GraphPane myPane = zgc.GraphPane;
- // Set the titles
- myPane.Title.Text = "Test Plot of Data";
- myPane.XAxis.Title.Text = "X Accel";
- myPane.YAxis.Title.Text = "X Jerk";
- // Fill the background of the chart rect and pane
- myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f);
- myPane.Fill = new Fill(Color.White, Color.SlateGray, 45.0f);
- // Populate a PointPairList
- PointPairList list = new PointPairList();
- for (int i = 0; i < this.fileData.Length; i++)
- {
- list.Add(this.fileData[i].xAccel, this.jerkData[0][i]);
- }
- // Add the curve
- LineItem myCurve = myPane.AddCurve("Data Points", list, Color.Black, SymbolType.Circle);
- // Don't display the line (This makes a scatter plot)
- myCurve.Line.IsVisible = false;
- // Hide the symbol outline
- myCurve.Symbol.Border.IsVisible = false;
- // Fill the symbol interior with color
- myCurve.Symbol.Fill = new Fill(Color.Firebrick);
- zgc.AxisChange();
- zgc.Refresh();
- }
- [DelimitedRecord(",")]
- private class DataVars
- {
- public double time;
- public double xAccel;
- public double yAccel;
- public double zAccel;
- public double alt;
- public double gpsLat;
- public double gpsLong;
- public double speed;
- }
- private class dataCoefs
- {
- public double[] alpha_PPAL = new double[3] {2, 3, 5};
- public double alpha_DTV = 1;
- public double[] atl = new double[3] { .0910, .159, .227 };
- public double[] dtl = new double[3] { -.141, -.235, -.329 };
- public double[] jtl = new double[3] { 1, 2, 3 };
- public double phi = 2.88;
- public double tau = 2.5;
- public double vt = 125.5;
- }
- private double[] numericalDiff(double[] values)
- {
- double[] diff = new double[values.Length];
- for (int i=1; i < values.Length; i++)
- {
- diff[i] = values[i] - values[i - 1];
- }
- diff[0] = diff[1];
- return diff;
- }
- private double[] calibData(double[] data, double offset)
- {
- double[] calibValues = new double[data.Length];
- for (int i = 0; i < data.Length; i++)
- {
- calibValues[i] = data[i] + offset;
- }
- return calibValues;
- }
- /* Under Construction Still
- private double[][] createLimitPlots()
- {
- dataCoefs data = new dataCoefs();
- double[] ra = new double[2];
- double[] rj = new double[2];
- double[] ca = new double[2];
- double[] cj = new double[2];
- for (int i=0; i<2; i++)
- {
- ra[i] = .5 * (data.atl[i] - data.dtl[i]);
- rj[i] = data.jtl[i];
- ca[i] = data.atl[i] - ra[i];
- cj[i] = data.jtl[i] - rj[i];
- for (int theta=0; theta<360; theta++)
- {
- theta_rad = deg2rad[theta];
- plots[1][i][theta+1] = ra[i]*cos[phi_rad]*cos[theta_rad]-rj[i]*sin[phi_rad]*sin[theta_rad]+ca[i];
- plots[2][i][theta+1] = rj[i]*cos[phi_rad]*sin[theta_rad]+ra[i]*sin[phi_rad]*cos[theta_rad]+cj[i];
- }
- }
- return 3.0;
- }
- private double[] deg2rad(double[] rad)
- {
- return 5;
- }
- */
- private void readDataFile(string filename)
- {
- FileHelperEngine engine = new FileHelperEngine(typeof(DataVars));
- engine.Options.IgnoreFirstLines = 1;
- try
- {
- DataVars[] result = engine.ReadFile(filename.Trim()) as DataVars[];
- this.fileData = result;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment