Deleted link to AsbCloudDb from AsbCloudApp + codefix

This commit is contained in:
KharchenkoVV 2021-08-09 14:01:57 +05:00
parent 433900a1ee
commit 91da4fa9c2
18 changed files with 108 additions and 94 deletions

View File

@ -4,12 +4,4 @@
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AsbCloudDb\AsbCloudDb.csproj" />
</ItemGroup>
</Project>

View File

@ -23,6 +23,11 @@ namespace AsbCloudApp.Data
/// </summary>
public int? Mode { get; set; }
/// <summary>
/// telemetry id
/// </summary>
public int IdTelemetry { get; set; }
/// <summary>
/// telemetry user
/// </summary>

View File

@ -0,0 +1,26 @@
namespace AsbCloudApp.Data
{
public class TelemetryAnalysisDto
{
public int Id { get; set; }
public int IdTelemetry { get; set; }
public int IdOperation { get; set; }
public long UnixDate { get; set; }
public int DurationSec { get; set; }
public double? OperationStartDepth { get; set; }
public double? OperationEndDepth { get; set; }
public bool IsWellDepthIncreasing { get; set; }
public bool IsWellDepthDecreasing { get; set; }
public bool IsBitPositionIncreasing { get; set; }
public bool IsBitPositionDecreasing { get; set; }
public bool IsBitPositionLt20 { get; set; }
public bool IsBlockPositionIncreasing { get; set; }
public bool IsBlockPositionDecreasing { get; set; }
public bool IsRotorSpeedLt3 { get; set; }
public bool IsRotorSpeedGt3 { get; set; }
public bool IsPressureLt20 { get; set; }
public bool IsPressureGt20 { get; set; }
public bool IsHookWeightNotChanges { get; set; }
public bool IsHookWeightLt3 { get; set; }
}
}

View File

@ -1,5 +1,4 @@
using AsbCloudApp.Data;
using AsbCloudDb.Model;
using System;
using System.Collections.Generic;
@ -17,6 +16,6 @@ namespace AsbCloudApp.Services
DateTime begin = default, DateTime end = default);
IEnumerable<TelemetryOperationInfoDto> GetOperationsToInterval(int idWell,
int intervalHoursTimestamp, int workBeginTimestamp);
void SaveAnalytics(DataSaubBase dataSaub);
void SaveAnalytics(DataSaubBaseDto dataSaub);
}
}

View File

@ -1,12 +1,12 @@
using AsbCloudDb.Model;
using System.Collections.Generic;
using System.Collections.Generic;
using AsbCloudApp.Data;
namespace AsbCloudApp.Services
{
public interface ISaubDataCache
{
TelemetryAnalysis CurrentAnalysis { get; set; }
IEnumerable<DataSaubBase> GetOrCreateCache(int telemetryId);
void AddData(DataSaubBase data);
TelemetryAnalysisDto CurrentAnalysis { get; set; }
IEnumerable<DataSaubBaseDto> GetOrCreateCache(int telemetryId);
void AddData(DataSaubBaseDto data);
}
}

View File

@ -1,5 +1,4 @@
using AsbCloudApp.Data;
using AsbCloudDb.Model;
namespace AsbCloudApp.Services
{
@ -9,6 +8,6 @@ namespace AsbCloudApp.Services
int GetOrCreateTemetryIdByUid(string uid);
double GetTimezoneOffsetByTelemetryId(int idTelemetry);
void UpdateInfo(string uid, TelemetryInfoDto info);
Telemetry GetTelemetryByidWell(int idWell);
int? GetIdTelemetryByIdWell(int idWell);
}
}

View File

@ -1,5 +1,4 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;

View File

