优化自动充电策略

master
lxw 4 weeks ago
parent 19c335511f
commit 897aeaae45

@ -32,7 +32,7 @@ public class AutoChargeTask : ITask
public int Interval() public int Interval()
{ {
return 1000 * 10; return 1000 * 15;
} }
public void Handle() public void Handle()
@ -142,7 +142,7 @@ public class AutoChargeTask : ITask
int needBatteryCount = opModelDetails[0].BatteryCount ?? 8; int needBatteryCount = opModelDetails[0].BatteryCount ?? 8;
List<BinInfo> canSwapList = allBinInfos.Where(it => List<BinInfo> canSwapList = allBinInfos.Where(it =>
it.Soc != null && Convert.ToSingle(it.Soc) >= StaticStationInfo.SwapSoc && it.CanSwapFlag == 1) it.Soc != null && Convert.ToSingle(it.Soc) >= StaticStationInfo.SwapSoc && it.CanSwapFlag == 1 && it.ChargeStatus!=1)
.ToList(); .ToList();
/*if (canSwapList.Count == needBatteryCount) /*if (canSwapList.Count == needBatteryCount)
{ {
@ -171,25 +171,27 @@ public class AutoChargeTask : ITask
}*/ }*/
#endregion #endregion
int stopCount = chargingList.Count + canSwapList.Count - needBatteryCount;
Log.Info($"chargingList.Count={chargingList.Count}, canSwapList.Count={canSwapList.Count},needBatteryCount={needBatteryCount}");
Log.Info($"stopCount={stopCount}");
if (canSwapList.Count < needBatteryCount) if (canSwapList.Count < needBatteryCount)
{ {
int stopCount = chargingList.Count + canSwapList.Count - needBatteryCount;
if (stopCount < 0) if (stopCount < 0)
{ {
Log.Info($"stopCount={stopCount}"); // Log.Info($"stopCount={stopCount}");
List<BinInfo> canChargeList = binInfos.Where(it => List<BinInfo> canChargeList = binInfos.Where(it =>
it.Soc != null && Convert.ToSingle(it.Soc) < StaticStationInfo.SwapSoc && it.Soc != null && Convert.ToSingle(it.Soc) < StaticStationInfo.SwapSoc &&
it.CanChargeFlag == 1 && it.Exists == 1 && it.ChargeStatus != 1) it.CanChargeFlag == 1 && it.Exists == 1 && it.ChargeStatus != 1)
.ToList(); .ToList();
//启动电量高的 //启动电量高的
canChargeList.Sort((a, b) => (b.Soc ?? 0).CompareTo(a.Soc ?? 0)); canChargeList.Sort((a, b) => (b.Soc ?? 0).CompareTo(a.Soc ?? 0));
stopCount = Math.Abs(stopCount);
byte chargeSoc = StaticStationInfo.ChargeSoc; byte chargeSoc = StaticStationInfo.ChargeSoc;
// int count = needBatteryCount - canSwapList.Count; // int count = needBatteryCount - canSwapList.Count;
Log.Info( Log.Info(
$"need start count={stopCount}, canChargeList={JsonConvert.SerializeObject(canChargeList.Select(info => info.Code + "," + info.ChargerNo).ToList())}"); $"need start count={-stopCount}, canChargeList={JsonConvert.SerializeObject(canChargeList.Select(info => info.Code + "," + info.ChargerNo).ToList())}");
int number = 0; int number = 0;
foreach (var binInfo in canChargeList) foreach (var binInfo in canChargeList)
{ {
@ -206,35 +208,32 @@ public class AutoChargeTask : ITask
number++; number++;
} }
if (stopCount == number) if (-stopCount == number)
{ {
Log.Info($"auto start charge count {stopCount}"); Log.Info($"auto start charge count {-stopCount}");
break; break;
} }
} }
} }
} }
else }
if (stopCount > 0)
{
if (chargingList.Count > 0)
{ {
Log.Info($"stopCount={stopCount}"); chargingList = chargingList.OrderByDescending(i => i.Soc).ToList();
if (stopCount > 0) int count = 0;
foreach (var ch in chargingList)
{ {
if (chargingList.Count > 0) if (ch.Soc < StaticStationInfo.ChargeSoc)
{ {
chargingList = chargingList.OrderByDescending(i => i.Soc).ToList(); Log.Info($"auto stop charge by more charging bin {ch.No} soc:{ch.Soc}");
int count = 0; ClientMgr.GetBySn(ch.ChargerNo)?.SendRemoteStopCharging();
foreach (var ch in chargingList) count++;
if (count == stopCount)
{ {
if (ch.Soc < StaticStationInfo.ChargeSoc) break;
{
Log.Info($"auto stop charge by more charging bin {ch.No} soc:{ch.Soc}");
ClientMgr.GetBySn(ch.ChargerNo)?.SendRemoteStopCharging();
count++;
if (count == stopCount)
{
break;
}
}
} }
} }
} }

Loading…
Cancel
Save