Забрал домой

This commit is contained in:
Фролов 2021-12-07 11:34:06 +05:00
parent 634bdee1e3
commit ee01ab30db
11 changed files with 37 additions and 61 deletions

View File

@ -1,22 +0,0 @@
using AsbCloudApp.Data;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudApp.Services
{
[Obsolete]
public interface IDataService
{
Task<IEnumerable<TelemetryDataSaubDto>> GetAsync(int idWell, DateTime dateBegin = default,
double intervalSec = 600d, int approxPointsCount = 1024,
CancellationToken token = default);
Task<int> UpdateDataAsync(string uid, IEnumerable<TelemetryDataSaubDto> dtos,
CancellationToken token);
Task<DatesRangeDto> GetDataDatesRangeAsync(int idWell,
CancellationToken token);
}
}

View File

@ -1,14 +1,13 @@
# Миграции # Миграции
## создать миграцию ## Создать миграцию
``` ```
dotnet ef migrations add <MigrationName> --project AsbCloudDb dotnet ef migrations add <MigrationName> --project AsbCloudDb
``` ```
## откатить миграцию ## Откатить миграцию
``` ```
dotnet ef migrations remvoe <MigrationName> --project AsbCloudDb dotnet ef migrations remvoe <MigrationName> --project AsbCloudDb
``` ```
\<MigrationName> - Name of migration class.
<MigrationName> - Name of migration class
После создания миграции обязательно прочитать сгенерированый код. После создания миграции обязательно прочитать сгенерированый код.
## Применить миграции ## Применить миграции
@ -17,14 +16,15 @@ dotnet ef migrations remvoe <MigrationName> --project AsbCloudDb
dotnet ef database update --project .\AsbCloudDb dotnet ef database update --project .\AsbCloudDb
``` ```
# Backup # Backup and restore
## Backup
Terminal: Terminal:
``` ```
sudo -u postgres pg_dump -Fc -U postgres postgres -W > dump_2021-11-26.bak sudo -u postgres pg_dump -Fc -U postgres postgres -W > dump_2021-11-26.bak
``` ```
# Restore backup ## Restore backup
## Step 1. (Re)Create DB and schema IF needeed. ### Step 1. (Re)Create DB and schema IF needed.
psql: psql:
``` ```
--drop schema public cascade; --drop schema public cascade;
@ -33,12 +33,13 @@ CREATE DATABASE postgres;
create schema public; create schema public;
``` ```
## Step 2. Innit timescaledb and prepare DB to restore ### Step 2. Innit timescaledb and prepare DB to restore
``` ```
CREATE EXTENSION IF NOT EXISTS timescaledb; CREATE EXTENSION IF NOT EXISTS timescaledb;
SELECT timescaledb_pre_restore(); SELECT timescaledb_pre_restore();
``` ```
## Step 3. Restore DB, then 'exit resore mode'. [Longest operation]
### Step 3. Restore DB, then [Longest operation]
Terminal: Terminal:
``` ```
sudo -u postgres psql -p 5499 -U postgres postgres -W < dump_2021-11-26.bak sudo -u postgres psql -p 5499 -U postgres postgres -W < dump_2021-11-26.bak
@ -47,7 +48,7 @@ OR psql:
``` ```
\! pg_restore -Fc -d postgres dump_2021-11-26.bak \! pg_restore -Fc -d postgres dump_2021-11-26.bak
``` ```
Then psql: Then 'exit resore mode' psql:
``` ```
SELECT timescaledb_post_restore(); SELECT timescaledb_post_restore();
``` ```

View File

@ -254,7 +254,7 @@ namespace AsbCloudInfrastructure.Services.Analysis
if (dataSaubPart is null) if (dataSaubPart is null)
break; break;
var count = dataSaubPart.Count(); var count = dataSaubPart.Count;
var skip = 0; var skip = 0;
if (step > count) if (step > count)
@ -434,31 +434,31 @@ namespace AsbCloudInfrastructure.Services.Analysis
var intervalEndDate = operations.First().IntervalStart + intervalSeconds; var intervalEndDate = operations.First().IntervalStart + intervalSeconds;
foreach (var op in operations) foreach (var (IntervalStart, OperationName, OperationDuration) in operations)
{ {
if (op.IntervalStart < intervalEndDate) if (IntervalStart < intervalEndDate)
{ {
groupedOperationsObj.Operations.Add(new TelemetryOperationDetailsDto groupedOperationsObj.Operations.Add(new TelemetryOperationDetailsDto
{ {
OperationName = op.OperationName, OperationName = OperationName,
DurationSec = op.OperationDuration DurationSec = OperationDuration
}); });
} }
else else
{ {
groupedOperationsList.Add(groupedOperationsObj); groupedOperationsList.Add(groupedOperationsObj);
intervalEndDate = op.IntervalStart + intervalSeconds; intervalEndDate = IntervalStart + intervalSeconds;
groupedOperationsObj = new TelemetryOperationInfoDto groupedOperationsObj = new TelemetryOperationInfoDto
{ {
IntervalBegin = DateTimeOffset.FromUnixTimeSeconds(op.IntervalStart), IntervalBegin = DateTimeOffset.FromUnixTimeSeconds(IntervalStart),
Operations = new List<TelemetryOperationDetailsDto>() Operations = new List<TelemetryOperationDetailsDto>()
}; };
groupedOperationsObj.Operations.Add(new TelemetryOperationDetailsDto groupedOperationsObj.Operations.Add(new TelemetryOperationDetailsDto
{ {
OperationName = op.OperationName, OperationName = OperationName,
DurationSec = op.OperationDuration DurationSec = OperationDuration
}); });
} }
} }

