public void FromBufferTest() { var target = new AccelParams(); var expected = new AccelParams { SensorNumber = 1, OffsetX = 20.0, OffsetY = -75.0, GravityX = -20.0, GravityY = 75.0 }; var buffer = new DataBuffer(Endianness.LittleEndian); buffer.WriteUInt16(1); buffer.WriteDouble(20.0); buffer.WriteDouble(-75.0); buffer.WriteDouble(-20.0); buffer.WriteDouble(75.0); target.FromBuffer(buffer); var tt = new DataBuffer(Endianness.LittleEndian); target.ToBuffer(tt); Assert.AreEqual(expected.SensorNumber,target.SensorNumber); Assert.AreEqual(expected.OffsetX, target.OffsetX); Assert.AreEqual(expected.OffsetY, target.OffsetY); Assert.AreEqual(expected.GravityX, target.GravityX); Assert.AreEqual(expected.GravityY, target.GravityY); }
public void ToBufferTest() { var target = new AccelParams { SensorNumber = 1, OffsetX = 20.0, OffsetY = -75.0, GravityX = 20.0, GravityY = -75.0 }; var expected = new byte[] { 1,0,0, 0, 0, 0, 0, 0, 52, 64, 0, 0, 0, 0, 0, 192, 82, 192, 0, 0, 0, 0, 0, 0, 52, 64, 0, 0, 0, 0, 0, 192, 82, 192 }; var buffer = new DataBuffer(Endianness.LittleEndian); target.ToBuffer(buffer); CollectionAssert.AreEqual(expected, buffer.RawData); }
/// <summary> /// Конструктор /// </summary> public CalibrationResult() { Parameters = new AccelParams(); Clusters = new List<AccelData>(); }
public void SaveAccelParamsTest() { string databaseFile = _testDbFile; ILogger logger = new LoggerStub(); var target = new LocalDatabaseStorage(databaseFile, logger); target.Open(); var data = new AccelParams { Date = DateTime.Now }; target.SaveAccelParams(data); var idCount = _testDb.GetIdCount("accel_params"); Assert.AreEqual(idCount, 1, "проверяем, что запись добавлена"); Assert.AreEqual(1, data.Id, "проверяем, что изменен идентификатор записи в базе"); target.Close(); }
/// <summary> /// Обновляет запись в базе /// </summary> /// <param name="data"></param> private void UpdateAccelParams(AccelParams data) { var command = new SqlCeCommand(); command.Connection = _connection; command.CommandText = @"UPDATE accel_params SET date=@date,sensorNumber=@sensorNumber, offsetX=@offsetX,offsetY=@offsetY,gravityX=@gravityX,gravityY=@gravityY WHERE id = @id"; command.Parameters.AddWithValue("@id", data.Id); command.Parameters.AddWithValue("@date", data.Date); command.Parameters.AddWithValue("@sensorNumber", data.SensorNumber); command.Parameters.AddWithValue("@offsetX", data.OffsetX); command.Parameters.AddWithValue("@offsetY", data.OffsetY); command.Parameters.AddWithValue("@gravityX", data.GravityX); command.Parameters.AddWithValue("@gravityY", data.GravityY); command.ExecuteNonQuery(); }
public void GetCalibrationResultByParamsTest() { _testDb.CreateDatabase(); _testDb.InitTestSchema(); _testDb.PopulateTestAccelData(); _testDb.PopulateTestAccelParams(); _testDb.PopulateTestCalibrationResult(); string databaseFile = _testDbFile; ILogger logger = new LoggerStub(); var target = new LocalDatabaseStorage(databaseFile, logger); target.Open(); var parameters = new AccelParams {Id = 1}; var actual = target.GetCalibrationResultByParams(parameters); Assert.AreEqual(2,actual.Clusters.Count); target.Close(); }
/// <summary> /// Удаляет результатов калбировки для заданных параметров /// </summary> /// <param name="parameters"></param> private void DeleteCalibrationResult(AccelParams parameters) { var command = new SqlCeCommand(); command.Connection = _connection; command.CommandText = @"DELETE FROM calibr_result WHERE accelParamsId = @id"; command.Parameters.AddWithValue("@id", parameters.Id); command.ExecuteNonQuery(); }
/// <summary> /// Создает в базе запись /// </summary> /// <param name="data"></param> private void CreateAccelParams(AccelParams data) { var command = new SqlCeCommand(); command.Connection = _connection; command.CommandText = @"INSERT INTO accel_params (date,sensorNumber, offsetX,offsetY,gravityX,gravityY) VALUES(@date,@sensorNumber,@offsetX,@offsetY,@gravityX,@gravityY)"; command.Parameters.AddWithValue("@date", data.Date); command.Parameters.AddWithValue("@sensorNumber", data.SensorNumber); command.Parameters.AddWithValue("@offsetX", data.OffsetX); command.Parameters.AddWithValue("@offsetY", data.OffsetY); command.Parameters.AddWithValue("@gravityX", data.GravityX); command.Parameters.AddWithValue("@gravityY", data.GravityY); command.ExecuteNonQuery(); command.CommandText = "SELECT @@IDENTITY"; var id = command.ExecuteScalar(); if (id != null) { data.Id = Convert.ToInt32((decimal)id); // записываем идентификатор записи в базе } }
/// <summary> /// Сохраняет в базе калибровочные данные /// </summary> /// <param name="data"></param> public void SaveAccelParams(AccelParams data) { if (data.Id > 0) { UpdateAccelParams(data); } else { CreateAccelParams(data); } }
/// <summary> /// Делает выборку по результатам калибровки для указанного идентификатора калибровочных параметров /// </summary> public CalibrationResult GetCalibrationResultByParams(AccelParams parameters) { var result = new CalibrationResult {Parameters = parameters}; var command = new SqlCeCommand(); command.Connection = _connection; command.CommandText = @"SELECT data.Id, data.date, data.Ax, data.Ay FROM calibr_result result JOIN accel_data data ON (result.accelDataId = data.id) WHERE result.accelParamsId = @paramsId"; command.Parameters.AddWithValue("@paramsId", parameters.Id); var reader = command.ExecuteReader(); while (reader.Read()) { var data = new AccelData(); data.Id = reader.GetInt32(0); data.Date = reader.GetDateTime(1); data.Ax = reader.GetDouble(2); data.Ay = reader.GetDouble(3); result.Clusters.Add(data); } return result; }
/// <summary> /// Возвращает калибровочных данных для указанного номера датчика /// </summary> /// <param name="sensorNumber">номер датчика</param> /// <returns></returns> public IList<AccelParams> GetAccelParamsBySensorNumber(UInt16 sensorNumber) { var result = new List<AccelParams>(); var command = new SqlCeCommand(); command.Connection = _connection; command.CommandText = @"SELECT date,sensorNumber,offsetX,offsetY,gravityX,gravityY FROM accel_params WHERE sensorNumber = @sensorNumber"; command.Parameters.AddWithValue("@sensorNumber", sensorNumber); var reader = command.ExecuteReader(); while (reader.Read()) { var data = new AccelParams(); data.Date = reader.GetDateTime(0); data.SensorNumber = (UInt16)reader.GetInt16(1); data.OffsetX = reader.GetDouble(2); data.OffsetY = reader.GetDouble(3); data.GravityX = reader.GetDouble(4); data.GravityY = reader.GetDouble(5); result.Add(data); } return result; }