Skip to content

Commit

Permalink
Remove device type from group
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryba1986 committed Nov 10, 2023
1 parent 57f1dd9 commit 1e988c5
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 57 deletions.
2 changes: 0 additions & 2 deletions src/Phoenix.Models/Base/Dto/PlcReportDtoBase.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
6 changes: 6 additions & 0 deletions src/Phoenix.Models/Plcs/Climatixs/Dto/ClimatixReportDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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; }
Expand All @@ -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; }
Expand Down
3 changes: 0 additions & 3 deletions src/Phoenix.Models/Plcs/PlcGroupBy.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
4 changes: 4 additions & 0 deletions src/Phoenix.Models/Plcs/Rvds/Dto/Rvd145ReportDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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; }
Expand Down
1 change: 0 additions & 1 deletion src/Phoenix.Services/Helpers/PlcHandlerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public static async Task<IReadOnlyDictionary<int, R[]>> GetPlcDataAsync<S, R>(Db
{
IReadOnlyCollection<R> result = await plc
.AsNoTracking()
.Include(x => x.Device)
.Where(x =>
x.Date >= range.Item1 &&
x.Date < range.Item2
Expand Down
7 changes: 6 additions & 1 deletion src/Phoenix.Services/Mappings/ClimatixMappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public static ClimatixChartDto ToClimatixChartDto(this Climatix climatix)
public static Expression<Func<IGrouping<PlcGroupBy, Climatix>, ClimatixReportDto>> ToClimatixReportDto = group => new()
{
DeviceId = group.Key.DeviceId,
DeviceType = group.Key.DeviceType,
Date = group.Min(x => x.Date),

OutsideTempAvg = group.Average(x => x.OutsideTemp),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down
1 change: 0 additions & 1 deletion src/Phoenix.Services/Mappings/KamstrupMappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public static KamstrupChartDto ToKamstrupChartDto(this Kamstrup kamstrup)
public static Expression<Func<IGrouping<PlcGroupBy, Kamstrup>, KamstrupReportDto>> ToKamstrupReportDto = group => new()
{
DeviceId = group.Key.DeviceId,
DeviceType = group.Key.DeviceType,
Date = group.Min(x => x.Date),

InletTempAvg = group.Average(x => x.InletTemp),
Expand Down
5 changes: 4 additions & 1 deletion src/Phoenix.Services/Mappings/Rvd145Mappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public static Rvd145ChartDto ToRvd145ChartDto(this Rvd145 rvd)
public static Expression<Func<IGrouping<PlcGroupBy, Rvd145>, Rvd145ReportDto>> ToRvd145ReportDto = group => new()
{
DeviceId = group.Key.DeviceId,
DeviceType = group.Key.DeviceType,
Date = group.Min(x => x.Date),

OutsideTempAvg = group.Average(x => x.OutsideTemp),
Expand All @@ -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),
Expand All @@ -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),
Expand Down
53 changes: 28 additions & 25 deletions src/Phoenix.Services/Reports/Plcs/ClimatixPlcProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -58,19 +57,22 @@ private static void FillData(ExcelWorksheet sheet, IReadOnlyCollection<ClimatixR
sheet.Cells[rowIndex, 8].Value = climatix.ChHighOutletPresureMin;
sheet.Cells[rowIndex, 9].Value = climatix.ChHighOutletPresureMax;

sheet.Cells[rowIndex, 10].Value = climatix.Ch1LowInletTempAvg.Round();
sheet.Cells[rowIndex, 11].Value = climatix.Ch1LowInletTempMin;
sheet.Cells[rowIndex, 12].Value = climatix.Ch1LowInletTempMax;
if (climatix.Ch1Status)
{
sheet.Cells[rowIndex, 10].Value = climatix.Ch1LowInletTempAvg.Round();
sheet.Cells[rowIndex, 11].Value = climatix.Ch1LowInletTempMin;
sheet.Cells[rowIndex, 12].Value = climatix.Ch1LowInletTempMax;

sheet.Cells[rowIndex, 13].Value = climatix.Ch1LowOutletTempAvg.Round();
sheet.Cells[rowIndex, 14].Value = climatix.Ch1LowOutletTempMin;
sheet.Cells[rowIndex, 15].Value = climatix.Ch1LowOutletTempMax;
sheet.Cells[rowIndex, 13].Value = climatix.Ch1LowOutletTempAvg.Round();
sheet.Cells[rowIndex, 14].Value = climatix.Ch1LowOutletTempMin;
sheet.Cells[rowIndex, 15].Value = climatix.Ch1LowOutletTempMax;

sheet.Cells[rowIndex, 16].Value = climatix.Ch1LowOutletPresureAvg.Round();
sheet.Cells[rowIndex, 17].Value = climatix.Ch1LowOutletPresureMin;
sheet.Cells[rowIndex, 18].Value = climatix.Ch1LowOutletPresureMax;
sheet.Cells[rowIndex, 16].Value = climatix.Ch1LowOutletPresureAvg.Round();
sheet.Cells[rowIndex, 17].Value = climatix.Ch1LowOutletPresureMin;
sheet.Cells[rowIndex, 18].Value = climatix.Ch1LowOutletPresureMax;
}

if (climatix.DeviceType == DeviceType.DoubleHeating)
if (climatix.Ch2Status)
{
sheet.Cells[rowIndex, 19].Value = climatix.Ch2LowInletTempAvg.Round();
sheet.Cells[rowIndex, 20].Value = climatix.Ch2LowInletTempMin;
Expand All @@ -85,7 +87,7 @@ private static void FillData(ExcelWorksheet sheet, IReadOnlyCollection<ClimatixR
sheet.Cells[rowIndex, 27].Value = climatix.Ch2LowOutletPresureMax;
}

if (climatix.DeviceType == DeviceType.HeatingDomestic)
if (climatix.DhwStatus)
{
sheet.Cells[rowIndex, 28].Value = climatix.DhwTempAvg.Round();
sheet.Cells[rowIndex, 29].Value = climatix.DhwTempMin;
Expand All @@ -105,21 +107,22 @@ private static void FillData(ExcelWorksheet sheet, IReadOnlyCollection<ClimatixR
sheet.Cells[sheet.Dimension.Rows, 8].Value = plcData.Min(x => 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);
Expand All @@ -134,7 +137,7 @@ private static void FillData(ExcelWorksheet sheet, IReadOnlyCollection<ClimatixR
sheet.Cells[sheet.Dimension.Rows, 27].Value = plcData.Max(x => 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);
Expand Down
35 changes: 20 additions & 15 deletions src/Phoenix.Services/Reports/Plcs/Rvd145PlcProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -55,15 +54,18 @@ private static void FillData(ExcelWorksheet sheet, IReadOnlyCollection<Rvd145Rep
sheet.Cells[rowIndex, 5].Value = rvd.ChHighInletPresureMin;
sheet.Cells[rowIndex, 6].Value = rvd.ChHighInletPresureMax;

sheet.Cells[rowIndex, 10].Value = rvd.Ch1LowInletTempAvg.Round();
sheet.Cells[rowIndex, 11].Value = rvd.Ch1LowInletTempMin;
sheet.Cells[rowIndex, 12].Value = rvd.Ch1LowInletTempMax;
if (rvd.Ch1Status)
{
sheet.Cells[rowIndex, 10].Value = rvd.Ch1LowInletTempAvg.Round();
sheet.Cells[rowIndex, 11].Value = rvd.Ch1LowInletTempMin;
sheet.Cells[rowIndex, 12].Value = rvd.Ch1LowInletTempMax;

sheet.Cells[rowIndex, 16].Value = rvd.Ch1LowOutletPresureAvg.Round();
sheet.Cells[rowIndex, 17].Value = rvd.Ch1LowOutletPresureMin;
sheet.Cells[rowIndex, 18].Value = rvd.Ch1LowOutletPresureMax;
sheet.Cells[rowIndex, 16].Value = rvd.Ch1LowOutletPresureAvg.Round();
sheet.Cells[rowIndex, 17].Value = rvd.Ch1LowOutletPresureMin;
sheet.Cells[rowIndex, 18].Value = rvd.Ch1LowOutletPresureMax;
}

if (rvd.DeviceType == DeviceType.HeatingDomestic)
if (rvd.DhwStatus)
{
sheet.Cells[rowIndex, 28].Value = rvd.DhwTempAvg.Round();
sheet.Cells[rowIndex, 29].Value = rvd.DhwTempMin;
Expand All @@ -83,15 +85,18 @@ private static void FillData(ExcelWorksheet sheet, IReadOnlyCollection<Rvd145Rep
sheet.Cells[sheet.Dimension.Rows, 5].Value = plcData.Min(x => 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);
Expand Down
3 changes: 1 addition & 2 deletions src/Phoenix.Services/Reports/Types/DayTypeProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public Expression<Func<T, PlcGroupBy>> GetPlcGroup<T>() where T : PlcBase
{
return x => new()
{
DeviceId = x.Device.Id,
DeviceType = x.Device.DeviceType,
DeviceId = x.DeviceId,
DatePart = x.Date.Hour,
};
}
Expand Down
3 changes: 1 addition & 2 deletions src/Phoenix.Services/Reports/Types/MonthTypeProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public Expression<Func<T, PlcGroupBy>> GetPlcGroup<T>() where T : PlcBase
{
return x => new()
{
DeviceId = x.Device.Id,
DeviceType = x.Device.DeviceType,
DeviceId = x.DeviceId,
DatePart = x.Date.Day,
};
}
Expand Down
3 changes: 1 addition & 2 deletions src/Phoenix.Services/Reports/Types/YearByDayTypeProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public Expression<Func<T, PlcGroupBy>> GetPlcGroup<T>() where T : PlcBase
{
return x => new()
{
DeviceId = x.Device.Id,
DeviceType = x.Device.DeviceType,
DeviceId = x.DeviceId,
DatePart = x.Date.DayOfYear,
};
}
Expand Down
3 changes: 1 addition & 2 deletions src/Phoenix.Services/Reports/Types/YearTypeProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public Expression<Func<T, PlcGroupBy>> GetPlcGroup<T>() where T : PlcBase
{
return x => new()
{
DeviceId = x.Device.Id,
DeviceType = x.Device.DeviceType,
DeviceId = x.DeviceId,
DatePart = x.Date.Month,
};
}
Expand Down

0 comments on commit 1e988c5

Please sign in to comment.