From 6abbf476b11f2ff23175146ba743d02946038d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Wed, 21 Jul 2021 15:29:19 +0500 Subject: [PATCH] =?UTF-8?q?=D0=B0=D0=B2=D1=82=D0=BE=D1=87=D0=B8=D1=81?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/ClusterDto.cs | 10 +- AsbCloudApp/Data/DepositDto.cs | 2 +- AsbCloudApp/Data/IMapPoint.cs | 8 +- AsbCloudApp/Data/WellDrillingStatDto.cs | 2 +- AsbCloudApp/Services/IAnalyticsService.cs | 6 +- AsbCloudApp/Services/IClusterService.cs | 4 - AsbCloudApp/Services/IReportService.cs | 6 +- AsbCloudApp/Services/ISaubDataCache.cs | 4 +- AsbCloudApp/Services/IWellService.cs | 1 - AsbCloudDb/Model/AsbCloudDbContext.cs | 22 ++--- AsbCloudDb/Model/CompanyType.cs | 3 +- AsbCloudDb/Model/IMapPoint.cs | 8 +- AsbCloudDb/Model/Operation.cs | 2 +- AsbCloudDb/Model/Report.cs | 4 +- AsbCloudDb/Model/Well.cs | 2 +- AsbCloudDb/Model/WellSection.cs | 3 +- AsbCloudDb/Model/WellSectionType.cs | 3 +- AsbCloudDb/Model/WellType.cs | 3 +- .../ReportDataSourcePgCloud.cs | 98 +++++++++---------- .../Services/AnalyticsService.cs | 46 +++++---- .../Services/BackgroundQueue.cs | 4 +- .../Services/BackgroundWorkerService.cs | 6 +- .../Services/Cache/CacheDb.cs | 4 +- .../Services/Cache/CacheTable.cs | 6 +- .../Services/DataService.cs | 16 +-- .../Services/InterpolationLine.cs | 4 +- .../Services/OperationDetector.cs | 4 +- .../Services/OperationDetectorService.cs | 26 ++--- .../Services/ReportService.cs | 39 ++++---- .../Services/SaubDataCache.cs | 6 +- .../Services/TelemetryTracker.cs | 4 +- .../Services/TelemetryUserService.cs | 4 +- .../Services/WellService.cs | 2 +- .../Services/СlusterService.cs | 11 +-- .../AnalyticsControllerTests.cs | 60 ++++++------ .../Controllers/AnalyticsController.cs | 12 +-- .../Controllers/ClusterController.cs | 22 ++--- .../Controllers/DepositController.cs | 4 - .../Controllers/MessageController.cs | 2 +- .../Controllers/ReportController.cs | 28 +++--- .../Controllers/TelemetryController.cs | 2 +- AsbCloudWebApi/Controllers/WellController.cs | 6 +- AsbCloudWebApi/DependencyInjection.cs | 1 - AsbCloudWebApi/SignalR/ReportsHub.cs | 4 +- ConsoleApp1/AnalyzeResult.cs | 19 ++-- ConsoleApp1/Program.cs | 5 +- DataTable/Program.cs | 16 +-- DataTable/PropertyHelper.cs | 6 +- DataTable/TableMapper.cs | 12 +-- DataTable/TestDto.cs | 4 - 50 files changed, 265 insertions(+), 311 deletions(-) diff --git a/AsbCloudApp/Data/ClusterDto.cs b/AsbCloudApp/Data/ClusterDto.cs index 4cb189e1..3e757ea8 100644 --- a/AsbCloudApp/Data/ClusterDto.cs +++ b/AsbCloudApp/Data/ClusterDto.cs @@ -1,12 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AsbCloudApp.Data +namespace AsbCloudApp.Data { - public class ClusterDto: IMapPoint + public class ClusterDto : IMapPoint { public int Id { get; set; } public string Name { get; set; } diff --git a/AsbCloudApp/Data/DepositDto.cs b/AsbCloudApp/Data/DepositDto.cs index a8055de2..61801a01 100644 --- a/AsbCloudApp/Data/DepositDto.cs +++ b/AsbCloudApp/Data/DepositDto.cs @@ -1,6 +1,6 @@ namespace AsbCloudApp.Data { - public class DepositDto: IMapPoint + public class DepositDto : IMapPoint { public int Id { get; set; } public string Name { get; set; } diff --git a/AsbCloudApp/Data/IMapPoint.cs b/AsbCloudApp/Data/IMapPoint.cs index c38b742c..fe2798ca 100644 --- a/AsbCloudApp/Data/IMapPoint.cs +++ b/AsbCloudApp/Data/IMapPoint.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AsbCloudApp.Data +namespace AsbCloudApp.Data { public interface IMapPoint { diff --git a/AsbCloudApp/Data/WellDrillingStatDto.cs b/AsbCloudApp/Data/WellDrillingStatDto.cs index 3decb785..e38cb10e 100644 --- a/AsbCloudApp/Data/WellDrillingStatDto.cs +++ b/AsbCloudApp/Data/WellDrillingStatDto.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace AsbCloudApp.Data { - public class WellDrillingStatDto: WellDto + public class WellDrillingStatDto : WellDto { public DateTime? PlanStart { get; set; } public DateTime? PlanEnd { get; set; } diff --git a/AsbCloudApp/Services/IAnalyticsService.cs b/AsbCloudApp/Services/IAnalyticsService.cs index 9a085a8e..d7952a74 100644 --- a/AsbCloudApp/Services/IAnalyticsService.cs +++ b/AsbCloudApp/Services/IAnalyticsService.cs @@ -1,7 +1,7 @@ -using System; -using System.Collections.Generic; -using AsbCloudApp.Data; +using AsbCloudApp.Data; using AsbCloudDb.Model; +using System; +using System.Collections.Generic; namespace AsbCloudApp.Services { diff --git a/AsbCloudApp/Services/IClusterService.cs b/AsbCloudApp/Services/IClusterService.cs index 4c949b31..8c7ce9ad 100644 --- a/AsbCloudApp/Services/IClusterService.cs +++ b/AsbCloudApp/Services/IClusterService.cs @@ -1,9 +1,5 @@ using AsbCloudApp.Data; -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AsbCloudApp.Services { diff --git a/AsbCloudApp/Services/IReportService.cs b/AsbCloudApp/Services/IReportService.cs index 8c3f0556..11c7db8e 100644 --- a/AsbCloudApp/Services/IReportService.cs +++ b/AsbCloudApp/Services/IReportService.cs @@ -1,13 +1,13 @@ -using System; +using AsbCloudApp.Data; +using System; using System.Collections.Generic; -using AsbCloudApp.Data; namespace AsbCloudApp.Services { public interface IReportService { string RootPath { get; } - int CreateReport(int wellId, int stepSeconds, int format, DateTime begin, DateTime end, + int CreateReport(int wellId, int stepSeconds, int format, DateTime begin, DateTime end, Action handleReportProgress, Action handleReportName); int GetReportPagesCount(int wellId, DateTime begin, DateTime end, int stepSeconds, int format); IEnumerable GetSuitableReports(int wellId, DateTime begin, DateTime end, int stepSeconds, int format); diff --git a/AsbCloudApp/Services/ISaubDataCache.cs b/AsbCloudApp/Services/ISaubDataCache.cs index 117b09d9..95745e34 100644 --- a/AsbCloudApp/Services/ISaubDataCache.cs +++ b/AsbCloudApp/Services/ISaubDataCache.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; -using AsbCloudDb.Model; +using AsbCloudDb.Model; +using System.Collections.Generic; namespace AsbCloudApp.Services { diff --git a/AsbCloudApp/Services/IWellService.cs b/AsbCloudApp/Services/IWellService.cs index 421578d7..63d42c4a 100644 --- a/AsbCloudApp/Services/IWellService.cs +++ b/AsbCloudApp/Services/IWellService.cs @@ -1,6 +1,5 @@ using AsbCloudApp.Data; using System.Collections.Generic; -using System.Security.Claims; namespace AsbCloudApp.Services { diff --git a/AsbCloudDb/Model/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs index a6c830da..73efec00 100644 --- a/AsbCloudDb/Model/AsbCloudDbContext.cs +++ b/AsbCloudDb/Model/AsbCloudDbContext.cs @@ -26,7 +26,7 @@ namespace AsbCloudDb.Model public virtual DbSet Wells { get; set; } public virtual DbSet Reports { get; set; } public virtual DbSet Operations { get; set; } - public virtual DbSet TelemetryAnalysis { get; set; } + public virtual DbSet TelemetryAnalysis { get; set; } public virtual DbSet SectionAnalysis { get; set; } public virtual DbSet WellTypes { get; set; } @@ -256,19 +256,19 @@ namespace AsbCloudDb.Model .Include(e => e.Company) .Where(e => e.Login == login); - public (DateTime From, DateTime To) GetDatesRange(int idTelemetry) + public (DateTime From, DateTime To) GetDatesRange(int idTelemetry) where TEntity : class, IIdTelemetryDate { var dbSet = Set(); - var datesRange = (from m in dbSet - where m.IdTelemetry == idTelemetry - group m by m.IdTelemetry into g - select new - { - From = g.Min(d => d.Date), - To = g.Max(d => d.Date) - }).FirstOrDefault(); + var datesRange = (from m in dbSet + where m.IdTelemetry == idTelemetry + group m by m.IdTelemetry into g + select new + { + From = g.Min(d => d.Date), + To = g.Max(d => d.Date) + }).FirstOrDefault(); if (datesRange is null) return (DateTime.MinValue, DateTime.MaxValue); @@ -276,7 +276,7 @@ namespace AsbCloudDb.Model return (datesRange.From, datesRange.To); } - public IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)> GetDepthToInterval (int telemetryId, + public IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)> GetDepthToInterval(int telemetryId, int intervalHoursTimestamp, int workStartTimestamp, double timezoneOffset) { //TODO: Сменить на LINQ группирование diff --git a/AsbCloudDb/Model/CompanyType.cs b/AsbCloudDb/Model/CompanyType.cs index 10e78ec9..0a30805b 100644 --- a/AsbCloudDb/Model/CompanyType.cs +++ b/AsbCloudDb/Model/CompanyType.cs @@ -1,5 +1,4 @@ -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; diff --git a/AsbCloudDb/Model/IMapPoint.cs b/AsbCloudDb/Model/IMapPoint.cs index 8979fa84..663671b2 100644 --- a/AsbCloudDb/Model/IMapPoint.cs +++ b/AsbCloudDb/Model/IMapPoint.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AsbCloudDb.Model +namespace AsbCloudDb.Model { public interface IMapPoint { diff --git a/AsbCloudDb/Model/Operation.cs b/AsbCloudDb/Model/Operation.cs index 7fb6aff9..112cc16d 100644 --- a/AsbCloudDb/Model/Operation.cs +++ b/AsbCloudDb/Model/Operation.cs @@ -1,7 +1,7 @@ using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System.Collections.Generic; namespace AsbCloudDb.Model { diff --git a/AsbCloudDb/Model/Report.cs b/AsbCloudDb/Model/Report.cs index 5e09a075..41bc2e62 100644 --- a/AsbCloudDb/Model/Report.cs +++ b/AsbCloudDb/Model/Report.cs @@ -1,5 +1,5 @@ -using System; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; diff --git a/AsbCloudDb/Model/Well.cs b/AsbCloudDb/Model/Well.cs index 06b2f338..ad3a3275 100644 --- a/AsbCloudDb/Model/Well.cs +++ b/AsbCloudDb/Model/Well.cs @@ -65,7 +65,7 @@ namespace AsbCloudDb.Model [ForeignKey(nameof(IdWellType))] [InverseProperty(nameof(Model.WellType.Wells))] public virtual WellType WellType { get; set; } - + [InverseProperty(nameof(WellSection.Well))] public virtual ICollection Sections { get; set; } diff --git a/AsbCloudDb/Model/WellSection.cs b/AsbCloudDb/Model/WellSection.cs index 037d4e40..0fe88015 100644 --- a/AsbCloudDb/Model/WellSection.cs +++ b/AsbCloudDb/Model/WellSection.cs @@ -1,7 +1,6 @@ using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System; using System.Text.Json.Serialization; #nullable disable @@ -19,7 +18,7 @@ namespace AsbCloudDb.Model public int IdWellSectionType { get; set; } [Column("id_well")] - public int IdWell{ get; set; } + public int IdWell { get; set; } [Column("well_depth_plan"), Comment("глубина план")] public double WellDepthPlan { get; set; } diff --git a/AsbCloudDb/Model/WellSectionType.cs b/AsbCloudDb/Model/WellSectionType.cs index 1d2d30b0..59c31505 100644 --- a/AsbCloudDb/Model/WellSectionType.cs +++ b/AsbCloudDb/Model/WellSectionType.cs @@ -1,9 +1,8 @@ using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System; using System.Text.Json.Serialization; -using System.Collections.Generic; #nullable disable namespace AsbCloudDb.Model diff --git a/AsbCloudDb/Model/WellType.cs b/AsbCloudDb/Model/WellType.cs index 3ac86c96..ee5e6ffc 100644 --- a/AsbCloudDb/Model/WellType.cs +++ b/AsbCloudDb/Model/WellType.cs @@ -1,9 +1,8 @@ using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System; using System.Text.Json.Serialization; -using System.Collections.Generic; #nullable disable namespace AsbCloudDb.Model diff --git a/AsbCloudInfrastructure/ReportDataSourcePgCloud.cs b/AsbCloudInfrastructure/ReportDataSourcePgCloud.cs index 2d230cbb..11d605d3 100644 --- a/AsbCloudInfrastructure/ReportDataSourcePgCloud.cs +++ b/AsbCloudInfrastructure/ReportDataSourcePgCloud.cs @@ -1,9 +1,9 @@ -using AsbSaubReport.Model; +using AsbCloudDb.Model; +using AsbSaubReport.Model; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; -using AsbCloudDb.Model; -using Microsoft.EntityFrameworkCore; namespace AsbSaubReport { @@ -27,9 +27,9 @@ namespace AsbSaubReport { this.context = context; var well = context.Wells - .Include(w=>w.Cluster) - .ThenInclude(c=>c.Deposit) - .Include(w=>w.Companies) + .Include(w => w.Cluster) + .ThenInclude(c => c.Deposit) + .Include(w => w.Companies) .Include(w => w.Telemetry) .FirstOrDefault(w => w.Id == wellId); @@ -50,56 +50,56 @@ namespace AsbSaubReport Deposit = well.Cluster.Deposit.Caption, Cluster = well.Cluster.Caption, Well = well.Caption, - Customer = well.Companies.First(c=>c.IdCompanyType == 1)?.Caption, - DrillingStartDate = well.Telemetry?.Info?.DrillingStartDate??default, - TimeZoneId = well.Telemetry?.Info?.TimeZoneId??default, + Customer = well.Companies.First(c => c.IdCompanyType == 1)?.Caption, + DrillingStartDate = well.Telemetry?.Info?.DrillingStartDate ?? default, + TimeZoneId = well.Telemetry?.Info?.TimeZoneId ?? default, }; } public IQueryable GetDataSaubItems(DateTime begin, DateTime end) => from item in context.DataSaubBases - where item.IdTelemetry == idTelemetry - && item.Date >= begin - && item.Date <= end - select new DataSaubReport - { - Id = item.Id, - Date = item.Date, - Mode = item.Mode, - WellDepth = item.WellDepth, - BitDepth = item.BitDepth, - BlockPosition = item.BlockPosition, - BlockSpeed = item.BlockSpeed, - BlockSpeedSp = item.BlockSpeedSp, - BlockSpeedSpDevelop = item.BlockSpeedSpDevelop, - Pressure = item.Pressure, - PressureSp = item.PressureSp, - AxialLoad = item.AxialLoad, - AxialLoadSp = item.AxialLoadSp, - AxialLoadLimitMax = item.AxialLoadLimitMax, - HookWeight = item.HookWeight, - RotorTorque = item.RotorTorque, - RotorTorqueSp = item.RotorTorqueSp, - RotorSpeed = item.RotorSpeed, - Flow = item.Flow, - PressureSpDevelop = item.PressureSpDevelop, - }; - + where item.IdTelemetry == idTelemetry + && item.Date >= begin + && item.Date <= end + select new DataSaubReport + { + Id = item.Id, + Date = item.Date, + Mode = item.Mode, + WellDepth = item.WellDepth, + BitDepth = item.BitDepth, + BlockPosition = item.BlockPosition, + BlockSpeed = item.BlockSpeed, + BlockSpeedSp = item.BlockSpeedSp, + BlockSpeedSpDevelop = item.BlockSpeedSpDevelop, + Pressure = item.Pressure, + PressureSp = item.PressureSp, + AxialLoad = item.AxialLoad, + AxialLoadSp = item.AxialLoadSp, + AxialLoadLimitMax = item.AxialLoadLimitMax, + HookWeight = item.HookWeight, + RotorTorque = item.RotorTorque, + RotorTorqueSp = item.RotorTorqueSp, + RotorSpeed = item.RotorSpeed, + Flow = item.Flow, + PressureSpDevelop = item.PressureSpDevelop, + }; + public IQueryable GetMessages(DateTime begin, DateTime end) => from item in context.Messages - where item.IdTelemetry == idTelemetry - && item.Date >= begin - && item.Date <= end - select new MessageReport - { - Id = item.Id, - Date = item.Date, - Category = categories[events[item.IdEvent].IdCategory], - User = item.IdTelemetryUser == null - ? "" - : users[(int)item.IdTelemetryUser].MakeDisplayName(), - Text = events[item.IdEvent].MakeMessageText(item) - }; + where item.IdTelemetry == idTelemetry + && item.Date >= begin + && item.Date <= end + select new MessageReport + { + Id = item.Id, + Date = item.Date, + Category = categories[events[item.IdEvent].IdCategory], + User = item.IdTelemetryUser == null + ? "" + : users[(int)item.IdTelemetryUser].MakeDisplayName(), + Text = events[item.IdEvent].MakeMessageText(item) + }; public WellInfoReport GetWellInfo() => info; diff --git a/AsbCloudInfrastructure/Services/AnalyticsService.cs b/AsbCloudInfrastructure/Services/AnalyticsService.cs index 0a663b4a..0fee272b 100644 --- a/AsbCloudInfrastructure/Services/AnalyticsService.cs +++ b/AsbCloudInfrastructure/Services/AnalyticsService.cs @@ -1,10 +1,10 @@ -using System; -using System.Linq; -using AsbCloudApp.Data; +using AsbCloudApp.Data; using AsbCloudApp.Services; -using AsbCloudInfrastructure.Services.Cache; using AsbCloudDb.Model; +using AsbCloudInfrastructure.Services.Cache; +using System; using System.Collections.Generic; +using System.Linq; namespace AsbCloudInfrastructure.Services { @@ -17,7 +17,7 @@ namespace AsbCloudInfrastructure.Services private readonly OperationDetectorService operationDetectorService; private readonly IEnumerable operations; - public AnalyticsService(IAsbCloudDbContext db, ITelemetryService telemetryService, + public AnalyticsService(IAsbCloudDbContext db, ITelemetryService telemetryService, ISaubDataCache saubDataCache, CacheDb cacheDb) { this.db = db; @@ -116,7 +116,7 @@ namespace AsbCloudInfrastructure.Services var unixEnd = (end - new DateTime(1970, 1, 1)).TotalSeconds; var operations = (from a in db.TelemetryAnalysis - where a.IdTelemetry == telemetry.Id && + where a.IdTelemetry == telemetry.Id && a.UnixDate > unixBegin && a.UnixDate < unixEnd && a.IdOperation != null join o in db.Operations on a.IdOperation equals o.Id @@ -147,10 +147,12 @@ namespace AsbCloudInfrastructure.Services where a.IdTelemetry == telemetry.Id && a.IdOperation != null join o in db.Operations on a.IdOperation equals o.Id - group a by new { + group a by new + { Interval = Math.Floor((a.UnixDate - workBeginSeconds + timezoneOffset) / intervalSeconds), - OperationId = a.IdOperation, - o.Name } into g + OperationId = a.IdOperation, + o.Name + } into g select new { IntervalStart = g.Min(d => d.UnixDate), @@ -159,14 +161,16 @@ namespace AsbCloudInfrastructure.Services }).ToList(); var operationsGroupedByInterval = operations.GroupBy(op => op.IntervalStart) - .Select(o => new OperationInfoDto { - IntervalBegin = DateTimeOffset.FromUnixTimeSeconds(o.Key), - Operations = o.Select(opr => new OperationDetailsDto { - OperationName = opr.OperationName, - Duration = opr.OperationsDuration + .Select(o => new OperationInfoDto + { + IntervalBegin = DateTimeOffset.FromUnixTimeSeconds(o.Key), + Operations = o.Select(opr => new OperationDetailsDto + { + OperationName = opr.OperationName, + Duration = opr.OperationsDuration }).ToList() }) - .OrderBy(ops => ops.IntervalBegin); + .OrderBy(ops => ops.IntervalBegin); return operationsGroupedByInterval; } @@ -205,22 +209,22 @@ namespace AsbCloudInfrastructure.Services var lastSaubDate = dataSaubBases.Last().Date; var saubWellDepths = dataSaubBases.Where(sw => sw.WellDepth is not null) - .Select(s => (Value: (double)s.WellDepth, + .Select(s => (Value: (double)s.WellDepth, (s.Date - dataSaubBases.First().Date).TotalSeconds)); var saubBitDepths = dataSaubBases.Where(sw => sw.BitDepth is not null) - .Select(s => (Value: (double)s.BitDepth, + .Select(s => (Value: (double)s.BitDepth, (s.Date - dataSaubBases.First().Date).TotalSeconds)); var saubBlockPositions = dataSaubBases.Where(sw => sw.BlockPosition is not null) - .Select(s => (Value: (double)s.BlockPosition, + .Select(s => (Value: (double)s.BlockPosition, (s.Date - dataSaubBases.First().Date).TotalSeconds)); var saubRotorSpeeds = dataSaubBases.Where(sw => sw.RotorSpeed is not null) - .Select(s => (Value: (double)s.RotorSpeed, + .Select(s => (Value: (double)s.RotorSpeed, (s.Date - dataSaubBases.First().Date).TotalSeconds)); var saubPressures = dataSaubBases.Where(sw => sw.Pressure is not null) - .Select(s => (Value: (double)s.Pressure, + .Select(s => (Value: (double)s.Pressure, (s.Date - dataSaubBases.First().Date).TotalSeconds)); var saubHookWeights = dataSaubBases.Where(sw => sw.HookWeight is not null) - .Select(s => (Value: (double)s.HookWeight, + .Select(s => (Value: (double)s.HookWeight, (s.Date - dataSaubBases.First().Date).TotalSeconds)); var wellDepthChangingIndex = new InterpolationLine(saubWellDepths).GetAForLinearFormula(); diff --git a/AsbCloudInfrastructure/Services/BackgroundQueue.cs b/AsbCloudInfrastructure/Services/BackgroundQueue.cs index 73d7be5c..629551f6 100644 --- a/AsbCloudInfrastructure/Services/BackgroundQueue.cs +++ b/AsbCloudInfrastructure/Services/BackgroundQueue.cs @@ -1,6 +1,6 @@ -using System; +using AsbCloudApp.Services; +using System; using System.Collections.Concurrent; -using AsbCloudApp.Services; namespace AsbCloudInfrastructure.Services { diff --git a/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs b/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs index e675db3a..2917fa26 100644 --- a/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs +++ b/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs @@ -1,7 +1,7 @@ -using System.Threading; -using System.Threading.Tasks; +using AsbCloudApp.Services; using Microsoft.Extensions.Hosting; -using AsbCloudApp.Services; +using System.Threading; +using System.Threading.Tasks; namespace AsbCloudInfrastructure.Services { diff --git a/AsbCloudInfrastructure/Services/Cache/CacheDb.cs b/AsbCloudInfrastructure/Services/Cache/CacheDb.cs index 73630000..9afe92b6 100644 --- a/AsbCloudInfrastructure/Services/Cache/CacheDb.cs +++ b/AsbCloudInfrastructure/Services/Cache/CacheDb.cs @@ -1,5 +1,5 @@ -using System; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using System; using System.Collections.Concurrent; using System.Collections.Generic; diff --git a/AsbCloudInfrastructure/Services/Cache/CacheTable.cs b/AsbCloudInfrastructure/Services/Cache/CacheTable.cs index 1856acd5..e2f9e4ba 100644 --- a/AsbCloudInfrastructure/Services/Cache/CacheTable.cs +++ b/AsbCloudInfrastructure/Services/Cache/CacheTable.cs @@ -28,7 +28,7 @@ namespace AsbCloudInfrastructure.Services.Cache var dbEntities = context.Set().ToList(); cached.AddRange(dbEntities); data.refreshDate = DateTime.Now; - return cached.Count; + return cached.Count; } public async Task RefreshAsync(CancellationToken token = default) @@ -228,7 +228,7 @@ namespace AsbCloudInfrastructure.Services.Cache else updated = dbSet.Add(entity); upsertedEntries.Add(updated.Entity); - } + } context.SaveChanges(); Refresh(); return upsertedEntries; @@ -296,7 +296,7 @@ namespace AsbCloudInfrastructure.Services.Cache dbEntities.Add(dbSet.Add(item).Entity); context.SaveChanges(); cached.AddRange(dbEntities); - return dbEntities; + return dbEntities; } public async Task> InsertAsync(IEnumerable newEntities, CancellationToken token = default) diff --git a/AsbCloudInfrastructure/Services/DataService.cs b/AsbCloudInfrastructure/Services/DataService.cs index bcbc98a8..58055f32 100644 --- a/AsbCloudInfrastructure/Services/DataService.cs +++ b/AsbCloudInfrastructure/Services/DataService.cs @@ -19,7 +19,7 @@ namespace AsbCloudInfrastructure.Services private readonly CacheTable cacheWells; public DataService(IAsbCloudDbContext db, ITelemetryService telemetryService, - IAnalyticsService analyticsService, ISaubDataCache saubDataCache, + IAnalyticsService analyticsService, ISaubDataCache saubDataCache, CacheDb cacheDb, MapperConfiguration mapperConfiguration) { this.db = db; @@ -57,8 +57,8 @@ namespace AsbCloudInfrastructure.Services if (fullDataCount > 1.75 * approxPointsCount) { - var m = (int)Math.Round(1d*fullDataCount / approxPointsCount); - if(m > 1) + var m = (int)Math.Round(1d * fullDataCount / approxPointsCount); + if (m > 1) fullData = fullData.Where(d => d.Id % m == 0); } @@ -81,10 +81,10 @@ namespace AsbCloudInfrastructure.Services var dtoMaxDate = dtos.Max(d => d.Date); var oldDataSaubBase = (from d in db.DataSaubBases - where d.IdTelemetry == telemetryId - && d.Date > dtoMinDate - && d.Date < dtoMaxDate - select d).ToList(); + where d.IdTelemetry == telemetryId + && d.Date > dtoMinDate + && d.Date < dtoMaxDate + select d).ToList(); if (oldDataSaubBase.Any()) { @@ -111,7 +111,7 @@ namespace AsbCloudInfrastructure.Services var (From, To) = db.GetDatesRange(telemetry.Id); - return new DatesRangeDto { From = From, To = To}; + return new DatesRangeDto { From = From, To = To }; } } } diff --git a/AsbCloudInfrastructure/Services/InterpolationLine.cs b/AsbCloudInfrastructure/Services/InterpolationLine.cs index fc1443f4..75a36e75 100644 --- a/AsbCloudInfrastructure/Services/InterpolationLine.cs +++ b/AsbCloudInfrastructure/Services/InterpolationLine.cs @@ -41,7 +41,7 @@ namespace AsbCloudInfrastructure.Services return (double)result; } - public static bool IsValueNotChanges(double value, + public static bool IsValueNotChanges(double value, (double upperBound, double lowerBound) bounds) => value < bounds.upperBound && value > bounds.lowerBound; @@ -51,7 +51,7 @@ namespace AsbCloudInfrastructure.Services public static bool IsValueDecreases(double value, double bound) => value < bound; - public static bool IsAverageLessThanBound(IEnumerable<(double Value, double TotalSeconds)> values, + public static bool IsAverageLessThanBound(IEnumerable<(double Value, double TotalSeconds)> values, double bound) => (values.Sum(s => s.Value) / values.Count()) < bound; diff --git a/AsbCloudInfrastructure/Services/OperationDetector.cs b/AsbCloudInfrastructure/Services/OperationDetector.cs index fbcec8e6..469ddc2f 100644 --- a/AsbCloudInfrastructure/Services/OperationDetector.cs +++ b/AsbCloudInfrastructure/Services/OperationDetector.cs @@ -1,5 +1,5 @@ -using System; -using AsbCloudDb.Model; +using AsbCloudDb.Model; +using System; namespace AsbCloudInfrastructure.Services { diff --git a/AsbCloudInfrastructure/Services/OperationDetectorService.cs b/AsbCloudInfrastructure/Services/OperationDetectorService.cs index 96555fa8..b1d5a8d2 100644 --- a/AsbCloudInfrastructure/Services/OperationDetectorService.cs +++ b/AsbCloudInfrastructure/Services/OperationDetectorService.cs @@ -1,6 +1,6 @@ -using System.Collections.Generic; +using AsbCloudDb.Model; +using System.Collections.Generic; using System.Linq; -using AsbCloudDb.Model; namespace AsbCloudInfrastructure.Services { @@ -18,7 +18,7 @@ namespace AsbCloudInfrastructure.Services Operation = operations.FirstOrDefault(o => o.Name.Equals("На поверхности")), Detect = (data) => { - return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing + return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && data.IsBitDepthLess20 && data.IsHookWeightLt3; } }, @@ -29,8 +29,8 @@ namespace AsbCloudInfrastructure.Services Detect = (data) => { return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && - !data.IsBitPositionIncreasing && !data.IsBitPositionDecreasing && - data.IsBlockPositionDecreasing && !data.IsBlockPositionIncreasing && + !data.IsBitPositionIncreasing && !data.IsBitPositionDecreasing && + data.IsBlockPositionDecreasing && !data.IsBlockPositionIncreasing && data.IsHookWeightLt3; } }, @@ -41,7 +41,7 @@ namespace AsbCloudInfrastructure.Services Detect = (data) => { return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && - data.IsBitPositionDecreasing && data.IsBlockPositionDecreasing && + data.IsBitPositionDecreasing && data.IsBlockPositionDecreasing && data.IsRotorSpeedGt3 && data.IsPressureGt20; } }, @@ -52,7 +52,7 @@ namespace AsbCloudInfrastructure.Services Detect = (data) => { return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && - data.IsBitPositionIncreasing && data.IsBitPositionIncreasing && + data.IsBitPositionIncreasing && data.IsBitPositionIncreasing && data.IsRotorSpeedGt3 && data.IsPressureGt20; } }, @@ -63,7 +63,7 @@ namespace AsbCloudInfrastructure.Services Detect = (data) => { return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && - data.IsBitPositionDecreasing && data.IsBitPositionDecreasing && + data.IsBitPositionDecreasing && data.IsBitPositionDecreasing && data.IsRotorSpeedLt3 && data.IsPressureGt20; } }, @@ -73,8 +73,8 @@ namespace AsbCloudInfrastructure.Services Operation = operations.FirstOrDefault(o => o.Name.Equals("Спуск с промывкой")), Detect = (data) => { - return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && - data.IsBitPositionIncreasing && data.IsBlockPositionIncreasing && + return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && + data.IsBitPositionIncreasing && data.IsBlockPositionIncreasing && data.IsRotorSpeedLt3 && data.IsPressureGt20; } }, @@ -84,8 +84,8 @@ namespace AsbCloudInfrastructure.Services Operation = operations.FirstOrDefault(o => o.Name.Equals("Спуск в скважину")), Detect = (data) => { - return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && - data.IsBitPositionIncreasing && data.IsBlockPositionIncreasing && + return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && + data.IsBitPositionIncreasing && data.IsBlockPositionIncreasing && data.IsRotorSpeedLt3 && data.IsPressureLt20; } }, @@ -130,7 +130,7 @@ namespace AsbCloudInfrastructure.Services { return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing && !data.IsBitPositionDecreasing && !data.IsBitPositionIncreasing && - !data.IsBlockPositionDecreasing && !data.IsBlockPositionIncreasing && + !data.IsBlockPositionDecreasing && !data.IsBlockPositionIncreasing && data.IsRotorSpeedLt3 && data.IsPressureGt20; } }, diff --git a/AsbCloudInfrastructure/Services/ReportService.cs b/AsbCloudInfrastructure/Services/ReportService.cs index 55cc730a..06a14f34 100644 --- a/AsbCloudInfrastructure/Services/ReportService.cs +++ b/AsbCloudInfrastructure/Services/ReportService.cs @@ -1,13 +1,13 @@ -using AsbCloudApp.Services; -using AsbCloudApp.Data; +using AsbCloudApp.Data; +using AsbCloudApp.Services; using AsbCloudDb.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.IO; +using AsbSaubReport; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; -using AsbSaubReport; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; namespace AsbCloudInfrastructure.Services { @@ -27,10 +27,10 @@ namespace AsbCloudInfrastructure.Services RootPath = "reports"; } - public string RootPath { get ; private set; } + public string RootPath { get; private set; } - public int CreateReport(int wellId, int stepSeconds, int format, DateTime begin, - DateTime end, Action progressHandler, Action reportNameHandler) + public int CreateReport(int wellId, int stepSeconds, int format, DateTime begin, + DateTime end, Action progressHandler, Action reportNameHandler) { var newReportId = queue.EnqueueTask((id) => { @@ -40,9 +40,9 @@ namespace AsbCloudInfrastructure.Services using (var context = new AsbCloudDbContext(optionsBuilder.Options)) { var generator = GetReportGenerator(wellId, begin, end, stepSeconds, format, context); - generator.OnProgress += (s,e) => progressHandler.Invoke(e.progress, e.operation, id); + generator.OnProgress += (s, e) => progressHandler.Invoke(e.progress, e.operation, id); var newReportName = generator.Make(); - if(newReportName is not null) + if (newReportName is not null) { var shorReportName = Path.GetFileName(newReportName); reportNameHandler.Invoke(shorReportName, id); @@ -76,7 +76,7 @@ namespace AsbCloudInfrastructure.Services { var suitableReportsFromDb = GetSuitableReportsFromDb(wellId, begin, end, stepSeconds, format); - var suitableReportsProperties = suitableReportsFromDb.Select(r => new ReportPropertiesDto + var suitableReportsProperties = suitableReportsFromDb.Select(r => new ReportPropertiesDto { Id = r.Id, Name = Path.GetFileName(r.Name), @@ -100,8 +100,8 @@ namespace AsbCloudInfrastructure.Services return null; var datesRange = (from d in db.DataSaubBases - where d.IdTelemetry == telemetry.Id - select d.Date).Union( + where d.IdTelemetry == telemetry.Id + select d.Date).Union( from m in db.Messages where m.IdTelemetry == telemetry.Id select m.Date).DefaultIfEmpty().GroupBy(g => true) @@ -109,10 +109,11 @@ namespace AsbCloudInfrastructure.Services { From = g.Min(), To = g.Max() - }).OrderBy(gr => gr.From).FirstOrDefault(); + }).OrderBy(gr => gr.From).FirstOrDefault(); - return new DatesRangeDto { - From = datesRange.From, + return new DatesRangeDto + { + From = datesRange.From, To = datesRange.To.Year == 1 ? DateTime.MaxValue : datesRange.To }; } @@ -143,7 +144,7 @@ namespace AsbCloudInfrastructure.Services WithEvents = true }; - switch(format) + switch (format) { case 0: return generator; diff --git a/AsbCloudInfrastructure/Services/SaubDataCache.cs b/AsbCloudInfrastructure/Services/SaubDataCache.cs index d2a9b659..21e4bced 100644 --- a/AsbCloudInfrastructure/Services/SaubDataCache.cs +++ b/AsbCloudInfrastructure/Services/SaubDataCache.cs @@ -1,6 +1,6 @@ -using System.Collections.Generic; -using AsbCloudApp.Services; +using AsbCloudApp.Services; using AsbCloudDb.Model; +using System.Collections.Generic; namespace AsbCloudInfrastructure.Services { @@ -8,7 +8,7 @@ namespace AsbCloudInfrastructure.Services { public TelemetryAnalysis CurrentAnalysis { get; set; } - private readonly Dictionary> saubData = + private readonly Dictionary> saubData = new Dictionary>(); public IEnumerable GetOrCreateCache(int telemetryId) diff --git a/AsbCloudInfrastructure/Services/TelemetryTracker.cs b/AsbCloudInfrastructure/Services/TelemetryTracker.cs index 21472af1..158dcb46 100644 --- a/AsbCloudInfrastructure/Services/TelemetryTracker.cs +++ b/AsbCloudInfrastructure/Services/TelemetryTracker.cs @@ -1,7 +1,7 @@ -using System; +using AsbCloudApp.Services; +using System; using System.Collections.Generic; using System.Linq; -using AsbCloudApp.Services; namespace AsbCloudInfrastructure.Services { diff --git a/AsbCloudInfrastructure/Services/TelemetryUserService.cs b/AsbCloudInfrastructure/Services/TelemetryUserService.cs index ef5b59de..a340ea61 100644 --- a/AsbCloudInfrastructure/Services/TelemetryUserService.cs +++ b/AsbCloudInfrastructure/Services/TelemetryUserService.cs @@ -1,6 +1,6 @@ -using AsbCloudApp.Data; +using AsbCloudApp.Comparators; +using AsbCloudApp.Data; using AsbCloudApp.Services; -using AsbCloudApp.Comparators; using AsbCloudDb.Model; using AsbCloudInfrastructure.Services.Cache; using System.Collections.Generic; diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index d91c7046..30cfbd86 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -2,9 +2,9 @@ using AsbCloudApp.Services; using AsbCloudDb.Model; using AsbCloudInfrastructure.Services.Cache; +using System; using System.Collections.Generic; using System.Linq; -using System; namespace AsbCloudInfrastructure.Services { diff --git a/AsbCloudInfrastructure/Services/СlusterService.cs b/AsbCloudInfrastructure/Services/СlusterService.cs index 4e7201cb..5721b98c 100644 --- a/AsbCloudInfrastructure/Services/СlusterService.cs +++ b/AsbCloudInfrastructure/Services/СlusterService.cs @@ -1,13 +1,9 @@ using AsbCloudApp.Data; using AsbCloudApp.Services; using AsbCloudDb.Model; -using AsbCloudInfrastructure.Services.Cache; using Microsoft.EntityFrameworkCore; -using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AsbCloudInfrastructure.Services { @@ -23,7 +19,7 @@ namespace AsbCloudInfrastructure.Services public IEnumerable GetDeposits(int idCompany) { var entities = db.GetWellsForCompany(idCompany) - .Select(e=>e.Cluster.Deposit) + .Select(e => e.Cluster.Deposit) .Distinct() .ToList(); @@ -60,7 +56,7 @@ namespace AsbCloudInfrastructure.Services { var entities = db.GetWellsForCompany(idCompany) .Select(e => e.Cluster) - .Where(e=>e.IdDeposit == depositId) + .Where(e => e.IdDeposit == depositId) .Distinct() .ToList(); @@ -120,7 +116,8 @@ namespace AsbCloudInfrastructure.Services RateOfPenetrationPlan = e.RateOfPenetrationPlan, RouteSpeedFact = e.RouteSpeedFact, RouteSpeedPlan = e.RouteSpeedPlan, - Sections = e.Sections.Select(s => new WellSectionDto { + Sections = e.Sections.Select(s => new WellSectionDto + { BhaDownSpeedFact = s.BhaDownSpeedFact, BhaDownSpeedPlan = s.BhaDownSpeedPlan, BhaUpSpeedFact = s.BhaUpSpeedFact, diff --git a/AsbCloudWebApi.Tests/ControllersTests/AnalyticsControllerTests.cs b/AsbCloudWebApi.Tests/ControllersTests/AnalyticsControllerTests.cs index eca4ab9a..1aa58d08 100644 --- a/AsbCloudWebApi.Tests/ControllersTests/AnalyticsControllerTests.cs +++ b/AsbCloudWebApi.Tests/ControllersTests/AnalyticsControllerTests.cs @@ -1,13 +1,13 @@ -using System; +using AsbCloudApp.Data; +using AsbCloudApp.Services; +using AsbCloudWebApi.Controllers; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Moq; +using System; using System.Collections.Generic; using System.Security.Claims; using Xunit; -using Moq; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Http; -using AsbCloudWebApi.Controllers; -using AsbCloudApp.Services; -using AsbCloudApp.Data; namespace AsbCloudWebApi.Tests.ControllersTests { @@ -56,7 +56,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests { var result = controller.GetWellDepthToDay(1); var okResult = result as OkObjectResult; - + Assert.NotNull(okResult); } @@ -66,7 +66,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests var result = controller.GetWellDepthToDay(1); var okResult = result as OkObjectResult; var resultCount = ((List)okResult.Value).Count; - + Assert.Equal(3, resultCount); } @@ -75,17 +75,17 @@ namespace AsbCloudWebApi.Tests.ControllersTests { var emptyUserController = new AnalyticsController(analyticsService.Object, wellService.Object); - + var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { }, "mock")); - + emptyUserController.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; - + var result = emptyUserController.GetWellDepthToDay(1); var forbidResult = result as ForbidResult; - + Assert.NotNull(forbidResult); } @@ -96,23 +96,23 @@ namespace AsbCloudWebApi.Tests.ControllersTests wellServiceReturnsFalse.Setup(s => s.CheckWellOwnership(It.IsAny(), It.IsAny())) .Returns(false); - + var newControllerInstance = new AnalyticsController(analyticsService.Object, wellServiceReturnsFalse.Object); - + var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim("idCompany", "1"), }, "mock")); - + newControllerInstance.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; - + var result = newControllerInstance.GetWellDepthToDay(1); var forbidResult = result as ForbidResult; - + Assert.NotNull(forbidResult); } @@ -120,26 +120,26 @@ namespace AsbCloudWebApi.Tests.ControllersTests public void It_should_return_204_if_dtos_is_empty() { var emptyAnalyticsService = new Mock(); - + emptyAnalyticsService.Setup(s => s.GetWellDepthToDay(It.IsAny())) .Returns(new List()); - + var newControllerInstance = new AnalyticsController(emptyAnalyticsService.Object, wellService.Object); - + var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim("idCompany", "1"), }, "mock")); - + newControllerInstance.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; - + var result = newControllerInstance.GetWellDepthToDay(1); var notFoundResult = result as NoContentResult; - + Assert.NotNull(notFoundResult); } @@ -147,26 +147,26 @@ namespace AsbCloudWebApi.Tests.ControllersTests public void It_should_return_204_if_dtos_is_null() { var emptyAnalyticsService = new Mock(); - + emptyAnalyticsService.Setup(s => s.GetWellDepthToDay(It.IsAny())) .Returns(value: null); - + var newControllerInstance = new AnalyticsController(emptyAnalyticsService.Object, wellService.Object); - + var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim("idCompany", "1"), }, "mock")); - + newControllerInstance.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; - + var result = newControllerInstance.GetWellDepthToDay(1); var notFoundResult = result as NoContentResult; - + Assert.NotNull(notFoundResult); } } diff --git a/AsbCloudWebApi/Controllers/AnalyticsController.cs b/AsbCloudWebApi/Controllers/AnalyticsController.cs index b9680bda..a7a79fa6 100644 --- a/AsbCloudWebApi/Controllers/AnalyticsController.cs +++ b/AsbCloudWebApi/Controllers/AnalyticsController.cs @@ -1,10 +1,10 @@ -using System; -using System.Linq; -using System.Collections.Generic; -using AsbCloudApp.Data; +using AsbCloudApp.Data; using AsbCloudApp.Services; -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; namespace AsbCloudWebApi.Controllers { @@ -78,7 +78,7 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [Route("{wellId}/wellDepthToInterval")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetWellDepthToInterval(int wellId, + public IActionResult GetWellDepthToInterval(int wellId, int intervalSeconds, int workBeginSeconds) { int? idCompany = User.GetCompanyId(); diff --git a/AsbCloudWebApi/Controllers/ClusterController.cs b/AsbCloudWebApi/Controllers/ClusterController.cs index 5d798772..ea6ec473 100644 --- a/AsbCloudWebApi/Controllers/ClusterController.cs +++ b/AsbCloudWebApi/Controllers/ClusterController.cs @@ -1,12 +1,8 @@ using AsbCloudApp.Data; using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using System; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace AsbCloudWebApi.Controllers { @@ -45,36 +41,36 @@ namespace AsbCloudWebApi.Controllers /// /// Получение доступных пользователю скважин /// - /// + /// /// - [HttpGet("{clusterId}")] + [HttpGet("{idCluster}")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetWells(int clusterId) + public IActionResult GetWells(int idCluster) { int? idCompany = User.GetCompanyId(); if (idCompany is null) return Forbid(); - var result = clusterService.GetWells((int)idCompany, clusterId); + var result = clusterService.GetWells((int)idCompany, idCluster); return Ok(result); } /// - /// Получение обопщенной аналитики по кусту (лучшая/худшая скважина) + /// Получение обопщенной статистики по кусту (лучшая/худшая скважина) /// - /// + /// /// - [HttpGet("{clusterId}/Analysis")] + [HttpGet("{idCluster}/Stat")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetAnalysis(int clusterId) + public IActionResult GetStat(int idCluster) { int? idCompany = User.GetCompanyId(); if (idCompany is null) return Forbid(); - var result = clusterService.GetStat((int)idCompany, clusterId); + var result = clusterService.GetStat((int)idCompany, idCluster); return Ok(result); } } diff --git a/AsbCloudWebApi/Controllers/DepositController.cs b/AsbCloudWebApi/Controllers/DepositController.cs index fb5f9708..af26dab9 100644 --- a/AsbCloudWebApi/Controllers/DepositController.cs +++ b/AsbCloudWebApi/Controllers/DepositController.cs @@ -1,12 +1,8 @@ using AsbCloudApp.Data; using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using System; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace AsbCloudWebApi.Controllers { diff --git a/AsbCloudWebApi/Controllers/MessageController.cs b/AsbCloudWebApi/Controllers/MessageController.cs index f016272e..0bf593b7 100644 --- a/AsbCloudWebApi/Controllers/MessageController.cs +++ b/AsbCloudWebApi/Controllers/MessageController.cs @@ -59,7 +59,7 @@ namespace AsbCloudWebApi.Controllers return Forbid(); bool isCompanyOwnsWell = wellService.CheckWellOwnership((int)idCompany, wellId); - + if (!isCompanyOwnsWell) return Forbid(); diff --git a/AsbCloudWebApi/Controllers/ReportController.cs b/AsbCloudWebApi/Controllers/ReportController.cs index 251829b6..efe63116 100644 --- a/AsbCloudWebApi/Controllers/ReportController.cs +++ b/AsbCloudWebApi/Controllers/ReportController.cs @@ -1,13 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.IO; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using AsbCloudApp.Data; +using AsbCloudApp.Data; using AsbCloudApp.Services; using AsbCloudWebApi.SignalR; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; namespace AsbCloudWebApi.Controllers { @@ -29,16 +29,18 @@ namespace AsbCloudWebApi.Controllers this.reportsHubContext = reportsHubContext; } - private void HandleReportProgressAsync (float progress, string operation, int id) => - Task.Run(()=> { + private void HandleReportProgressAsync(float progress, string operation, int id) => + Task.Run(() => + { reportsHubContext.Clients.Group($"Report_{id}").SendAsync( nameof(IReportHubClient.GetReportProgress), new { Progress = progress, Operation = operation, ReportName = "" } ); }); - private void HandleReportNameAsync (string reportName, int groupId) => - Task.Run(() => { + private void HandleReportNameAsync(string reportName, int groupId) => + Task.Run(() => + { reportsHubContext.Clients.All.SendAsync( nameof(IReportHubClient.GetReportProgress), new { Progress = 100, Operation = "Отчет успешно создан", ReportName = reportName } @@ -58,9 +60,9 @@ namespace AsbCloudWebApi.Controllers [HttpPost] [Route("{wellId}/report")] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] - public IActionResult CreateReport(int wellId, int stepSeconds, int format, + public IActionResult CreateReport(int wellId, int stepSeconds, int format, DateTime begin = default, DateTime end = default) - { + { int? idCompany = User.GetCompanyId(); if (idCompany is null) diff --git a/AsbCloudWebApi/Controllers/TelemetryController.cs b/AsbCloudWebApi/Controllers/TelemetryController.cs index fbbd82b0..f7534813 100644 --- a/AsbCloudWebApi/Controllers/TelemetryController.cs +++ b/AsbCloudWebApi/Controllers/TelemetryController.cs @@ -41,7 +41,7 @@ namespace AsbCloudWebApi.Controllers this.telemetryHubContext = telemetryHubContext; this.telemetryTracker = telemetryTracker; } - + /// /// Принимает общую информацию по скважине /// diff --git a/AsbCloudWebApi/Controllers/WellController.cs b/AsbCloudWebApi/Controllers/WellController.cs index 5401f2e5..abfb1c7e 100644 --- a/AsbCloudWebApi/Controllers/WellController.cs +++ b/AsbCloudWebApi/Controllers/WellController.cs @@ -44,18 +44,18 @@ namespace AsbCloudWebApi.Controllers { var idCompany = User.GetCompanyId(); - if(idCompany is null) + if (idCompany is null) { return NoContent(); } - + var transmittingWells = wellService.GetTransmittingWells((int)idCompany); if (transmittingWells is null || !transmittingWells.Any()) return NoContent(); return Ok(transmittingWells); - + } } } diff --git a/AsbCloudWebApi/DependencyInjection.cs b/AsbCloudWebApi/DependencyInjection.cs index 3c4cec14..0741aad5 100644 --- a/AsbCloudWebApi/DependencyInjection.cs +++ b/AsbCloudWebApi/DependencyInjection.cs @@ -1,6 +1,5 @@ using AsbCloudInfrastructure.Services; using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi.Models; diff --git a/AsbCloudWebApi/SignalR/ReportsHub.cs b/AsbCloudWebApi/SignalR/ReportsHub.cs index 534063bd..364e731d 100644 --- a/AsbCloudWebApi/SignalR/ReportsHub.cs +++ b/AsbCloudWebApi/SignalR/ReportsHub.cs @@ -1,6 +1,6 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.SignalR; +using System.Threading.Tasks; namespace AsbCloudWebApi.SignalR { diff --git a/ConsoleApp1/AnalyzeResult.cs b/ConsoleApp1/AnalyzeResult.cs index e6eb8581..0dfe9eea 100644 --- a/ConsoleApp1/AnalyzeResult.cs +++ b/ConsoleApp1/AnalyzeResult.cs @@ -1,20 +1,17 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace ConsoleApp1 { - public enum WellDepthState {Idle, Increase } - public enum BitDepthState {Idle, Increase, Decrease, OnSurface} - public enum BlockState {Idle, Increase, Decrease} - public enum RotorState {Inactive, Active} + public enum WellDepthState { Idle, Increase } + public enum BitDepthState { Idle, Increase, Decrease, OnSurface } + public enum BlockState { Idle, Increase, Decrease } + public enum RotorState { Inactive, Active } public enum PressureState { Inactive, Active } public enum HookWeightState { Idle, None } - public enum DrillingOperation { - Unknown, - RotorDrilling, + public enum DrillingOperation + { + Unknown, + RotorDrilling, SlideDrilling, TrippingOutReaming, TrippingInReaming, diff --git a/ConsoleApp1/Program.cs b/ConsoleApp1/Program.cs index 7635e3f7..ea1428e4 100644 --- a/ConsoleApp1/Program.cs +++ b/ConsoleApp1/Program.cs @@ -29,7 +29,8 @@ namespace ConsoleApp1 .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True") .Options; - var acfg = new MapperConfiguration(cfg => { + var acfg = new MapperConfiguration(cfg => + { cfg.CreateMap(); cfg.CreateMap(); @@ -46,7 +47,7 @@ namespace ConsoleApp1 var telemetryService = new TelemetryService(context, cachedDb, acfg); var telemetryUserService = new TelemetryUserService(context, cachedDb, telemetryService); - var tusers = new List { + var tusers = new List { new TelemetryUserDto{ Id=1, Level=0, diff --git a/DataTable/Program.cs b/DataTable/Program.cs index 061ba1ea..b7bdb23a 100644 --- a/DataTable/Program.cs +++ b/DataTable/Program.cs @@ -1,12 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.Serialization; -using System.Runtime.Serialization.Formatters.Binary; -using System.Text.Json; - -namespace DataTable +namespace DataTable { class Program { @@ -60,7 +52,7 @@ namespace DataTable // }); //var tMapper = new TableMapper(); - + //var tab = tMapper.MakeTable(listDtos); //var e = tMapper.AsEnumerable(tab); @@ -76,12 +68,12 @@ namespace DataTable //formatter.Serialize(mem, tab); //var tabBinBytes = new byte[mem.Length]; //Array.Copy(mem.GetBuffer(), tabBinBytes, mem.Length); - + //mem = new MemoryStream(); //formatter.Serialize(mem, listDtos); //var listBinBytes = new byte[mem.Length]; //Array.Copy(mem.GetBuffer(), listBinBytes, mem.Length); - + //Console.WriteLine($"tabJsonBytes:{tabJsonBytes.Length}"); //Console.WriteLine($"listJsonBytes:{listJsonBytes.Length}"); //Console.WriteLine($"tabBinBytes:{tabBinBytes.Length}"); diff --git a/DataTable/PropertyHelper.cs b/DataTable/PropertyHelper.cs index 2d7c563e..9b453051 100644 --- a/DataTable/PropertyHelper.cs +++ b/DataTable/PropertyHelper.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq.Expressions; using System.Reflection; -using System.ComponentModel; namespace DataTable { @@ -43,7 +43,7 @@ namespace DataTable private string GetDescription(PropertyInfo property) { - var descriptionAttr = property.GetCustomAttribute(); + var descriptionAttr = property.GetCustomAttribute(); return descriptionAttr?.Description ?? string.Empty; } @@ -56,7 +56,7 @@ namespace DataTable public object Get(object instance) => Getter(instance); - public static string MakeIdentity(string propertyTypeName, string propertyName) + public static string MakeIdentity(string propertyTypeName, string propertyName) => $"{propertyTypeName}_{propertyName}".ToLower(); } } diff --git a/DataTable/TableMapper.cs b/DataTable/TableMapper.cs index e41b5821..1af75273 100644 --- a/DataTable/TableMapper.cs +++ b/DataTable/TableMapper.cs @@ -4,7 +4,7 @@ using System.Linq; namespace DataTable { public class TableMapper - where T: new() + where T : new() { private readonly Dictionary props; @@ -23,14 +23,14 @@ namespace DataTable { if ((table?.Headers is null) || (table?.Rows is null) || - (!table.Headers.Any()) || + (!table.Headers.Any()) || (!table.Rows.Any()) || - (!props.Any()) ) + (!props.Any())) yield break; var headerIdToProp = new Dictionary(props.Count); - foreach(var (_, propHelper) in props) - for(var i = 0; i < table.Headers.Count(); i++) + foreach (var (_, propHelper) in props) + for (var i = 0; i < table.Headers.Count(); i++) { var header = table.Headers.ElementAt(i); var columnType = System.Type.GetType(header.ColumnType); @@ -64,7 +64,7 @@ namespace DataTable }).ToArray(); var rows = new List>(data.Count()); - foreach(var dataItem in data) + foreach (var dataItem in data) rows.Add(MakeRow(dataItem)); table.Rows = rows; diff --git a/DataTable/TestDto.cs b/DataTable/TestDto.cs index 4264e0c9..78824ba1 100644 --- a/DataTable/TestDto.cs +++ b/DataTable/TestDto.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace DataTable {