From 674fe9586cbadb96576dae07a84929a5d7e871ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Fri, 8 Oct 2021 11:30:57 +0500 Subject: [PATCH] nit Console1. Add some order to experiments --- ConsoleApp1/ActionWellOperationsRefactor.cs | 70 +++++++++++++++++++ ConsoleApp1/ConsoleApp1.csproj | 1 + .../DebugWellOperationImportService.cs | 32 +++++++++ ConsoleApp1/DebugWellOperationsStatService.cs | 46 ++++++++++++ ConsoleApp1/Program.cs | 49 +------------ 5 files changed, 151 insertions(+), 47 deletions(-) create mode 100644 ConsoleApp1/ActionWellOperationsRefactor.cs create mode 100644 ConsoleApp1/DebugWellOperationImportService.cs create mode 100644 ConsoleApp1/DebugWellOperationsStatService.cs diff --git a/ConsoleApp1/ActionWellOperationsRefactor.cs b/ConsoleApp1/ActionWellOperationsRefactor.cs new file mode 100644 index 00000000..234d6e3a --- /dev/null +++ b/ConsoleApp1/ActionWellOperationsRefactor.cs @@ -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 +{ + /// + /// Split WellDepth to DepthStart and DepthEnd + /// + static class ActionWellOperationsRefactor + { + private static DbContextOptions options = new DbContextOptionsBuilder() + .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 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; + } + } + } +} diff --git a/ConsoleApp1/ConsoleApp1.csproj b/ConsoleApp1/ConsoleApp1.csproj index ea6513f8..29536cbc 100644 --- a/ConsoleApp1/ConsoleApp1.csproj +++ b/ConsoleApp1/ConsoleApp1.csproj @@ -3,6 +3,7 @@ Exe net5.0 + ConsoleApp1.Program diff --git a/ConsoleApp1/DebugWellOperationImportService.cs b/ConsoleApp1/DebugWellOperationImportService.cs new file mode 100644 index 00000000..6e3cb035 --- /dev/null +++ b/ConsoleApp1/DebugWellOperationImportService.cs @@ -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() + .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("_"); + } + } +} diff --git a/ConsoleApp1/DebugWellOperationsStatService.cs b/ConsoleApp1/DebugWellOperationsStatService.cs new file mode 100644 index 00000000..35a6ee1e --- /dev/null +++ b/ConsoleApp1/DebugWellOperationsStatService.cs @@ -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() + .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> tvd) + { + Console.WriteLine("|\tplan\t|\tfact\t|\tprog\t|"); + Console.WriteLine("|:-------------:|:-------------:|:-------------:|"); + foreach (var item in tvd) + Print(item); + } + + private static void Print(PlanFactPredictBase 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|"); + } + } +} diff --git a/ConsoleApp1/Program.cs b/ConsoleApp1/Program.cs index 2c6f70a5..5b6b1a22 100644 --- a/ConsoleApp1/Program.cs +++ b/ConsoleApp1/Program.cs @@ -1,18 +1,4 @@ -using System; -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 +namespace ConsoleApp1 { //var options = new DbContextOptionsBuilder() // .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True") @@ -23,38 +9,7 @@ namespace ConsoleApp1 { static void Main(/*string[] args*/) { - var options = new DbContextOptionsBuilder() - .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> tvd) - { - Console.WriteLine("|\tplan\t|\tfact\t|\tprog\t|"); - Console.WriteLine("|:-------------:|:-------------:|:-------------:|"); - foreach (var item in tvd) - Print(item); - } - - private static void Print(PlanFactPredictBase 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|"); - + ActionWellOperationsRefactor.Main(); } } }