@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Mapster;
namespace AsbCloudInfrastructure.Services
{
@ -31,13 +32,13 @@ namespace AsbCloudInfrastructure.Services
public IEnumerable<WellDepthToDayDto> GetWellDepthToDay(int idWell)
{
var telemetry = telemetryService.GetTelemetryByidWell(idWell);
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
if (telemetry is null)
if (telemetryId is null)
return null;
var depthToTimeData = (from d in db.DataSaubBases
where d.IdTelemetry == telemetry.Id
where d.IdTelemetry == telemetryId
select new
{
d.Id,
@ -64,14 +65,14 @@ namespace AsbCloudInfrastructure.Services
{
intervalSeconds = intervalSeconds == 0 ? 86400 : intervalSeconds;
var telemetry = telemetryService.GetTelemetryByidWell(idWell);
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
if (telemetry is null)
if (telemetryId is null)
return null;
var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId(telemetry.Id);
var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId((int)telemetryId);
var drillingPeriodsInfo = db.GetDepthToInterval(telemetry.Id, intervalSeconds,
var drillingPeriodsInfo = db.GetDepthToInterval((int)telemetryId, intervalSeconds,
workBeginSeconds, timezoneOffset);
var wellDepthToIntervalData = drillingPeriodsInfo.Select(d => new WellDepthToIntervalDto
@ -87,14 +88,14 @@ namespace AsbCloudInfrastructure.Services
IEnumerable<int> categoryIds = default, DateTime begin = default,
DateTime end = default, int skip = 0, int take = 32)
{
var telemetry = telemetryService.GetTelemetryByidWell(idWell);
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
if (telemetry is null)
if (telemetryId is null)
return null;
var operations = from a in db.TelemetryAnalysis.Include(t => t.Operation)
where a.IdTelemetry == telemetry.Id
select a;
where a.IdTelemetry == telemetryId
select a;
if ((categoryIds != default) && (categoryIds.Any()))
operations = operations.Where(o => categoryIds.Contains(o.IdOperation));
@ -150,16 +151,16 @@ namespace AsbCloudInfrastructure.Services
public IEnumerable<TelemetryOperationDurationDto> GetOperationsSummary(int idWell,
DateTime begin = default, DateTime end = default)
{
var telemetry = telemetryService.GetTelemetryByidWell(idWell);
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
if (telemetry is null)
if (telemetryId is null)
return null;
var unixBegin = (begin - new DateTime(1970, 1, 1)).TotalSeconds;
var unixEnd = (end - new DateTime(1970, 1, 1)).TotalSeconds;
var operations = (from a in db.TelemetryAnalysis
where a.IdTelemetry == telemetry.Id &&
where a.IdTelemetry == telemetryId &&
a.UnixDate > unixBegin && a.UnixDate < unixEnd
join o in db.Operations on a.IdOperation equals o.Id
group a by new { a.IdOperation, o.Name } into g
@ -178,15 +179,15 @@ namespace AsbCloudInfrastructure.Services
{
intervalSeconds = intervalSeconds == 0 ? 86400 : intervalSeconds;
var telemetry = telemetryService.GetTelemetryByidWell(idWell);
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
if (telemetry is null)
if (telemetryId is null)
return null;
var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId(telemetry.Id);
var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId((int)telemetryId);
var operations = (from a in db.TelemetryAnalysis
where a.IdTelemetry == telemetry.Id
where a.IdTelemetry == telemetryId
join o in db.Operations on a.IdOperation equals o.Id
group a by new
{
@ -216,36 +217,36 @@ namespace AsbCloudInfrastructure.Services
return operationsGroupedByInterval;
}
public void SaveAnalytics(DataSaubBase dataSaub)
public void SaveAnalytics(DataSaubBaseDto dataSaubDto)
{
saubDataCache.AddData(dataSaub);
saubDataCache.AddData(dataSaubDto);
if (saubDataCache.GetOrCreateCache(dataSaub.IdTelemetry).Count() > 1)
if (saubDataCache.GetOrCreateCache(dataSaubDto.IdTelemetry).Count() > 1)
{
var dataSaubs = saubDataCache.GetOrCreateCache(dataSaub.IdTelemetry)
var dataSaubs = saubDataCache.GetOrCreateCache(dataSaubDto.IdTelemetry)
.OrderBy(d => d.Date);
var telemetryAnalysis = GetDrillingAnalysis(dataSaubs);
var telemetryAnalysisDto = GetDrillingAnalysis(dataSaubs);
if (saubDataCache.CurrentAnalysis is null)
saubDataCache.CurrentAnalysis = telemetryAnalysis;
saubDataCache.CurrentAnalysis = telemetryAnalysisDto;
if (saubDataCache.CurrentAnalysis.IdOperation == telemetryAnalysis.IdOperation)
if (saubDataCache.CurrentAnalysis.IdOperation == telemetryAnalysisDto.IdOperation)
{
saubDataCache.CurrentAnalysis.DurationSec +=
telemetryAnalysis.DurationSec;
saubDataCache.CurrentAnalysis.OperationEndDepth = dataSaub.WellDepth;
telemetryAnalysisDto.DurationSec;
saubDataCache.CurrentAnalysis.OperationEndDepth = dataSaubDto.WellDepth;
}
else
{
db.TelemetryAnalysis.Add(saubDataCache.CurrentAnalysis);
saubDataCache.CurrentAnalysis = telemetryAnalysis;
saubDataCache.CurrentAnalysis.OperationStartDepth = dataSaub.WellDepth;
db.TelemetryAnalysis.Add(saubDataCache.CurrentAnalysis.Adapt<TelemetryAnalysis>());
saubDataCache.CurrentAnalysis = telemetryAnalysisDto;
saubDataCache.CurrentAnalysis.OperationStartDepth = dataSaubDto.WellDepth;
}
}
}
private TelemetryAnalysis GetDrillingAnalysis(IEnumerable<DataSaubBase> dataSaubBases)
private TelemetryAnalysisDto GetDrillingAnalysis(IEnumerable<DataSaubBaseDto> dataSaubBases)
{
var lastSaubDate = dataSaubBases.Last().Date;
@ -279,7 +280,7 @@ namespace AsbCloudInfrastructure.Services
var IsBlockGoesDown = InterpolationLine.IsValueIncreases(blockPositionChangingIndex, 0.0001);
var IsBlockStandsStill = InterpolationLine.IsValueNotChanges(blockPositionChangingIndex, (0.0001, -0.0001));
var drillingAnalysis = new TelemetryAnalysis
var drillingAnalysis = new TelemetryAnalysisDto
{
IdTelemetry = dataSaubBases.First().IdTelemetry,
UnixDate = (long)(lastSaubDate - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds,

View File

@ -4,7 +4,6 @@ using AsbCloudDb.Model;
using AsbCloudApp.Services;
using Mapster;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
namespace AsbCloudInfrastructure.Services
{
@ -22,12 +21,12 @@ namespace AsbCloudInfrastructure.Services
dbSet = context.Set<TModel>();
}
public IEnumerable<Tdto> GetAll(System.Linq.Expressions.Expression<System.Func<TModel, bool>> predicate = null)
public IEnumerable<Tdto> GetAll(System.Linq.Expressions.Expression<System.Func<object, bool>> predicate = null)
{
IQueryable<TModel> entities = dbSet;
if (predicate is not null)
entities = entities.Where(predicate);
entities = entities.Where(predicate).Cast<TModel>();
var dto = entities.Adapt<Tdto>();
return dto;

View File

@ -85,13 +85,14 @@ namespace AsbCloudInfrastructure.Services
db.DataSaubBases.RemoveRange(oldDataSaubBase);
foreach (var item in dtos)
foreach (var dto in dtos)
{
var dataSaub = item.Adapt<DataSaubBase>();
var dataSaub = dto.Adapt<DataSaubBase>();
dataSaub.IdTelemetry = telemetryId;
db.DataSaubBases.Add(dataSaub);
analyticsService.SaveAnalytics(dataSaub);
dto.IdTelemetry = telemetryId;
analyticsService.SaveAnalytics(dto);
}
db.SaveChanges();
@ -99,11 +100,11 @@ namespace AsbCloudInfrastructure.Services
public DatesRangeDto GetDataDatesRange(int idWell)
{
var telemetry = telemetryService.GetTelemetryByidWell(idWell);
if (telemetry is null)
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
if (telemetryId is null)
return null;
var (From, To) = db.GetDatesRange<DataSaubBase>(telemetry.Id);
var (From, To) = db.GetDatesRange<DataSaubBase>((int)telemetryId);
return new DatesRangeDto { From = From, To = To };
}

View File

@ -49,10 +49,6 @@ namespace AsbCloudInfrastructure.Services
int idCategory, DateTime begin = default, DateTime end = default,
int skip = 0, int take = 32)
{
var telemetry = telemetryService.GetTelemetryByidWell(idWell);
if (telemetry is null)
return null;
var filesInfoQuery = db.Files.Include(f => f.User)
.Where(f => f.IdWell == idWell &&
f.IdCategory == idCategory);

View File

@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Linq;
using AsbCloudDb.Model;
using AsbCloudApp.Services;
using Mapster;

View File

@ -27,17 +27,17 @@ namespace AsbCloudInfrastructure.Services
public PaginationContainer<MessageDto> GetMessages(int idWell, IEnumerable<int> categoryids = default, DateTime begin = default, DateTime end = default, int skip = 0, int take = 32)
{
var telemetry = telemetryService.GetTelemetryByidWell(idWell);
if (telemetry is null)
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
if (telemetryId is null)
return null;
var events = cacheEvents.Select(e => e.IdTelemetry == telemetry.Id);
var events = cacheEvents.Select(e => e.IdTelemetry == telemetryId);
if (!events.Any())
return null;
var messages = from m in db.Messages
where m.IdTelemetry == telemetry.Id
where m.IdTelemetry == telemetryId
select m;
if ((categoryids != default) && (categoryids.Any()))
@ -72,7 +72,7 @@ namespace AsbCloudInfrastructure.Services
if (messagesList.Count == 0)
return result;
var users = cacheTUsers.Select(u => u.IdTelemetry == telemetry.Id);
var users = cacheTUsers.Select(u => u.IdTelemetry == telemetryId);
foreach (var message in messagesList)
{
@ -98,11 +98,11 @@ namespace AsbCloudInfrastructure.Services
public DatesRangeDto GetMessagesDatesRange(int idWell)
{
var telemetry = telemetryService.GetTelemetryByidWell(idWell);
if (telemetry is null)
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
if (telemetryId is null)
return null;
var (From, To) = db.GetDatesRange<Message>(telemetry.Id);
var (From, To) = db.GetDatesRange<Message>((int)telemetryId);
return new DatesRangeDto { From = From, To = To };
}

View File

@ -111,16 +111,16 @@ namespace AsbCloudInfrastructure.Services
public DatesRangeDto GetReportsDatesRange(int idWell)
{
var telemetry = telemetryService.GetTelemetryByidWell(idWell);
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
if (telemetry is null)
if (telemetryId is null)
return null;
var datesRange = (from d in db.DataSaubBases
where d.IdTelemetry == telemetry.Id
where d.IdTelemetry == telemetryId
select d.Date).Union(
from m in db.Messages
where m.IdTelemetry == telemetry.Id
where m.IdTelemetry == telemetryId
select m.Date).DefaultIfEmpty().GroupBy(g => true)
.Select(g => new
{

View File

@ -1,25 +1,25 @@
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using System.Collections.Generic;
namespace AsbCloudInfrastructure.Services
{
public class SaubDataCache : ISaubDataCache
{
public TelemetryAnalysis CurrentAnalysis { get; set; }
public TelemetryAnalysisDto CurrentAnalysis { get; set; }
private readonly Dictionary<int, List<DataSaubBase>> saubData =
new Dictionary<int, List<DataSaubBase>>();
private readonly Dictionary<int, List<DataSaubBaseDto>> saubData =
new Dictionary<int, List<DataSaubBaseDto>>();
public IEnumerable<DataSaubBase> GetOrCreateCache(int telemetryId)
public IEnumerable<DataSaubBaseDto> GetOrCreateCache(int telemetryId)
{
if (!saubData.ContainsKey(telemetryId))
saubData[telemetryId] = new List<DataSaubBase>();
saubData[telemetryId] = new List<DataSaubBaseDto>();
return saubData[telemetryId];
}
public void AddData(DataSaubBase data)
public void AddData(DataSaubBaseDto data)
{
GetOrCreateCache(data.IdTelemetry);

View File

@ -1,4 +1,5 @@
using AsbCloudDb.Model;
using AsbCloudApp.Data;
using System;
namespace AsbCloudInfrastructure.Services
@ -7,6 +8,6 @@ namespace AsbCloudInfrastructure.Services
{
public int Order { get; set; }
public TelemetryOperation Operation { get; set; }
public Func<TelemetryAnalysis, bool> Detect { get; set; }
public Func<TelemetryAnalysisDto, bool> Detect { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using AsbCloudDb.Model;
using AsbCloudApp.Data;
using System.Collections.Generic;
using System.Linq;
@ -179,7 +180,7 @@ namespace AsbCloudInfrastructure.Services
};
}
public TelemetryOperation DetectOperation(TelemetryAnalysis data) =>
public TelemetryOperation DetectOperation(TelemetryAnalysisDto data) =>
detectors.OrderBy(d => d.Order).First(o => o.Detect(data)).Operation
?? new TelemetryOperation { Id = 1, Name = "Невозможно определить операцию" };
}

View File

@ -33,17 +33,13 @@ namespace AsbCloudInfrastructure.Services
cacheTelemetry.Upsert(telemetry);
}
public Telemetry GetTelemetryByidWell(int idWell)
public int? GetIdTelemetryByIdWell(int idWell)
{
var well = cacheWells.FirstOrDefault(w => w.Id == idWell);
if (well is null)
return null;
var telemetry = cacheTelemetry.FirstOrDefault(t => t.Id == well.Id);
if (telemetry is null)
return null;
return telemetry;
return well.IdTelemetry;
}
private Well GetWellByTelemetryUid(string uid)