public void SelfTest() { var lsc = new LeastSquareCalculator(); lsc.Add(1, -1); lsc.Add(4, 11); lsc.Add(-1, -9); lsc.Add(-2, -13); Debug.Assert(lsc.Sloppe == 4); Debug.Assert(lsc.Ordinate == -5); }
private void ButtonCalculateSlopeAndOrdinateClick(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; try { DbReader.ExecuteNonQuery("exec TV_UpdateContainsValidTimeFlag"); _atc.Clear(); _atc.LoadFromDb(); string currentTrack = ""; string currentSurface = ""; string currentTrackDesc = ""; _projectionVariables = new List<ProjectionVariables>(); LeastSquareCalculator lsq = null; foreach (var at in _atc) { if (at.TrackCode != currentTrack || at.Surface != currentSurface) { if (null != lsq) { _projectionVariables.Add(new ProjectionVariables() {TrackCode = currentTrack, Surface = currentSurface, Slope = lsq.Sloppe, Ordinate = lsq.Ordinate, TrackDesc = currentTrackDesc}); } currentTrack = at.TrackCode; currentSurface = at.Surface; currentTrackDesc = at.TrackDesc; lsq = new LeastSquareCalculator(); } lsq.Add(at.Distance, at.FinalTime); } if (null != lsq) { _projectionVariables.Add(new ProjectionVariables() {TrackCode = currentTrack, Surface = currentSurface, Slope = lsq.Sloppe, Ordinate = lsq.Ordinate, TrackDesc = currentTrackDesc}); } _gridProjectionVariables.DataSource = _projectionVariables; } catch (Exception exception) { MessageBox.Show(exception.Message); } finally { Cursor = Cursors.Default; } }