From 54d917c17e33e3c1161cf9a49cfb5f34cc6438cb Mon Sep 17 00:00:00 2001 From: KharchenkoVV Date: Tue, 20 Jul 2021 15:13:26 +0500 Subject: [PATCH] =?UTF-8?q?CS2-34:=20=D0=92=20AnalyticsService=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=BC=D0=B5=D1=82?= =?UTF-8?q?=D0=BE=D0=B4,=20=D0=B2=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=89?= =?UTF-8?q?=D0=B0=D1=8E=D1=89=D0=B8=D0=B9=20=D0=B2=D1=81=D0=B5=20=D0=BE?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=81=D0=BA=D0=B2=D0=B0=D0=B6=D0=B8=D0=BD=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/OperationDto.cs | 13 ++++++++++ AsbCloudApp/Services/IAnalyticsService.cs | 1 + .../Services/AnalyticsService.cs | 22 +++++++++++++++++ .../Controllers/AnalyticsController.cs | 24 ++++++++++++++++++- 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 AsbCloudApp/Data/OperationDto.cs diff --git a/AsbCloudApp/Data/OperationDto.cs b/AsbCloudApp/Data/OperationDto.cs new file mode 100644 index 00000000..b74cd57e --- /dev/null +++ b/AsbCloudApp/Data/OperationDto.cs @@ -0,0 +1,13 @@ +using System; + +namespace AsbCloudApp.Data +{ + public class OperationDto + { + public string Name { get; set; } + public DateTime Begin { get; set; } + public DateTime End { get; set; } + public double OperationStartDepth { get; set; } + public double OperationEndDepth { get; set; } + } +} diff --git a/AsbCloudApp/Services/IAnalyticsService.cs b/AsbCloudApp/Services/IAnalyticsService.cs index 6654ee68..9a085a8e 100644 --- a/AsbCloudApp/Services/IAnalyticsService.cs +++ b/AsbCloudApp/Services/IAnalyticsService.cs @@ -7,6 +7,7 @@ namespace AsbCloudApp.Services { public interface IAnalyticsService { + IEnumerable GetOperations(int wellId); IEnumerable GetWellDepthToDay(int wellId); IEnumerable GetWellDepthToInterval(int wellId, int intervalHoursTimestamp, int workBeginTimestamp); diff --git a/AsbCloudInfrastructure/Services/AnalyticsService.cs b/AsbCloudInfrastructure/Services/AnalyticsService.cs index 6e9a0f5b..0a663b4a 100644 --- a/AsbCloudInfrastructure/Services/AnalyticsService.cs +++ b/AsbCloudInfrastructure/Services/AnalyticsService.cs @@ -28,6 +28,28 @@ namespace AsbCloudInfrastructure.Services operationDetectorService = new OperationDetectorService(operations); } + public IEnumerable GetOperations(int wellId) + { + var telemetry = telemetryService.GetTelemetryByWellId(wellId); + + if (telemetry is null) + return null; + + var operations = (from a in db.TelemetryAnalysis + where a.IdTelemetry == telemetry.Id + join o in db.Operations on a.IdOperation equals o.Id + select new OperationDto + { + Name = o.Name, + Begin = DateTimeOffset.FromUnixTimeSeconds(a.UnixDate).DateTime, + End = DateTimeOffset.FromUnixTimeSeconds(a.UnixDate + a.Duration).DateTime, + OperationStartDepth = a.OperationStartDepth ?? 0.0, + OperationEndDepth = a.OperationEndDepth ?? 0.0 + }).ToList().OrderBy(op => op.Begin); + + return operations; + } + public IEnumerable GetWellDepthToDay(int wellId) { var telemetry = telemetryService.GetTelemetryByWellId(wellId); diff --git a/AsbCloudWebApi/Controllers/AnalyticsController.cs b/AsbCloudWebApi/Controllers/AnalyticsController.cs index e7947017..82c06521 100644 --- a/AsbCloudWebApi/Controllers/AnalyticsController.cs +++ b/AsbCloudWebApi/Controllers/AnalyticsController.cs @@ -22,6 +22,29 @@ namespace AsbCloudWebApi.Controllers this.wellService = wellService; } + /// + /// Возвращает список операций на скважине за все время + /// + /// id скважины + /// Список операций на скважине за все время + [HttpGet] + [Route("{wellId}/operations")] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + public IActionResult GetOperations(int wellId) + { + int? idCustomer = User.GetCustomerId(); + + if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId)) + return Forbid(); + + var analytics = analyticsService.GetOperations(wellId); + + if (analytics is null || !analytics.Any()) + return NoContent(); + + return Ok(analytics); + } + /// /// Возвращает данные по скважине "глубина-день" /// @@ -104,7 +127,6 @@ namespace AsbCloudWebApi.Controllers /// количество секунд в необходимом интервале времени /// количество секунд в времени начала смены /// Коллекцию операций на скважине - [HttpGet] [Route("{wellId}/operationsToInterval")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)]