forked from ddrilling/AsbCloudServer
nit Console1. Add some order to experiments
This commit is contained in:
parent
4fe570f3e9
commit
674fe9586c
70
ConsoleApp1/ActionWellOperationsRefactor.cs
Normal file
70
ConsoleApp1/ActionWellOperationsRefactor.cs
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
using AsbCloudDb.Model;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ConsoleApp1
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Split WellDepth to DepthStart and DepthEnd
|
||||||
|
/// </summary>
|
||||||
|
static class ActionWellOperationsRefactor
|
||||||
|
{
|
||||||
|
private static DbContextOptions<AsbCloudDbContext> options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||||
|
.UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
||||||
|
.Options;
|
||||||
|
|
||||||
|
public static void Main()
|
||||||
|
{
|
||||||
|
using var db = new AsbCloudDbContext(options);
|
||||||
|
|
||||||
|
var wellsIds = db.WellOperations
|
||||||
|
.Select(o => o.IdWell)
|
||||||
|
.Distinct()
|
||||||
|
.ToList();
|
||||||
|
var transaction = db.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (var idWell in wellsIds)
|
||||||
|
{
|
||||||
|
var operations = db.WellOperations
|
||||||
|
.Where(o => o.IdWell == idWell)
|
||||||
|
.OrderBy(o => o.DateStart)
|
||||||
|
.ThenBy(o => o.DepthEnd)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var operationsPlan = operations.Where(o => o.IdType == 0);
|
||||||
|
RefactorWellOperations(operationsPlan);
|
||||||
|
|
||||||
|
var operationsFact = operations.Where(o => o.IdType == 1);
|
||||||
|
RefactorWellOperations(operationsFact);
|
||||||
|
|
||||||
|
db.SaveChanges();
|
||||||
|
}
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RefactorWellOperations(IEnumerable<WellOperation> operations)
|
||||||
|
{
|
||||||
|
if (!operations.Any())
|
||||||
|
return;
|
||||||
|
var oi = operations.GetEnumerator();
|
||||||
|
oi.MoveNext();
|
||||||
|
var pre = oi.Current;
|
||||||
|
oi.Current.DepthStart = 0d;
|
||||||
|
while (oi.MoveNext())
|
||||||
|
{
|
||||||
|
oi.Current.DepthStart = pre.DepthEnd;
|
||||||
|
pre = oi.Current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
<StartupObject>ConsoleApp1.Program</StartupObject>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
32
ConsoleApp1/DebugWellOperationImportService.cs
Normal file
32
ConsoleApp1/DebugWellOperationImportService.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using AsbCloudDb.Model;
|
||||||
|
using AsbCloudInfrastructure.Services;
|
||||||
|
using AsbCloudInfrastructure.Services.Cache;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ConsoleApp1
|
||||||
|
{
|
||||||
|
public static class DebugWellOperationImportService
|
||||||
|
{
|
||||||
|
public static void Main(/*string[] args*/)
|
||||||
|
{
|
||||||
|
var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||||
|
.UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
||||||
|
.Options;
|
||||||
|
using var db = new AsbCloudDbContext(options);
|
||||||
|
|
||||||
|
var cacheDb = new CacheDb();
|
||||||
|
var wellService = new WellService(db, new TelemetryTracker(), cacheDb);
|
||||||
|
|
||||||
|
var wellOperationImportService = new WellOperationImportService();
|
||||||
|
|
||||||
|
var ops = wellOperationImportService.ParseFile(@"C:\temp\Миграция.xlsx");
|
||||||
|
|
||||||
|
Console.WriteLine("_");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
46
ConsoleApp1/DebugWellOperationsStatService.cs
Normal file
46
ConsoleApp1/DebugWellOperationsStatService.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
using AsbCloudInfrastructure.Services;
|
||||||
|
using AsbCloudInfrastructure.Services.Cache;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ConsoleApp1
|
||||||
|
{
|
||||||
|
public static class DebugWellOperationsStatService
|
||||||
|
{
|
||||||
|
public static void Main(/*string[] args*/)
|
||||||
|
{
|
||||||
|
var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||||
|
.UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
||||||
|
.Options;
|
||||||
|
using var db = new AsbCloudDbContext(options);
|
||||||
|
var cacheDb = new CacheDb();
|
||||||
|
var wellService = new WellService(db, new TelemetryTracker(), cacheDb);
|
||||||
|
var wellOptsStat = new WellOperationsStatService(db, cacheDb, wellService);
|
||||||
|
var tvd = wellOptsStat.GetTvdAsync(1, default).Result;
|
||||||
|
Print(tvd);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Print(IEnumerable<PlanFactPredictBase<WellOperationDto>> tvd)
|
||||||
|
{
|
||||||
|
Console.WriteLine("|\tplan\t|\tfact\t|\tprog\t|");
|
||||||
|
Console.WriteLine("|:-------------:|:-------------:|:-------------:|");
|
||||||
|
foreach (var item in tvd)
|
||||||
|
Print(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Print(PlanFactPredictBase<WellOperationDto> item)
|
||||||
|
{
|
||||||
|
static string GetText(WellOperationDto item)
|
||||||
|
=> (item is null)
|
||||||
|
? " --------- "
|
||||||
|
: $"{item.IdCategory} d:{item.DepthStart} ";
|
||||||
|
Console.WriteLine($"|\t{GetText(item.Plan)}\t|\t{GetText(item.Fact)}\t|\t{GetText(item.Predict)}\t|");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,18 +1,4 @@
|
|||||||
using System;
|
namespace ConsoleApp1
|
||||||
using System.IO;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using ClosedXML.Excel;
|
|
||||||
using ClosedXML.Excel.Drawings;
|
|
||||||
using AsbCloudApp.Data;
|
|
||||||
using AsbCloudDb.Model;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using AsbCloudInfrastructure.Services.Cache;
|
|
||||||
using AsbCloudInfrastructure.Services;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace ConsoleApp1
|
|
||||||
{
|
{
|
||||||
//var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
//var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||||
// .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
// .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
||||||
@ -23,38 +9,7 @@ namespace ConsoleApp1
|
|||||||
{
|
{
|
||||||
static void Main(/*string[] args*/)
|
static void Main(/*string[] args*/)
|
||||||
{
|
{
|
||||||
var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
ActionWellOperationsRefactor.Main();
|
||||||
.UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
|
||||||
.Options;
|
|
||||||
using var db = new AsbCloudDbContext(options);
|
|
||||||
|
|
||||||
var cacheDb = new CacheDb();
|
|
||||||
var wellService = new WellService(db, new TelemetryTracker(), cacheDb);
|
|
||||||
|
|
||||||
var wellOptsStat = new WellOperationsStatService(db, cacheDb, wellService);
|
|
||||||
|
|
||||||
var tvd = wellOptsStat.GetTvdAsync(1, default).Result;
|
|
||||||
Print(tvd);
|
|
||||||
Console.WriteLine("_");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void Print(IEnumerable<PlanFactPredictBase<WellOperationDto>> tvd)
|
|
||||||
{
|
|
||||||
Console.WriteLine("|\tplan\t|\tfact\t|\tprog\t|");
|
|
||||||
Console.WriteLine("|:-------------:|:-------------:|:-------------:|");
|
|
||||||
foreach (var item in tvd)
|
|
||||||
Print(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void Print(PlanFactPredictBase<WellOperationDto> item)
|
|
||||||
{
|
|
||||||
static string GetText(WellOperationDto item)
|
|
||||||
=> (item is null)
|
|
||||||
? " --------- "
|
|
||||||
: $"{item.IdCategory} d:{item.WellDepth} ";
|
|
||||||
|
|
||||||
Console.WriteLine($"|\t{GetText(item.Plan)}\t|\t{GetText(item.Fact)}\t|\t{GetText(item.Predict)}\t|");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user