Skip to content

Commit

Permalink
GSYE-679: Keep 2 market slots in buffer in order to be able to calcul…
Browse files Browse the repository at this point in the history
…ate the statitics of the last market slot(s)
  • Loading branch information
hannesdiedrich committed Jan 23, 2024
1 parent 1c54ab4 commit d3aad89
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/gsy_e/gsy_e_core/user_profile_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class ProfileDBConnectionException(Exception):
"prosumption_kWh_profile_uuid"
]

NUMBER_OF_TIMESTAMPS_TO_KEEP = 2


class ProfileDBConnectionHandler:
"""
Expand Down Expand Up @@ -242,13 +244,15 @@ def _get_start_end_time(current_timestamp: DateTime) -> (DateTime, DateTime):
Returns: tuple of timestamps
"""
time_stamps = generate_market_slot_list(current_timestamp)
time_stamps = generate_market_slot_list(
current_timestamp - NUMBER_OF_TIMESTAMPS_TO_KEEP * GlobalConfig.slot_length)
if not time_stamps:
log.error(
"Empty market slot list. Current timestamp %s, duration %s, is canary %s, "
"slot length %s", current_timestamp, GlobalConfig.sim_duration,
GlobalConfig.is_canary_network(), GlobalConfig.slot_length)
return min(time_stamps), max(time_stamps)
return (min(time_stamps),
max(time_stamps) + NUMBER_OF_TIMESTAMPS_TO_KEEP * GlobalConfig.slot_length)

def _should_buffer_profiles(self, current_timestamp: DateTime):
return (self._profile_uuids is None or
Expand Down Expand Up @@ -289,6 +293,7 @@ class ProfilesHandler:
"""
Handles profiles rotation of all profiles (stored in DB and in memory)
"""

def __init__(self):
self.db = None
self._current_timestamp = GlobalConfig.start_date
Expand Down Expand Up @@ -353,8 +358,14 @@ def rotate_profile(self, profile_type: InputProfileTypes,
"""
if profile_uuid is None and self.should_create_profile(profile):
return read_arbitrary_profile(profile_type,
profile, current_timestamp=self.current_timestamp)
new_profile = read_arbitrary_profile(profile_type,
profile, current_timestamp=self.current_timestamp)
if isinstance(profile, dict):
profile_tail = {
p[0]: p[1] for p in list(profile.items())[-NUMBER_OF_TIMESTAMPS_TO_KEEP:]}
else:
profile_tail = {}
return {**profile_tail, **new_profile}
if self.time_to_rotate_profile(profile):
return self._read_new_datapoints_from_buffer_or_rotate_profile(
profile, profile_uuid, profile_type)
Expand Down

0 comments on commit d3aad89

Please sign in to comment.