This commit is contained in:
Фролов 2021-07-16 09:19:50 +05:00
commit e99b476f47
22 changed files with 335 additions and 253 deletions

2
.gitignore vendored
View File

@ -30,7 +30,7 @@ bld/
# Visual Studio 2015/2017 cache/options directory # Visual Studio 2015/2017 cache/options directory
.vs/ .vs/
# Uncomment if you have tasks that create the project's static files in wwwroot # Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/ wwwroot/
# Visual Studio 2017 auto generated files # Visual Studio 2017 auto generated files
Generated\ Files/ Generated\ Files/

View File

@ -1,11 +1,8 @@
using System; namespace AsbCloudApp.Data
namespace AsbCloudApp.Data
{ {
public class OperationDetailsDto public class OperationDetailsDto
{ {
public string OperationName { get; set; } public string OperationName { get; set; }
public DateTime OperationStartTime { get; set; } public int Duration { get; set; }
public double DurationHours { get; set; }
} }
} }

View File

@ -1,8 +1,8 @@
namespace AsbCloudApp.Data namespace AsbCloudApp.Data
{ {
public class OperationPercentageDto public class OperationDurationDto
{ {
public string ProcessName { get; set; } public string ProcessName { get; set; }
public double Percentage { get; set; } public double Duration { get; set; }
} }
} }

View File

@ -6,7 +6,6 @@ namespace AsbCloudApp.Data
public class OperationInfoDto public class OperationInfoDto
{ {
public DateTime IntervalBegin { get; set; } public DateTime IntervalBegin { get; set; }
public DateTime IntervalEnd { get; set; } public IEnumerable<OperationDetailsDto> Operations { get; set; }
public IEnumerable<OperationDetailsDto> OperationData { get; set; }
} }
} }

View File

@ -10,10 +10,10 @@ namespace AsbCloudApp.Services
IEnumerable<WellDepthToDayDto> GetWellDepthToDay(int wellId); IEnumerable<WellDepthToDayDto> GetWellDepthToDay(int wellId);
IEnumerable<WellDepthToIntervalDto> GetWellDepthToInterval(int wellId, IEnumerable<WellDepthToIntervalDto> GetWellDepthToInterval(int wellId,
int intervalHoursTimestamp, int workBeginTimestamp); int intervalHoursTimestamp, int workBeginTimestamp);
IEnumerable<OperationPercentageDto> GetOperationsSummary(int wellId, IEnumerable<OperationDurationDto> GetOperationsSummary(int wellId,
DateTime begin = default, DateTime end = default);
IEnumerable<OperationInfoDto> GetOperationsToTime(int wellId,
DateTime begin = default, DateTime end = default); DateTime begin = default, DateTime end = default);
IEnumerable<OperationInfoDto> GetOperationsToInterval(int wellId,
int intervalHoursTimestamp, int workBeginTimestamp);
DrillingAnalysis GetDrillingAnalysis(IEnumerable<DataSaubBase> dataSaubBases); DrillingAnalysis GetDrillingAnalysis(IEnumerable<DataSaubBase> dataSaubBases);
} }
} }

View File

@ -20,6 +20,12 @@ namespace AsbCloudDb.Model
[Column("date", TypeName = "timestamp with time zone"), Comment("'2021-10-19 18:23:54+05'")] [Column("date", TypeName = "timestamp with time zone"), Comment("'2021-10-19 18:23:54+05'")]
public DateTime Date { get; set; } public DateTime Date { get; set; }
[Column("unix_date", TypeName = "bigint"), Comment("Unix timestamp для Linq запросов с вычислением дат")]
public long UnixDate { get; set; }
[Column("duration"), Comment("Кол-во секунд после предыдущей операции")]
public int Duration { get; set; }
[Column("id_operation")] [Column("id_operation")]
public int? IdOperation { get; set; } public int? IdOperation { get; set; }

View File

