forked from ddrilling/AsbCloudServer
Move logic from AsbCloudDbContext.GetDepthToIntervalAsync() to TelemetryAnalyticsService.GetWellDepthToIntervalAsync()
This commit is contained in:
parent
ca969c99ad
commit
e7d6aef6a6
@ -15,7 +15,7 @@ namespace AsbCloudApp.Services
|
|||||||
Task<IEnumerable<WellDepthToDayDto>> GetWellDepthToDayAsync(int idWell,
|
Task<IEnumerable<WellDepthToDayDto>> GetWellDepthToDayAsync(int idWell,
|
||||||
CancellationToken token = default);
|
CancellationToken token = default);
|
||||||
Task<IEnumerable<WellDepthToIntervalDto>> GetWellDepthToIntervalAsync(int idWell,
|
Task<IEnumerable<WellDepthToIntervalDto>> GetWellDepthToIntervalAsync(int idWell,
|
||||||
int intervalHoursTimestamp, int workBeginTimestamp,
|
int intervalHoursTimestamp, int shiftStartSec,
|
||||||
CancellationToken token = default);
|
CancellationToken token = default);
|
||||||
Task<IEnumerable<TelemetryOperationDurationDto>> GetOperationsSummaryAsync(int idWell,
|
Task<IEnumerable<TelemetryOperationDurationDto>> GetOperationsSummaryAsync(int idWell,
|
||||||
DateTime begin = default, DateTime end = default,
|
DateTime begin = default, DateTime end = default,
|
||||||
|
@ -466,37 +466,5 @@ namespace AsbCloudDb.Model
|
|||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)>> GetDepthToIntervalAsync(int telemetryId,
|
|
||||||
int intervalHoursTimestamp, int workStartTimestamp, double timezoneOffset, CancellationToken token)
|
|
||||||
{
|
|
||||||
//TODO: Сменить на LINQ группирование
|
|
||||||
using var command = Database.GetDbConnection().CreateCommand();
|
|
||||||
|
|
||||||
command.CommandText = $@"SELECT Min(t.bit_depth) AS MinDepth, Max(t.bit_depth) AS MaxDepth, Min(t.Date) AS dateStart
|
|
||||||
FROM t_telemetry_data_saub AS t
|
|
||||||
WHERE id_telemetry = {telemetryId} AND t.Id % 10 = 0
|
|
||||||
GROUP BY floor((extract(epoch from t.date) - {workStartTimestamp} + {timezoneOffset}) / {intervalHoursTimestamp});";
|
|
||||||
|
|
||||||
Database.OpenConnection();
|
|
||||||
using var reader = await command.ExecuteReaderAsync(token);
|
|
||||||
|
|
||||||
var result = new List<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)>();
|
|
||||||
|
|
||||||
if (reader.HasRows)
|
|
||||||
{
|
|
||||||
while (reader.Read())
|
|
||||||
{
|
|
||||||
result.Add(
|
|
||||||
(
|
|
||||||
(double?)reader.GetValue(0),
|
|
||||||
(double?)reader.GetValue(1),
|
|
||||||
(DateTime)reader.GetValue(2)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,5 @@ namespace AsbCloudDb.Model
|
|||||||
|
|
||||||
DbSet<TEntity> Set<TEntity>() where TEntity : class;
|
DbSet<TEntity> Set<TEntity>() where TEntity : class;
|
||||||
|
|
||||||
Task<IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)>> GetDepthToIntervalAsync(int telemetryId,
|
|
||||||
int intervalHoursTimestamp, int workStartTimestamp, double timezoneOffset, CancellationToken token);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -61,7 +61,7 @@ namespace AsbCloudInfrastructure.Services.Analysis
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<WellDepthToIntervalDto>> GetWellDepthToIntervalAsync(int idWell,
|
public async Task<IEnumerable<WellDepthToIntervalDto>> GetWellDepthToIntervalAsync(int idWell,
|
||||||
int intervalSeconds, int workBeginSeconds, CancellationToken token = default)
|
int intervalSeconds, int shiftStartSec, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
intervalSeconds = intervalSeconds == 0 ? 86400 : intervalSeconds;
|
intervalSeconds = intervalSeconds == 0 ? 86400 : intervalSeconds;
|
||||||
|
|
||||||
@ -72,13 +72,23 @@ namespace AsbCloudInfrastructure.Services.Analysis
|
|||||||
|
|
||||||
var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId((int)telemetryId);
|
var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId((int)telemetryId);
|
||||||
|
|
||||||
var drillingPeriodsInfo = await db.GetDepthToIntervalAsync((int)telemetryId, intervalSeconds,
|
var drillingPeriodsInfo = await db.TelemetryDataSaub
|
||||||
workBeginSeconds, timezoneOffset, token).ConfigureAwait(false);
|
.Where(t => t.IdTelemetry == telemetryId)
|
||||||
|
.GroupBy(t => Math.Floor((((t.Date.DayOfYear * 24 + t.Date.Hour) * 60 + t.Date.Minute) * 60 + t.Date.Second + timezoneOffset - shiftStartSec) / intervalSeconds))
|
||||||
|
.Select(g => new {
|
||||||
|
WellDepthMin = g.Min(t => t.WellDepth),
|
||||||
|
WellDepthMax = g.Max(t => t.WellDepth),
|
||||||
|
DateMin = g.Min(t => t.Date),
|
||||||
|
DateMax = g.Max(t => t.Date),
|
||||||
|
})
|
||||||
|
.OrderBy(g=>g.DateMin)
|
||||||
|
.ToListAsync(token);
|
||||||
|
|
||||||
var wellDepthToIntervalData = drillingPeriodsInfo.Select(d => new WellDepthToIntervalDto
|
var wellDepthToIntervalData = drillingPeriodsInfo.Select(d => new WellDepthToIntervalDto
|
||||||
{
|
{
|
||||||
IntervalStartDate = d.BeginPeriodDate,
|
IntervalStartDate = d.DateMin,
|
||||||
IntervalDepthProgress = (d.MaxDepth - d.MinDepth) ?? 0.0 / intervalSeconds
|
IntervalDepthProgress = (d.WellDepthMax - d.WellDepthMin) ?? 0.0
|
||||||
|
// / (d.DateMax - d.DateMin).TotalHours,
|
||||||
}).OrderBy(d => d.IntervalStartDate).ToList();
|
}).OrderBy(d => d.IntervalStartDate).ToList();
|
||||||
|
|
||||||
return wellDepthToIntervalData;
|
return wellDepthToIntervalData;
|
||||||
|
@ -89,14 +89,14 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">id скважины</param>
|
/// <param name="idWell">id скважины</param>
|
||||||
/// <param name="intervalSeconds">количество секунд в необходимом интервале времени</param>
|
/// <param name="intervalSeconds">количество секунд в необходимом интервале времени</param>
|
||||||
/// <param name="workBeginSeconds">количество секунд в времени начала смены</param>
|
/// <param name="shiftStartSec">количество секунд в времени начала смены</param>
|
||||||
/// <param name="token">Токен отмены задачи</param>
|
/// <param name="token">Токен отмены задачи</param>
|
||||||
/// <returns>Коллекцию данных по глубине скважины за период</returns>
|
/// <returns>Коллекцию данных по глубине скважины за период</returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("wellDepthToInterval")]
|
[Route("wellDepthToInterval")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<WellDepthToIntervalDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<WellDepthToIntervalDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetWellDepthToIntervalAsync(int idWell,
|
public async Task<IActionResult> GetWellDepthToIntervalAsync(int idWell,
|
||||||
int intervalSeconds, int workBeginSeconds, CancellationToken token = default)
|
int intervalSeconds, int shiftStartSec, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var wellDepthToIntervalData = await analyticsService.GetWellDepthToIntervalAsync(idWell,
|
var wellDepthToIntervalData = await analyticsService.GetWellDepthToIntervalAsync(idWell,
|
||||||
intervalSeconds, workBeginSeconds, token).ConfigureAwait(false);
|
intervalSeconds, shiftStartSec, token).ConfigureAwait(false);
|
||||||
|
|
||||||
if (wellDepthToIntervalData is null || !wellDepthToIntervalData.Any())
|
if (wellDepthToIntervalData is null || !wellDepthToIntervalData.Any())
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
Loading…
Reference in New Issue
Block a user