CS2-24: Добавлены данные аналитики по операциям

This commit is contained in:
KharchenkoVV 2021-06-30 10:16:06 +05:00
parent 3e6a55b547
commit fd5871a9ec
8 changed files with 95 additions and 175 deletions

View File

@ -1,11 +1,8 @@
using System; namespace AsbCloudApp.Data
namespace AsbCloudApp.Data
{ {
public class OperationDetailsDto public class OperationDetailsDto
{ {
public string OperationName { get; set; } public string OperationName { get; set; }
public DateTime OperationStartTime { get; set; } public int Duration { get; set; }
public double DurationHours { get; set; }
} }
} }

View File

@ -1,8 +1,8 @@
namespace AsbCloudApp.Data namespace AsbCloudApp.Data
{ {
public class OperationPercentageDto public class OperationDurationDto
{ {
public string ProcessName { get; set; } public string ProcessName { get; set; }
public double Percentage { get; set; } public double Duration { get; set; }
} }
} }

View File

@ -6,7 +6,6 @@ namespace AsbCloudApp.Data
public class OperationInfoDto public class OperationInfoDto
{ {
public DateTime IntervalBegin { get; set; } public DateTime IntervalBegin { get; set; }
public DateTime IntervalEnd { get; set; } public IEnumerable<OperationDetailsDto> Operations { get; set; }
public IEnumerable<OperationDetailsDto> OperationData { get; set; }
} }
} }

View File

@ -10,10 +10,10 @@ namespace AsbCloudApp.Services
IEnumerable<WellDepthToDayDto> GetWellDepthToDay(int wellId); IEnumerable<WellDepthToDayDto> GetWellDepthToDay(int wellId);
IEnumerable<WellDepthToIntervalDto> GetWellDepthToInterval(int wellId, IEnumerable<WellDepthToIntervalDto> GetWellDepthToInterval(int wellId,
int intervalHoursTimestamp, int workBeginTimestamp); int intervalHoursTimestamp, int workBeginTimestamp);
IEnumerable<OperationPercentageDto> GetOperationsSummary(int wellId, IEnumerable<OperationDurationDto> GetOperationsSummary(int wellId,
DateTime begin = default, DateTime end = default);
IEnumerable<OperationInfoDto> GetOperationsToTime(int wellId,
DateTime begin = default, DateTime end = default); DateTime begin = default, DateTime end = default);
IEnumerable<OperationInfoDto> GetOperationsToInterval(int wellId,
int intervalHoursTimestamp, int workBeginTimestamp);
DrillingAnalysis GetDrillingAnalysis(IEnumerable<DataSaubBase> dataSaubBases); DrillingAnalysis GetDrillingAnalysis(IEnumerable<DataSaubBase> dataSaubBases);
} }
} }

View File

@ -20,6 +20,12 @@ namespace AsbCloudDb.Model
[Column("date", TypeName = "timestamp with time zone"), Comment("'2021-10-19 18:23:54+05'")] [Column("date", TypeName = "timestamp with time zone"), Comment("'2021-10-19 18:23:54+05'")]
public DateTime Date { get; set; } public DateTime Date { get; set; }
[Column("unix_date", TypeName = "bigint"), Comment("Unix timestamp для Linq запросов с вычислением дат")]
public long UnixDate { get; set; }
[Column("duration"), Comment("Кол-во секунд после предыдущей операции")]
public int Duration { get; set; }
[Column("id_operation")] [Column("id_operation")]
public int? IdOperation { get; set; } public int? IdOperation { get; set; }

View File

