From 1e988c5cb8b1e82689fde725e88ce77b65a8b5ca Mon Sep 17 00:00:00 2001 From: Maciej Rybarczyk Date: Fri, 10 Nov 2023 16:39:33 +0100 Subject: [PATCH] Remove device type from group --- .../Base/Dto/PlcReportDtoBase.cs | 2 - .../Plcs/Climatixs/Dto/ClimatixReportDto.cs | 6 +++ src/Phoenix.Models/Plcs/PlcGroupBy.cs | 3 -- .../Plcs/Rvds/Dto/Rvd145ReportDto.cs | 4 ++ .../Helpers/PlcHandlerHelper.cs | 1 - .../Mappings/ClimatixMappings.cs | 7 ++- .../Mappings/KamstrupMappings.cs | 1 - .../Mappings/Rvd145Mappings.cs | 5 +- .../Reports/Plcs/ClimatixPlcProcessor.cs | 53 ++++++++++--------- .../Reports/Plcs/Rvd145PlcProcessor.cs | 35 ++++++------ .../Reports/Types/DayTypeProcessor.cs | 3 +- .../Reports/Types/MonthTypeProcessor.cs | 3 +- .../Reports/Types/YearByDayTypeProcessor.cs | 3 +- .../Reports/Types/YearTypeProcessor.cs | 3 +- 14 files changed, 72 insertions(+), 57 deletions(-) diff --git a/src/Phoenix.Models/Base/Dto/PlcReportDtoBase.cs b/src/Phoenix.Models/Base/Dto/PlcReportDtoBase.cs index 70ce512..1a76318 100644 --- a/src/Phoenix.Models/Base/Dto/PlcReportDtoBase.cs +++ b/src/Phoenix.Models/Base/Dto/PlcReportDtoBase.cs @@ -1,12 +1,10 @@ using System; -using Phoenix.Shared.Enums.Devices; namespace Phoenix.Models.Base.Dto { public abstract class PlcReportDtoBase { public int DeviceId { get; init; } - public DeviceType DeviceType { get; init; } public DateTime Date { get; init; } } } diff --git a/src/Phoenix.Models/Plcs/Climatixs/Dto/ClimatixReportDto.cs b/src/Phoenix.Models/Plcs/Climatixs/Dto/ClimatixReportDto.cs index 7769fa5..22c6151 100644 --- a/src/Phoenix.Models/Plcs/Climatixs/Dto/ClimatixReportDto.cs +++ b/src/Phoenix.Models/Plcs/Climatixs/Dto/ClimatixReportDto.cs @@ -16,6 +16,8 @@ public sealed class ClimatixReportDto : PlcReportDtoBase public float ChHighOutletPresureMin { get; init; } public float ChHighOutletPresureMax { get; init; } + public bool Ch1Status { get; init; } + public float Ch1LowInletTempAvg { get; init; } public float Ch1LowInletTempMin { get; init; } public float Ch1LowInletTempMax { get; init; } @@ -28,6 +30,8 @@ public sealed class ClimatixReportDto : PlcReportDtoBase public float Ch1LowOutletPresureMin { get; init; } public float Ch1LowOutletPresureMax { get; init; } + public bool Ch2Status { get; init; } + public float Ch2LowInletTempAvg { get; init; } public float Ch2LowInletTempMin { get; init; } public float Ch2LowInletTempMax { get; init; } @@ -40,6 +44,8 @@ public sealed class ClimatixReportDto : PlcReportDtoBase public float Ch2LowOutletPresureMin { get; init; } public float Ch2LowOutletPresureMax { get; init; } + public bool DhwStatus { get; init; } + public float DhwTempAvg { get; init; } public float DhwTempMin { get; init; } public float DhwTempMax { get; init; } diff --git a/src/Phoenix.Models/Plcs/PlcGroupBy.cs b/src/Phoenix.Models/Plcs/PlcGroupBy.cs index 7886326..26e4fed 100644 --- a/src/Phoenix.Models/Plcs/PlcGroupBy.cs +++ b/src/Phoenix.Models/Plcs/PlcGroupBy.cs @@ -1,11 +1,8 @@ -using Phoenix.Shared.Enums.Devices; - namespace Phoenix.Models.Plcs { public readonly struct PlcGroupBy { public int DeviceId { get; init; } - public DeviceType DeviceType { get; init; } public int DatePart { get; init; } } } diff --git a/src/Phoenix.Models/Plcs/Rvds/Dto/Rvd145ReportDto.cs b/src/Phoenix.Models/Plcs/Rvds/Dto/Rvd145ReportDto.cs index 2614255..07d2243 100644 --- a/src/Phoenix.Models/Plcs/Rvds/Dto/Rvd145ReportDto.cs +++ b/src/Phoenix.Models/Plcs/Rvds/Dto/Rvd145ReportDto.cs @@ -12,6 +12,8 @@ public sealed class Rvd145ReportDto : PlcReportDtoBase public float ChHighInletPresureMin { get; init; } public float ChHighInletPresureMax { get; init; } + public bool Ch1Status { get; init; } + public float Ch1LowInletTempAvg { get; init; } public float Ch1LowInletTempMin { get; init; } public float Ch1LowInletTempMax { get; init; } @@ -20,6 +22,8 @@ public sealed class Rvd145ReportDto : PlcReportDtoBase public float Ch1LowOutletPresureMin { get; init; } public float Ch1LowOutletPresureMax { get; init; } + public bool DhwStatus { get; init; } + public float DhwTempAvg { get; init; } public float DhwTempMin { get; init; } public float DhwTempMax { get; init; } diff --git a/src/Phoenix.Services/Helpers/PlcHandlerHelper.cs b/src/Phoenix.Services/Helpers/PlcHandlerHelper.cs index 791f112..bf81be7 100644 --- a/src/Phoenix.Services/Helpers/PlcHandlerHelper.cs +++ b/src/Phoenix.Services/Helpers/PlcHandlerHelper.cs @@ -85,7 +85,6 @@ public static async Task> GetPlcDataAsync(Db { IReadOnlyCollection result = await plc .AsNoTracking() - .Include(x => x.Device) .Where(x => x.Date >= range.Item1 && x.Date < range.Item2 diff --git a/src/Phoenix.Services/Mappings/ClimatixMappings.cs b/src/Phoenix.Services/Mappings/ClimatixMappings.cs index 9556d04..2bf5832 100644 --- a/src/Phoenix.Services/Mappings/ClimatixMappings.cs +++ b/src/Phoenix.Services/Mappings/ClimatixMappings.cs @@ -77,7 +77,6 @@ public static ClimatixChartDto ToClimatixChartDto(this Climatix climatix) public static Expression, ClimatixReportDto>> ToClimatixReportDto = group => new() { DeviceId = group.Key.DeviceId, - DeviceType = group.Key.DeviceType, Date = group.Min(x => x.Date), OutsideTempAvg = group.Average(x => x.OutsideTemp), @@ -92,6 +91,8 @@ public static ClimatixChartDto ToClimatixChartDto(this Climatix climatix) ChHighOutletPresureMin = group.Min(x => x.ChHighOutletPresure), ChHighOutletPresureMax = group.Max(x => x.ChHighOutletPresure), + Ch1Status = group.Max(x => x.Ch1Status), + Ch1LowInletTempAvg = group.Average(x => x.Ch1LowInletTemp), Ch1LowInletTempMin = group.Min(x => x.Ch1LowInletTemp), Ch1LowInletTempMax = group.Max(x => x.Ch1LowInletTemp), @@ -104,6 +105,8 @@ public static ClimatixChartDto ToClimatixChartDto(this Climatix climatix) Ch1LowOutletPresureMin = group.Min(x => x.Ch1LowOutletPresure), Ch1LowOutletPresureMax = group.Max(x => x.Ch1LowOutletPresure), + Ch2Status = group.Max(x => x.Ch2Status), + Ch2LowInletTempAvg = group.Average(x => x.Ch2LowInletTemp), Ch2LowInletTempMin = group.Min(x => x.Ch2LowInletTemp), Ch2LowInletTempMax = group.Max(x => x.Ch2LowInletTemp), @@ -116,6 +119,8 @@ public static ClimatixChartDto ToClimatixChartDto(this Climatix climatix) Ch2LowOutletPresureMin = group.Min(x => x.Ch2LowOutletPresure), Ch2LowOutletPresureMax = group.Max(x => x.Ch2LowOutletPresure), + DhwStatus = group.Max(x => x.DhwStatus), + DhwTempAvg = group.Average(x => x.DhwTemp), DhwTempMin = group.Min(x => x.DhwTemp), DhwTempMax = group.Max(x => x.DhwTemp), diff --git a/src/Phoenix.Services/Mappings/KamstrupMappings.cs b/src/Phoenix.Services/Mappings/KamstrupMappings.cs index 48e814b..6bb978c 100644 --- a/src/Phoenix.Services/Mappings/KamstrupMappings.cs +++ b/src/Phoenix.Services/Mappings/KamstrupMappings.cs @@ -44,7 +44,6 @@ public static KamstrupChartDto ToKamstrupChartDto(this Kamstrup kamstrup) public static Expression, KamstrupReportDto>> ToKamstrupReportDto = group => new() { DeviceId = group.Key.DeviceId, - DeviceType = group.Key.DeviceType, Date = group.Min(x => x.Date), InletTempAvg = group.Average(x => x.InletTemp), diff --git a/src/Phoenix.Services/Mappings/Rvd145Mappings.cs b/src/Phoenix.Services/Mappings/Rvd145Mappings.cs index c5f1426..adeca70 100644 --- a/src/Phoenix.Services/Mappings/Rvd145Mappings.cs +++ b/src/Phoenix.Services/Mappings/Rvd145Mappings.cs @@ -58,7 +58,6 @@ public static Rvd145ChartDto ToRvd145ChartDto(this Rvd145 rvd) public static Expression, Rvd145ReportDto>> ToRvd145ReportDto = group => new() { DeviceId = group.Key.DeviceId, - DeviceType = group.Key.DeviceType, Date = group.Min(x => x.Date), OutsideTempAvg = group.Average(x => x.OutsideTemp), @@ -69,6 +68,8 @@ public static Rvd145ChartDto ToRvd145ChartDto(this Rvd145 rvd) ChHighInletPresureMin = group.Min(x => x.ChHighInletPresure), ChHighInletPresureMax = group.Max(x => x.ChHighInletPresure), + Ch1Status = group.Max(x => x.Ch1Status), + Ch1LowInletTempAvg = group.Average(x => x.Ch1LowInletTemp), Ch1LowInletTempMin = group.Min(x => x.Ch1LowInletTemp), Ch1LowInletTempMax = group.Max(x => x.Ch1LowInletTemp), @@ -77,6 +78,8 @@ public static Rvd145ChartDto ToRvd145ChartDto(this Rvd145 rvd) Ch1LowOutletPresureMin = group.Min(x => x.Ch1LowOutletPresure), Ch1LowOutletPresureMax = group.Max(x => x.Ch1LowOutletPresure), + DhwStatus = group.Max(x => x.DhwStatus), + DhwTempAvg = group.Average(x => x.DhwTemp), DhwTempMin = group.Min(x => x.DhwTemp), DhwTempMax = group.Max(x => x.DhwTemp), diff --git a/src/Phoenix.Services/Reports/Plcs/ClimatixPlcProcessor.cs b/src/Phoenix.Services/Reports/Plcs/ClimatixPlcProcessor.cs index cfb793b..9064b7d 100644 --- a/src/Phoenix.Services/Reports/Plcs/ClimatixPlcProcessor.cs +++ b/src/Phoenix.Services/Reports/Plcs/ClimatixPlcProcessor.cs @@ -9,7 +9,6 @@ using Phoenix.Services.Mappings; using Phoenix.Services.Reports.Base; using Phoenix.Services.Repositories; -using Phoenix.Shared.Enums.Devices; using Phoenix.Shared.Extensions; namespace Phoenix.Services.Reports.Plcs @@ -58,19 +57,22 @@ private static void FillData(ExcelWorksheet sheet, IReadOnlyCollection x.ChHighOutletPresureMin); sheet.Cells[sheet.Dimension.Rows, 9].Value = plcData.Max(x => x.ChHighOutletPresureMax); - sheet.Cells[sheet.Dimension.Rows, 10].Value = plcData.Average(x => x.Ch1LowInletTempAvg).Round(); - sheet.Cells[sheet.Dimension.Rows, 11].Value = plcData.Min(x => x.Ch1LowInletTempMin); - sheet.Cells[sheet.Dimension.Rows, 12].Value = plcData.Max(x => x.Ch1LowInletTempMax); - - sheet.Cells[sheet.Dimension.Rows, 13].Value = plcData.Average(x => x.Ch1LowOutletTempAvg).Round(); - sheet.Cells[sheet.Dimension.Rows, 14].Value = plcData.Min(x => x.Ch1LowOutletTempMin); - sheet.Cells[sheet.Dimension.Rows, 15].Value = plcData.Max(x => x.Ch1LowOutletTempMax); + if (plcData.Max(x => x.Ch1Status)) + { + sheet.Cells[sheet.Dimension.Rows, 10].Value = plcData.Average(x => x.Ch1LowInletTempAvg).Round(); + sheet.Cells[sheet.Dimension.Rows, 11].Value = plcData.Min(x => x.Ch1LowInletTempMin); + sheet.Cells[sheet.Dimension.Rows, 12].Value = plcData.Max(x => x.Ch1LowInletTempMax); - sheet.Cells[sheet.Dimension.Rows, 16].Value = plcData.Average(x => x.Ch1LowOutletPresureAvg).Round(); - sheet.Cells[sheet.Dimension.Rows, 17].Value = plcData.Min(x => x.Ch1LowOutletPresureMin); - sheet.Cells[sheet.Dimension.Rows, 18].Value = plcData.Max(x => x.Ch1LowOutletPresureMax); + sheet.Cells[sheet.Dimension.Rows, 13].Value = plcData.Average(x => x.Ch1LowOutletTempAvg).Round(); + sheet.Cells[sheet.Dimension.Rows, 14].Value = plcData.Min(x => x.Ch1LowOutletTempMin); + sheet.Cells[sheet.Dimension.Rows, 15].Value = plcData.Max(x => x.Ch1LowOutletTempMax); - DeviceType deviceType = plcData.First().DeviceType; + sheet.Cells[sheet.Dimension.Rows, 16].Value = plcData.Average(x => x.Ch1LowOutletPresureAvg).Round(); + sheet.Cells[sheet.Dimension.Rows, 17].Value = plcData.Min(x => x.Ch1LowOutletPresureMin); + sheet.Cells[sheet.Dimension.Rows, 18].Value = plcData.Max(x => x.Ch1LowOutletPresureMax); + } - if (deviceType == DeviceType.DoubleHeating) + if (plcData.Max(x => x.Ch2Status)) { sheet.Cells[sheet.Dimension.Rows, 19].Value = plcData.Average(x => x.Ch2LowInletTempAvg).Round(); sheet.Cells[sheet.Dimension.Rows, 20].Value = plcData.Min(x => x.Ch2LowInletTempMin); @@ -134,7 +137,7 @@ private static void FillData(ExcelWorksheet sheet, IReadOnlyCollection x.Ch2LowOutletPresureMax); } - if (deviceType == DeviceType.HeatingDomestic) + if (plcData.Max(x => x.DhwStatus)) { sheet.Cells[sheet.Dimension.Rows, 28].Value = plcData.Average(x => x.DhwTempAvg).Round(); sheet.Cells[sheet.Dimension.Rows, 29].Value = plcData.Min(x => x.DhwTempMin); diff --git a/src/Phoenix.Services/Reports/Plcs/Rvd145PlcProcessor.cs b/src/Phoenix.Services/Reports/Plcs/Rvd145PlcProcessor.cs index c3dc441..4192e9a 100644 --- a/src/Phoenix.Services/Reports/Plcs/Rvd145PlcProcessor.cs +++ b/src/Phoenix.Services/Reports/Plcs/Rvd145PlcProcessor.cs @@ -9,7 +9,6 @@ using Phoenix.Services.Mappings; using Phoenix.Services.Reports.Base; using Phoenix.Services.Repositories; -using Phoenix.Shared.Enums.Devices; using Phoenix.Shared.Extensions; @@ -55,15 +54,18 @@ private static void FillData(ExcelWorksheet sheet, IReadOnlyCollection x.ChHighInletPresureMin); sheet.Cells[sheet.Dimension.Rows, 6].Value = plcData.Max(x => x.ChHighInletPresureMax); - sheet.Cells[sheet.Dimension.Rows, 10].Value = plcData.Average(x => x.Ch1LowInletTempAvg).Round(); - sheet.Cells[sheet.Dimension.Rows, 11].Value = plcData.Min(x => x.Ch1LowInletTempMin); - sheet.Cells[sheet.Dimension.Rows, 12].Value = plcData.Max(x => x.Ch1LowInletTempMax); + if (plcData.Max(x => x.Ch1Status)) + { + sheet.Cells[sheet.Dimension.Rows, 10].Value = plcData.Average(x => x.Ch1LowInletTempAvg).Round(); + sheet.Cells[sheet.Dimension.Rows, 11].Value = plcData.Min(x => x.Ch1LowInletTempMin); + sheet.Cells[sheet.Dimension.Rows, 12].Value = plcData.Max(x => x.Ch1LowInletTempMax); - sheet.Cells[sheet.Dimension.Rows, 16].Value = plcData.Average(x => x.Ch1LowOutletPresureAvg).Round(); - sheet.Cells[sheet.Dimension.Rows, 17].Value = plcData.Min(x => x.Ch1LowOutletPresureMin); - sheet.Cells[sheet.Dimension.Rows, 18].Value = plcData.Max(x => x.Ch1LowOutletPresureMax); + sheet.Cells[sheet.Dimension.Rows, 16].Value = plcData.Average(x => x.Ch1LowOutletPresureAvg).Round(); + sheet.Cells[sheet.Dimension.Rows, 17].Value = plcData.Min(x => x.Ch1LowOutletPresureMin); + sheet.Cells[sheet.Dimension.Rows, 18].Value = plcData.Max(x => x.Ch1LowOutletPresureMax); + } - if (plcData.First().DeviceType == DeviceType.HeatingDomestic) + if (plcData.Max(x => x.DhwStatus)) { sheet.Cells[sheet.Dimension.Rows, 28].Value = plcData.Average(x => x.DhwTempAvg).Round(); sheet.Cells[sheet.Dimension.Rows, 29].Value = plcData.Min(x => x.DhwTempMin); diff --git a/src/Phoenix.Services/Reports/Types/DayTypeProcessor.cs b/src/Phoenix.Services/Reports/Types/DayTypeProcessor.cs index 90bb2de..4e1e319 100644 --- a/src/Phoenix.Services/Reports/Types/DayTypeProcessor.cs +++ b/src/Phoenix.Services/Reports/Types/DayTypeProcessor.cs @@ -40,8 +40,7 @@ public Expression> GetPlcGroup() where T : PlcBase { return x => new() { - DeviceId = x.Device.Id, - DeviceType = x.Device.DeviceType, + DeviceId = x.DeviceId, DatePart = x.Date.Hour, }; } diff --git a/src/Phoenix.Services/Reports/Types/MonthTypeProcessor.cs b/src/Phoenix.Services/Reports/Types/MonthTypeProcessor.cs index 3c0f6e3..8f75690 100644 --- a/src/Phoenix.Services/Reports/Types/MonthTypeProcessor.cs +++ b/src/Phoenix.Services/Reports/Types/MonthTypeProcessor.cs @@ -40,8 +40,7 @@ public Expression> GetPlcGroup() where T : PlcBase { return x => new() { - DeviceId = x.Device.Id, - DeviceType = x.Device.DeviceType, + DeviceId = x.DeviceId, DatePart = x.Date.Day, }; } diff --git a/src/Phoenix.Services/Reports/Types/YearByDayTypeProcessor.cs b/src/Phoenix.Services/Reports/Types/YearByDayTypeProcessor.cs index 829d6d5..bc4a866 100644 --- a/src/Phoenix.Services/Reports/Types/YearByDayTypeProcessor.cs +++ b/src/Phoenix.Services/Reports/Types/YearByDayTypeProcessor.cs @@ -40,8 +40,7 @@ public Expression> GetPlcGroup() where T : PlcBase { return x => new() { - DeviceId = x.Device.Id, - DeviceType = x.Device.DeviceType, + DeviceId = x.DeviceId, DatePart = x.Date.DayOfYear, }; } diff --git a/src/Phoenix.Services/Reports/Types/YearTypeProcessor.cs b/src/Phoenix.Services/Reports/Types/YearTypeProcessor.cs index ec8b0aa..3ce5116 100644 --- a/src/Phoenix.Services/Reports/Types/YearTypeProcessor.cs +++ b/src/Phoenix.Services/Reports/Types/YearTypeProcessor.cs @@ -40,8 +40,7 @@ public Expression> GetPlcGroup() where T : PlcBase { return x => new() { - DeviceId = x.Device.Id, - DeviceType = x.Device.DeviceType, + DeviceId = x.DeviceId, DatePart = x.Date.Month, }; }