From c445941aa23c8d0e6aa9555756d6251ec70b0fe2 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 3 Feb 2022 09:46:41 +0100 Subject: [PATCH 1/3] wip x calcolo --- GWMS.Data/Controllers/GWMSController.cs | 85 +++++++++++-------------- 1 file changed, 37 insertions(+), 48 deletions(-) diff --git a/GWMS.Data/Controllers/GWMSController.cs b/GWMS.Data/Controllers/GWMSController.cs index 117dd3e..4f4f062 100644 --- a/GWMS.Data/Controllers/GWMSController.cs +++ b/GWMS.Data/Controllers/GWMSController.cs @@ -847,9 +847,10 @@ namespace GWMS.Data.Controllers .OrderBy(x => x.DtOrder) .ToList(); + // imposto x ora a soli 2 gg (torno indietro di 1...) int numDays = 1; DateTime oggi = DateTime.Today; - // Ciclare su ultimi numDays gg + // recupero ultimi record carichi x numDays gg var rawDepOrderData = localDbCtx .DbSetOrders .Where(x => x.PlantId == PlantId && x.ExecutionQty > 0 && x.DtExecStart >= oggi.AddDays(-numDays)) @@ -857,60 +858,32 @@ namespace GWMS.Data.Controllers .ToList(); // ciclo numDays giorni precedenti - double startLevel = 0; + double venduto = 0; + double versatoQty = 0; + PlantLogModel firstRecord = null; + PlantLogModel nextRecord = null; + DateTime currDay = oggi; for (int i = numDays; i > 0; i--) { - DateTime currDay = oggi.AddDays(-i); - var firstRecord = rawLevelData.Where(x => x.DtEvent >= currDay).FirstOrDefault(); - var nextRecord = rawLevelData.Where(x => x.DtEvent >= currDay.AddDays(1)).FirstOrDefault(); - if (firstRecord == null || nextRecord == null) - { - double venduto = 0; - } - else - { - double venduto = firstRecord.ValNumber - nextRecord.ValNumber; - // controllo se ho ordini chiusi ieri - var ordQty = rawDepOrderData.Where(x => x.DtExecStart.Date == currDay).Sum(x => x.ExecutionQty); - if (ordQty > 0 ) - { - venduto += ordQty; - } + currDay = oggi.AddDays(-i); + firstRecord = rawLevelData.Where(x => x.DtEvent >= currDay).FirstOrDefault(); + nextRecord = rawLevelData.Where(x => x.DtEvent >= currDay.AddDays(1)).FirstOrDefault(); + versatoQty = rawDepOrderData.Where(x => x.DtExecStart.Date == currDay).Sum(x => x.ExecutionQty); + venduto = calcVenduto(versatoQty, firstRecord, nextRecord); - // salvo TS - SoldTS.Add(new TSData() { DtEvent = currDay, ValDouble = venduto }); - if (SoldTS[0] == null) - { - SoldTS.Add(new TSData() { DtEvent = currDay, ValDouble = 0 }); - } - } + // salvo TS + SoldTS.Add(new TSData() { DtEvent = currDay, ValDouble = venduto }); } // aggiungo oggi - DateTime today = oggi; - var firstRecord1 = rawLevelData.Where(x => x.DtEvent >= today).FirstOrDefault(); - var lastRecord1 = rawLevelData.Where(x => x.DtEvent >= today).LastOrDefault(); - if (firstRecord1 == null || lastRecord1 == null) - { - double vendutoOggi = 0; - } - else - { - double vendutoOggi = firstRecord1.ValNumber - lastRecord1.ValNumber; - // controllo se ho ordini chiusi oggi - var ordQty = rawDepOrderData.Where(x => x.DtExecStart.Date == today).Sum(x => x.ExecutionQty); - if (ordQty > 0 ) - { - vendutoOggi += ordQty; - } + currDay = oggi; + firstRecord = rawLevelData.Where(x => x.DtEvent >= currDay).FirstOrDefault(); + nextRecord = rawLevelData.Where(x => x.DtEvent >= currDay).LastOrDefault(); + versatoQty = rawDepOrderData.Where(x => x.DtExecStart.Date == currDay).Sum(x => x.ExecutionQty); + venduto = calcVenduto(versatoQty, firstRecord, nextRecord); + // salvo TS + SoldTS.Add(new TSData() { DtEvent = currDay, ValDouble = venduto }); - // salvo TS - SoldTS.Add(new TSData() { DtEvent = today, ValDouble = vendutoOggi }); - if (SoldTS[1] == null) - { - SoldTS.Add(new TSData() { DtEvent = today, ValDouble = 0 }); - } - } LevelTS = rawLevelData .Select(x => new TSData() { DtEvent = x.DtEvent, ValDouble = x.ValNumber }).ToList(); @@ -963,6 +936,22 @@ namespace GWMS.Data.Controllers return answ; } + private static double calcVenduto(double versatoQty, PlantLogModel firstRecord, PlantLogModel nextRecord) + { + double venduto; + if (firstRecord == null || nextRecord == null) + { + venduto = 0; + } + else + { + venduto = firstRecord.ValNumber - nextRecord.ValNumber; + venduto += versatoQty; + } + + return venduto; + } + /// /// Recupero da DB l'ultimo record per ogni flusso /// From 45a2d1aa8193e757c55f5cf09a46f3cd9e610d6d Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 3 Feb 2022 10:02:23 +0100 Subject: [PATCH 2/3] Fix calcolo venduto x dati mancanti gg --- GWMS.Data/Controllers/GWMSController.cs | 43 ++++++++----------------- GWMS.UI/GWMS.UI.csproj | 2 +- Resources/ChangeLog.html | 2 +- Resources/VersNum.txt | 2 +- Resources/manifest.xml | 2 +- 5 files changed, 18 insertions(+), 33 deletions(-) diff --git a/GWMS.Data/Controllers/GWMSController.cs b/GWMS.Data/Controllers/GWMSController.cs index 4f4f062..ea9a0b3 100644 --- a/GWMS.Data/Controllers/GWMSController.cs +++ b/GWMS.Data/Controllers/GWMSController.cs @@ -863,28 +863,29 @@ namespace GWMS.Data.Controllers PlantLogModel firstRecord = null; PlantLogModel nextRecord = null; DateTime currDay = oggi; - for (int i = numDays; i > 0; i--) + for (int i = numDays; i >= 0; i--) { currDay = oggi.AddDays(-i); firstRecord = rawLevelData.Where(x => x.DtEvent >= currDay).FirstOrDefault(); nextRecord = rawLevelData.Where(x => x.DtEvent >= currDay.AddDays(1)).FirstOrDefault(); + if (nextRecord == null) + { + nextRecord = rawLevelData.Where(x => x.DtEvent < currDay.AddDays(1)).OrderByDescending(x => x.DtEvent).FirstOrDefault(); + } versatoQty = rawDepOrderData.Where(x => x.DtExecStart.Date == currDay).Sum(x => x.ExecutionQty); - venduto = calcVenduto(versatoQty, firstRecord, nextRecord); - + if (firstRecord == null || nextRecord == null) + { + venduto = 0; + } + else + { + venduto = firstRecord.ValNumber - nextRecord.ValNumber; + venduto += versatoQty; + } // salvo TS SoldTS.Add(new TSData() { DtEvent = currDay, ValDouble = venduto }); } - // aggiungo oggi - currDay = oggi; - firstRecord = rawLevelData.Where(x => x.DtEvent >= currDay).FirstOrDefault(); - nextRecord = rawLevelData.Where(x => x.DtEvent >= currDay).LastOrDefault(); - versatoQty = rawDepOrderData.Where(x => x.DtExecStart.Date == currDay).Sum(x => x.ExecutionQty); - venduto = calcVenduto(versatoQty, firstRecord, nextRecord); - // salvo TS - SoldTS.Add(new TSData() { DtEvent = currDay, ValDouble = venduto }); - - LevelTS = rawLevelData .Select(x => new TSData() { DtEvent = x.DtEvent, ValDouble = x.ValNumber }).ToList(); @@ -936,22 +937,6 @@ namespace GWMS.Data.Controllers return answ; } - private static double calcVenduto(double versatoQty, PlantLogModel firstRecord, PlantLogModel nextRecord) - { - double venduto; - if (firstRecord == null || nextRecord == null) - { - venduto = 0; - } - else - { - venduto = firstRecord.ValNumber - nextRecord.ValNumber; - venduto += versatoQty; - } - - return venduto; - } - /// /// Recupero da DB l'ultimo record per ogni flusso /// diff --git a/GWMS.UI/GWMS.UI.csproj b/GWMS.UI/GWMS.UI.csproj index 2929722..77c0a37 100644 --- a/GWMS.UI/GWMS.UI.csproj +++ b/GWMS.UI/GWMS.UI.csproj @@ -2,7 +2,7 @@ net5.0 - 1.0.2202.0309 + 1.0.2202.0310 95c9f021-52d1-4390-a670-5810b7b777b0 true true diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html index 0e00f51..2577e63 100644 --- a/Resources/ChangeLog.html +++ b/Resources/ChangeLog.html @@ -1,6 +1,6 @@ GWMS - Gas Warehouse Management System -

