public async Task <IActionResult> Create(ShellTemperatureRecord record) { try { if (!record.RecordedDateTime.HasValue) { record.RecordedDateTime = DateTime.Now; } ShellTemp shellTemp = new ShellTemp(record.Id, record.Temperature, (DateTime)record.RecordedDateTime, record.Latitude, record.Longitude, record.DeviceInfo); bool result = await _shellTempRepository.Create(shellTemp); if (!result) { return(BadRequest()); } return(Ok()); } catch (ArgumentNullException ex) { return(BadRequest()); } }
public void WriteShellTempsToExcelFile() { // Arrange // path and sheet info for the excel file string path = Path.GetTempPath() + Guid.NewGuid() + ".xlsx"; const string worksheetName = "test"; IExcelData excelData = new ExcelData(path); IExcelStyler excelStyler = new ExcelStyler(excelData); excelData.CreateExcelWorkSheet(path, worksheetName); bool exists = File.Exists(path); Assert.IsTrue(exists); Assert.IsTrue(excelData.Package != null); Assert.IsTrue(excelData.Worksheet != null); Assert.AreEqual(worksheetName, excelData.Worksheet.Name); ExcelWriter excelWriter = new ExcelWriter(excelData, excelStyler); Random random = new Random(); ShellTemperatureRecord[] temps = new ShellTemperatureRecord[1000]; for (int i = 0; i < temps.Length; i++) { float? lat = null; float? lon = null; DeviceInfo device = new DeviceInfo { DeviceAddress = "CraigsAddress", DeviceName = "Spiderman", Id = Guid.NewGuid() }; if (i % 4 == 0) { lat = random.Next(0, 1000); lon = random.Next(0, 4000); } ShellTemperatureRecord temp = new ShellTemperatureRecord { Id = Guid.NewGuid(), Latitude = lat, Longitude = lon, Temperature = random.Next(20, 80), RecordedDateTime = DateTime.Now, Device = device, Comment = i.ToString() }; temps[i] = temp; } // add headers string[] headers = temps[0].GetType().GetProperties().Select(x => x.Name).ToArray(); excelWriter.WriteHeaders(headers); excelWriter.WriteToExcelFile(temps); Assert.AreEqual(temps.Length, excelData.Worksheet.Dimension.End.Row - 1); excelData.DeleteExcelFile(); Assert.IsFalse(File.Exists(path)); }
/// <summary> /// Get all the live and sd card shell temperatures along with /// the comments and positions /// </summary> /// <returns></returns> public ShellTemperatureRecord[] GetShellTemperatureRecords(DateTime start, DateTime end, DeviceInfo deviceInfo = null) { ShellTemp[] tempData; SdCardShellTemp[] sdCardShellTemps; // Has device information, user selected device if (deviceInfo != null) { // Get live data and live data comments and positions tempData = _shellTemperatureRepository.GetShellTemperatureData(start, end, deviceInfo.DeviceName, deviceInfo.DeviceAddress).ToArray(); // Get SD Card data and SD card data comments sdCardShellTemps = _sdCardShellTemperatureRepository.GetShellTemperatureData(start, end, deviceInfo.DeviceName, deviceInfo.DeviceAddress).ToArray(); } else // No device information, just use dates { // Get live data and live data comments and positions tempData = _shellTemperatureRepository.GetShellTemperatureData(start, end).ToArray(); // Get SD Card data and SD card data comments sdCardShellTemps = _sdCardShellTemperatureRepository.GetShellTemperatureData(start, end).ToArray(); } // Get the live comments ShellTemperatureComment[] liveDataComments = _commentRepository.GetAll() .Where(x => x.ShellTemp.RecordedDateTime >= start && x.ShellTemp.RecordedDateTime <= end) .ToArray(); // Get the live positions ShellTemperaturePosition[] positions = _shellTemperaturePositionRepository.GetAll().ToArray(); // Sd card comments SdCardShellTemperatureComment[] sdCardComments = _sdCardCommentRepository.GetAll().ToArray(); // Create new temp list of records List <ShellTemperatureRecord> records = new List <ShellTemperatureRecord>(); // For ever item in ShellTemps, find and match the comment that may have been made foreach (ShellTemp shellTemp in tempData) { ShellTemperatureRecord shellTemperatureRecord = new ShellTemperatureRecord(shellTemp.Id, shellTemp.Temperature, shellTemp.RecordedDateTime, shellTemp.Latitude, shellTemp.Longitude, shellTemp.Device, false); // Not from SD // Find the comment for the shell temperature ShellTemperatureComment comment = liveDataComments.FirstOrDefault(x => x.ShellTemp.Id == shellTemperatureRecord.Id); ShellTemperaturePosition position = positions.FirstOrDefault(x => x.ShellTemp.Id == shellTemperatureRecord.Id); if (comment?.Comment != null) { shellTemperatureRecord.Comment = comment.Comment.Comment; } if (position?.Position != null) { shellTemperatureRecord.Position = position.Position.Position; } records.Add(shellTemperatureRecord); } // Find the sd card data shell temps foreach (SdCardShellTemp shellTemp in sdCardShellTemps) { if (!shellTemp.RecordedDateTime.HasValue) // Doesn't have DateTime, skip { continue; } ShellTemperatureRecord shellTemperatureRecord = new ShellTemperatureRecord(shellTemp.Id, shellTemp.Temperature, (DateTime)shellTemp.RecordedDateTime, shellTemp.Latitude, shellTemp.Longitude, shellTemp.Device, true); // This is from SD // Find the comment for the sd card shell temperature SdCardShellTemperatureComment temp = sdCardComments.FirstOrDefault(x => x.SdCardShellTemp.Id == shellTemperatureRecord.Id); if (temp?.Comment != null) { shellTemperatureRecord.Comment = temp.Comment.Comment; } records.Add(shellTemperatureRecord); } return(records.ToArray()); }
public void SetState(ShellTemperatureRecord shellTemp) { _shellTemp = shellTemp; NotifyAllObservers(); }