@ -60,9 +60,6 @@ namespace AsbCloudInfrastructure.Services
{ {
intervalHoursTimestamp = intervalHoursTimestamp == 0 ? 86400 : intervalHoursTimestamp; intervalHoursTimestamp = intervalHoursTimestamp == 0 ? 86400 : intervalHoursTimestamp;
var intervalTime = new TimeSpan(0, 0, intervalHoursTimestamp);
var workDayBeginTime = new TimeSpan(0, 0, workBeginTimestamp);
var telemetry = telemetryService.GetTelemetryByWellId(wellId); var telemetry = telemetryService.GetTelemetryByWellId(wellId);
if (telemetry is null) if (telemetry is null)
@ -70,8 +67,8 @@ namespace AsbCloudInfrastructure.Services
var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId(telemetry.Id); var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId(telemetry.Id);
var drillingPeriodsInfo = db.GetDepthToInterval(telemetry.Id, (int)intervalTime.TotalSeconds, var drillingPeriodsInfo = db.GetDepthToInterval(telemetry.Id, intervalHoursTimestamp,
(int)workDayBeginTime.TotalSeconds, timezoneOffset); workBeginTimestamp, timezoneOffset);
var wellDepthToIntervalData = drillingPeriodsInfo.Select(d => new WellDepthToIntervalDto var wellDepthToIntervalData = drillingPeriodsInfo.Select(d => new WellDepthToIntervalDto
{ {
@ -82,142 +79,68 @@ namespace AsbCloudInfrastructure.Services
return wellDepthToIntervalData; return wellDepthToIntervalData;
} }
public IEnumerable<OperationPercentageDto> GetOperationsSummary(int wellId, public IEnumerable<OperationDurationDto> GetOperationsSummary(int wellId,
DateTime begin = default, DateTime end = default) DateTime begin = default, DateTime end = default)
{ {
return new List<OperationPercentageDto> var telemetry = telemetryService.GetTelemetryByWellId(wellId);
{
new OperationPercentageDto { ProcessName = "Роторное бурение", Percentage = 19.7 }, if (telemetry is null)
new OperationPercentageDto { ProcessName = "Подъем с проработкой", Percentage = 6.2 }, return null;
new OperationPercentageDto { ProcessName = "Спуск с проработкой", Percentage = 9.4 },
new OperationPercentageDto { ProcessName = "Подъем с промывкой", Percentage = 18.4 }, var operations = (from a in db.DrillingAnalysis
new OperationPercentageDto { ProcessName = "Неподвижное состояние", Percentage = 12.1 }, where a.IdTelemetry == telemetry.Id &&
new OperationPercentageDto { ProcessName = "Вращение без циркуляции", Percentage = 7.4 }, a.Date > begin && a.Date < end &&
new OperationPercentageDto { ProcessName = "Спуск в скважину", Percentage = 16.7 }, a.IdOperation != null
new OperationPercentageDto { ProcessName = "На поверхности", Percentage = 10.1 } join o in db.Operations on a.IdOperation equals o.Id
}; group a by new { a.IdOperation, o.Name } into g
select new OperationDurationDto
{
ProcessName = g.Key.Name,
Duration = g.Where(g => g.Duration > 0)
.Sum(a => a.Duration)
}).ToList();
return operations;
} }
public IEnumerable<OperationInfoDto> GetOperationsToTime(int wellId, public IEnumerable<OperationInfoDto> GetOperationsToInterval(int wellId,
DateTime begin = default, DateTime end = default) int intervalHoursTimestamp, int workBeginTimestamp)
{ {
return new List<OperationInfoDto> intervalHoursTimestamp = intervalHoursTimestamp == 0 ? 86400 : intervalHoursTimestamp;
{
new OperationInfoDto var telemetry = telemetryService.GetTelemetryByWellId(wellId);
{
IntervalBegin = new DateTime(2021, 06, 01, 08, 00, 00), if (telemetry is null)
IntervalEnd = new DateTime(2021, 06, 02, 08, 00, 00), return null;
OperationData = new List<OperationDetailsDto>
{ var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId(telemetry.Id);
new OperationDetailsDto
{ var operations = (from a in db.DrillingAnalysis
OperationName = "Роторное бурение", where a.IdTelemetry == telemetry.Id &&
OperationStartTime = new DateTime(2021, 06, 01, 10, 00, 00), a.IdOperation != null
DurationHours = 1.2 join o in db.Operations on a.IdOperation equals o.Id
}, group a by new {
new OperationDetailsDto Interval = Math.Floor((a.UnixDate - workBeginTimestamp + timezoneOffset) / intervalHoursTimestamp),
{ OperationId = a.IdOperation,
OperationName = "Подъем с проработкой", o.Name } into g
OperationStartTime = new DateTime(2021, 06, 01, 11, 00, 00), select new
DurationHours = 3.2 {
}, IntervalStart = g.Min(d => d.Date).Date,
new OperationDetailsDto OperationName = g.Key.Name,
{ OperationsDuration = g.Sum(an => an.Duration)
OperationName = "Роторное бурение", }).ToList();
OperationStartTime = new DateTime(2021, 06, 01, 12, 00, 00),
DurationHours = 1.5 var operationsGroupedByInterval = operations.GroupBy(op => op.IntervalStart)
}, .Select(o => new OperationInfoDto {
new OperationDetailsDto IntervalBegin = o.Key,
{ Operations = o.Select(opr => new OperationDetailsDto {
OperationName = "Неподвижное состояние", OperationName = opr.OperationName,
OperationStartTime = new DateTime(2021, 06, 01, 13, 00, 00), Duration = opr.OperationsDuration
DurationHours = 0.2 }).ToList()
}, })
new OperationDetailsDto .OrderBy(ops => ops.IntervalBegin);
{
OperationName = "Роторное бурение", return operationsGroupedByInterval;
OperationStartTime = new DateTime(2021, 06, 01, 14, 00, 00),
DurationHours = 3.2
}
}
},
new OperationInfoDto
{
IntervalBegin = new DateTime(2021, 06, 02, 08, 00, 00),
IntervalEnd = new DateTime(2021, 06, 03, 08, 00, 00),
OperationData = new List<OperationDetailsDto>
{
new OperationDetailsDto
{
OperationName = "На поверхности",
OperationStartTime = new DateTime(2021, 06, 13, 10, 01, 00),
DurationHours = 2.2
},
new OperationDetailsDto
{
OperationName = "Спуск в скважину",
OperationStartTime = new DateTime(2021, 06, 13, 11, 10, 00),
DurationHours = 0.4
},
new OperationDetailsDto
{
OperationName = "На поверхности",
OperationStartTime = new DateTime(2021, 06, 13, 12, 20, 00),
DurationHours = 2.5
},
new OperationDetailsDto
{
OperationName = "Вращение без циркуляции",
OperationStartTime = new DateTime(2021, 06, 13, 13, 00, 00),
DurationHours = 1.2
},
new OperationDetailsDto
{
OperationName = "Роторное бурение",
OperationStartTime = new DateTime(2021, 06, 13, 14, 00, 00),
DurationHours = 5.2
}
}
},
new OperationInfoDto
{
IntervalBegin = new DateTime(2021, 06, 03, 08, 00, 00),
IntervalEnd = new DateTime(2021, 06, 04, 08, 00, 00),
OperationData = new List<OperationDetailsDto>
{
new OperationDetailsDto
{
OperationName = "Подъем с проработкой",
OperationStartTime = new DateTime(2021, 06, 12, 10, 00, 00),
DurationHours = 3.2
},
new OperationDetailsDto
{
OperationName = "Спуск с проработкой",
OperationStartTime = new DateTime(2021, 06, 12, 11, 00, 00),
DurationHours = 1.4
},
new OperationDetailsDto
{
OperationName = "Подъем с проработкой",
OperationStartTime = new DateTime(2021, 06, 12, 12, 00, 00),
DurationHours = 0.5
},
new OperationDetailsDto
{
OperationName = "На поверхности",
OperationStartTime = new DateTime(2021, 06, 12, 13, 00, 00),
DurationHours = 3.2
},
new OperationDetailsDto
{
OperationName = "Роторное бурение",
OperationStartTime = new DateTime(2021, 06, 13, 14, 00, 00),
DurationHours = 1.2
}
}
}
};
} }
public DrillingAnalysis GetDrillingAnalysis(IEnumerable<DataSaubBase> dataSaubBases) public DrillingAnalysis GetDrillingAnalysis(IEnumerable<DataSaubBase> dataSaubBases)
@ -258,6 +181,8 @@ namespace AsbCloudInfrastructure.Services
{ {
IdTelemetry = dataSaubBases.First().IdTelemetry, IdTelemetry = dataSaubBases.First().IdTelemetry,
Date = lastSaubDate, Date = lastSaubDate,
UnixDate = (long)(lastSaubDate - new DateTime(1970,1,1,0,0,0)).TotalSeconds,
Duration = (int)(dataSaubBases.Last().Date - dataSaubBases.ElementAt(dataSaubBases.Count() - 2).Date).TotalSeconds,
IsDepthChanges = LinearFunctionCalculator.IsValueChanges(wellDepthChangingIndex, (0.0001, -0.0001)), IsDepthChanges = LinearFunctionCalculator.IsValueChanges(wellDepthChangingIndex, (0.0001, -0.0001)),
IsDepthNotChanges = LinearFunctionCalculator.IsValueNotChanges(wellDepthChangingIndex, (0.0001, -0.0001)), IsDepthNotChanges = LinearFunctionCalculator.IsValueNotChanges(wellDepthChangingIndex, (0.0001, -0.0001)),
IsBitRising = LinearFunctionCalculator.IsValueGoesDown(bitPositionChangingIndex, -0.0001), IsBitRising = LinearFunctionCalculator.IsValueGoesDown(bitPositionChangingIndex, -0.0001),

View File

@ -103,8 +103,10 @@ namespace AsbCloudInfrastructure.Services
if (saubDataCache.GetOrCreateCache(dataSaub.IdTelemetry).Count() > 1) if (saubDataCache.GetOrCreateCache(dataSaub.IdTelemetry).Count() > 1)
{ {
var drillingAnalysis = analyticsService.GetDrillingAnalysis( var dataSaubs = saubDataCache.GetOrCreateCache(dataSaub.IdTelemetry)
saubDataCache.GetOrCreateCache(dataSaub.IdTelemetry)); .OrderBy(d => d.Date);
var drillingAnalysis = analyticsService.GetDrillingAnalysis(dataSaubs);
db.DrillingAnalysis.Add(drillingAnalysis); db.DrillingAnalysis.Add(drillingAnalysis);
} }

View File

@ -33,10 +33,7 @@ namespace AsbCloudWebApi.Controllers
{ {
int? idCustomer = User.GetCustomerId(); int? idCustomer = User.GetCustomerId();
if (idCustomer is null) if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid(); return Forbid();
var wellDepthToDayData = analyticsService.GetWellDepthToDay(wellId); var wellDepthToDayData = analyticsService.GetWellDepthToDay(wellId);
@ -54,17 +51,16 @@ namespace AsbCloudWebApi.Controllers
[HttpGet] [HttpGet]
[Route("{wellId}/wellDepthToInterval")] [Route("{wellId}/wellDepthToInterval")]
[ProducesResponseType(typeof(IEnumerable<WellDepthToIntervalDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<WellDepthToIntervalDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetWellDepthToInterval(int wellId, int intervalHoursTimestamp, int workBeginTimestamp) public IActionResult GetWellDepthToInterval(int wellId,
int intervalHoursTimestamp, int workBeginTimestamp)
{ {
int? idCustomer = User.GetCustomerId(); int? idCustomer = User.GetCustomerId();
if (idCustomer is null) if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid(); return Forbid();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId)) var wellDepthToIntervalData = analyticsService.GetWellDepthToInterval(wellId,
return Forbid(); intervalHoursTimestamp, workBeginTimestamp);
var wellDepthToIntervalData = analyticsService.GetWellDepthToInterval(wellId, intervalHoursTimestamp, workBeginTimestamp);
return Ok(wellDepthToIntervalData); return Ok(wellDepthToIntervalData);
} }
@ -78,15 +74,12 @@ namespace AsbCloudWebApi.Controllers
/// <returns>Коллекцию операций на скважине</returns> /// <returns>Коллекцию операций на скважине</returns>
[HttpGet] [HttpGet]
[Route("{wellId}/operationsSummary")] [Route("{wellId}/operationsSummary")]
[ProducesResponseType(typeof(IEnumerable<OperationPercentageDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<OperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetOperationsSummary(int wellId, DateTime begin = default, DateTime end = default) public IActionResult GetOperationsSummary(int wellId, DateTime begin = default, DateTime end = default)
{ {
int? idCustomer = User.GetCustomerId(); int? idCustomer = User.GetCustomerId();
if (idCustomer is null) if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid(); return Forbid();
var analytics = analyticsService.GetOperationsSummary(wellId, begin, end); var analytics = analyticsService.GetOperationsSummary(wellId, begin, end);
@ -98,24 +91,22 @@ namespace AsbCloudWebApi.Controllers
/// Возвращает детальные данные по операциям на скважине за период /// Возвращает детальные данные по операциям на скважине за период
/// </summary> /// </summary>
/// <param name="wellId">id скважины</param> /// <param name="wellId">id скважины</param>
/// <param name="begin">дата начала интервала</param> /// <param name="intervalHoursTimestamp">количество секунд в необходимом интервале времени</param>
/// <param name="end">дата окончания интервала</param> /// <param name="workBeginTimestamp">количество секунд в времени начала смены</param>
/// <returns>Коллекцию операций на скважине</returns> /// <returns>Коллекцию операций на скважине</returns>
[HttpGet] [HttpGet]
[Route("{wellId}/operationsToTime")] [Route("{wellId}/operationsToInterval")]
[ProducesResponseType(typeof(IEnumerable<OperationPercentageDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<OperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetOperationsToTime(int wellId, DateTime begin = default, DateTime end = default) public IActionResult GetOperationsToInterval(int wellId,
int intervalHoursTimestamp, int workBeginTimestamp)
{ {
int? idCustomer = User.GetCustomerId(); int? idCustomer = User.GetCustomerId();
if (idCustomer is null) if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid(); return Forbid();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId)) var analytics = analyticsService.GetOperationsToInterval(wellId, intervalHoursTimestamp, workBeginTimestamp);
return Forbid();
var analytics = analyticsService.GetOperationsToTime(wellId, begin, end);
return Ok(analytics); return Ok(analytics);
} }