Правка по результатам ревью

This commit is contained in:
Olga Nemt 2024-09-12 12:46:46 +05:00
parent 31efdbf406
commit 6007fb181c
6 changed files with 42 additions and 32 deletions

View File

@ -7,9 +7,9 @@ namespace AsbCloudApp.Data;
public class StatCriticalMessageDto public class StatCriticalMessageDto
{ {
/// <summary> /// <summary>
/// ключ телеметрии /// ключ скважины
/// </summary> /// </summary>
public int IdTelemetry { get; set; } public int IdWell { get; set; }
/// <summary> /// <summary>
/// ключ категории /// ключ категории

View File

@ -92,13 +92,13 @@ public class MessageTelemetryRequest : MessageRequestBase
/// <summary> /// <summary>
/// телеметрии /// телеметрии
/// </summary> /// </summary>
public IEnumerable<TelemetryBaseDto> Telemetries { get; set; } = Enumerable.Empty<TelemetryBaseDto>(); public IEnumerable<TelemetryDto> Telemetries { get; set; } = Enumerable.Empty<TelemetryDto>();
/// <inheritdoc/> /// <inheritdoc/>
public MessageTelemetryRequest( public MessageTelemetryRequest(
MessageRequestBase request, MessageRequestBase request,
IEnumerable<TelemetryEventDto> events, IEnumerable<TelemetryEventDto> events,
IEnumerable<TelemetryBaseDto> telemetries) : base(request) IEnumerable<TelemetryDto> telemetries) : base(request)
{ {
Events = events; Events = events;
Telemetries = telemetries; Telemetries = telemetries;

View File

@ -52,7 +52,7 @@ public interface ITelemetryService
/// </summary> /// </summary>
/// <param name="idsWells">ключи скважин</param> /// <param name="idsWells">ключи скважин</param>
/// <returns></returns> /// <returns></returns>
IEnumerable<TelemetryBaseDto> GetOrDefaultTelemetriesByIdsWells(IEnumerable<int> idsWells); IEnumerable<TelemetryDto> GetOrDefaultTelemetriesByIdsWells(IEnumerable<int> idsWells);
/// <summary> /// <summary>
/// получить диапазон дат за которые есть данные /// получить диапазон дат за которые есть данные
/// </summary> /// </summary>

View File

@ -17,19 +17,21 @@ namespace AsbCloudInfrastructure.Tests.Services;
public class MessageServiceTest public class MessageServiceTest
{ {
private static readonly List<TelemetryBaseDto> telemetries = new List<TelemetryBaseDto>() private static readonly List<TelemetryDto> telemetries = new List<TelemetryDto>()
{ {
new TelemetryBaseDto() new TelemetryDto()
{ {
Id = 1, Id = 1,
IdWell = 1,
TimeZone = new SimpleTimezoneDto() TimeZone = new SimpleTimezoneDto()
{ {
Hours = 5 Hours = 5
} }
}, },
new TelemetryBaseDto() new TelemetryDto()
{ {
Id = 2, Id = 2,
IdWell = 2,
TimeZone = new SimpleTimezoneDto() TimeZone = new SimpleTimezoneDto()
{ {
Hours = 5 Hours = 5
@ -243,47 +245,47 @@ public class MessageServiceTest
Assert.Equal(6, result.Count()); Assert.Equal(6, result.Count());
var сообщение_1_1 = result var messageStat_1_1 = result
.Where(x => x.IdTelemetry == 1) .Where(x => x.IdWell == 1)
.Where(x => x.IdCategory == 1) .Where(x => x.IdCategory == 1)
.Where(x => x.MessageTemplate == "Шаблон сообщения 1 категории 1") .Where(x => x.MessageTemplate == "Шаблон сообщения 1 категории 1")
.Single(); .Single();
Assert.Equal(3, сообщение_1_1.MessagesCount); Assert.Equal(3, messageStat_1_1.MessagesCount);
var сообщение_1_2 = result var messageStat_1_2 = result
.Where(x => x.IdTelemetry == 1) .Where(x => x.IdWell == 1)
.Where(x => x.IdCategory == 1) .Where(x => x.IdCategory == 1)
.Where(x => x.MessageTemplate == "Шаблон сообщения 2 категории 1") .Where(x => x.MessageTemplate == "Шаблон сообщения 2 категории 1")
.Single(); .Single();
Assert.Equal(3, сообщение_1_2.MessagesCount); Assert.Equal(3, messageStat_1_2.MessagesCount);
var сообщение_1_3 = result var messageStat_1_3 = result
.Where(x => x.IdTelemetry == 1) .Where(x => x.IdWell == 1)
.Where(x => x.IdCategory == 1) .Where(x => x.IdCategory == 1)
.Where(x => x.MessageTemplate == "Шаблон сообщения 3 категории 1") .Where(x => x.MessageTemplate == "Шаблон сообщения 3 категории 1")
.Single(); .Single();
Assert.Equal(3, сообщение_1_3.MessagesCount); Assert.Equal(3, messageStat_1_3.MessagesCount);
var сообщение_2_2 = result var messageStat_2_2 = result
.Where(x => x.IdTelemetry == 1) .Where(x => x.IdWell == 1)
.Where(x => x.IdCategory == 2) .Where(x => x.IdCategory == 2)
.Where(x => x.MessageTemplate == "Шаблон сообщения 2 категории 2") .Where(x => x.MessageTemplate == "Шаблон сообщения 2 категории 2")
.Single(); .Single();
Assert.Equal(2, сообщение_2_2.MessagesCount); Assert.Equal(2, messageStat_2_2.MessagesCount);
var сообщение_2_1 = result var messageStat_2_1 = result
.Where(x => x.IdTelemetry == 1) .Where(x => x.IdWell == 1)
.Where(x => x.IdCategory == 2) .Where(x => x.IdCategory == 2)
.Where(x => x.MessageTemplate == "Шаблон сообщения 1 категории 2") .Where(x => x.MessageTemplate == "Шаблон сообщения 1 категории 2")
.Single(); .Single();
Assert.Equal(2, сообщение_2_1.MessagesCount); Assert.Equal(2, messageStat_2_1.MessagesCount);
var сообщение_3_1 = result var messageStat_3_1 = result
.Where(x => x.IdTelemetry == 2) .Where(x => x.IdWell == 2)
.Where(x => x.IdCategory == 3) .Where(x => x.IdCategory == 3)
.Where(x => x.MessageTemplate == "Шаблон сообщения 1 категории 3") .Where(x => x.MessageTemplate == "Шаблон сообщения 1 категории 3")
.Single(); .Single();
Assert.Equal(3, сообщение_3_1.MessagesCount); Assert.Equal(3, messageStat_3_1.MessagesCount);
} }

View File

@ -45,20 +45,23 @@ public class MessageService : IMessageService
var groupedMessages = telemetryMessages.GroupBy(x => new { x.IdTelemetry, x.IdEvent }); var groupedMessages = telemetryMessages.GroupBy(x => new { x.IdTelemetry, x.IdEvent });
var events = messageTelemetryRequest.Events.ToDictionary(e => e.Id); var events = messageTelemetryRequest.Events.ToDictionary(e => e.Id);
var idsWellsDict = messageTelemetryRequest.Telemetries.ToDictionary(e => e.Id, e => e.IdWell);
var result = groupedMessages var result = groupedMessages
.Select(m => new .Select(m => new
{ {
m.Key.IdTelemetry, IdWell = idsWellsDict.GetValueOrDefault(m.Key.IdTelemetry),
events.GetValueOrDefault(m.Key.IdEvent)?.IdCategory, events.GetValueOrDefault(m.Key.IdEvent)?.IdCategory,
events.GetValueOrDefault(m.Key.IdEvent)?.MessageTemplate, events.GetValueOrDefault(m.Key.IdEvent)?.MessageTemplate,
Count = m.Count() Count = m.Count(),
}) })
.Where(m => m.IdCategory != null) .Where(m => m.IdCategory != null)
.Where(m => m.IdWell != null)
.Where(m => m.MessageTemplate != null) .Where(m => m.MessageTemplate != null)
.GroupBy(m => new { m.IdTelemetry, m.IdCategory, m.MessageTemplate }) .GroupBy(m => new { m.IdWell, m.IdCategory, m.MessageTemplate })
.Select(m => new StatCriticalMessageDto() .Select(m => new StatCriticalMessageDto()
{ {
IdTelemetry = m.Key.IdTelemetry, IdWell = m.First().IdWell!.Value,
IdCategory = m.Key.IdCategory, IdCategory = m.Key.IdCategory,
MessageTemplate = m.Key.MessageTemplate, MessageTemplate = m.Key.MessageTemplate,
MessagesCount = m.Select(z => z.Count).Sum() MessagesCount = m.Select(z => z.Count).Sum()

View File

@ -150,7 +150,7 @@ public class TelemetryService : ITelemetryService
return dto; return dto;
} }
public IEnumerable<TelemetryBaseDto> GetOrDefaultTelemetriesByIdsWells(IEnumerable<int> idsWells) public IEnumerable<TelemetryDto> GetOrDefaultTelemetriesByIdsWells(IEnumerable<int> idsWells)
{ {
var entities = GetTelemetryCache() var entities = GetTelemetryCache()
.Where(t => t.Well != null) .Where(t => t.Well != null)
@ -162,7 +162,12 @@ public class TelemetryService : ITelemetryService
}); });
var dtos = entities.Select(t => t.Adapt<TelemetryBaseDto>()); var dtos = entities.Select(t => {
var dto = t.Adapt<TelemetryDto>();
dto.IdWell = t.Well?.Id;
return dto;
});
return dtos; return dtos;
} }