private void DBUpdatePoint(TeachPoint tpoint) { // find data row DataRow dr = _dt.Rows.Find(tpoint.Name); if (dr == null) { return; } //dr["ID"] = tpoint.ID; //dr["Category"] = ""; //dr["GUID"] = tpoint.SavedBy; //dr["Time"] = DateTime.Now; for (int dim = 0; dim < tpoint.Dimension; dim++) { string dimName = tpoint.DimensionNames[dim]; for (int colIdx = 0; colIdx < _dt.Columns.Count; colIdx++) { string sColName = _dt.Columns[colIdx].Caption; if (sColName == dimName) { dr[colIdx] = tpoint[dim].ToString("F3"); } } } }
// Deserializes the class from the config file. public bool Load() { bool loaded = false; XmlSerializer mySerializer = null; FileStream myFileStream = null; try { // Create a Type array. Type [] extraTypes = new Type[3]; extraTypes[0] = typeof(NPoint); extraTypes[1] = typeof(TeachPoint); extraTypes[2] = typeof(TeachPointHistory); // Create the XmlSerializer instance. mySerializer = new XmlSerializer(typeof(TeachPointStore), extraTypes); FileInfo fi = new FileInfo(_fileName); // If the config file exists, open it. if (fi.Exists) { // Reading a file requires a FileStream. myFileStream = fi.OpenRead(); // Create a new instance of the PersistentXML by deserializing the config file. TeachPointStore pointStoreCopy = (TeachPointStore)mySerializer.Deserialize(myFileStream); foreach (TeachPoint tpoint in pointStoreCopy.Points) { TeachPoint localTeachPoint = GetPoint(tpoint.Name); if (localTeachPoint != null) { localTeachPoint.ShallowClone(tpoint); } } DBUpdate(); if (PointStoreChanged != null) { PointStoreChanged(); } loaded = true; } } catch (Exception ex) { Console.WriteLine("Failed to deserialize. Reason: " + ex.Message); } finally { // If the FileStream is open, close it. if (myFileStream != null) { myFileStream.Close(); } } return(loaded); }
private void UpdateStatistics(TeachPoint pt) { for (int i=0; i<pt.Dimension; i++) { if (history.Count == 1) { sum[i] = pt.Coordinate[i]; sumX2[i] = pt.Coordinate[i] * pt.Coordinate[i]; max[i] = pt.Coordinate[i]; min[i] = pt.Coordinate[i]; } else { sum[i] += pt.Coordinate[i]; sumX2[i] += (pt.Coordinate[i] * pt.Coordinate[i]); if (pt.Coordinate[i] > max[i]) max[i] = pt.Coordinate[i]; if (pt.Coordinate[i] < min[i]) min[i] = pt.Coordinate[i]; } } double tempVal = 0; for (int i=0; i<pt.Dimension; i++) { average[i] = sum[i]/history.Count; if (history.Count > 2) tempVal = (history.Count*sumX2[i] - sum[i]*sum[i])/(history.Count*(history.Count-1)); if (tempVal > 0) stdev[i] = Math.Sqrt(tempVal); else stdev[i] = 0; } LoadStatisticsTable(); }
public void SelectTeachPoint(TeachPoint point) { gridTeachPoints.UnSelect(gridTeachPoints.CurrentRowIndex); // find row number DataTable dt = (DataTable)gridTeachPoints.DataSource; int rowNum; for (rowNum = 0; rowNum < dt.Rows.Count; rowNum++) { DataRow row = dt.Rows[rowNum]; string ptn = row[0].ToString(); if (ptn == point.Name) { break; } } if (rowNum < dt.Rows.Count) { //lastRowSelect = rowNum; gridTeachPoints.Select(rowNum); gridTeachPoints.CurrentRowIndex = rowNum; _currentPoint = point; } }
public void ShallowClone(TeachPoint point) { NPoint npoint = point as NPoint; base.ShallowClone(npoint); // clone the rest this.History = point.History; // initialize history PointHistory.LoadInit(this); }
private void gridTeachPoinst_CurrentCellChanged(object sender, System.EventArgs e) { // find teach point int rowNum = gridTeachPoints.CurrentCell.RowNumber; string tpName = gridTeachPoints[rowNum, 0].ToString(); _currentPoint = pointStore.GetPoint(tpName); if (SelectEvent != null) { SelectEvent(_currentPoint); } }
// Methods ------------------------------------------------------------- public void ArchiveTeachPoint(TeachPoint point) { NPoint pt = new NPoint(point); history.Add(pt); UpdateStatistics(point); // remove oldest element(s) added (fifo) while (history.Count > queueSize) history.RemoveAt(0); LoadHistoryTable(); }
public void LoadInit(TeachPoint point) { average = new double[dimension]; stdev = new double[dimension]; sum = new double[dimension]; sumX2 = new double[dimension]; min = new double[dimension]; max = new double[dimension]; Recalculate(); CreateDBTable(point); LoadHistoryTable(); LoadStatisticsTable(); }
public TeachPointHistory(TeachPoint teachPoint, int historySize) { this.dimension = teachPoint.Dimension; this.queueSize = historySize; average = new double[dimension]; stdev = new double[dimension]; sum = new double[dimension]; sumX2 = new double[dimension]; min = new double[dimension]; max = new double[dimension]; ResetStatistics(); CreateDBTable(teachPoint); }
public TeachPoint CreateTeachPoint(string name, int historySize, string[] dimensionNames, double[] defaultValues) { TeachPoint teachPoint = GetPoint(name); Debug.Assert(teachPoint == null); teachPoint = new TeachPoint(name, historySize, dimensionNames, defaultValues); _teachPoints.Add(teachPoint); DBInsertPoint(teachPoint); teachPoint.PointChanged += new TeachPoint.PointChangedEventHandler(this.OnPointChange); if (PointStoreChanged != null) { PointStoreChanged(); } return(teachPoint); }
private void DBInsertPoint(TeachPoint tpoint) { // insert data DataRow dr = _dt.NewRow(); dr["Name"] = tpoint.Name; //dr["ID"] = tpoint.ID; //dr["Category"] = ""; //dr["GUID"] = tpoint.SavedBy; //dr["Time"] = DateTime.Now; // check/add column(s) for (int dim = 0; dim < tpoint.Dimension; dim++) { string dimName = tpoint.DimensionNames[dim]; double dimValue = tpoint[dim]; int colIdx; for (colIdx = 0; colIdx < _dt.Columns.Count; colIdx++) { string sColName = _dt.Columns[colIdx].Caption; if (sColName == dimName) { break; } } if (colIdx == _dt.Columns.Count) { // not found, add it in DataColumn axisPositionColumn = new DataColumn(); axisPositionColumn.DataType = System.Type.GetType("System.Double"); axisPositionColumn.Caption = dimName; axisPositionColumn.ColumnName = dimName; axisPositionColumn.AllowDBNull = true; _dt.Columns.Add(axisPositionColumn); } dr[dimName] = dimValue.ToString("F3"); } _dt.Rows.Add(dr); }
public TeachPoint GetPoint(string pointName) { TeachPoint tp = null; bool found = false; for (int tpidx = 0; tpidx < _teachPoints.Count; tpidx++) { tp = (TeachPoint)_teachPoints[tpidx]; if (tp.Name == pointName) { found = true; break; } } if (found) { return(tp); } else { return(null); } }
// Call this method from the Form_Load method, passing your ZedGraphControl public void CreateChart(ZedGraphControl zgc, TeachPoint tPoint) { // clear previous values GraphPane myPane = zgc.GraphPane; myPane.CurveList.Clear(); // Set the titles and axis labels // myPane.Title = "Teachpoint shift:" + tPoint.Name; // myPane.XAxis.Title = "Updates"; // myPane.YAxis.Title = "Parameter A"; // myPane.Y2Axis.Title = "Parameter B"; // Make up some data points based on the Sine function //PointPairList[] list = new PointPairList[tPoint.Dimension]; //PointPairList list = new PointPairList(); LineItem myCurve = null; SymbolType simbol = SymbolType.Circle; System.Drawing.Color color = Color.Blue; for (int dim = 0; dim < tPoint.Dimension; dim++) { PointPairList list = new PointPairList(); list.Clear(); for (int idx = 0; idx < tPoint.History.History.Count; idx++) { NPoint npoint = (NPoint)tPoint.History.History[idx]; double y = npoint.Coordinate[dim]; list.Add((double)idx, y); } myCurve = myPane.AddCurve(tPoint.DimensionNames[dim], list, color, simbol++); myCurve.Symbol.Fill = new Fill(Color.Gray); } // Associate this curve with the Y2 axis //myCurve.IsY2Axis = true; // // Show the x axis grid // myPane.XAxis.IsShowGrid = true; // // // Make the Y axis scale red // myPane.YAxis.ScaleFontSpec.FontColor = Color.Blue; // myPane.YAxis.TitleFontSpec.FontColor = Color.Blue; // // turn off the opposite tics so the Y tics don't show up on the Y2 axis // myPane.YAxis.IsOppositeTic = false; // myPane.YAxis.IsMinorOppositeTic = false; // // Don't display the Y zero line // myPane.YAxis.IsZeroLine = false; // // Align the Y axis labels so they are flush to the axis // myPane.YAxis.ScaleAlign = AlignP.Inside; // // Manually set the axis range // //myPane.YAxis.Min = -30; // //myPane.YAxis.Max = 30; // // Enable the Y2 axis display //myPane.Y2Axis.IsVisible = true; // Make the Y2 axis scale blue //myPane.Y2Axis.ScaleFontSpec.FontColor = Color.Blue; //myPane.Y2Axis.TitleFontSpec.FontColor = Color.Blue; // turn off the opposite tics so the Y2 tics don't show up on the Y axis //myPane.Y2Axis.IsOppositeTic = false; //myPane.Y2Axis.IsMinorOppositeTic = false; // Display the Y2 axis grid lines //myPane.Y2Axis.IsShowGrid = true; // Align the Y2 axis labels so they are flush to the axis //myPane.Y2Axis.ScaleAlign = AlignP.Inside; // Fill the axis background with a gradient // myPane.AxisFill = new Fill( Color.White, Color.LightGray, 45.0f ); // Calculate the Axis Scale Ranges zgc.AxisChange(); zgc.Refresh(); }
public void AssignTeachPoint(TeachPoint tPoint) { CreateChart(zedGraphControl1, tPoint); }
private void CreateDBTable(TeachPoint tpoint) { // Create a new DataTable titled 'Points.' _dtHist = new DataTable("History"); // check/add column(s); add dimensions for(int dim = 0; dim < tpoint.Dimension; dim++) { string dimName = tpoint.DimensionNames[dim]; double dimValue = tpoint[dim]; int colIdx; for (colIdx = 0; colIdx < _dtHist.Columns.Count; colIdx++) { string sColName = _dtHist.Columns[colIdx].Caption; if (sColName == dimName) break; } if (colIdx == _dtHist.Columns.Count) { // not found, add it in DataColumn axisPositionColumn = new DataColumn(); axisPositionColumn.DataType = System.Type.GetType("System.Double"); axisPositionColumn.Caption = dimName; axisPositionColumn.ColumnName = dimName; axisPositionColumn.AllowDBNull = true; _dtHist.Columns.Add(axisPositionColumn); } } /* DataColumn categoryColumn = new DataColumn(); categoryColumn.DataType = System.Type.GetType("System.String"); categoryColumn.Caption = "Category"; categoryColumn.ColumnName = "Category"; categoryColumn.AllowDBNull = false; _dtHist.Columns.Add(categoryColumn); DataColumn pointIDColumn = new DataColumn(); pointIDColumn.DataType = System.Type.GetType("System.Int32"); pointIDColumn.Caption = "ID"; pointIDColumn.ColumnName = "ID"; _dtHist.Columns.Add(pointIDColumn); */ DataColumn timestampColumn = new DataColumn(); timestampColumn.DataType = System.Type.GetType("System.DateTime"); timestampColumn.Caption = "Time"; timestampColumn.ColumnName = "Time"; timestampColumn.AllowDBNull = false; _dtHist.Columns.Add(timestampColumn); DataColumn guidColumn = new DataColumn(); guidColumn.DataType = System.Type.GetType("System.String"); guidColumn.Caption = "GUID"; guidColumn.ColumnName = "GUID"; guidColumn.AllowDBNull = false; _dtHist.Columns.Add(guidColumn); ///////////////////////////// // create Statistics table _dtStat = new DataTable("Statistics"); DataColumn statItemCol = new DataColumn(); statItemCol.DataType = System.Type.GetType("System.String"); statItemCol.Caption = "Item"; statItemCol.ColumnName = "Item"; statItemCol.AllowDBNull = true; _dtStat.Columns.Add(statItemCol); // check/add column(s); add dimensions for(int dim = 0; dim < tpoint.Dimension; dim++) { string dimName = tpoint.DimensionNames[dim]; double dimValue = tpoint[dim]; int colIdx; for (colIdx = 0; colIdx < _dtStat.Columns.Count; colIdx++) { string sColName = _dtStat.Columns[colIdx].Caption; if (sColName == dimName) break; } if (colIdx == _dtStat.Columns.Count) { DataColumn axisStatColumn = new DataColumn(); axisStatColumn.DataType = System.Type.GetType("System.Double"); axisStatColumn.Caption = dimName; axisStatColumn.ColumnName = dimName; axisStatColumn.AllowDBNull = true; _dtStat.Columns.Add(axisStatColumn); } } }
public void AssignTeachPoint(TeachPoint tPoint) { dataTeachHistoryStat.CaptionText = "Teach Point: " + tPoint.Name; dataTeachHistoryStat.DataSource = tPoint.History.StatisticsTable; dataTeachHistoryStat.Refresh(); }
public void AssignTeachPoint(TeachPoint tPoint) { gridTPointHistory.CaptionText = "Teach Point: " + tPoint.Name; gridTPointHistory.DataSource = tPoint.History.HistoryTable; gridTPointHistory.Refresh(); }