Skip to content

Commit

Permalink
Merge pull request #182 from whylabs/sourcery/WHY-2415_regression_metics
Browse files Browse the repository at this point in the history
regression metrics (Sourcery refactored)
  • Loading branch information
lalmei authored Mar 25, 2021
2 parents f47c445 + 1f50c92 commit 5699ca0
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions src/whylogs/app/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,31 +158,33 @@ def _intialize_profiles(self,
{"full_profile": full_profile, "segmented_profiles": {}})

def _set_rotation(self, with_rotation_time: str = None):
if with_rotation_time is not None:
self.with_rotation_time = with_rotation_time.lower()

m = re.match(r'^(\d*)([smhd])$', with_rotation_time.lower())
if m is None:
raise TypeError("Invalid rotation interval, expected integer followed by one of 's', 'm', 'h', or 'd'")

interval = 1 if m.group(1) == '' else int(m.group(1))
if m.group(2) == 's':
self.suffix = "%Y-%m-%d_%H-%M-%S"
elif m.group(2) == 'm':
interval *= 60 # one minute
self.suffix = "%Y-%m-%d_%H-%M"
elif m.group(2) == 'h':
interval *= 60 * 60 # one hour
self.suffix = "%Y-%m-%d_%H"
elif m.group(2) == 'd':
interval *= 60 * 60 * 24 # one day
self.suffix = "%Y-%m-%d"
else:
raise TypeError("Invalid rotation interval, expected integer followed by one of 's', 'm', 'h', or 'd'")
# time in seconds
current_time = int(datetime.datetime.utcnow().timestamp())
self.interval = interval * self.interval_multiplier
self.rotate_at = self.rotate_when(current_time)
if with_rotation_time is None:
return

self.with_rotation_time = with_rotation_time.lower()

m = re.match(r'^(\d*)([smhd])$', with_rotation_time.lower())
if m is None:
raise TypeError("Invalid rotation interval, expected integer followed by one of 's', 'm', 'h', or 'd'")

interval = 1 if m.group(1) == '' else int(m.group(1))
if m.group(2) == 's':
self.suffix = "%Y-%m-%d_%H-%M-%S"
elif m.group(2) == 'm':
interval *= 60 # one minute
self.suffix = "%Y-%m-%d_%H-%M"
elif m.group(2) == 'h':
interval *= 60 * 60 # one hour
self.suffix = "%Y-%m-%d_%H"
elif m.group(2) == 'd':
interval *= 60 * 60 * 24 # one day
self.suffix = "%Y-%m-%d"
else:
raise TypeError("Invalid rotation interval, expected integer followed by one of 's', 'm', 'h', or 'd'")
# time in seconds
current_time = int(datetime.datetime.utcnow().timestamp())
self.interval = interval * self.interval_multiplier
self.rotate_at = self.rotate_when(current_time)

def rotate_when(self, time):
return time + self.interval
Expand Down

0 comments on commit 5699ca0

Please sign in to comment.