@@ -135,7 +135,7 @@ def calc_optimum(
135135 self .notify (
136136 "Er ontbreken voor een aantal uur gegevens; er kan niet worden gerekend"
137137 )
138- return
138+ return None
139139 if u_data <= 8 or u_prices <= 8 :
140140 logging .warning (
141141 f"Er ontbreken voor een aantal uur meteogegevens "
@@ -409,7 +409,8 @@ def calc_optimum(
409409 hour = int (key )
410410 power = value / 1000
411411 for u in range (U ):
412- if uur [u ] == hour :
412+ int_uur = uur [u ] if self .interval == "1hour" else int (uur [u ][0 :2 ])
413+ if int_uur == hour :
413414 red_power [u ] = power
414415 reduced_power .append (red_power )
415416 if reduced :
@@ -797,7 +798,7 @@ def calc_optimum(
797798 f"'min soc end opt' ({ min_soc_end_opt } ); "
798799 f"het programma kan nu geen optimale oplossing berekenem"
799800 )
800- return
801+ return None
801802
802803 model += soc [b ][U ] >= max (opt_low_level [b ] / 2 , min_soc_end_opt )
803804 model += soc [b ][U ] <= max_soc_end_opt
@@ -1204,7 +1205,8 @@ def calc_optimum(
12041205 for j in range(U)[max(0, u - est_needed_intv[u]+1): u + 1]:
12051206 # print(f"len(est_needed_elec_st[j]): {len(est_needed_elec_st[j])}")
12061207 if est_needed_intv[u]>0 and u - j < len(est_needed_elec_st[j]):
1207- print(f"j: {j}, est_needed_elec_st[j][u - j]: {est_needed_elec_st[j][u - j]}")
1208+ print(f"j: {j}, est_needed_elec_st[j][u - j]: "
1209+ f"{est_needed_elec_st[j][u - j]}")
12081210 """
12091211 model += boiler_on [u ] == xsum (
12101212 boiler_st [j ]
@@ -1548,7 +1550,7 @@ def calc_optimum(
15481550 model .add_var (var_type = CONTINUOUS , lb = 0 ) # , ub=max_power[e])
15491551 for _ in range (U )
15501552 ]
1551- for e in range (EV )
1553+ for _ in range (EV )
15521554 ] # consumption vermogen
15531555 ev_accu_in = [
15541556 [
@@ -2154,7 +2156,8 @@ def calc_optimum(
21542156 if self .hp_adjustment == "on/off" :
21552157 blocks_num = math .ceil (hp_hours / min_run_length )
21562158 else :
2157- blocks_num = math .ceil (max (hours_avail / 4 , hp_hours / min_run_length ))
2159+ blocks_num = math .ceil (min (hours_avail / (3 + min_run_length ), hp_hours / min_run_length ))
2160+ # blocks_num = math.ceil(max(hours_avail / 4, hp_hours / min_run_length))
21582161 # if self.hp_adjustment!="on/off":
21592162 if blocks_num == 0 :
21602163 logging .info (f'Omdat de wp meer dan 75% van de uren draait wordt de wp zonder '
@@ -2202,7 +2205,7 @@ def calc_optimum(
22022205 # eerste blok
22032206 block_len .append (int (first_block_len * 3600 / self .interval_s ))
22042207 # tussenliggende blokken
2205- for j in range (blocks_num )[1 :- 1 ]:
2208+ for _ in range (blocks_num )[1 :- 1 ]:
22062209 block_len .append (int (min_run_length * 3600 / self .interval_s ))
22072210 # laatste
22082211 block_len .append (int (last_block_len * 3600 / self .interval_s ))
@@ -2785,15 +2788,15 @@ def calc_optimum(
27852788 logging .info (f"Rekentijd: { end_calc - start_calc :<5.2f} sec" )
27862789 if model .num_solutions == 0 :
27872790 logging .warning (f"Geen oplossing voor: { self .strategy } " )
2788- return
2791+ return None
27892792 elif self .strategy == "minimize consumption" :
27902793 strategie = "minimale levering"
27912794 logging .info (f"Strategie: { strategie } " )
27922795 model .objective = minimize (delivery )
27932796 model .optimize ()
27942797 if model .num_solutions == 0 :
27952798 logging .warning (f"Geen oplossing voor: { self .strategy } " )
2796- return
2799+ return None
27972800 min_delivery = max (0.0 , delivery .x )
27982801 logging .info ("Eerste berekening" )
27992802 logging .info (f"Kosten (euro): { cost .x :<6.2f} " )
@@ -2808,14 +2811,14 @@ def calc_optimum(
28082811 logging .warning (
28092812 f"Geen oplossing in na herberekening voor: { self .strategy } "
28102813 )
2811- return
2814+ return None
28122815 logging .info ("Herberekening" )
28132816 logging .info (f"Kosten (euro): { cost .x :<6.2f} " )
28142817 logging .info (f"Levering (kWh): { delivery .x :<6.2f} " )
28152818 else :
28162819 logging .error ("Kies een strategie in options" )
28172820 # strategie = 'niet gekozen'
2818- return
2821+ return None
28192822
28202823 # Suppress FutureWarning messages
28212824 import warnings
@@ -2826,7 +2829,7 @@ def calc_optimum(
28262829 logging .error (
28272830 f"Er is helaas geen oplossing gevonden, kijk naar je instellingen."
28282831 )
2829- return
2832+ return None
28302833
28312834 # er is een oplossing
28322835 # afdrukken van de resultaten
@@ -3218,12 +3221,13 @@ def calc_optimum(
32183221
32193222 logging .info (
32203223 "\n Calculation profit after optimize in €\n "
3221- f"Cost before optimize { old_cost_da : 7.2f} \n "
3224+ f"Cost before optimize { old_cost_da : 7.2f} \n "
32223225 f"Cost consumption { cost_consumption : 7.2f} \n "
32233226 f"Cycle cost { total_cycle_cost : 7.2f} \n "
32243227 f"Penalty cost { total_penalty_cost : 7.2f} \n "
32253228 f"Battery storage { battery_storage : 7.2f} \n "
32263229 f"Boiler storage { boiler_storage : 7.2f} \n "
3230+ f"Profit production { profit_production : 7.2f} \n "
32273231 f"Total { total_cost : 7.2f} \n "
32283232 f"Cost after optimize { cost .x : 7.2f} \n "
32293233 f"Profit: { old_cost_da - cost .x : 7.2f} "
@@ -3252,7 +3256,8 @@ def calc_optimum(
32523256 logging .debug ("nr uur st on cons temp" )
32533257 for u in range (U ):
32543258 logging .debug (
3255- f"{ u :.0f} { uur [u ]} { boiler_st [u ].x :.0f} { boiler_on [u ].x :.0f} { c_b [u ].x :.2f} { boiler_temp [u ].x :.2f} "
3259+ f"{ u :.0f} { uur [u ]} { boiler_st [u ].x :.0f} { boiler_on [u ].x :.0f} { c_b [u ].x :.2f} "
3260+ f"{ boiler_temp [u ].x :.2f} "
32563261 )
32573262 logging .debug ("\n " )
32583263
@@ -3331,6 +3336,23 @@ def calc_optimum(
33313336 end = " " ,
33323337 )
33333338 print (f" { c_ev [e ][u ].x :.3f} { p_ev [e ][u ].x :.3f} " )
3339+
3340+ start_ev_laden = stop_ev_laden = None
3341+ for u in range (U ):
3342+ if c_ev [e ][u ].x > 0 :
3343+ if start_ev_laden is None :
3344+ start_ev_laden = tijd [u ]
3345+ else :
3346+ if start_ev_laden is not None and c_ev [e ][u - 1 ].x > 0 :
3347+ stop_ev_laden = tijd [u ]
3348+ if start_ev_laden is not None :
3349+ if stop_ev_laden is None :
3350+ stop_ev_laden = tijd [U - 1 ]+ dt .timedelta (seconds = self .interval_s )
3351+ logging .info (f"{ self .ev_options [e ]['name' ]} wordt geladen tussen "
3352+ f"{ start_ev_laden } en { stop_ev_laden } " )
3353+ else :
3354+ logging .info (f"Laden van { self .ev_options [e ]['name' ]} is niet ingepland" )
3355+
33343356 entity_charge_switch = self .ev_options [e ]["charge switch" ]
33353357 entity_charging_ampere = self .ev_options [e ][
33363358 "entity set charging ampere"
@@ -3487,7 +3509,7 @@ def calc_optimum(
34873509 battery_state_on_value = self .config .get (
34883510 ["entity set operating mode on" ], self .battery_options [b ], "Aan"
34893511 )
3490- battery_state_off_value = entity_pv_switch = self .config .get (
3512+ battery_state_off_value = self .config .get (
34913513 ["entity set operating mode off" ], self .battery_options [b ], "Uit"
34923514 )
34933515 bat_name = self .battery_options [b ]["name" ]
@@ -4380,6 +4402,7 @@ def calc_optimum(
43804402 plt .show ()
43814403 plt .close ("all" )
43824404 self .notify ("DAO calc afgerond" , self .notification_berekening )
4405+ return None
43834406
43844407 def calc_optimum_debug (self ):
43854408 self .debug = True
0 commit comments