@ -60,9 +60,6 @@ namespace AsbCloudInfrastructure.Services
{ {
intervalHoursTimestamp = intervalHoursTimestamp == 0 ? 86400 : intervalHoursTimestamp; intervalHoursTimestamp = intervalHoursTimestamp == 0 ? 86400 : intervalHoursTimestamp;
var intervalTime = new TimeSpan(0, 0, intervalHoursTimestamp);
var workDayBeginTime = new TimeSpan(0, 0, workBeginTimestamp);
var telemetry = telemetryService.GetTelemetryByWellId(wellId); var telemetry = telemetryService.GetTelemetryByWellId(wellId);
if (telemetry is null) if (telemetry is null)
@ -70,8 +67,8 @@ namespace AsbCloudInfrastructure.Services
var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId(telemetry.Id); var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId(telemetry.Id);
var drillingPeriodsInfo = db.GetDepthToInterval(telemetry.Id, (int)intervalTime.TotalSeconds, var drillingPeriodsInfo = db.GetDepthToInterval(telemetry.Id, intervalHoursTimestamp,
(int)workDayBeginTime.TotalSeconds, timezoneOffset); workBeginTimestamp, timezoneOffset);
var wellDepthToIntervalData = drillingPeriodsInfo.Select(d => new WellDepthToIntervalDto var wellDepthToIntervalData = drillingPeriodsInfo.Select(d => new WellDepthToIntervalDto
{ {
@ -82,191 +79,125 @@ namespace AsbCloudInfrastructure.Services
return wellDepthToIntervalData; return wellDepthToIntervalData;
} }
public IEnumerable<OperationPercentageDto> GetOperationsSummary(int wellId, public IEnumerable<OperationDurationDto> GetOperationsSummary(int wellId,
DateTime begin = default, DateTime end = default) DateTime begin = default, DateTime end = default)
{ {
return new List<OperationPercentageDto> var telemetry = telemetryService.GetTelemetryByWellId(wellId);
{
new OperationPercentageDto { ProcessName = "Роторное бурение", Percentage = 19.7 }, if (telemetry is null)
new OperationPercentageDto { ProcessName = "Подъем с проработкой", Percentage = 6.2 }, return null;
new OperationPercentageDto { ProcessName = "Спуск с проработкой", Percentage = 9.4 },
new OperationPercentageDto { ProcessName = "Подъем с промывкой", Percentage = 18.4 }, var operations = (from a in db.DrillingAnalysis
new OperationPercentageDto { ProcessName = "Неподвижное состояние", Percentage = 12.1 }, where a.IdTelemetry == telemetry.Id &&
new OperationPercentageDto { ProcessName = "Вращение без циркуляции", Percentage = 7.4 }, a.Date > begin && a.Date < end &&
new OperationPercentageDto { ProcessName = "Спуск в скважину", Percentage = 16.7 }, a.IdOperation != null
new OperationPercentageDto { ProcessName = "На поверхности", Percentage = 10.1 } join o in db.Operations on a.IdOperation equals o.Id
}; group a by new { a.IdOperation, o.Name } into g
select new OperationDurationDto
{
ProcessName = g.Key.Name,
Duration = g.Where(g => g.Duration > 0)
.Sum(a => a.Duration)
}).ToList();
return operations;
} }
public IEnumerable<OperationInfoDto> GetOperationsToTime(int wellId, public IEnumerable<OperationInfoDto> GetOperationsToInterval(int wellId,
DateTime begin = default, DateTime end = default) int intervalHoursTimestamp, int workBeginTimestamp)
{ {
return new List<OperationInfoDto> intervalHoursTimestamp = intervalHoursTimestamp == 0 ? 86400 : intervalHoursTimestamp;
{
new OperationInfoDto var telemetry = telemetryService.GetTelemetryByWellId(wellId);
{
IntervalBegin = new DateTime(2021, 06, 01, 08, 00, 00), if (telemetry is null)
IntervalEnd = new DateTime(2021, 06, 02, 08, 00, 00), return null;
OperationData = new List<OperationDetailsDto>
{ var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId(telemetry.Id);
new OperationDetailsDto
{ var operations = (from a in db.DrillingAnalysis
OperationName = "Роторное бурение", where a.IdTelemetry == telemetry.Id &&
OperationStartTime = new DateTime(2021, 06, 01, 10, 00, 00), a.IdOperation != null
DurationHours = 1.2 join o in db.Operations on a.IdOperation equals o.Id
}, group a by new {
new OperationDetailsDto Interval = Math.Floor((a.UnixDate - workBeginTimestamp + timezoneOffset) / intervalHoursTimestamp),
{ OperationId = a.IdOperation,
OperationName = "Подъем с проработкой", o.Name } into g
OperationStartTime = new DateTime(2021, 06, 01, 11, 00, 00), select new
DurationHours = 3.2 {
}, IntervalStart = g.Min(d => d.Date).Date,
new OperationDetailsDto OperationName = g.Key.Name,
{ OperationsDuration = g.Sum(an => an.Duration)
OperationName = "Роторное бурение", }).ToList();
OperationStartTime = new DateTime(2021, 06, 01, 12, 00, 00),
DurationHours = 1.5 var operationsGroupedByInterval = operations.GroupBy(op => op.IntervalStart)
}, .Select(o => new OperationInfoDto {
new OperationDetailsDto IntervalBegin = o.Key,
{ Operations = o.Select(opr => new OperationDetailsDto {
OperationName = "Неподвижное состояние", OperationName = opr.OperationName,
OperationStartTime = new DateTime(2021, 06, 01, 13, 00, 00), Duration = opr.OperationsDuration
DurationHours = 0.2 }).ToList()
}, })
new OperationDetailsDto .OrderBy(ops => ops.IntervalBegin);
{
OperationName = "Роторное бурение", return operationsGroupedByInterval;
OperationStartTime = new DateTime(2021, 06, 01, 14, 00, 00),
DurationHours = 3.2
}
}
},
new OperationInfoDto
{
IntervalBegin = new DateTime(2021, 06, 02, 08, 00, 00),
IntervalEnd = new DateTime(2021, 06, 03, 08, 00, 00),
OperationData = new List<OperationDetailsDto>
{
new OperationDetailsDto
{
OperationName = "На поверхности",
OperationStartTime = new DateTime(2021, 06, 13, 10, 01, 00),
DurationHours = 2.2
},
new OperationDetailsDto
{
OperationName = "Спуск в скважину",
OperationStartTime = new DateTime(2021, 06, 13, 11, 10, 00),
DurationHours = 0.4
},
new OperationDetailsDto
{
OperationName = "На поверхности",
OperationStartTime = new DateTime(2021, 06, 13, 12, 20, 00),
DurationHours = 2.5
},
new OperationDetailsDto
{
OperationName = "Вращение без циркуляции",
OperationStartTime = new DateTime(2021, 06, 13, 13, 00, 00),
DurationHours = 1.2
},
new OperationDetailsDto
{
OperationName = "Роторное бурение",
OperationStartTime = new DateTime(2021, 06, 13, 14, 00, 00),
DurationHours = 5.2
}
}
},
new OperationInfoDto
{
IntervalBegin = new DateTime(2021, 06, 03, 08, 00, 00),
IntervalEnd = new DateTime(2021, 06, 04, 08, 00, 00),
OperationData = new List<OperationDetailsDto>
{
new OperationDetailsDto
{
OperationName = "Подъем с проработкой",
OperationStartTime = new DateTime(2021, 06, 12, 10, 00, 00),
DurationHours = 3.2
},
new OperationDetailsDto
{
OperationName = "Спуск с проработкой",
OperationStartTime = new DateTime(2021, 06, 12, 11, 00, 00),
DurationHours = 1.4
},
new OperationDetailsDto
{
OperationName = "Подъем с проработкой",
OperationStartTime = new DateTime(2021, 06, 12, 12, 00, 00),
DurationHours = 0.5
},
new OperationDetailsDto
{
OperationName = "На поверхности",
OperationStartTime = new DateTime(2021, 06, 12, 13, 00, 00),
DurationHours = 3.2
},
new OperationDetailsDto
{
OperationName = "Роторное бурение",
OperationStartTime = new DateTime(2021, 06, 13, 14, 00, 00),
DurationHours = 1.2
}
}
}
};
} }
public DrillingAnalysis GetDrillingAnalysis(IEnumerable<DataSaubBase> dataSaubBases) public DrillingAnalysis GetDrillingAnalysis(IEnumerable<DataSaubBase> dataSaubBases)
{ {
var saubWellDepths = dataSaubBases.Select(s => (s.WellDepth, var lastSaubDate = dataSaubBases.Last().Date;
TotalSeconds: (s.Date -
new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds - 1530000000));
var saubBitDepths = dataSaubBases.Select(s => (s.BitDepth,
TotalSeconds: (s.Date -
new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds - 1530000000));
var saubBlockPositions = dataSaubBases.Select(s => (s.BlockPosition,
TotalSeconds: (s.Date -
new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds - 1530000000));
var saubRotorSpeeds = dataSaubBases.Select(s => (s.RotorSpeed,
TotalSeconds: (s.Date -
new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds - 1530000000));
var saubPressures = dataSaubBases.Select(s => (s.Pressure,
TotalSeconds: (s.Date -
new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds - 1530000000));
var saubHookWeights = dataSaubBases.Select(s => (s.HookWeight,
TotalSeconds: (s.Date -
new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds - 1530000000));
var wellDepthChangingIndex = GetAForLinearFormula(saubWellDepths); var saubWellDepths = dataSaubBases.Where(sw => sw.WellDepth is not null)
var bitPositionChangingIndex = GetAForLinearFormula(saubBitDepths); .Select(s => (Value: (double)s.WellDepth,
var blockPositionChangingIndex = GetAForLinearFormula(saubBlockPositions); (s.Date - dataSaubBases.First().Date).TotalSeconds));
var rotorSpeedChangingIndex = GetAForLinearFormula(saubRotorSpeeds); var saubBitDepths = dataSaubBases.Where(sw => sw.BitDepth is not null)
var pressureChangingIndex = GetAForLinearFormula(saubPressures); .Select(s => (Value: (double)s.BitDepth,
var hookWeightChangingIndex = GetAForLinearFormula(saubHookWeights); (s.Date - dataSaubBases.First().Date).TotalSeconds));
var saubBlockPositions = dataSaubBases.Where(sw => sw.BlockPosition is not null)
.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,
(s.Date - dataSaubBases.First().Date).TotalSeconds));
var saubPressures = dataSaubBases.Where(sw => sw.Pressure is not null)
.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,
(s.Date - dataSaubBases.First().Date).TotalSeconds));
var wellDepthChangingIndex = LinearFunctionCalculator.GetAForLinearFormula(saubWellDepths);
var bitPositionChangingIndex = LinearFunctionCalculator.GetAForLinearFormula(saubBitDepths);
var blockPositionChangingIndex = LinearFunctionCalculator.GetAForLinearFormula(saubBlockPositions);
var rotorSpeedChangingIndex = LinearFunctionCalculator.GetAForLinearFormula(saubRotorSpeeds);
var pressureChangingIndex = LinearFunctionCalculator.GetAForLinearFormula(saubPressures);
var hookWeightChangingIndex = LinearFunctionCalculator.GetAForLinearFormula(saubHookWeights);
var IsBlockRising = LinearFunctionCalculator.IsValueGoesDown(blockPositionChangingIndex, -0.0001);
var IsBlockGoesDown = LinearFunctionCalculator.IsValueGoesUp(blockPositionChangingIndex, 0.0001);
var IsBlockStandsStill = LinearFunctionCalculator.IsValueNotChanges(blockPositionChangingIndex, (0.0001, -0.0001));
var drillingAnalysis = new DrillingAnalysis var drillingAnalysis = new DrillingAnalysis
{ {
IdTelemetry = dataSaubBases.First().IdTelemetry, IdTelemetry = dataSaubBases.First().IdTelemetry,
Date = dataSaubBases.Last().Date, Date = lastSaubDate,
IsDepthChanges = wellDepthChangingIndex >= 0.0001 || wellDepthChangingIndex <= -0.0001, UnixDate = (long)(lastSaubDate - new DateTime(1970,1,1,0,0,0)).TotalSeconds,
IsDepthNotChanges = wellDepthChangingIndex < 0.0001 && wellDepthChangingIndex > -0.0001, Duration = (int)(dataSaubBases.Last().Date - dataSaubBases.ElementAt(dataSaubBases.Count() - 2).Date).TotalSeconds,
IsBitRising = bitPositionChangingIndex >= 0.0001, IsDepthChanges = LinearFunctionCalculator.IsValueChanges(wellDepthChangingIndex, (0.0001, -0.0001)),
IsBitGoesDown = bitPositionChangingIndex <= -0.0001, IsDepthNotChanges = LinearFunctionCalculator.IsValueNotChanges(wellDepthChangingIndex, (0.0001, -0.0001)),
IsBitStandsStill = bitPositionChangingIndex < 0.0001 && bitPositionChangingIndex > -0.0001, IsBitRising = LinearFunctionCalculator.IsValueGoesDown(bitPositionChangingIndex, -0.0001),
IsBitDepthLess20 = (saubBitDepths.Sum(s => s.BitDepth) / saubBitDepths.Count()) < 20.0, IsBitGoesDown = LinearFunctionCalculator.IsValueGoesUp(bitPositionChangingIndex, 0.0001),
IsBlockRising = blockPositionChangingIndex >= 0.0001, IsBitStandsStill = LinearFunctionCalculator.IsValueNotChanges(bitPositionChangingIndex, (0.0001, -0.0001)),
IsBlockGoesDown = blockPositionChangingIndex <= -0.0001, IsBitDepthLess20 = LinearFunctionCalculator.IsAverageLessThanBound(saubBitDepths, 20),
IsBlockStandsStill = blockPositionChangingIndex < 0.001 && blockPositionChangingIndex > -0.0001, IsBlockRising = LinearFunctionCalculator.IsValueGoesDown(blockPositionChangingIndex, -0.0001),
IsRotorSpeedLess3 = (saubRotorSpeeds.Sum(s => s.RotorSpeed) / saubRotorSpeeds.Count()) < 3, IsBlockGoesDown = LinearFunctionCalculator.IsValueGoesUp(blockPositionChangingIndex, 0.0001),
IsRotorSpeedMore3 = (saubRotorSpeeds.Sum(s => s.RotorSpeed) / saubRotorSpeeds.Count()) >= 3, IsBlockStandsStill = LinearFunctionCalculator.IsValueNotChanges(blockPositionChangingIndex, (0.0001, -0.0001)),
IsPressureLess20 = (saubPressures.Sum(s => s.Pressure) / saubPressures.Count()) < 20.0, IsRotorSpeedLess3 = LinearFunctionCalculator.IsAverageLessThanBound(saubRotorSpeeds, 3),
IsPressureMore20 = (saubPressures.Sum(s => s.Pressure) / saubPressures.Count()) >= 20.0, IsRotorSpeedMore3 = LinearFunctionCalculator.IsAverageMoreThanBound(saubRotorSpeeds, 3),
IsHookWeightNotChanges = hookWeightChangingIndex < 0.0001 && hookWeightChangingIndex > 0.0001, IsPressureLess20 = LinearFunctionCalculator.IsAverageLessThanBound(saubPressures, 20),
IsHookWeightLess3 = (saubHookWeights.Sum(s => s.HookWeight) / saubHookWeights.Count()) < 3.0, IsPressureMore20 = LinearFunctionCalculator.IsAverageMoreThanBound(saubPressures, 20),
IsHookWeightNotChanges = LinearFunctionCalculator.IsValueNotChanges(hookWeightChangingIndex, (0.0001, -0.0001)),
IsHookWeightLess3 = LinearFunctionCalculator.IsAverageLessThanBound(saubHookWeights, 3),
IdOperation = 1 IdOperation = 1
}; };
@ -275,7 +206,7 @@ namespace AsbCloudInfrastructure.Services
return drillingAnalysis; return drillingAnalysis;
} }
private static double GetAForLinearFormula(IEnumerable<(double? x, double y)> rawData) private static double GetAForLinearFormula(IEnumerable<(double?, double)> rawData)
{ {
var (xSum, ySum, xySum, x2Sum) = GetFormulaVariables(rawData); var (xSum, ySum, xySum, x2Sum) = GetFormulaVariables(rawData);

View File

@ -103,8 +103,10 @@ namespace AsbCloudInfrastructure.Services
if (saubDataCache.GetOrCreateCache(dataSaub.IdTelemetry).Count() > 1) if (saubDataCache.GetOrCreateCache(dataSaub.IdTelemetry).Count() > 1)
{ {
var drillingAnalysis = analyticsService.GetDrillingAnalysis( var dataSaubs = saubDataCache.GetOrCreateCache(dataSaub.IdTelemetry)
saubDataCache.GetOrCreateCache(dataSaub.IdTelemetry)); .OrderBy(d => d.Date);
var drillingAnalysis = analyticsService.GetDrillingAnalysis(dataSaubs);
db.DrillingAnalysis.Add(drillingAnalysis); db.DrillingAnalysis.Add(drillingAnalysis);
} }

View File

@ -0,0 +1,66 @@
using System.Collections.Generic;
using System.Linq;
namespace AsbCloudInfrastructure.Services
{
public static class LinearFunctionCalculator
{
public static double GetAForLinearFormula(IEnumerable<(double value, double timestamp)> rawData)
{
var (xSum, ySum, xySum, x2Sum) = GetFormulaVariables(rawData);
var result = (xSum * ySum - rawData.Count() * xySum) /
(xSum * xSum - rawData.Count() * x2Sum);
return (double)result;
}
public static double GetBForLinearFormula(IEnumerable<(double value, double timestamp)> rawData)
{
var (xSum, ySum, xySum, x2Sum) = GetFormulaVariables(rawData);
var result = (xSum * xySum - x2Sum * ySum) /
(xSum * xSum - rawData.Count() * x2Sum);
return (double)result;
}
public static bool IsValueChanges(double value,
(double upperBound, double lowerBound) bounds) =>
value >= bounds.upperBound || value <= bounds.lowerBound;
public static bool IsValueNotChanges(double value,
(double upperBound, double lowerBound) bounds) =>
value < bounds.upperBound && value > bounds.lowerBound;
public static bool IsValueGoesUp(double value, double bound) =>
value >= bound;
public static bool IsValueGoesDown(double value, double bound) =>
value <= bound;
public static bool IsAverageLessThanBound(IEnumerable<(double Value, double TotalSeconds)> values,
double bound) =>
(values.Sum(s => s.Value) / values.Count()) < bound;
public static bool IsAverageMoreThanBound(IEnumerable<(double Value, double TotalSeconds)> values,
double bound) =>
(values.Sum(s => s.Value) / values.Count()) >= bound;
private static (decimal xSum, decimal ySum, decimal xySum, decimal x2Sum) GetFormulaVariables(
IEnumerable<(double value, double timestamp)> rawData)
{
var data = rawData.Select((d) => new
{
X = d.timestamp,
Y = d.value
});
var xSum = (decimal)data.Sum(d => d.X);
var ySum = (decimal)data.Sum(d => d.Y);
var xySum = (decimal)data.Sum(d => d.X * d.Y);
var x2Sum = (decimal)data.Sum(d => d.X * d.X);
return (xSum, ySum, xySum, x2Sum);
}
}
}

View File

@ -44,7 +44,7 @@ namespace AsbCloudInfrastructure.Services
var newReportName = generator.Make(); var newReportName = generator.Make();
if(newReportName is not null) if(newReportName is not null)
{ {
var shorReportName = newReportName.Split(Path.DirectorySeparatorChar).Last(); var shorReportName = Path.GetFileName(newReportName);
reportNameHandler.Invoke(shorReportName, id); reportNameHandler.Invoke(shorReportName, id);
var newReportProperties = new Report var newReportProperties = new Report
@ -99,25 +99,22 @@ namespace AsbCloudInfrastructure.Services
if (telemetry is null) if (telemetry is null)
return null; return null;
try var datesRange = (from d in db.DataSaubBases
{ where d.IdTelemetry == telemetry.Id
var datesRange = (from d in db.DataSaubBases select d.Date).Union(
where d.IdTelemetry == telemetry.Id from m in db.Messages
select d.Date).Union( where m.IdTelemetry == telemetry.Id
from m in db.Messages select m.Date).DefaultIfEmpty().GroupBy(g => true)
where m.IdTelemetry == telemetry.Id .Select(g => new
select m.Date).GroupBy(g => true) {
.Select(g => new From = g.Min(),
{ To = g.Max()
From = g.Min(), }).OrderBy(gr => gr.From).FirstOrDefault();
To = g.Max()
}).FirstOrDefault(); return new DatesRangeDto {
return new DatesRangeDto { From = datesRange.From, To = datesRange.To }; From = datesRange.From,
} To = datesRange.To.Year == 1 ? DateTime.MaxValue : datesRange.To
catch(InvalidOperationException) };
{
return new DatesRangeDto { From = DateTime.MinValue, To = DateTime.MaxValue };
}
} }
private IEnumerable<Report> GetSuitableReportsFromDb(int wellId, DateTime begin, DateTime end, int stepSeconds, int format) private IEnumerable<Report> GetSuitableReportsFromDb(int wellId, DateTime begin, DateTime end, int stepSeconds, int format)

View File

@ -13,6 +13,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.4" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.4" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="5.0.7" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.1" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.1.1" /> <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.1.1" />
</ItemGroup> </ItemGroup>

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using AsbCloudApp.Data; using AsbCloudApp.Data;
using AsbCloudApp.Services; using AsbCloudApp.Services;
@ -33,14 +34,14 @@ namespace AsbCloudWebApi.Controllers
{ {
int? idCustomer = User.GetCustomerId(); int? idCustomer = User.GetCustomerId();
if (idCustomer is null) if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId))
return BadRequest();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid(); return Forbid();
var wellDepthToDayData = analyticsService.GetWellDepthToDay(wellId); var wellDepthToDayData = analyticsService.GetWellDepthToDay(wellId);
if (wellDepthToDayData is null || !wellDepthToDayData.Any())
return NoContent();
return Ok(wellDepthToDayData); return Ok(wellDepthToDayData);
} }
@ -54,17 +55,19 @@ namespace AsbCloudWebApi.Controllers
[HttpGet] [HttpGet]
[Route("{wellId}/wellDepthToInterval")] [Route("{wellId}/wellDepthToInterval")]
[ProducesResponseType(typeof(IEnumerable<WellDepthToIntervalDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<WellDepthToIntervalDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetWellDepthToInterval(int wellId, int intervalHoursTimestamp, int workBeginTimestamp) public IActionResult GetWellDepthToInterval(int wellId,
int intervalHoursTimestamp, int workBeginTimestamp)
{ {
int? idCustomer = User.GetCustomerId(); int? idCustomer = User.GetCustomerId();
if (idCustomer is null) if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId))
return BadRequest();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid(); return Forbid();
var wellDepthToIntervalData = analyticsService.GetWellDepthToInterval(wellId, intervalHoursTimestamp, workBeginTimestamp); var wellDepthToIntervalData = analyticsService.GetWellDepthToInterval(wellId,
intervalHoursTimestamp, workBeginTimestamp);
if (wellDepthToIntervalData is null || !wellDepthToIntervalData.Any())
return NoContent();
return Ok(wellDepthToIntervalData); return Ok(wellDepthToIntervalData);
} }
@ -78,19 +81,19 @@ namespace AsbCloudWebApi.Controllers
/// <returns>Коллекцию операций на скважине</returns> /// <returns>Коллекцию операций на скважине</returns>
[HttpGet] [HttpGet]
[Route("{wellId}/operationsSummary")] [Route("{wellId}/operationsSummary")]
[ProducesResponseType(typeof(IEnumerable<OperationPercentageDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<OperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetOperationsSummary(int wellId, DateTime begin = default, DateTime end = default) public IActionResult GetOperationsSummary(int wellId, DateTime begin = default, DateTime end = default)
{ {
int? idCustomer = User.GetCustomerId(); int? idCustomer = User.GetCustomerId();
if (idCustomer is null) if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId))
return BadRequest();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid(); return Forbid();
var analytics = analyticsService.GetOperationsSummary(wellId, begin, end); var analytics = analyticsService.GetOperationsSummary(wellId, begin, end);
if (analytics is null || !analytics.Any())
return NoContent();
return Ok(analytics); return Ok(analytics);
} }
@ -98,24 +101,25 @@ namespace AsbCloudWebApi.Controllers
/// Возвращает детальные данные по операциям на скважине за период /// Возвращает детальные данные по операциям на скважине за период
/// </summary> /// </summary>
/// <param name="wellId">id скважины</param> /// <param name="wellId">id скважины</param>
/// <param name="begin">дата начала интервала</param> /// <param name="intervalHoursTimestamp">количество секунд в необходимом интервале времени</param>
/// <param name="end">дата окончания интервала</param> /// <param name="workBeginTimestamp">количество секунд в времени начала смены</param>
/// <returns>Коллекцию операций на скважине</returns> /// <returns>Коллекцию операций на скважине</returns>
[HttpGet] [HttpGet]
[Route("{wellId}/operationsToTime")] [Route("{wellId}/operationsToInterval")]
[ProducesResponseType(typeof(IEnumerable<OperationPercentageDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<OperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetOperationsToTime(int wellId, DateTime begin = default, DateTime end = default) public IActionResult GetOperationsToInterval(int wellId,
int intervalHoursTimestamp, int workBeginTimestamp)
{ {
int? idCustomer = User.GetCustomerId(); int? idCustomer = User.GetCustomerId();
if (idCustomer is null) if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId))
return BadRequest();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid(); return Forbid();
var analytics = analyticsService.GetOperationsToTime(wellId, begin, end); var analytics = analyticsService.GetOperationsToInterval(wellId, intervalHoursTimestamp, workBeginTimestamp);
if (analytics is null || !analytics.Any())
return NoContent();
return Ok(analytics); return Ok(analytics);
} }

View File

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace AsbCloudWebApi.Controllers namespace AsbCloudWebApi.Controllers
{ {
@ -41,6 +42,10 @@ namespace AsbCloudWebApi.Controllers
if (begin == default) if (begin == default)
begin = DateTime.Now.AddSeconds(-intervalSec); begin = DateTime.Now.AddSeconds(-intervalSec);
var content = telemetryDataService.Get(wellId, begin, intervalSec, approxPointsCount); var content = telemetryDataService.Get(wellId, begin, intervalSec, approxPointsCount);
if (content is null || !content.Any())
return NoContent();
return Ok(content); return Ok(content);
} }
@ -52,7 +57,7 @@ namespace AsbCloudWebApi.Controllers
int? idCustomer = User.GetCustomerId(); int? idCustomer = User.GetCustomerId();
if (idCustomer is null) if (idCustomer is null)
return BadRequest(); return Forbid();
bool isCustomerOwnsWell = wellService.CheckWellOwnership((int)idCustomer, wellId); bool isCustomerOwnsWell = wellService.CheckWellOwnership((int)idCustomer, wellId);

View File

@ -41,6 +41,10 @@ namespace AsbCloudWebApi.Controllers
begin = default; begin = default;
var result = messageService.GetMessages(wellId, categoryids, begin, end, skip, take); var result = messageService.GetMessages(wellId, categoryids, begin, end, skip, take);
if (result is null || result.Count == 0)
return NoContent();
return Ok(result); return Ok(result);
} }
@ -52,7 +56,7 @@ namespace AsbCloudWebApi.Controllers
int? idCustomer = User.GetCustomerId(); int? idCustomer = User.GetCustomerId();
if (idCustomer is null) if (idCustomer is null)
return BadRequest(); return Forbid();
bool isCustomerOwnsWell = wellService.CheckWellOwnership((int)idCustomer, wellId); bool isCustomerOwnsWell = wellService.CheckWellOwnership((int)idCustomer, wellId);

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -63,7 +64,7 @@ namespace AsbCloudWebApi.Controllers
int? idCustomer = User.GetCustomerId(); int? idCustomer = User.GetCustomerId();
if (idCustomer is null) if (idCustomer is null)
return BadRequest(); return Forbid();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId)) if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid(); return Forbid();
@ -89,7 +90,7 @@ namespace AsbCloudWebApi.Controllers
int? idCustomer = User.GetCustomerId(); int? idCustomer = User.GetCustomerId();
if (idCustomer is null) if (idCustomer is null)
return BadRequest(); return Forbid();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId)) if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid(); return Forbid();
@ -120,6 +121,10 @@ namespace AsbCloudWebApi.Controllers
DateTime begin = default, DateTime end = default) DateTime begin = default, DateTime end = default)
{ {
var suitableReportsNames = reportService.GetSuitableReports(wellId, begin, end, stepSeconds, format); var suitableReportsNames = reportService.GetSuitableReports(wellId, begin, end, stepSeconds, format);
if (suitableReportsNames is null || !suitableReportsNames.Any())
return NoContent();
return Ok(suitableReportsNames); return Ok(suitableReportsNames);
} }
@ -140,7 +145,7 @@ namespace AsbCloudWebApi.Controllers
int? idCustomer = User.GetCustomerId(); int? idCustomer = User.GetCustomerId();
if (idCustomer is null) if (idCustomer is null)
return BadRequest(); return Forbid();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId)) if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid(); return Forbid();
@ -163,7 +168,7 @@ namespace AsbCloudWebApi.Controllers
int? idCustomer = User.GetCustomerId(); int? idCustomer = User.GetCustomerId();
if (idCustomer is null) if (idCustomer is null)
return BadRequest(); return Forbid();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId)) if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid(); return Forbid();

