From 8a89dbaec0e9277199bda96320a7480535e9d9b6 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 7 Aug 2023 12:13:38 +0200 Subject: [PATCH] Update x permettere split parziali --- .../WebUserControls/cmp_batchDetailSplit.ascx | 12 +- .../cmp_batchDetailSplit.ascx.cs | 123 +++++++++++++----- .../WebUserControls/cmp_orderExtList.ascx.cs | 2 +- 3 files changed, 98 insertions(+), 39 deletions(-) diff --git a/NKC_WF/WebUserControls/cmp_batchDetailSplit.ascx b/NKC_WF/WebUserControls/cmp_batchDetailSplit.ascx index db62e63..5b99962 100644 --- a/NKC_WF/WebUserControls/cmp_batchDetailSplit.ascx +++ b/NKC_WF/WebUserControls/cmp_batchDetailSplit.ascx @@ -42,11 +42,11 @@
- +
- +
@@ -75,11 +75,11 @@
- +
- +
@@ -108,11 +108,11 @@
- +
- +
diff --git a/NKC_WF/WebUserControls/cmp_batchDetailSplit.ascx.cs b/NKC_WF/WebUserControls/cmp_batchDetailSplit.ascx.cs index 36b6cd7..3c2b926 100644 --- a/NKC_WF/WebUserControls/cmp_batchDetailSplit.ascx.cs +++ b/NKC_WF/WebUserControls/cmp_batchDetailSplit.ascx.cs @@ -393,9 +393,12 @@ namespace NKC_WF.WebUserControls protected void lbtBalance_Click(object sender, EventArgs e) { - Ratio01 = 0.33; - Ratio02 = 0.34; - Ratio03 = 0.33; + // imposto la % secondo numero di abilitati... + Ratio01 = enable01 ? (double)1 / numEnabled : 0; + Ratio02 = enable02 ? (double)1 / numEnabled : 0; + Ratio03 = enable03 ? (double)1 / numEnabled : 0; + //Ratio02 = 0.34; + //Ratio03 = 0.33; lastRatio01 = 0; lastRatio02 = 0; lastRatio03 = 0; @@ -461,6 +464,7 @@ namespace NKC_WF.WebUserControls if (!Page.IsPostBack) { // verifica visualizzazione + enableAll(); fixChildBatch(); fixRatio(); checkDisplayMode(); @@ -471,6 +475,13 @@ namespace NKC_WF.WebUserControls cmp_orderExtListNE03.eh_doRefresh += Cmp_orderExtListNE03_eh_doRefresh; } + private void enableAll() + { + enable01 = true; + enable02 = true; + enable03 = true; + } + #endregion Protected Methods #region Private Properties @@ -479,7 +490,7 @@ namespace NKC_WF.WebUserControls { get { - bool answ = false; + bool answ = true; bool.TryParse(hfEnabled01.Value, out answ); return answ; } @@ -521,11 +532,18 @@ namespace NKC_WF.WebUserControls { get { - int numEnab = 0; - numEnab += enable01 ? 1 : 0; - numEnab += enable02 ? 1 : 0; - numEnab += enable03 ? 1 : 0; - return numEnab == 2; + return numEnabled == 2; + } + } + private int numEnabled + { + get + { + int answ = 0; + answ += enable01 ? 1 : 0; + answ += enable02 ? 1 : 0; + answ += enable03 ? 1 : 0; + return answ; } } @@ -625,12 +643,12 @@ namespace NKC_WF.WebUserControls lbtToggle01.CssClass = enable01 ? "btn btn-sm btn-dark" : "btn btn-sm btn-secondary"; lbtToggle02.CssClass = enable02 ? "btn btn-sm btn-dark" : "btn btn-sm btn-secondary"; lbtToggle03.CssClass = enable03 ? "btn btn-sm btn-dark" : "btn btn-sm btn-secondary"; - lbtOrdAdd01.CssClass = movEnabled && enable01 ? "btn btn-primary px-3" : "btn btn-secondary disabled"; - lbtOrdRem01.CssClass = movEnabled && enable01 ? "btn btn-primary px-3" : "btn btn-secondary disabled"; - lbtOrdAdd02.CssClass = movEnabled && enable02 ? "btn btn-primary px-3" : "btn btn-secondary disabled"; - lbtOrdRem02.CssClass = movEnabled && enable02 ? "btn btn-primary px-3" : "btn btn-secondary disabled"; - lbtOrdAdd03.CssClass = movEnabled && enable03 ? "btn btn-primary px-3" : "btn btn-secondary disabled"; - lbtOrdRem03.CssClass = movEnabled && enable03 ? "btn btn-primary px-3" : "btn btn-secondary disabled"; + lbtOrdAdd01.CssClass = movEnabled && enable01 ? "btn btn-primary px-3" : "btn btn-secondary px-3 disabled"; + lbtOrdRem01.CssClass = movEnabled && enable01 ? "btn btn-primary px-3" : "btn btn-secondary px-3 disabled"; + lbtOrdAdd02.CssClass = movEnabled && enable02 ? "btn btn-primary px-3" : "btn btn-secondary px-3 disabled"; + lbtOrdRem02.CssClass = movEnabled && enable02 ? "btn btn-primary px-3" : "btn btn-secondary px-3 disabled"; + lbtOrdAdd03.CssClass = movEnabled && enable03 ? "btn btn-primary px-3" : "btn btn-secondary px-3 disabled"; + lbtOrdRem03.CssClass = movEnabled && enable03 ? "btn btn-primary px-3" : "btn btn-secondary px-3 disabled"; lbtOrdRemAll01.CssClass = movEnabled && enable01 ? "btn btn-danger" : "btn btn-secondary disabled"; lbtOrdAddAll01.CssClass = movEnabled && enable01 ? "btn btn-success" : "btn btn-secondary disabled"; lbtOrdRemAll02.CssClass = movEnabled && enable02 ? "btn btn-danger" : "btn btn-secondary disabled"; @@ -847,20 +865,22 @@ namespace NKC_WF.WebUserControls // inizio immaginando di usare TUTTI gli ordini FullSet.OrderSet = OrderedList; // calcolo i valori target iniziali - SetNe01.TargetValue = FullSet.ActualValue * Ratio01; - SetNe02.TargetValue = FullSet.ActualValue * Ratio02; - SetNe03.TargetValue = FullSet.ActualValue * Ratio03; + SetNe01.TargetValue = enable01 ? FullSet.ActualValue * Ratio01 : 0; + SetNe02.TargetValue = enable02 ? FullSet.ActualValue * Ratio02 : 0; + SetNe03.TargetValue = enable03 ? FullSet.ActualValue * Ratio03 : 0; // salvo i set su cui lavorare, SE ho 4+ ordini, prendo i 3 task + lunghi x assegnarli in modo deterministico - if (OrderedList.Count > 3) + int num2proc = numEnabled; + if (OrderedList.Count > num2proc) { directAssign = true; - StartSet.OrderSet = OrderedList.OrderByDescending(x => x.Value).Take(3).ToDictionary(t => t.Key, t => t.Value); + StartSet.OrderSet = OrderedList.OrderByDescending(x => x.Value).Take(num2proc).ToDictionary(t => t.Key, t => t.Value); // tolgo ordini lunghi tra quelli da processare - OrderedList = OrderedList.Take(OrderedList.Count - 3).ToDictionary(t => t.Key, t => t.Value); - // imposto nuovi target - SetNe01.TargetValue -= StartSet.OrderSet.FirstOrDefault().Value; - SetNe02.TargetValue -= StartSet.OrderSet.Skip(1).FirstOrDefault().Value; - SetNe03.TargetValue -= StartSet.OrderSet.Skip(2).FirstOrDefault().Value; ; + OrderedList = OrderedList.Take(OrderedList.Count - num2proc).ToDictionary(t => t.Key, t => t.Value); + // imposto nuovi target secondo sia abilitato + int idx = 0; + SetNe01.TargetValue -= enable01 ? StartSet.OrderSet.Skip(idx++).FirstOrDefault().Value : 0; + SetNe02.TargetValue -= enable02 ? StartSet.OrderSet.Skip(idx++).FirstOrDefault().Value : 0; + SetNe03.TargetValue -= enable03 ? StartSet.OrderSet.Skip(idx++).FirstOrDefault().Value : 0; } // ciclo x riempire il + primo...SE manca ... @@ -879,17 +899,54 @@ namespace NKC_WF.WebUserControls SetNe02.OrderSet = findLocalMin(ordRemain, SetNe02.TargetValue, maxDepth); } // l'ultimo รจ la differenza - SetNe03.OrderSet = ordRemain; - foreach (var item in SetNe02.OrderSet) + if (SetNe03.TargetValue > 0) { - SetNe03.OrderSet.Remove(item.Key); + SetNe03.OrderSet = ordRemain; + foreach (var item in SetNe02.OrderSet) + { + SetNe03.OrderSet.Remove(item.Key); + } + } + else + { + // riporto ai precedenti + if(enable02) + { + foreach (var item in ordRemain) + { + if(!SetNe02.OrderSet.ContainsKey(item.Key)) + { + SetNe02.OrderSet.Add(item.Key, item.Value); + } + } + } + else if(enable01) + { + foreach (var item in ordRemain) + { + if (!SetNe01.OrderSet.ContainsKey(item.Key)) + { + SetNe01.OrderSet.Add(item.Key, item.Value); + } + } + } } // se directAssign --> reinserisco i 3 ordini grandi if (directAssign) { - SetNe01.OrderSet.Add(StartSet.OrderSet.FirstOrDefault().Key, StartSet.OrderSet.FirstOrDefault().Value); - SetNe02.OrderSet.Add(StartSet.OrderSet.Skip(1).FirstOrDefault().Key, StartSet.OrderSet.Skip(1).FirstOrDefault().Value); - SetNe03.OrderSet.Add(StartSet.OrderSet.Skip(2).FirstOrDefault().Key, StartSet.OrderSet.Skip(2).FirstOrDefault().Value); + int idx = 0; + if (enable01) + { + SetNe01.OrderSet.Add(StartSet.OrderSet.Skip(idx).FirstOrDefault().Key, StartSet.OrderSet.Skip(idx++).FirstOrDefault().Value); + } + if (enable02) + { + SetNe02.OrderSet.Add(StartSet.OrderSet.Skip(idx).FirstOrDefault().Key, StartSet.OrderSet.Skip(idx++).FirstOrDefault().Value); + } + if (enable03) + { + SetNe03.OrderSet.Add(StartSet.OrderSet.Skip(idx).FirstOrDefault().Key, StartSet.OrderSet.Skip(idx++).FirstOrDefault().Value); + } } // riorganizzo tabOrders... foreach (var orderItem in TabOrders) @@ -922,6 +979,7 @@ namespace NKC_WF.WebUserControls stopWatch.Stop(); Log.Instance.Info($"Rebalance executed | R01: {Ratio01} | R02: {Ratio02} | R03: {Ratio03} | maxDepth: {maxDepth} | elapsed ms: {stopWatch.ElapsedMilliseconds}"); } +#if false // calcolo min/max.. var actMax = totTime01 > totTime02 ? totTime01 : totTime02; var actMin = totTime01 < totTime02 ? totTime01 : totTime02; @@ -929,7 +987,8 @@ namespace NKC_WF.WebUserControls actMin = totTime03 < actMin ? totTime03 : actMin; enable01 = (totTime01 == actMin || totTime01 == actMax); enable02 = (totTime02 == actMin || totTime02 == actMax); - enable03 = (totTime03 == actMin || totTime03 == actMax); + enable03 = (totTime03 == actMin || totTime03 == actMax); +#endif } #endregion Private Methods diff --git a/NKC_WF/WebUserControls/cmp_orderExtList.ascx.cs b/NKC_WF/WebUserControls/cmp_orderExtList.ascx.cs index e3ae997..412355d 100644 --- a/NKC_WF/WebUserControls/cmp_orderExtList.ascx.cs +++ b/NKC_WF/WebUserControls/cmp_orderExtList.ascx.cs @@ -64,7 +64,7 @@ namespace NKC_WF.WebUserControls protected string moveCss { - get => enableMove ? "btn btn-dark btn-sm py-0" : "btn btn-secondary disabled btn-sm py-0"; + get => enableMove ? "btn btn-primary btn-sm py-0" : "btn btn-secondary disabled btn-sm py-0"; } #endregion Protected Properties