Uses .NET8 and nuget libraries Newtonsoft.Json, NodaTime and TimeZoneConverter.
var jsonText = File.ReadAllText("ExampleData/EUI-F84F25000001A0AD_2024-01-12_01_25_17.json");
// Deserialize the JSON file using the MeasurementFileFormat.cs class
MeasurementFileFormat measurementFile = JsonConvert.DeserializeObject<MeasurementFileFormat>(jsonText);
Console.WriteLine($"The loaded measurement file has {measurementFile.Body.Count} measurements with {measurementFile.Header.MeasurementDefinitionsInBody.Length} channels and {measurementFile.Header.ChannelCalculations.Count} calculated channel/s.");
// These are the use with methods of KELLER to create CSV data using the KellerAg.Shared.x libraries:
List<ChannelInfo> channelInfos = measurementFile.Header.MeasurementDefinitionsInBody.Select(ChannelInfo.GetChannelInfo).ToList();
var exportFileInfo = new ExportFileInfo("", "filename.csv", Filetype.Csv);
var request = new ExportRequest(exportFileInfo, measurementFile, channelInfos, measurementFile.Header.ChannelCalculations);
object[,] table = ExportHelper.CreateDataTable(request, new CsvExportPreferences(',') , true);
// Print first 50 rows CSV style
for (int row = 0; row < 50 && row < table.GetLength(0); row++)
{
for (int column = 0; column < table.GetLength(1); column++)
{
Console.Write(table[row, column] + ",");
}
Console.WriteLine();
}
The process is:
- Read the measurement file
- Tabulate the measurement data from "Body" into a table
- If necessary, change the time from UTC to another (local) time zone
- Use a lookup table to translate the integer IDs from "MeasurementDefinitionsInBody" into the correct channel names
- If necessary, calculate values for the calculated channels in "ChannelCalculations" and add them to the table