View File

@ -3,6 +3,7 @@ using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace AsbCloudWebApi.Controllers namespace AsbCloudWebApi.Controllers
{ {
@ -31,6 +32,9 @@ namespace AsbCloudWebApi.Controllers
var wells = wellService.GetWellsByCustomer((int)idCustomer); var wells = wellService.GetWellsByCustomer((int)idCustomer);
if (wells is null || !wells.Any())
return NoContent();
return Ok(wells); return Ok(wells);
} }
@ -47,6 +51,9 @@ namespace AsbCloudWebApi.Controllers
var transmittingWells = wellService.GetTransmittingWells((int)idCustomer); var transmittingWells = wellService.GetTransmittingWells((int)idCustomer);
if (transmittingWells is null || !transmittingWells.Any())
return NoContent();
return Ok(transmittingWells); return Ok(transmittingWells);
} }

View File

@ -75,6 +75,11 @@ namespace AsbCloudWebApi
endpoints.MapHub<TelemetryHub>("/hubs/telemetry"); endpoints.MapHub<TelemetryHub>("/hubs/telemetry");
endpoints.MapHub<ReportsHub>("/hubs/reports"); endpoints.MapHub<ReportsHub>("/hubs/reports");
}); });
app.UseSpa(spa =>
{
spa.Options.SourcePath = "wwwroot";
});
} }
} }
} }

