Inserimento progress in dedup FL
This commit is contained in:
@@ -8,6 +8,7 @@ using NLog.LayoutRenderers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
@@ -553,6 +554,7 @@ namespace MP.Data.Controllers
|
||||
/// <returns></returns>
|
||||
public async Task<bool> FluxLogDataRedux(string idxMaccSel, List<string> fluxList, Periodo currPeriodo, Enum.ValSelection valMode, Enum.DataInterval intReq)
|
||||
{
|
||||
Log.Info($"Inizio FluxLogDataRedux | idxMaccSel: {idxMaccSel} | periodo: {currPeriodo.Inizio} --> {currPeriodo.Fine}");
|
||||
bool fatto = false;
|
||||
TimeSpan step = TimeSpan.FromHours(1);
|
||||
switch (intReq)
|
||||
@@ -569,6 +571,7 @@ namespace MP.Data.Controllers
|
||||
default:
|
||||
break;
|
||||
}
|
||||
List<LogFLDedupModel> procStats = new List<LogFLDedupModel>();
|
||||
|
||||
// setup parametri costanti x stored
|
||||
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMaccSel);
|
||||
@@ -578,6 +581,10 @@ namespace MP.Data.Controllers
|
||||
// processo 1:1 ogni flusso
|
||||
foreach (var item in fluxList)
|
||||
{
|
||||
Log.Info($"FluxLogDataRedux | Flux: {item}");
|
||||
int numRecProc = 0;
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
// parametri x flusso
|
||||
var pCodFlux = new SqlParameter("@CodFlux", item);
|
||||
// inizializzo cursore timer
|
||||
@@ -596,67 +603,14 @@ namespace MP.Data.Controllers
|
||||
.Where(x => (x.CodFlux == item) && (x.dtEvento >= dtCursStart && x.dtEvento < dtCursEnd) && (x.IdxMacchina == idxMaccSel))
|
||||
.ToListAsync();
|
||||
|
||||
// incremento dt fine periodo
|
||||
dtCursStart = dtCursEnd;
|
||||
dtCursEnd = dtCursStart.Add(step);
|
||||
int numRec = currFlux.Count;
|
||||
numRecProc += numRec;
|
||||
if (numRec > 1)
|
||||
{
|
||||
if (dtCursStart > currPeriodo.Fine)
|
||||
{
|
||||
setCompleted = true;
|
||||
}
|
||||
#if false
|
||||
//var set2del = currFlux;
|
||||
|
||||
//switch (valMode)
|
||||
//{
|
||||
// case Enum.ValSelection.First:
|
||||
// // tolgo il primo (che quindi lascio)
|
||||
// set2del.RemoveAt(0);
|
||||
// break;
|
||||
// case Enum.ValSelection.Last:
|
||||
// set2del.RemoveAt(numRec - 1);
|
||||
// break;
|
||||
// case Enum.ValSelection.Center:
|
||||
// set2del.RemoveAt(numRec / 2);
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
//}
|
||||
//dbCtx.DbSetFluxLog.RemoveRange(set2del);
|
||||
#endif
|
||||
|
||||
#if false
|
||||
switch (valMode)
|
||||
{
|
||||
case Enum.ValSelection.First:
|
||||
// tolgo il primo (che quindi lascio)
|
||||
currFlux.RemoveAt(0);
|
||||
break;
|
||||
case Enum.ValSelection.Last:
|
||||
currFlux.RemoveAt(numRec - 1);
|
||||
break;
|
||||
case Enum.ValSelection.Center:
|
||||
currFlux.RemoveAt(numRec / 2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
dbCtx.RemoveRange(currFlux);
|
||||
|
||||
dbCtx.ChangeTracker.DetectChanges();
|
||||
Log.Trace(dbCtx.ChangeTracker.DebugView.LongView);
|
||||
try
|
||||
{
|
||||
// salvo
|
||||
await dbCtx.SaveChangesAsync(false);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in deduplica dati FluxLog{Environment.NewLine}{exc}");
|
||||
}
|
||||
#endif
|
||||
List<Periodo> listPeriodi = new List<Periodo>();
|
||||
|
||||
|
||||
@@ -687,8 +641,6 @@ namespace MP.Data.Controllers
|
||||
// ciclo x tutti i periodi e chiamo stored...
|
||||
foreach (var slot in listPeriodi)
|
||||
{
|
||||
|
||||
|
||||
// parametri x periodo (base)
|
||||
var pDtStart = new SqlParameter("@DtStart", slot.Inizio);
|
||||
var pDtEnd = new SqlParameter("@DtEnd", slot.Fine);
|
||||
@@ -696,99 +648,52 @@ namespace MP.Data.Controllers
|
||||
.Database
|
||||
.ExecuteSqlRaw("EXEC man.stp_ReduceFluxLog @IdxMacchina, @CodFlux, @DtStart, @DtEnd, @OnlyTest, @DoReIndex", pIdxMacchina, pCodFlux, pDtStart, pDtEnd, pOnlyTest, pDoReIndex);
|
||||
}
|
||||
|
||||
#if false
|
||||
if (dtCursStart > currPeriodo.Fine)
|
||||
{
|
||||
setCompleted = true;
|
||||
}
|
||||
var currSet = currFlux.ToList();
|
||||
if (currSet.Count > 0)
|
||||
{
|
||||
switch (valMode)
|
||||
{
|
||||
case Enum.ValSelection.First:
|
||||
// tolgo il primo (che quindi lascio)
|
||||
currSet.RemoveAt(0);
|
||||
break;
|
||||
case Enum.ValSelection.Last:
|
||||
currSet.RemoveAt(currSet.Count - 1);
|
||||
break;
|
||||
case Enum.ValSelection.Center:
|
||||
currSet.RemoveAt(currSet.Count / 2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//// elimino i dati processati
|
||||
//foreach (var item2del in currSet)
|
||||
//{
|
||||
// currFlux.Remove(item2del);
|
||||
//}
|
||||
dbCtx.DbSetFluxLog.RemoveRange(currSet);
|
||||
try
|
||||
{
|
||||
// salvo
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in deduplica dati FluxLog{Environment.NewLine}{exc}");
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if false
|
||||
// seleziono dati da processare
|
||||
var currSet = currFlux.Where(x => x.dtEvento < dtCursStart).ToList();
|
||||
if (currSet.Count > 0)
|
||||
{
|
||||
switch (valMode)
|
||||
{
|
||||
case Enum.ValSelection.First:
|
||||
// tolgo il primo (che quindi lascio)
|
||||
currSet.RemoveAt(0);
|
||||
break;
|
||||
case Enum.ValSelection.Last:
|
||||
currSet.RemoveAt(currSet.Count - 1);
|
||||
break;
|
||||
case Enum.ValSelection.Center:
|
||||
currSet.RemoveAt(currSet.Count / 2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//// elimino i dati processati
|
||||
//foreach (var item2del in currSet)
|
||||
//{
|
||||
// currFlux.Remove(item2del);
|
||||
//}
|
||||
dbCtx.DbSetFluxLog.RemoveRange(currSet);
|
||||
try
|
||||
{
|
||||
// salvo
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in deduplica dati FluxLog{Environment.NewLine}{exc}");
|
||||
}
|
||||
|
||||
// tengo solo i dati successivi x prossimo giro...
|
||||
currFlux = currFlux.Where(x => x.dtEvento >= dtCursStart).ToList();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// incremento dt fine periodo
|
||||
dtCursStart = dtCursEnd;
|
||||
dtCursEnd = dtCursStart.Add(step);
|
||||
}
|
||||
}
|
||||
// fermo cronometro e salvo su DB...
|
||||
sw.Stop();
|
||||
LogFLDedupModel currStat = new LogFLDedupModel()
|
||||
{
|
||||
IdxMacchina = idxMaccSel,
|
||||
CodFlux = item,
|
||||
DtRif = DateTime.Now,
|
||||
NumRec = numRecProc,
|
||||
ProcTime = sw.Elapsed.TotalSeconds
|
||||
};
|
||||
procStats.Add(currStat);
|
||||
}
|
||||
|
||||
// salvo le statistiche di processing...
|
||||
fatto = LogFLDedupInsert(procStats);
|
||||
Log.Info($"FINE FluxLogDataRedux | idxMaccSel: {idxMaccSel} | periodo: {currPeriodo.Inizio} --> {currPeriodo.Fine}");
|
||||
return fatto;
|
||||
}
|
||||
/// <summary>
|
||||
/// Inserimento record risultati deduplica FluxLog
|
||||
/// </summary>
|
||||
/// <param name="rec2ins"></param>
|
||||
/// <returns></returns>
|
||||
protected bool LogFLDedupInsert(List<LogFLDedupModel> rec2ins)
|
||||
{
|
||||
bool fatto = false;
|
||||
using (var dbCtx = new MoonProContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
dbCtx.DbSetLogFLDedup.AddRange(rec2ins);
|
||||
var res = dbCtx.SaveChanges();
|
||||
fatto = res != 0;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in fase inserimento log dedup x FL{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
//await Task.Delay(1500);
|
||||
return fatto;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
|
||||
#nullable disable
|
||||
// <Auto-Generated>
|
||||
// This is here so CodeMaid doesn't reorganize this document
|
||||
// </Auto-Generated>
|
||||
namespace MP.Data.DatabaseModels
|
||||
{
|
||||
[Table("LogFLDedup")]
|
||||
public partial class LogFLDedupModel
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int DedupIdx { get; set; } = 0;
|
||||
|
||||
[MaxLength(50)]
|
||||
public string IdxMacchina { get; set; } = "";
|
||||
|
||||
[MaxLength(50)]
|
||||
public string CodFlux { get; set; } = "";
|
||||
|
||||
public DateTime DtRif { get; set; }=DateTime.Now;
|
||||
|
||||
/// <summary>
|
||||
/// Num record processati
|
||||
/// </summary>
|
||||
public int NumRec { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Tempo processing (secondi)
|
||||
/// </summary>
|
||||
public double ProcTime { get; set; } = 1;
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,9 @@ namespace MP.Data
|
||||
|
||||
public virtual DbSet<CommentiModel> DbSetCommenti { get; set; }
|
||||
public virtual DbSet<FermiNonQualModel> DbSetFNQ { get; set; }
|
||||
public virtual DbSet<LogFLDedupModel> DbSetLogFLDedup { get; set; }
|
||||
|
||||
|
||||
|
||||
public virtual DbSet<vSelEventiBCodeModel> DbSetVSEB { get; set; }
|
||||
public virtual DbSet<vSelOdlModel> DbSetVSODL { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user