Discharge Mask Bug, Tests updated, simple Price Forecast with linear weighting

This commit is contained in:
Andreas 2024-12-26 07:50:25 +01:00
parent 56aa0ac2f5
commit 8b9ad60759
5 changed files with 483 additions and 473 deletions

View File

@ -436,13 +436,22 @@ class optimization_problem:
# New check: Activate discharge when battery SoC is 0
battery_soc_per_hour = np.array(
o.get("Battery_SoC_pro_Stunde", [])
o.get("akku_soc_pro_stunde", [])
) # Example key for battery SoC
if battery_soc_per_hour is not None:
if battery_soc_per_hour is None or discharge_hours_bin is None:
raise ValueError("battery_soc_per_hour or discharge_hours_bin is None")
min_length = min(battery_soc_per_hour.size, discharge_hours_bin.size)
battery_soc_per_hour_tail = battery_soc_per_hour[-min_length:]
discharge_hours_bin_tail = discharge_hours_bin[-min_length:]
len_ac = len(self._config.eos.available_charging_rates_in_percentage)
# Find hours where battery SoC is 0
zero_soc_mask = battery_soc_per_hour == 0
discharge_hours_bin[zero_soc_mask] = 1 # Activate discharge for these hours
zero_soc_mask = battery_soc_per_hour_tail == 0
discharge_hours_bin_tail[zero_soc_mask] = (
len_ac + 2
) # Activate discharge for these hours
# Merge the updated discharge_hours_bin back into the individual
adjusted_individual = self.merge_individual(

View File

@ -155,24 +155,25 @@ class HourlyElectricityPriceForecast:
raise ValueError(
"Not enough data to calculate the average for the last 7 days.", price_data
)
# Calculate the overall average price across all data
# overall_average_price = np.mean(price_data)
# Create an array of 24 hourly values filled with the overall average
# average_prices = np.full(24, overall_average_price)
# print("Overall AVG (duplicated for 24 hours):", average_prices)
# return average_prices
# Reshape the data into a 7x24 matrix (7 rows for days, 24 columns for hours)
price_matrix = price_data.reshape(-1, 24)
# Calculate the average price for each hour across the 7 days
average_prices = np.average(
price_matrix,
axis=0,
weights=np.array([1, 2, 4, 8, 16, 32, 64]) / np.sum(np.array([1, 2, 4, 8, 16, 32, 64])),
)
return average_prices
final_weights = np.linspace(1, 0, price_matrix.shape[1])
# Weight last known price linear falling
average_prices_with_final_weight = [
(average_prices[i] * (1 - final_weights[i]))
+ (price_matrix[-1, -1] * (final_weights[i]))
for i in range(price_matrix.shape[1])
]
return np.array(average_prices_with_final_weight)
def get_price_for_daterange(
self, start_date_str: str, end_date_str: str, repeat: bool = False

View File

@ -63,8 +63,8 @@ def test_optimize(
start_hour = 10
# Activate with pytest --full-run
if ngen > 10 and not is_full_run:
pytest.skip()
# if ngen > 10 and not is_full_run:
# pytest.skip()
visualize_filename = str((DIR_TESTDATA / f"new_{fn_out}").with_suffix(".pdf"))

View File

@ -1,19 +1,25 @@
{
"ac_charge": [
0.5,
0.0,
0.0,
0.0,
0.0,
0.75,
0.0,
0.5,
0.375,
0.0,
0.0,
1.0,
0.0,
0.0,
0.75,
0.75,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.375,
0.0,
0.0,
0.0,
@ -30,17 +36,11 @@
0.0,
0.0,
0.0,
0.75,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.625,
0.5,
0.0,
0.0,
0.0,
@ -102,75 +102,75 @@
"discharge_allowed": [
0,
1,
1,
0,
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
1,
1,
1,
1,
1,
1,
1,
0,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
1,
0,
0,
0,
0,
1,
0,
1,
0,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
1,
1,
1,
0,
0,
1,
0,
0,
0,
0,
0,
0
1,
1
],
"eautocharge_hours_float": [
0.875,
0.75,
0.875,
0.5,
0.375,
0.75,
0.875,
1.0,
0.625,
0.5,
0.625,
0.375,
0.5,
0.75,
0.375,
0.75,
0.875,
0.375,
1.0,
0.0,
0.875,
0.5,
1.0,
0.375,
0.75,
0.625,
0.875,
1.0,
0.0,
0.5,
0.625,
0.75,
0.0,
0.0,
0.0,
@ -202,17 +202,17 @@
"result": {
"Last_Wh_pro_Stunde": [
4986.07,
1063.91,
14247.56,
12626.029999999999,
11529.67,
7731.82,
10393.22,
1103.78,
6373.12,
7733.71,
4299.98,
988.56,
11551.91,
1320.56,
10309.03,
6407.67,
11664.82,
5149.22,
8969.78,
7000.12,
3053.71,
3550.98,
3488.56,
912.38,
704.61,
516.37,
@ -221,7 +221,7 @@
608.79,
556.31,
488.89,
4256.91,
506.91,
804.89,
1141.98,
1056.97,
@ -231,7 +231,7 @@
1257.98,
1232.67,
871.26,
3985.88,
3360.88,
1158.03,
1222.72,
1221.04,
@ -243,15 +243,15 @@
"EAuto_SoC_pro_Stunde": [
5.0,
11.555,
11.555,
26.85,
35.589999999999996,
48.699999999999996,
59.62499999999999,
74.92,
74.92,
83.66,
94.585,
29.035,
29.035,
44.330000000000005,
53.06999999999999,
70.55,
77.105,
90.215,
100.0,
100.0,
100.0,
100.0,
100.0,
@ -320,11 +320,18 @@
0.0,
0.0
],
"Gesamt_Verluste": 9872.776074746695,
"Gesamtbilanz_Euro": 12.332782378812306,
"Gesamt_Verluste": 8120.988554782056,
"Gesamtbilanz_Euro": 10.524080664893,
"Gesamteinnahmen_Euro": 0.0,
"Gesamtkosten_Euro": 12.332782378812306,
"Gesamtkosten_Euro": 10.524080664893,
"Home_appliance_wh_per_hour": [
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
@ -355,94 +362,87 @@
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
],
"Kosten_Euro_pro_Stunde": [
0.0,
0.004569992000000018,
2.750373626,
2.1541494859999997,
1.0128942300000001,
0.0,
1.4118501319999999,
0.0,
0.0,
0.55162953,
0.0,
0.0,
1.218515592,
0.04475252599999999,
1.7187851859999999,
0.07147063000000006,
1.2316083,
0.0,
1.3510631400000002,
0.017097885000000056,
0.65386953,
0.0,
0.5669364879999996,
0.26650619799999997,
0.19588158,
0.174739608,
0.0,
0.0,
0.28801899,
0.22802125600000003,
0.199865757,
0.182970359,
0.162995926,
1.4005233899999998,
0.16677339,
0.26411047,
0.24530383800000005,
0.08545095,
0.007989913613567745,
0.028255713342252034,
0.025392879919306634,
0.0,
0.0,
0.0,
0.0003442778967139274,
0.6945180797975209,
0.5571430797975209,
0.0,
0.04565364324294593,
0.08231598,
0.174597189,
0.293043269,
0.214398479,
0.16484566
0.0,
0.0
],
"Netzbezug_Wh_pro_Stunde": [
0.0,
20.660000000000082,
13140.82,
11464.339999999998,
5510.85,
0.0,
6423.339999999999,
0.0,
0.0,
1726.54,
0.0,
0.0,
5508.66,
213.81999999999994,
9147.34,
388.85000000000036,
6145.75,
0.0,
5951.820000000001,
57.05000000000018,
2046.54,
0.0,
1909.5199999999986,
912.38,
704.61,
516.37,
0.0,
0.0,
868.05,
694.34,
608.79,
556.31,
488.89,
4256.91,
506.91,
799.85,
806.3900000000001,
351.65,
35.04348076126204,
127.73830624887898,
121.32288542430308,
0.0,
0.0,
0.0,
1.7179535764168035,
3159.7728835192033,
2534.7728835192033,
0.0,
152.3311419517715,
257.64,
566.69,
987.01,
733.99,
592.97
0.0,
0.0
],
"Netzeinspeisung_Wh_pro_Stunde": [
0.0,
@ -486,83 +486,83 @@
],
"Verluste_Pro_Stunde": [
760.062272727273,
1233.818181818182,
0.0,
933.0,
726.0,
414.0,
646.7386363636365,
483.0,
230.91336797704525,
880.0977272727268,
1026.818181818182,
713.7695454545456,
133.72909090909081,
124.41545454545451,
96.08318181818186,
0.0,
118.37045454545455,
94.68272727272722,
276.0,
552.0,
367.81909090909085,
414.0,
990.818181818182,
225.0,
440.6331818181816,
214.24909090909114,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
450.0,
0.0,
0.0,
0.0,
11.233982308648535,
38.52740325013451,
145.08565374908358,
161.62968357967037,
21.962728535423857,
538.2984000000038,
441.7178455708299,
630.8276539776955,
555.8276539776955,
171.99990368477063,
41.441862965787436,
0.0,
0.0,
0.0,
0.0,
0.0
100.08954545454549,
80.85954545454547
],
"akku_soc_pro_stunde": [
80.0,
62.54222623966943,
62.54222623966943,
75.04222623966943,
87.54222623966943,
87.54222623966943,
78.01764807162535,
78.01764807162535,
83.83265434833275,
64.76391295714818,
43.24187438965506,
26.108997323539356,
21.88775076706553,
17.96049525742366,
14.927566538415393,
14.927566538415393,
11.191125422712915,
8.20240297092228,
8.20240297092228,
8.20240297092228,
8.20240297092228,
20.70240297092228,
20.70240297092228,
20.70240297092228,
20.70240297092228,
21.014458035051405,
22.08466368088848,
26.114820729474133,
26.264822435793555,
41.217555769125156,
53.48749592387043,
71.01048631213975,
74.78520719328002,
75.93637005344077,
75.93637005344077,
75.93637005344077,
75.93637005344077,
75.93637005344077
41.02018767217631,
41.02018767217631,
41.02018767217631,
41.02018767217631,
41.02018767217631,
35.94382747933885,
35.94382747933885,
14.421788911845734,
20.671788911845734,
6.762913223140502,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.3120550641291261,
1.3822607099661959,
4.890194594707572,
5.040196301026997,
19.992929634358592,
32.26286978910387,
47.70252684403985,
51.477247725180106,
52.628410585340866,
52.628410585340866,
52.628410585340866,
52.628410585340866,
49.469018367710014
],
"Electricity_price": [
0.000228,
@ -715,75 +715,74 @@
"start_soc_prozent": 5
},
"start_solution": [
16.0,
13.0,
6.0,
11.0,
5.0,
9.0,
14.0,
2.0,
18.0,
3.0,
16.0,
15.0,
3.0,
4.0,
20.0,
12.0,
2.0,
18.0,
18.0,
1.0,
13.0,
4.0,
7.0,
9.0,
8.0,
10.0,
12.0,
10.0,
10.0,
14.0,
8.0,
7.0,
2.0,
6.0,
4.0,
18.0,
3.0,
4.0,
3.0,
5.0,
14.0,
14.0,
10.0,
13.0,
3.0,
17.0,
11.0,
10.0,
4.0,
3.0,
6.0,
14.0,
13.0,
0.0,
7.0,
15.0,
10.0,
9.0,
9.0,
9.0,
9.0,
9.0,
9.0,
9.0,
9.0,
9.0,
9.0,
9.0,
9.0,
13.0,
7.0,
4.0,
13.0,
13.0,
13.0,
14.0,
16.0,
11.0,
0.0,
14.0,
4.0,
0.0,
13.0,
11.0,
2.0,
6.0,
3.0,
2.0,
3.0,
5.0,
1.0,
4.0,
5.0,
2.0,
1.0,
4.0,
5.0,
3.0,
1.0,
2.0,
1.0,
6.0,
0.0,
5.0,
2.0,
6.0,
1.0,
4.0,
3.0,
5.0,
0.0,
2.0,
3.0,
4.0,
6.0,
0.0,
0.0,
0.0,
@ -811,7 +810,8 @@
0.0,
0.0,
0.0,
13.0
0.0,
20.0
],
"washingstart": 13
"washingstart": 20
}

View File

@ -3,13 +3,14 @@
0.0,
0.0,
0.0,
1.0,
1.0,
0.0,
0.75,
0.0,
0.0,
0.375,
0.0,
1.0,
0.0,
0.5,
0.0,
0.0,
0.0,
@ -18,7 +19,6 @@
0.0,
0.0,
0.0,
0.5,
0.0,
0.0,
0.0,
@ -103,6 +103,12 @@
0,
1,
0,
1,
0,
1,
0,
0,
0,
0,
0,
0,
@ -111,17 +117,20 @@
1,
0,
1,
1,
1,
0,
0,
0,
1,
1,
0,
1,
1,
0,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
@ -130,18 +139,9 @@
1,
0,
1,
1,
0,
1,
1,
0,
1,
1,
1,
1,
0,
0,
1,
1,
1,
1,
@ -150,24 +150,24 @@
1
],
"eautocharge_hours_float": [
0.5,
0.375,
0.625,
0.0,
0.875,
1.0,
0.5,
0.75,
0.625,
0.5,
0.5,
0.375,
0.375,
0.75,
0.0,
0.5,
0.375,
0.0,
0.0,
0.5,
0.625,
0.625,
0.625,
0.5,
0.625,
0.5,
0.5,
0.0,
0.0,
0.0,
@ -185,14 +185,14 @@
0.0,
0.0,
0.0,
0.375,
0.0,
0.0,
0.0,
0.375,
0.0,
0.0,
0.625,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
@ -202,15 +202,15 @@
"result": {
"Last_Wh_pro_Stunde": [
4986.07,
1063.91,
1320.56,
8876.029999999999,
8907.67,
7731.82,
6460.22,
6307.91,
7875.5599999999995,
7687.03,
7718.67,
6420.82,
7771.22,
6347.78,
3629.12,
1178.71,
3678.71,
1050.98,
988.56,
912.38,
@ -226,14 +226,14 @@
1141.98,
1056.97,
992.46,
5088.99,
1155.99,
827.01,
1257.98,
1232.67,
4804.26,
871.26,
860.88,
1158.03,
7777.72,
1222.72,
1221.04,
949.99,
987.01,
@ -243,37 +243,37 @@
"EAuto_SoC_pro_Stunde": [
5.0,
11.555,
11.555,
11.555,
20.294999999999998,
29.035,
39.96,
48.699999999999996,
57.440000000000005,
57.440000000000005,
57.440000000000005,
57.440000000000005,
57.440000000000005,
57.440000000000005,
57.440000000000005,
57.440000000000005,
57.440000000000005,
57.440000000000005,
57.440000000000005,
57.440000000000005,
57.440000000000005,
57.440000000000005,
57.440000000000005,
57.440000000000005,
57.440000000000005,
57.440000000000005,
63.995000000000005,
63.995000000000005,
63.995000000000005,
63.995000000000005,
70.55,
70.55,
70.55,
31.22,
42.144999999999996,
53.06999999999999,
61.809999999999995,
72.735,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
81.475,
@ -320,11 +320,16 @@
0.0,
0.0
],
"Gesamt_Verluste": 7755.845910804702,
"Gesamtbilanz_Euro": 4.690157296412734,
"Gesamt_Verluste": 7087.636815800874,
"Gesamtbilanz_Euro": 5.921655371576468,
"Gesamteinnahmen_Euro": 0.0,
"Gesamtkosten_Euro": 4.690157296412734,
"Gesamtkosten_Euro": 5.921655371576468,
"Home_appliance_wh_per_hour": [
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
@ -357,92 +362,87 @@
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
],
"Kosten_Euro_pro_Stunde": [
0.92472012,
1.164542792,
1.416714026,
1.226111386,
0.0,
0.1807107,
0.0,
0.0,
1.4495244859999996,
0.53097063,
0.44343509999999997,
0.0,
0.0,
0.8107800974767518,
0.0,
0.0,
0.291163892,
0.7558691399999999,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.182970359,
0.0,
0.0,
0.26411047,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.13629985200000028,
0.08545095,
0.007989913613567745,
0.012219458233588571,
0.0,
0.002459704740224363,
0.010682755832597498,
0.0,
0.0,
0.05016012000000004,
0.0076430797975209205,
0.0,
0.31687880399999996,
0.0003442778967139274,
0.0,
0.0,
0.0,
0.16722497978466921,
0.16484566
0.0,
0.0,
0.0,
0.0,
0.0
],
"Netzbezug_Wh_pro_Stunde": [
4055.79,
5264.66,
6768.82,
6525.34,
0.0,
901.75,
0.0,
0.0,
7714.339999999998,
2888.8500000000004,
2212.75,
0.0,
0.0,
2705.305630553059,
0.0,
0.0,
980.68,
3329.8199999999997,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
556.31,
0.0,
0.0,
799.85,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
448.06000000000085,
351.65,
35.04348076126204,
55.24167375040041,
0.0,
11.752053226107805,
56.853410498124,
0.0,
0.0,
250.30000000000018,
34.77288351920346,
0.0,
1057.3199999999997,
1.7179535764168035,
0.0,
0.0,
0.0,
572.4922279516235,
592.97
0.0,
0.0,
0.0,
0.0,
0.0
],
"Netzeinspeisung_Wh_pro_Stunde": [
0.0,
@ -485,84 +485,84 @@
0.0
],
"Verluste_Pro_Stunde": [
760.062272727273,
2.817272727272737,
29.157272727272726,
276.0,
207.0,
276.0,
345.0,
615.5918181818183,
730.0663636363638,
373.0373243336329,
23.391818181818195,
345.0,
576.7977272727273,
276.0,
863.3645454545458,
276.0,
229.91590909090905,
364.30090909090904,
99.72409090909093,
0.0,
133.72909090909081,
124.41545454545451,
96.08318181818186,
70.41409090909087,
118.37045454545455,
94.68272727272722,
83.01681818181817,
0.0,
75.86045454545456,
66.66681818181814,
69.12409090909085,
109.0704545454546,
48.863181818181715,
0.0,
109.96227272727276,
47.952272727272714,
11.233982308648535,
682.1181818181817,
160.0271308670193,
21.962728535423857,
48.41330768174522,
161.62968357967037,
14.209990740225123,
538.2984000000038,
207.0,
255.8276539776955,
441.7178455708299,
260.56941082122324,
171.99990368477063,
1026.818181818182,
62.214291413756285,
35.132727272727266,
77.27590909090907,
134.59227272727276,
22.022423461142267,
0.0
100.08954545454549,
80.85954545454547
],
"akku_soc_pro_stunde": [
80.0,
62.54222623966943,
62.45329717630854,
61.532928719008275,
61.532928719008275,
61.532928719008275,
61.532928719008275,
50.81349001377411,
36.480587121212125,
46.842735019368604,
46.10435692019505,
42.95650051523637,
42.95650051523637,
39.029245005594504,
35.996316286586236,
33.77364927556696,
30.03720815986448,
27.048485708073848,
24.428005336173022,
24.428005336173022,
22.32362344912068,
20.141676135071094,
20.141676135071094,
16.670644798982938,
15.156999826531148,
15.469054890660274,
0.471637535288375,
4.030157048585656,
4.180158754905081,
19.132892088236673,
19.132892088236673,
26.239215809839333,
30.01393669097958,
8.49189812348647,
7.382910520180684,
4.9436457130181495,
0.6951522557178741,
0.0
80.0,
80.0,
80.0,
80.0,
72.68315254820936,
72.68315254820936,
56.320635330578504,
56.320635330578504,
49.063188705234154,
37.563791322314046,
34.41593491735537,
30.194688360881543,
26.26743285123967,
23.2345041322314,
21.011837121212118,
17.275396005509634,
14.286673553719003,
11.666193181818178,
9.27160812672176,
7.167226239669419,
4.9852789256198315,
1.5423984159779582,
0.0,
0.0,
0.3120550641291261,
1.07020564583707,
4.578139530578446,
4.9728614955846995,
19.925594828916292,
32.195534983661574,
39.152182037223575,
42.92690291836383,
43.42237043610133,
42.31338283279554,
39.87411802563301,
35.62562456833274,
32.46623235070188
],
"Electricity_price": [
0.000228,
@ -715,72 +715,72 @@
"start_soc_prozent": 5
},
"start_solution": [
14.0,
13.0,
0.0,
20.0,
20.0,
18.0,
5.0,
3.0,
9.0,
16.0,
12.0,
13.0,
8.0,
4.0,
0.0,
14.0,
11.0,
9.0,
16.0,
8.0,
9.0,
5.0,
10.0,
13.0,
13.0,
8.0,
8.0,
9.0,
5.0,
10.0,
7.0,
2.0,
8.0,
12.0,
2.0,
9.0,
11.0,
10.0,
10.0,
6.0,
1.0,
12.0,
13.0,
0.0,
9.0,
18.0,
12.0,
5.0,
15.0,
4.0,
20.0,
14.0,
2.0,
14.0,
3.0,
13.0,
14.0,
13.0,
2.0,
9.0,
8.0,
10.0,
12.0,
10.0,
9.0,
13.0,
9.0,
9.0,
9.0,
9.0,
9.0,
9.0,
9.0,
9.0,
9.0,
9.0,
9.0,
10.0,
14.0,
13.0,
2.0,
9.0,
9.0,
13.0,
12.0,
11.0,
2.0,
10.0,
9.0,
13.0,
1.0,
3.0,
0.0,
5.0,
6.0,
2.0,
4.0,
3.0,
2.0,
2.0,
1.0,
1.0,
4.0,
0.0,
2.0,
1.0,
0.0,
0.0,
2.0,
3.0,
3.0,
3.0,
2.0,
3.0,
2.0,
2.0,
0.0,
0.0,
0.0,
@ -798,20 +798,20 @@
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
3.0,
0.0,
0.0,
0.0,
0.0,
0.0,
13.0
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
18.0
],
"washingstart": 13
"washingstart": 18
}