View File

@ -0,0 +1,34 @@
{
"files": {
"main.css": "/static/css/main.78f652ed.chunk.css",
"main.js": "/static/js/main.bc9ed2e6.chunk.js",
"main.js.map": "/static/js/main.bc9ed2e6.chunk.js.map",
"runtime-main.js": "/static/js/runtime-main.bfbc5d7c.js",
"runtime-main.js.map": "/static/js/runtime-main.bfbc5d7c.js.map",
"static/js/2.d2927f6c.chunk.js": "/static/js/2.d2927f6c.chunk.js",
"static/js/2.d2927f6c.chunk.js.map": "/static/js/2.d2927f6c.chunk.js.map",
"static/js/3.e81cf339.chunk.js": "/static/js/3.e81cf339.chunk.js",
"static/js/3.e81cf339.chunk.js.map": "/static/js/3.e81cf339.chunk.js.map",
"index.html": "/index.html",
"static/css/main.78f652ed.chunk.css.map": "/static/css/main.78f652ed.chunk.css.map",
"static/js/2.d2927f6c.chunk.js.LICENSE.txt": "/static/js/2.d2927f6c.chunk.js.LICENSE.txt",
"static/media/40752.04f88a90.png": "/static/media/40752.04f88a90.png",
"static/media/40808.9c38815a.png": "/static/media/40808.9c38815a.png",
"static/media/40997.3601b273.png": "/static/media/40997.3601b273.png",
"static/media/42483.54ae2d28.png": "/static/media/42483.54ae2d28.png",
"static/media/43745.0c1185c0.png": "/static/media/43745.0c1185c0.png",
"static/media/asb-logo.5d662174.png": "/static/media/asb-logo.5d662174.png",
"static/media/map_background.08470ca4.png": "/static/media/map_background.08470ca4.png",
"static/media/pointer.31629e02.svg": "/static/media/pointer.31629e02.svg",
"static/media/well-chart-1.0ba3a280.png": "/static/media/well-chart-1.0ba3a280.png",
"static/media/well-chart-2.d79caafa.png": "/static/media/well-chart-2.d79caafa.png",
"static/media/well-chart-3.98133e57.png": "/static/media/well-chart-3.98133e57.png",
"static/media/well-chart-8.9c38815a.png": "/static/media/well-chart-8.9c38815a.png"
},
"entrypoints": [
"static/js/runtime-main.bfbc5d7c.js",
"static/js/2.d2927f6c.chunk.js",
"static/css/main.78f652ed.chunk.css",
"static/js/main.bc9ed2e6.chunk.js"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 KiB

View File

@ -1,10 +1 @@
<!DOCTYPE html> <!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="manifest" href="/manifest.json"/><title>АСБ Vision</title><link href="/static/css/main.78f652ed.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,a,i=r[0],c=r[1],l=r[2],s=0,p=[];s<i.length;s++)a=i[s],Object.prototype.hasOwnProperty.call(o,a)&&o[a]&&p.push(o[a][0]),o[a]=0;for(n in c)Object.prototype.hasOwnProperty.call(c,n)&&(e[n]=c[n]);for(f&&f(r);p.length;)p.shift()();return u.push.apply(u,l||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,i=1;i<t.length;i++){var c=t[i];0!==o[c]&&(n=!1)}n&&(u.splice(r--,1),e=a(a.s=t[0]))}return e}var n={},o={1:0},u=[];function a(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,a),t.l=!0,t.exports}a.e=function(e){var r=[],t=o[e];if(0!==t)if(t)r.push(t[2]);else{var n=new Promise((function(r,n){t=o[e]=[r,n]}));r.push(t[2]=n);var u,i=document.createElement("script");i.charset="utf-8",i.timeout=120,a.nc&&i.setAttribute("nonce",a.nc),i.src=function(e){return a.p+"static/js/"+({}[e]||e)+"."+{3:"e81cf339"}[e]+".chunk.js"}(e);var c=new Error;u=function(r){i.onerror=i.onload=null,clearTimeout(l);var t=o[e];if(0!==t){if(t){var n=r&&("load"===r.type?"missing":r.type),u=r&&r.target&&r.target.src;c.message="Loading chunk "+e+" failed.\n("+n+": "+u+")",c.name="ChunkLoadError",c.type=n,c.request=u,t[1](c)}o[e]=void 0}};var l=setTimeout((function(){u({type:"timeout",target:i})}),12e4);i.onerror=i.onload=u,document.head.appendChild(i)}return Promise.all(r)},a.m=e,a.c=n,a.d=function(e,r,t){a.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,r){if(1&r&&(e=a(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(a.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)a.d(t,n,function(r){return e[r]}.bind(null,n));return t},a.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(r,"a",r),r},a.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},a.p="/",a.oe=function(e){throw console.error(e),e};var i=this.webpackJsonpasb_cloud_front_react=this.webpackJsonpasb_cloud_front_react||[],c=i.push.bind(i);i.push=r,i=i.slice();for(var l=0;l<i.length;l++)r(i[l]);var f=c;t()}([])</script><script src="/static/js/2.d2927f6c.chunk.js"></script><script src="/static/js/main.bc9ed2e6.chunk.js"></script></body></html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
</body>
</html>

View File

@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

View File

@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow: