forked from ddrilling/AsbCloudServer
Забрал домой
This commit is contained in:
parent
634bdee1e3
commit
ee01ab30db
@ -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);
|
||||
}
|
||||
}
|
@ -1,14 +1,13 @@
|
||||
# Миграции
|
||||
## создать миграцию
|
||||
## Создать миграцию
|
||||
```
|
||||
dotnet ef migrations add <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
|
||||
```
|
||||
|
||||
# Backup
|
||||
# Backup and restore
|
||||
## Backup
|
||||
Terminal:
|
||||
```
|
||||
sudo -u postgres pg_dump -Fc -U postgres postgres -W > dump_2021-11-26.bak
|
||||
```
|
||||
|
||||
# Restore backup
|
||||
## Step 1. (Re)Create DB and schema IF needeed.
|
||||
## Restore backup
|
||||
### Step 1. (Re)Create DB and schema IF needed.
|
||||
psql:
|
||||
```
|
||||
--drop schema public cascade;
|
||||
@ -33,12 +33,13 @@ CREATE DATABASE postgres;
|
||||
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;
|
||||
SELECT timescaledb_pre_restore();
|
||||
```
|
||||
## Step 3. Restore DB, then 'exit resore mode'. [Longest operation]
|
||||
|
||||
### Step 3. Restore DB, then [Longest operation]
|
||||
Terminal:
|
||||
```
|
||||
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
|
||||
```
|
||||
Then psql:
|
||||
Then 'exit resore mode' psql:
|
||||
```
|
||||
SELECT timescaledb_post_restore();
|
||||
```
|
@ -254,7 +254,7 @@ namespace AsbCloudInfrastructure.Services.Analysis
|
||||
if (dataSaubPart is null)
|
||||
break;
|
||||
|
||||
var count = dataSaubPart.Count();
|
||||
var count = dataSaubPart.Count;
|
||||
var skip = 0;
|
||||
|
||||
if (step > count)
|
||||
@ -434,31 +434,31 @@ namespace AsbCloudInfrastructure.Services.Analysis
|
||||
|
||||
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
|
||||
{
|
||||
OperationName = op.OperationName,
|
||||
DurationSec = op.OperationDuration
|
||||
OperationName = OperationName,
|
||||
DurationSec = OperationDuration
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
groupedOperationsList.Add(groupedOperationsObj);
|
||||
|
||||
intervalEndDate = op.IntervalStart + intervalSeconds;
|
||||
intervalEndDate = IntervalStart + intervalSeconds;
|
||||
groupedOperationsObj = new TelemetryOperationInfoDto
|
||||
{
|
||||
IntervalBegin = DateTimeOffset.FromUnixTimeSeconds(op.IntervalStart),
|
||||
IntervalBegin = DateTimeOffset.FromUnixTimeSeconds(IntervalStart),
|
||||
Operations = new List<TelemetryOperationDetailsDto>()
|
||||
};
|
||||
|
||||
groupedOperationsObj.Operations.Add(new TelemetryOperationDetailsDto
|
||||
{
|
||||
OperationName = op.OperationName,
|
||||
DurationSec = op.OperationDuration
|
||||
OperationName = OperationName,
|
||||
DurationSec = OperationDuration
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
return userPermissionsInfo.Select(p => new
|
||||
{
|
||||
PermissionName = cachePermissions.FirstOrDefault(c => c.Id == p.IdPermission)?.Name,
|
||||
PermissionValue = p.PermissionValue
|
||||
p.PermissionValue
|
||||
}).ToDictionary(k => k.PermissionName, v => v.PermissionValue);
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
select well).ToListAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var gDepositEntities = groupWells(wellEntities);
|
||||
var gDepositEntities = GroupWells(wellEntities);
|
||||
|
||||
var dtos = CreateDepositDto(gDepositEntities);
|
||||
|
||||
@ -54,7 +54,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
select well).ToListAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var gDepositEntities = groupWells(wellEntities);
|
||||
var gDepositEntities = GroupWells(wellEntities);
|
||||
|
||||
var dtos = CreateDepositDto(gDepositEntities);
|
||||
|
||||
@ -114,7 +114,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
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
|
||||
.GroupBy(w => w.Cluster)
|
||||
|
@ -104,7 +104,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
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)
|
||||
return 0;
|
||||
var entity = Convert(item);
|
||||
|
@ -16,7 +16,6 @@ namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
private readonly IAsbCloudDbContext db;
|
||||
private readonly ITelemetryService telemetryService;
|
||||
private readonly CacheTable<Telemetry> cacheTelemetry;
|
||||
private readonly CacheTable<TelemetryEvent> cacheEvents;
|
||||
private readonly CacheTable<TelemetryUser> cacheTUsers;
|
||||
|
||||
@ -24,7 +23,6 @@ namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
this.db = db;
|
||||
this.telemetryService = telemetryService;
|
||||
cacheTelemetry = cacheDb.GetCachedTable<Telemetry>((AsbCloudDbContext)db);
|
||||
cacheEvents = cacheDb.GetCachedTable<TelemetryEvent>((AsbCloudDbContext)db);
|
||||
cacheTUsers = cacheDb.GetCachedTable<TelemetryUser>((AsbCloudDbContext)db);
|
||||
}
|
||||
|
@ -18,13 +18,12 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
const int fastLimitMs = 500;
|
||||
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>();
|
||||
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)
|
||||
private static IEnumerable<RequestLogDto> Get(IEnumerable<RequestLogDto> list, int take = -1)
|
||||
{
|
||||
IEnumerable<RequestLogDto> orderedlist = list.OrderByDescending(r => r.Date);
|
||||
if (take > 0)
|
||||
|
@ -109,7 +109,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
||||
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);
|
||||
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();
|
||||
for (int i = 0; i < operationsList.Count(); i++)
|
||||
for (int i = 0; i < operationsList.Count; i++)
|
||||
{
|
||||
var row = sheet.Row(1 + i + headerRowsCount);
|
||||
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(columnCategory).Value = operation.OperationCategory?.Name;
|
||||
|
@ -141,13 +141,13 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
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);
|
||||
|
||||
if (well is 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);
|
||||
|
||||
return clusterWells.Select(w => w.Id);
|
||||
|
@ -27,7 +27,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
[Route("/reduntentUids")]
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user