/// <summary> /// Saves a list of models to csv. /// </summary> /// <param name="data">Data to save to csv</param> /// <param name="JS">Page calling this requires passing an injected JSRuntime</param> /// <param name="identifier">Unique part of name used to identify the file</param> public async static void SaveToCsv(List <Vibe2020DataModel> data, IJSRuntime JS, string identifier = "") // should create a DataModel base class if more data models are created and then generalize this { string fileName = $"{identifier}-{DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss")}.csv"; using (MemoryStream stream = new MemoryStream()) { using (StreamWriter writer = new StreamWriter(stream)) { await writer.WriteLineAsync(Vibe2020DataModel.GetHeader()); foreach (var item in data) { await writer.WriteLineAsync(item.ToCsvLine()); } } await JS.SaveAs(fileName, stream.ToArray()); } }
public static Vibe2020DataModel ConvertToDataModel(DeviceDataModel deviceData) { Vibe2020DataModel model = new Vibe2020DataModel(); if (deviceData?.AccelData != null && deviceData.AccelData.Count > 0) { model.AccelData_Raw = new int[] { deviceData.AccelData[0], deviceData.AccelData[1], deviceData.AccelData[2] }; model.AccelData = new double[] { ScaleAccelerometer(deviceData.AccelData[0]), ScaleAccelerometer(deviceData.AccelData[1]), ScaleAccelerometer(deviceData.AccelData[2]) }; } if (deviceData?.GyroData != null && deviceData.GyroData.Count > 0) { Span <int> data = new int[4] { deviceData.GyroData[0], deviceData.GyroData[1], deviceData.GyroData[2], deviceData.GyroData[3] }; Span <byte> bytes = MemoryMarshal.Cast <int, byte>(data); model.GyroData_Raw = GyroConversionHelper.CombineBytes(bytes).ToArray(); model.GyroData = GyroConversionHelper.GetGyroscopeDetails(model.GyroData_Raw).ToArray(); } model.ResultStatus = (ResultStatus)deviceData.ResultStatus; model.TransactionTime = new DateTime(deviceData.TransactionTime).ToLocalTime(); model.CpuTemp = deviceData.CpuTemp; return(model); }