Continuo pagina ordini: ok step spostamento e bilanciamento xoxo

This commit is contained in:
Samuele Locatelli
2021-06-11 15:48:45 +02:00
parent 4e47b89baf
commit 13a4b4478e
5 changed files with 121 additions and 106 deletions
+1 -1
View File
@@ -1442,7 +1442,7 @@ namespace AppData
// salvo in cache
rawData = JsonConvert.SerializeObject(answ);
memLayer.ML.setRSV(redKey, rawData, 5 * 60);
memLayer.ML.setRSV(redKey, rawData, 1);
}
}
return answ;
@@ -111,6 +111,7 @@
</div>
<div class="col-10">
<asp:HiddenField runat="server" ID="hfNeedSave" />
<asp:HiddenField runat="server" ID="hfLastRatio" />
<asp:TextBox runat="server" ID="txtRatio" TextMode="Range" CssClass="form-control-range" AutoPostBack="true" OnTextChanged="txtRatio_TextChanged" />
</div>
<div class="col-1">
+101 -105
View File
@@ -19,6 +19,23 @@ namespace NKC_WF.WebUserControls
#region Protected Properties
protected int lastValRatio
{
get
{
int answ = 50;
if (!string.IsNullOrEmpty(hfLastRatio.Value))
{
int.TryParse(hfLastRatio.Value, out answ);
}
return answ;
}
set
{
hfLastRatio.Value = $"{value}";
}
}
protected bool needSave
{
get
@@ -44,7 +61,7 @@ namespace NKC_WF.WebUserControls
}
}
protected DS_App.OrderListTreeDataTable TabOrdersFromDb
protected DS_App.OrderListTreeDataTable TabOrders
{
get
{
@@ -64,6 +81,10 @@ namespace NKC_WF.WebUserControls
}
return answ;
}
set
{
txtRatio.Text = $"{value}";
}
}
#endregion Protected Properties
@@ -307,98 +328,92 @@ namespace NKC_WF.WebUserControls
/// </summary>
private void rebalanceOrder()
{
// costruisco vettore durata ordini
OrderSetSim FullSet = new OrderSetSim();
OrderSetSim SetNe01 = new OrderSetSim();
OrderSetSim SetNe02 = new OrderSetSim();
// creo liste x i valori da processare...
Dictionary<int, double> RawList = new Dictionary<int, double>();
Dictionary<int, double> OrderedList = new Dictionary<int, double>();
var TabOrders = TabOrdersFromDb;
foreach (var item in TabOrders)
{
RawList.Add(item.OrdID, item.EstProcTime);
}
// ordino la lista x processing successivo
OrderedList = RawList.OrderBy(x => x.Value).ToDictionary(t => t.Key, t => t.Value);
// salvo i set
FullSet.OrderSet = OrderedList;
// IndexScore = errore di stima corrente
double IScoreCurr = FullSet.ActualValue;
// lavoro sull'ottimizzare il MINORE
double ValRatio = (double)valRatio / 100;
if (ValRatio <= 0.5)
{
SetNe01.TargetValue = FullSet.ActualValue * ValRatio;
SetNe01.OrderSet = findLocalMin(OrderedList, SetNe01.TargetValue, IScoreCurr);
// l'altro è la differenza
SetNe02.OrderSet = OrderedList;
foreach (var item in SetNe01.OrderSet)
{
SetNe02.OrderSet.Remove(item.Key);
}
}
else
{
SetNe02.TargetValue = FullSet.ActualValue * (1 - ValRatio);
SetNe02.OrderSet = findLocalMin(OrderedList, SetNe02.TargetValue, IScoreCurr);
// l'altro è la differenza
SetNe01.OrderSet = OrderedList;
foreach (var item in SetNe02.OrderSet)
{
SetNe01.OrderSet.Remove(item.Key);
}
}
// tecupero ed imposto i batch descendant
var TabBatch = TabBatchDesc;
int BatchNe01 = TabBatchDesc[0].BatchID;
int BatchNe02 = TabBatchDesc[1].BatchID;
// riorganizzo tabOrders...
List<OrderPrev> OrdersNe01 = new List<OrderPrev>();
List<OrderPrev> OrdersNe02 = new List<OrderPrev>();
foreach (var orderItem in TabOrders)
// solo se variato il ratio...
if (valRatio != lastValRatio)
{
if (SetNe01.OrderSet.ContainsKey(orderItem.OrdID))
lastValRatio = valRatio;
// costruisco vettore durata ordini
OrderSetSim FullSet = new OrderSetSim();
OrderSetSim SetNe01 = new OrderSetSim();
OrderSetSim SetNe02 = new OrderSetSim();
// creo liste x i valori da processare...
Dictionary<int, double> RawList = new Dictionary<int, double>();
Dictionary<int, double> OrderedList = new Dictionary<int, double>();
foreach (var item in TabOrders)
{
#if false
OrdersNe01.Add(new OrderPrev() { OrderId = orderItem.OrdID, OrderExtCode = orderItem.OrderExtCode, NumBin = orderItem.EstNumBin, NumCart = orderItem.EstNumCart, TotTime = orderItem.EstProcTime, Quota = orderItem.TimeQuota });
#endif
if (orderItem.BatchID != BatchNe01)
RawList.Add(item.OrdID, item.EstProcTime);
}
// ordino la lista x processing successivo
OrderedList = RawList.OrderBy(x => x.Value).ToDictionary(t => t.Key, t => t.Value);
// salvo i set
FullSet.OrderSet = OrderedList;
// lavoro sull'ottimizzare il MINORE
double ValRatio = (double)valRatio / 100;
if (ValRatio <= 0.5)
{
SetNe01.TargetValue = FullSet.ActualValue * ValRatio;
SetNe01.OrderSet = findLocalMin(OrderedList, SetNe01.TargetValue);
// l'altro è la differenza
SetNe02.OrderSet = OrderedList;
foreach (var item in SetNe01.OrderSet)
{
DLMan.taOLT.updateBatch(orderItem.BatchID, orderItem.OrdID, BatchNe01);
SetNe02.OrderSet.Remove(item.Key);
}
}
else
{
#if false
OrdersNe02.Add(new OrderPrev() { OrderId = orderItem.OrdID, OrderExtCode = orderItem.OrderExtCode, NumBin = orderItem.EstNumBin, NumCart = orderItem.EstNumCart, TotTime = orderItem.EstProcTime, Quota = orderItem.TimeQuota });
#endif
if (orderItem.BatchID != BatchNe01)
SetNe02.TargetValue = FullSet.ActualValue * (1 - ValRatio);
SetNe02.OrderSet = findLocalMin(OrderedList, SetNe02.TargetValue);
// l'altro è la differenza
SetNe01.OrderSet = OrderedList;
foreach (var item in SetNe02.OrderSet)
{
DLMan.taOLT.updateBatch(orderItem.BatchID, orderItem.OrdID, BatchNe02);
SetNe01.OrderSet.Remove(item.Key);
}
}
// riorganizzo tabOrders...
foreach (var orderItem in TabOrders)
{
if (SetNe01.OrderSet.ContainsKey(orderItem.OrdID))
{
if (orderItem.BatchID != BatchNe01)
{
DLMan.taOLT.updateBatch(orderItem.BatchID, orderItem.OrdID, BatchNe01);
}
}
else
{
if (orderItem.BatchID != BatchNe02)
{
DLMan.taOLT.updateBatch(orderItem.BatchID, orderItem.OrdID, BatchNe02);
}
}
}
// aggiorno valore ratio e ratio last...
double newRatio = (SetNe01.ActualValue * 100 / (SetNe01.ActualValue + SetNe02.ActualValue));
valRatio = (int)newRatio;
lastValRatio = valRatio;
// ...aggiorno display
cmp_orderExtListNE01.BatchId = BatchNe01;
cmp_orderExtListNE02.BatchId = BatchNe02;
cmp_orderExtListNE01.doUpdate();
cmp_orderExtListNE02.doUpdate();
// --> richiede salvataggio
needSave = true;
}
// ...e poi mostro
cmp_orderExtListNE01.BatchId = BatchNe01;
cmp_orderExtListNE02.BatchId = BatchNe02;
#if false
// ...e poi mostro
cmp_orderExtListNE01.CurrOrders = OrdersNe01;
cmp_orderExtListNE02.CurrOrders = OrdersNe02;
#endif
// --> richiede salvataggio
needSave = true;
}
/// <summary>
@@ -407,7 +422,7 @@ namespace NKC_WF.WebUserControls
private void showBatchDescendant()
{
// se ho qualcosa aggiorno visualizzazione...
if (TabOrdersFromDb.Count > 0)
if (TabOrders.Count > 0)
{
// suddivido
rebalanceOrder();
@@ -423,9 +438,8 @@ namespace NKC_WF.WebUserControls
/// </summary>
/// <param name="OrderedList">Lista ordinata oggetti (INT) + valore</param>
/// <param name="TargetVal">Valore desiderato (comeSOMMA)</param>
/// <param name="CurrIndexScore">Indice score = errore minimo da migliorare</param>
/// <returns></returns>
protected Dictionary<int, double> findLocalMin(Dictionary<int, double> OrderedList, double TargetVal, double CurrIndexScore)
protected Dictionary<int, double> findLocalMin(Dictionary<int, double> OrderedList, double TargetVal)
{
Dictionary<int, double> answ = new Dictionary<int, double>();
List<OrderSetSim> Candidates = new List<OrderSetSim>();
@@ -439,12 +453,7 @@ namespace NKC_WF.WebUserControls
CurrSimSet = new OrderSetSim();
CurrSimSet.TargetValue = TargetVal;
CurrSimSet.OrderSet.Add(currOrder.Key, currOrder.Value);
// se lo score è migliorativo...
if (CurrSimSet.IndexScore < CurrIndexScore)
{
Candidates.Add(CurrSimSet);
CurrIndexScore = CurrSimSet.IndexScore;
}
Candidates.Add(CurrSimSet);
}
// ora guardo gli elementi restanti.. se ci sono
@@ -455,32 +464,23 @@ namespace NKC_WF.WebUserControls
CurrSimSet = new OrderSetSim();
CurrSimSet.TargetValue = TargetVal;
CurrSimSet.OrderSet.Add(currOrder.Key, currOrder.Value);
// se lo score è migliorativo...
if (CurrSimSet.IndexScore < CurrIndexScore)
{
Candidates.Add(CurrSimSet);
CurrIndexScore = CurrSimSet.IndexScore;
}
Candidates.Add(CurrSimSet);
// prendo i restanti tranne il primo
OrdInf.Remove(currOrder.Key);
// se rimane qualcosa...
if (OrdInf != null && OrdInf.Any())
{
// calcolo il minimo locale nei 2 casi, da soli
Dictionary<int, double> TestOrderSet01 = findLocalMin(OrdInf, TargetVal, CurrIndexScore);
Dictionary<int, double> TestOrderSet01 = findLocalMin(OrdInf, TargetVal);
if (TestOrderSet01.Count > 0)
{
OrderSetSim CurrSet = new OrderSetSim();
CurrSet.TargetValue = TargetVal;
CurrSet.OrderSet = TestOrderSet01;
if (CurrSet.IndexScore < CurrIndexScore)
{
Candidates.Add(CurrSimSet);
CurrIndexScore = CurrSimSet.IndexScore;
}
Candidates.Add(CurrSet);
}
// ...e con il primo valore...
Dictionary<int, double> TestOrderSet02 = findLocalMin(OrdInf, TargetVal - currOrder.Value, CurrIndexScore);
Dictionary<int, double> TestOrderSet02 = findLocalMin(OrdInf, TargetVal - currOrder.Value);
TestOrderSet02.Add(currOrder.Key, currOrder.Value);
// verifico se migliorativo...
if (TestOrderSet02.Count > 0)
@@ -488,11 +488,7 @@ namespace NKC_WF.WebUserControls
OrderSetSim CurrSet = new OrderSetSim();
CurrSet.TargetValue = TargetVal - currOrder.Value;
CurrSet.OrderSet = TestOrderSet02;
if (CurrSet.IndexScore < CurrIndexScore)
{
Candidates.Add(CurrSimSet);
CurrIndexScore = CurrSimSet.IndexScore;
}
Candidates.Add(CurrSet);
}
}
}
+9
View File
@@ -104,6 +104,15 @@ namespace NKC_WF.WebUserControls
/// </remarks>
protected global::System.Web.UI.WebControls.HiddenField hfNeedSave;
/// <summary>
/// hfLastRatio control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.HiddenField hfLastRatio;
/// <summary>
/// txtRatio control.
/// </summary>
@@ -37,5 +37,14 @@ namespace NKC_WF.WebUserControls
}
#endregion Protected Methods
#region Public Methods
public void doUpdate()
{
grView.DataBind();
}
#endregion Public Methods
}
}