View File

@ -195,7 +195,7 @@ namespace AsbCloudInfrastructure.Services
return userPermissionsInfo.Select(p => new return userPermissionsInfo.Select(p => new
{ {
PermissionName = cachePermissions.FirstOrDefault(c => c.Id == p.IdPermission)?.Name, PermissionName = cachePermissions.FirstOrDefault(c => c.Id == p.IdPermission)?.Name,
PermissionValue = p.PermissionValue p.PermissionValue
}).ToDictionary(k => k.PermissionName, v => v.PermissionValue); }).ToDictionary(k => k.PermissionName, v => v.PermissionValue);
} }

View File

@ -33,7 +33,7 @@ namespace AsbCloudInfrastructure.Services
select well).ToListAsync(token) select well).ToListAsync(token)
.ConfigureAwait(false); .ConfigureAwait(false);
var gDepositEntities = groupWells(wellEntities); var gDepositEntities = GroupWells(wellEntities);
var dtos = CreateDepositDto(gDepositEntities); var dtos = CreateDepositDto(gDepositEntities);
@ -54,7 +54,7 @@ namespace AsbCloudInfrastructure.Services
select well).ToListAsync(token) select well).ToListAsync(token)
.ConfigureAwait(false); .ConfigureAwait(false);
var gDepositEntities = groupWells(wellEntities); var gDepositEntities = GroupWells(wellEntities);
var dtos = CreateDepositDto(gDepositEntities); var dtos = CreateDepositDto(gDepositEntities);
@ -114,7 +114,7 @@ namespace AsbCloudInfrastructure.Services
return dtos; return dtos;
} }
private IEnumerable<IGrouping<Deposit, IGrouping<Cluster, Well>>> groupWells(IEnumerable<Well> wellEntities) private static IEnumerable<IGrouping<Deposit, IGrouping<Cluster, Well>>> GroupWells(IEnumerable<Well> wellEntities)
{ {
return wellEntities return wellEntities
.GroupBy(w => w.Cluster) .GroupBy(w => w.Cluster)

View File

@ -104,7 +104,7 @@ namespace AsbCloudInfrastructure.Services
public virtual async Task<int> UpdateAsync(int id, TDto item, CancellationToken token = default) public virtual async Task<int> UpdateAsync(int id, TDto item, CancellationToken token = default)
{ {
var existingEntity = await dbSet.AsNoTracking().FirstOrDefaultAsync(e => e.Id == id).ConfigureAwait(false); var existingEntity = await dbSet.AsNoTracking().FirstOrDefaultAsync(e => e.Id == id, token).ConfigureAwait(false);
if (existingEntity is null) if (existingEntity is null)
return 0; return 0;
var entity = Convert(item); var entity = Convert(item);

View File

@ -16,7 +16,6 @@ namespace AsbCloudInfrastructure.Services
{ {
private readonly IAsbCloudDbContext db; private readonly IAsbCloudDbContext db;
private readonly ITelemetryService telemetryService; private readonly ITelemetryService telemetryService;
private readonly CacheTable<Telemetry> cacheTelemetry;
private readonly CacheTable<TelemetryEvent> cacheEvents; private readonly CacheTable<TelemetryEvent> cacheEvents;
private readonly CacheTable<TelemetryUser> cacheTUsers; private readonly CacheTable<TelemetryUser> cacheTUsers;
@ -24,7 +23,6 @@ namespace AsbCloudInfrastructure.Services
{ {
this.db = db; this.db = db;
this.telemetryService = telemetryService; this.telemetryService = telemetryService;
cacheTelemetry = cacheDb.GetCachedTable<Telemetry>((AsbCloudDbContext)db);
cacheEvents = cacheDb.GetCachedTable<TelemetryEvent>((AsbCloudDbContext)db); cacheEvents = cacheDb.GetCachedTable<TelemetryEvent>((AsbCloudDbContext)db);
cacheTUsers = cacheDb.GetCachedTable<TelemetryUser>((AsbCloudDbContext)db); cacheTUsers = cacheDb.GetCachedTable<TelemetryUser>((AsbCloudDbContext)db);
} }

View File

@ -18,13 +18,12 @@ namespace AsbCloudInfrastructure.Services
const int fastLimitMs = 500; const int fastLimitMs = 500;
static readonly char[] stackTraceSeparators = "\r\n".ToCharArray(); static readonly char[] stackTraceSeparators = "\r\n".ToCharArray();
private readonly ConcurrentQueue<RequestLogDto> fastRequests = new ConcurrentQueue<RequestLogDto>();
private readonly ConcurrentQueue<RequestLogDto> slowRequests = new ConcurrentQueue<RequestLogDto>();
private readonly ConcurrentQueue<RequestLogDto> errorRequests = new ConcurrentQueue<RequestLogDto>();
private readonly ConcurrentDictionary<string, RequestLogUserDto> users = new ConcurrentDictionary<string, RequestLogUserDto>();
ConcurrentQueue<RequestLogDto> fastRequests = new ConcurrentQueue<RequestLogDto>(); private static IEnumerable<RequestLogDto> Get(IEnumerable<RequestLogDto> list, int take = -1)
ConcurrentQueue<RequestLogDto> slowRequests = new ConcurrentQueue<RequestLogDto>();
ConcurrentQueue<RequestLogDto> errorRequests = new ConcurrentQueue<RequestLogDto>();
ConcurrentDictionary<string, RequestLogUserDto> users = new ConcurrentDictionary<string, RequestLogUserDto>();
private IEnumerable<RequestLogDto> Get(IEnumerable<RequestLogDto> list, int take = -1)
{ {
IEnumerable<RequestLogDto> orderedlist = list.OrderByDescending(r => r.Date); IEnumerable<RequestLogDto> orderedlist = list.OrderByDescending(r => r.Date);
if (take > 0) if (take > 0)

View File

@ -109,7 +109,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
return memoryStream; return memoryStream;
} }
private void AddOperationsToWorkbook(XLWorkbook workbook, IEnumerable<WellOperation> operations) private static void AddOperationsToWorkbook(XLWorkbook workbook, IEnumerable<WellOperation> operations)
{ {
var planOperations = operations.Where(o => o.IdType == 0); var planOperations = operations.Where(o => o.IdType == 0);
if (planOperations.Any()) if (planOperations.Any())
@ -126,17 +126,17 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
} }
} }
private void AddOperationsToSheet(IXLWorksheet sheet, IEnumerable<WellOperation> operations) private static void AddOperationsToSheet(IXLWorksheet sheet, IEnumerable<WellOperation> operations)
{ {
var operationsList = operations.ToList(); var operationsList = operations.ToList();
for (int i = 0; i < operationsList.Count(); i++) for (int i = 0; i < operationsList.Count; i++)
{ {
var row = sheet.Row(1 + i + headerRowsCount); var row = sheet.Row(1 + i + headerRowsCount);
AddOperationToRow(row, operationsList[i]); AddOperationToRow(row, operationsList[i]);
} }
} }
private void AddOperationToRow(IXLRow row, WellOperation operation) private static void AddOperationToRow(IXLRow row, WellOperation operation)
{ {
row.Cell(columnSection).Value = operation.WellSectionType?.Caption; row.Cell(columnSection).Value = operation.WellSectionType?.Caption;
row.Cell(columnCategory).Value = operation.OperationCategory?.Name; row.Cell(columnCategory).Value = operation.OperationCategory?.Name;

View File

@ -141,13 +141,13 @@ namespace AsbCloudInfrastructure.Services
public async Task<IEnumerable<int>> GetClusterWellsIdsAsync(int idWell, CancellationToken token) public async Task<IEnumerable<int>> GetClusterWellsIdsAsync(int idWell, CancellationToken token)
{ {
var well = await cacheWells.FirstOrDefaultAsync(w => w.Id == idWell) var well = await cacheWells.FirstOrDefaultAsync(w => w.Id == idWell, token)
.ConfigureAwait(false); .ConfigureAwait(false);
if (well is null) if (well is null)
return null; return null;
var clusterWells = await cacheWells.WhereAsync(w => w.IdCluster == well.IdCluster) var clusterWells = await cacheWells.WhereAsync(w => w.IdCluster == well.IdCluster, token)
.ConfigureAwait(false); .ConfigureAwait(false);
return clusterWells.Select(w => w.Id); return clusterWells.Select(w => w.Id);

View File

@ -27,7 +27,7 @@ namespace AsbCloudWebApi.Controllers
[Route("/reduntentUids")] [Route("/reduntentUids")]
public IActionResult GetRedundentRemoteUids() public IActionResult GetRedundentRemoteUids()
{ {
var result = telemetryService.GetRedundentRemoteUids().Select(i => new { i.Key, ids = i.Item2 }); var result = telemetryService.GetRedundentRemoteUids().Select(i => new { i.Key, ids = i.Ids });
return Ok(result); return Ok(result);
} }