nit Console1. Add some order to experiments

This commit is contained in:
Фролов 2021-10-08 11:30:57 +05:00
parent 4fe570f3e9
commit 674fe9586c
5 changed files with 151 additions and 47 deletions

View 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;
}
}
}
}

View File

@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<StartupObject>ConsoleApp1.Program</StartupObject>
</PropertyGroup>
<ItemGroup>

View 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("_");
}
}
}

View 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|");
}
}
}

View File

@ -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<AsbCloudDbContext>()
// .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<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);
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|");
ActionWellOperationsRefactor.Main();
}
}
}