Versione: 1.0.2202.0309

+

Versione: 1.0.2202.0310


Note di rilascio:
  • diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt index 3b733b0..4f02577 100644 --- a/Resources/VersNum.txt +++ b/Resources/VersNum.txt @@ -1 +1 @@ -1.0.2202.0309 +1.0.2202.0310 diff --git a/Resources/manifest.xml b/Resources/manifest.xml index 05a44b2..d28558f 100644 --- a/Resources/manifest.xml +++ b/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.0.2202.0309 + 1.0.2202.0310 http://nexus.steamware.net/repository/SWS/GWMS/stable/0/GWMS.UI.zip http://nexus.steamware.net/repository/SWS/GWMS/stable/0/ChangeLog.html false From 9243321336d6ae43136bda312c58995642fd4333 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 3 Feb 2022 10:03:05 +0100 Subject: [PATCH 3/3] refresh --- GWMS.UI/GWMS.UI.csproj | 2 +- Resources/ChangeLog.html | 2 +- Resources/VersNum.txt | 2 +- Resources/manifest.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/GWMS.UI/GWMS.UI.csproj b/GWMS.UI/GWMS.UI.csproj index 2929722..77c0a37 100644 --- a/GWMS.UI/GWMS.UI.csproj +++ b/GWMS.UI/GWMS.UI.csproj @@ -2,7 +2,7 @@ net5.0 - 1.0.2202.0309 + 1.0.2202.0310 95c9f021-52d1-4390-a670-5810b7b777b0 true true diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html index 0e00f51..2577e63 100644 --- a/Resources/ChangeLog.html +++ b/Resources/ChangeLog.html @@ -1,6 +1,6 @@ GWMS - Gas Warehouse Management System -

    Versione: 1.0.2202.0309

    +

    Versione: 1.0.2202.0310


    Note di rilascio:
    • diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt index 3b733b0..4f02577 100644 --- a/Resources/VersNum.txt +++ b/Resources/VersNum.txt @@ -1 +1 @@ -1.0.2202.0309 +1.0.2202.0310 diff --git a/Resources/manifest.xml b/Resources/manifest.xml index 05a44b2..d28558f 100644 --- a/Resources/manifest.xml +++ b/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.0.2202.0309 + 1.0.2202.0310 http://nexus.steamware.net/repository/SWS/GWMS/stable/0/GWMS.UI.zip http://nexus.steamware.net/repository/SWS/GWMS/stable/0/ChangeLog.html false