Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: strategy-heat-capacitor-functions.js #208

Open
volkmarnissen opened this issue Sep 25, 2024 · 3 comments
Open

Bug: strategy-heat-capacitor-functions.js #208

volkmarnissen opened this issue Sep 25, 2024 · 3 comments

Comments

@volkmarnissen
Copy link

Hi,

I am working on a test case to evaluate the heat-capacitor strategy.
It uses the temperature data of my own heat pump.

The idea behind it:
I'd like to use the strategy to load the hot water tank at cheapest tibber prices.
So, the complete configuration for the strategy will be set before starting a calculation,
because the configuration data is dependent on the tank temperature and the current consumption of hot water.

My test case executes the same procedure for different values.
The output will be validated against the expected reaction.
This is still in progress.

However, when testing it, I came across the following issue:

strategy-heat-capacitor-functions.js:22
If pattern.length == 0, the reduce() call of the dot() function will throw an exception

19  const dot = (a, b) => a.map((x, i) => a[i] * b[i]).reduce((m, n) => m + n);
20 const procurementOpportunities = Array(prices.length * 60 - pattern.length + 1);
21  for (let i = 0; i < procurementOpportunities.length; i++) {
22    procurementOpportunities[i] = dot(weightedPattern, tempPrice.slice(i, i + pattern.length));
23 }
24  return procurementOpportunities;

you can repdroduce this using the source code at
https://github.com/volkmarnissen/node-red-contrib-power-saver/tree/heat-capacitor-hot-water

The test case "ps-strategy-heat-capacitor hot water" will fail when processing the 5th set of data.
msg.payload.time == '2021-10-11T00:30:00.004+02:00

@volkmarnissen
Copy link
Author

I needed to change a little of the code in src/strategy-heat-capacitor.js.
The component used Date.now() instead of msg.payload.time.
The test case use the time field to identify the test data.

@volkmarnissen
Copy link
Author

I assume, it will help to add the pattern.length > 0 to the for loop

21  for (let i = 0; i < procurementOpportunities.length && pattern.length > 0; i++) {

and
add buyLength to the condition of the while loop

  let i = 0;
35  while (buyLength > 0 && i < priceBuy.length - 1) {
    // Find Local Minima

@volkmarnissen
Copy link
Author

If you agree, I can create a pull request to do these changes easily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant