Skip to content

Commit

Permalink
Fix data mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryba1986 committed Jul 4, 2022
1 parent 4b01f78 commit 67a775a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ internal sealed class MeterProfile : Profile
{
public MeterProfile()
{
CreateProjection<Meter, MeterDto>();

CreateProjection<Tuple<Meter, Device>, MeterDto>()
.ForMember(dst => dst.DeviceId, opt => opt.MapFrom(src => src.Item1.DeviceId))
.ForMember(dst => dst.Date, opt => opt.MapFrom(src => src.Item1.Date))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ internal sealed class RvdProfile : Profile
{
public RvdProfile()
{
CreateProjection<Rvd145, Rvd145Dto>();

CreateProjection<Tuple<Rvd145, Device>, Rvd145Dto>()
.ForMember(dst => dst.DeviceId, opt => opt.MapFrom(src => src.Item1.DeviceId))
.ForMember(dst => dst.Date, opt => opt.MapFrom(src => src.Item1.Date))
Expand Down
14 changes: 7 additions & 7 deletions src/Zeus.Infrastructure/Plc/MeterPlcProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public async Task FillDataAsync(UnitOfWork uow, ExcelWorksheet sheet, DateOnly d
return;
}

MeterReportDto beforePlc = await GetBeforeDataAsync(uow.Meter.AsQueryable(), date, device, reportProcessor, mapper, cancellationToken);
MeterDto beforePlc = await GetBeforeDataAsync(uow.Meter.AsQueryable(), date, device, reportProcessor, mapper, cancellationToken);
startColumn += FillSheet(sheet, device, beforePlc, currentPlcData, startColumn, reportProcessor);
}
}

private static int FillSheet(ExcelWorksheet sheet, DeviceReportDto device, MeterReportDto beforeMeter, IReadOnlyCollection<MeterReportDto> currentData, int startColumn, IReportProcessor reportProcessor)
private static int FillSheet(ExcelWorksheet sheet, DeviceReportDto device, MeterDto beforeMeter, IReadOnlyCollection<MeterReportDto> currentData, int startColumn, IReportProcessor reportProcessor)
{
float beforeVolumeSummary = beforeMeter.VolumeSummary;
float beforeEnergySummary = beforeMeter.EnergySummary;
Expand Down Expand Up @@ -123,20 +123,20 @@ private static int FillSheet(ExcelWorksheet sheet, DeviceReportDto device, Meter
return summaryColIndex;
}

private static async Task<MeterReportDto> GetBeforeDataAsync(IMongoQueryable<Meter> plc, DateOnly date, DeviceReportDto device, IReportProcessor reportProcessor, IMapper mapper, CancellationToken cancellationToken)
private static async Task<MeterDto> GetBeforeDataAsync(IMongoQueryable<Meter> plc, DateOnly date, DeviceReportDto device, IReportProcessor reportProcessor, IMapper mapper, CancellationToken cancellationToken)
{
DateRange range = reportProcessor.GetRange(date);

MeterReportDto? before = await plc
MeterDto? before = await plc
.Where(x =>
x.DeviceId == device.Id &&
x.Date < range.Start
)
.OrderByDescending(x => x.Date)
.ProjectTo<MeterReportDto>(mapper)
.ProjectTo<MeterDto>(mapper)
.FirstOrDefaultAsync(cancellationToken);

if (before != null)
if (before is not null)
{
return before;
}
Expand All @@ -147,7 +147,7 @@ private static async Task<MeterReportDto> GetBeforeDataAsync(IMongoQueryable<Met
x.Date < range.End
)
.OrderBy(x => x.Date)
.ProjectTo<MeterReportDto>(mapper)
.ProjectTo<MeterDto>(mapper)
.FirstAsync(cancellationToken);

return before;
Expand Down

0 comments on commit 67a775a

Please sign in to comment.