Skip to content

Commit

Permalink
Added chart data export as inverter.plot
Browse files Browse the repository at this point in the history
SoC calculation now stores chart data as inverter.plot[] so it can be accessed at higher levels.
  • Loading branch information
salewis38 authored Aug 18, 2023
1 parent 514bfdf commit c3a3a55
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
9 changes: 8 additions & 1 deletion palm.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,14 +549,21 @@ def balance_loads():
if ((stgs.pg.test_mode or stgs.pg.once_mode) and stgs.pg.loop_counter == 2) or \
stgs.pg.t_now_mins == (t_to_mins(stgs.GE.start_time) + 1438) % 1440:
# compute & set SoC target

try:
inverter.get_load_hist()
logger.info("Forecast weighting: "+ str(stgs.Solcast.weight))
inverter.set_mode(inverter.compute_tgt_soc(pv_forecast, stgs.Solcast.weight, True))
except Exception:
logger.error("Warning; unable to set SoC")

# Send plot data to logfile in CSV format
logger.info("SoC Chart Data - Start")
i = 0
while i < 5:
logger.info(inverter.plot[i])
i += 1
logger.info("SoC Chart Data - End")

# if running in once mode, quit after inverter SoC update
if stgs.pg.once_mode:
logger.info("PALM Once Mode complete. Exiting...")
Expand Down
8 changes: 8 additions & 0 deletions palm_soc.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,12 @@ def GivTCP_write_soc(cmd: str):
logger.info("Forecast weighting: "+ str(PV_WEIGHT))
GivTCP_write_soc(inverter.compute_tgt_soc(pv_forecast, PV_WEIGHT, True))

# Send plot data to logfile in CSV format
logger.info("SoC Chart Data - Start")
i = 0
while i < 5:
logger.info(inverter.plot[i])
i += 1
logger.info("SoC Chart Data - End")

# End of main
33 changes: 16 additions & 17 deletions palm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def __init__(self):
self.base_load = stgs.GE.base_load
self.tgt_soc = 100
self.cmd_list = stgs.GE_Command_list['data']
self.plot = [""] * 5

logger.debug("Valid inverter commands:")
for line in self.cmd_list:
Expand Down Expand Up @@ -385,12 +386,12 @@ def compute_tgt_soc(self, gen_fcast, weight: int, commit: bool) -> str:
logger.info("{:<20} {:>10} {:>10} {:>10} {:>10} {:>10} {:>10}".format("SoC Calc;",
"Day", "Hour", "Charge", "Cons", "Gen", "SoC"))

# Array definition for export of SoC forecast in chart form
plot_x = []
plot_y1 = []
plot_y2 = []
plot_y3 = []
plot_y4 = []
# Definitions for export of SoC forecast in chart form
plot_x = ["Time"]
plot_y1 = ["Calculated SoC"]
plot_y2 = ["Adjusted SoC"]
plot_y3 = ["Max"]
plot_y4 = ["Reserve"]

if stgs.GE.end_time != "":
end_charge_period = int(stgs.GE.end_time[0:2]) * 2
Expand Down Expand Up @@ -484,21 +485,19 @@ def compute_tgt_soc(self, gen_fcast, weight: int, commit: bool) -> str:
i = 0
while i < 48:
if day == 1 and i == 0:
diff = plot_y2[47] - plot_y1[48]
if plot_y1[day*48 + i] + diff > 100: # Correct for SoC > 100%
diff = plot_y2[48] - plot_y1[49]
if plot_y1[day*48 + i + 1] + diff > 100: # Correct for SoC > 100%
diff = 100 - plot_y1[day*48 + i]
plot_y2.append(plot_y1[day*48 + i] + diff)
plot_y2.append(plot_y1[day*48 + i + 1] + diff)
i += 1
day += 1

# Send plot data to logfile in CSV format
logger.info("SoC Chart Data")
logger.info("Time,"+ str(plot_x))
logger.info("Calculated SoC,"+ str(plot_y1))
logger.info("Adjusted SoC,"+ str(plot_y2))
logger.info("Max,"+ str(plot_y3))
logger.info("Reserve,"+ str(plot_y4))
logger.info("End of SoC Chart Data")
# Store plot data
self.plot[0] = str(plot_x)
self.plot[1] = str(plot_y1)
self.plot[2] = str(plot_y2)
self.plot[3] = str(plot_y3)
self.plot[4] = str(plot_y4)

logger.info("{:<25} {:>10} {:>10} {:>10} {:>10} {:>10}".format("SoC Calc Summary;",
"Max Charge", "Min Charge", "Max %", "Min %", "Target SoC"))
Expand Down

0 comments on commit c3a3a55

Please sign in to comment.